Linux运行级别和chkconfig/service

运行级别

什么是运行级别呢?简单点来说,运行级别就是操作系统当前正在运行的功能级别。级别是从0到6(7个运行级别),具有不同的功能。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[root@Automation ~]# more /etc/inittab
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:

简单说明:

  1. 查看运行级别用:runlevel
  2. 进入其它运行级别用:init N,如果init 3则进入终端模式,init 5则又登录图形GUI模式
  3. 标准的Linux运行级别为3或5,如果是3的话,系统就在多用户状态;如果是5的话,则是运行着X Window系统。
  4. 不同的运行级别有不同的用处,也应该根据自己的不同情形来设置。例如,如果丢失了root口令,那么可以让机器启动进入单用户状态来设置。

chkconfig

chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息。chkconfig命令可以快速地设置开机时需要自动启动的服务程序。
用法:

1
2
3
4
5
chkconfig [--list] [--type <type>] [name]
chkconfig --add <name>
chkconfig --del <name>
chkconfig --override <name>
chkconfig [--level <levels>] [--type <type>] <name> <on|off|reset|resetpriorities>

例子:

1
2
3
4
chkconfig --list      列出所有的系统服务
chkconfig --add httpd 增加httpd服务
chkconfig --del httpd 删除httpd服务
chkconfig --level httpd 2345 on 把httpd在运行级别为2345的情况下都是on(开启)的状态。

service

service命令可以快速地开启和停止linux中的服务程。
用法:

1
Usage: service < option > | --status-all | [ service_name [ command | --full-restart ] ]

例子:

1
2
3
service mysqld start
service mysqld restart
service mysqld stop

唐胡璐 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
分享创造价值,您的支持将鼓励我继续前行!