修改默认运行级别传统方式是更改/etc/inittab文件。但是在Centos7中,该文件的内容:
# inittab is no longer used when using systemd. # # ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # # Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target # # systemd uses 'targets' instead of runlevels. By default, there are two main targets: # # multi-user.target: analogous to runlevel 3 # graphical.target: analogous to runlevel 5 # # To view current default target, run: # systemctl get-default # # To set a default target, run: # systemctl set-default TARGET.target表示该文件已经不起作用,可以使用命令方式修改:
multi-user.target: runlevel 3graphical.target: runlevel 5使用 systemctl get-default 获取默认级别。使用 systemctl set-default TARGET.target 设置默认级别
获得默认运行级别
[root@localhost etc]# systemctl get-default graphical.target设置默认运行级别为字符界面:
[root@localhost etc]# systemctl set-default multi-user.target Removed symlink /etc/systemd/system/default.target. Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.chkconfig –list 查看服务自启动状态,可以看到所有RPM包安装的服务
[root@localhost rc.d]# chkconfig --list NetworkManager 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭 abrt-ccpp 0:关闭 1:关闭 2:关闭 3:启用 4:关闭 5:启用 6:关闭 abrtd 0:关闭 1:关闭 2:关闭 3:启用 4:关闭 5:启用 6:关闭 acpid 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭 atd 0:关闭 1:关闭 2:关闭 3:启用 4:启用 5:启用 6:关闭 auditd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭 autofs 0:关闭 1:关闭 2:关闭 3:启用 4:启用 5:启用 6:关闭通过绝对路径启动(标准启动方式)
/etc/init.d/httpd start /etc/rc.d/init.d/httpd start
service 命令启动(rethat系统专有命令) service httpd start|stop|restart|status
chkconfig 和 ntsysv 做出的更改会同步,但是在rc.local文件中做出的修改,在chkconfig中无法查看到
更改 /etc/rc.d/rc.local 文件,将启动命令追加到文件末尾即可。 chkconfig 命令不能识别源码包服务。
将源码包的启动脚本复制到init.d目录下,改脚本需要能接受相关参数,比如start|stop等
在init.d 目录下的脚本中起始处添加 # chkconfig: 35 86 76
chkconfig: 运行级别 启动顺序 关闭顺序 (/etc/rc3.d/)
在脚本中添加 # description: ..
说明, 内容随意
chkconfig --add 脚本名称 将init.d下的启动脚本加入chkconfig到命令中
Tony老师的Linux服务列表