service命令其实是去/etc/init.d/目录下,去执行相关程序,init.d目录包含许多系统各种服务启动和停止脚本。
1)当Linux启动时,会寻找这些/etc/init.d/目录中的服务脚本
2)根据脚本的run level确定不同的启动级别。
如:init3下启动的程序
3)service常用使用方法:
service
service
service
4)chkconfig常用使用方法:
chkconfig --list #显示所有运行级系统服务的运行状态信息(on或off)。如果指定了name,那么只显示指定的服务在不同运行级的状态
chkconfig –add
chkconfig --level 35 mysqld on #设定mysqld在等级3和5为开机运行服务,--level 35表示操作只在等级3和5执行,on表示启动,off表示关闭
chkconfig
chkconfig
chkconfig
在systemd管理体系中,被管理的deamon(守护进程)称作unit(单元),对于单元的管理是通过命令systemctl来进行控制的。
1)在systemctl中,文件目录有所不同,在/lib/systemd/system/目录下创建一个脚本文件
[Unit] 表示这是基础信息
Description 是描述
After 是在那个服务后面启动,一般是网络服务启动后启动
[Service] 表示这里是服务信息
ExecStart 是启动服务的命令
ExecStop 是停止服务的指令
[Install] 表示这是是安装相关信息
WantedBy 是以哪种方式启动:multi-user.target表明当系统以多用户方式(默认的运行级别)启动时,这个服务需要被自动运行。
2)刷新配置
刚刚配置的服务需要让systemctl能识别,就必须刷新配置
systemctl daemon-reload #重新加载服务的配置文件
3)systemctl常用使用方法:
systemctl start redis #启动
systemctl restart redis # 重启
systemctl stop redis #停止
加入nginx服务开机启动:
systemctl enable nginx
禁止nginx服务开机启动
systemctl disable nginx
查看nginx服务状态
systemctl status nginx
查看已经启动的Unit
systemctl list-units
查看系统上一共装了多少个Unit
systemctl list-unit-files
筛选只查看service类型的Unit:
systemctl list-units --type=service -all
查看加载失败的Unit
systemctl --failed



