1、脚本目录:
/usr/lib/systemd/
2、服务配置文件目录(开机自启动):
/usr/lib/systemd/system
3、服务文件
服务格式:
*.service
服务文件格式:
1
2
3
4
5
6
7
8
9
10
11
|
[Unit]
//
用户服务说明
Description=xxx
//
描述服务
After=xxx
//
描述服务类别
[Service]
//
服务具体运行参数
Type=forking
//
服务后台运行
PIDFile=
/path/pid
//PID
的路径
ExecStart=
//
服务运行的命令与参数(绝对路径)
ExecReload=
//
服务重启的命令与参数(绝对路径)
ExecStop=
//
服务停止运行的命令与参数(绝对路径)
PrivateTmp=True
//
为服务分配独立的临时空间
[Install]
//
服务安装的配置
|
4、服务使用方法
1
2
3
4
|
systemctl start [服务文件名]
systemctl restart [服务文件名]
systemctl stop [服务文件名]
systemctl status [服务文件名]
|
5、相关命令
1
2
3
4
5
6
7
8
|
任务 旧指令 新指令
使某服务自动启动 chkconfig --level 3 httpd on systemctl
enable
httpd.service
使某服务不自动启动 chkconfig --level 3 httpd off systemctl disable httpd.service
检查服务状态 service httpd status systemctl status httpd.service (服务详细信息) systemctl is-active httpd.service (仅显示是否 Active)
显示所有已启动的服务 chkconfig --list systemctl list-
units
--
type
=service
启动某服务 service httpd start systemctl start httpd.service
停止某服务 service httpd stop systemctl stop httpd.service
重启某服务 service httpd restart systemctl restart httpd.service
|
本文转自 tanzhenchao 51CTO博客,原文链接:http://blog.51cto.com/cmdschool/1754197,如需转载请自行联系原作者