第一趴:设置nginx的
vim /usr/lib/systemd/system/nginx.service
在上面的文件中加入以下代码,记得路径换成自己的绝对路径
[Unit]
Description=nginx service
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
上面代码解释
[Unit]服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
保存退出后,开机自启命令
systemctl enable nginx.service
检查是否设置
systemctl is-enabled nginx.service
如果显示enabled则成功
第二趴:设置php
为什么写在一起呢,因为很像 哈哈哈哈
vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
保存退出后,开机自启命令
systemctl enable php-fpm.service
检查
systemctl is-enabled php-fpm.service
你是不是发现了什么呢!对的,开机自启大部分服务这套流程 哈哈