Press "Enter" to skip to content

Linux设置程序为系统服务

https://blog.csdn.net/Spider_xiaoma/article/details/105077789

  1. 添加php-fpm.service文件
vim /etc/systemd/system/php-fpm.service

添加如下内容:

[Unit]

Description=php-fpm

After=network.target

[Service]

Type=forking

ExecStart=/usr/local/php/sbin/php-fpm

PrivateTmp=True

[Install]

WantedBy=multi-user.target
  1. 设置php-fpm服务开机自启动:
systemctl enable php-fpm.service
  1. 启动/关闭php-fpm服务:
启动:systemctl start php-fpm.service
关闭:systemctl stop php-fpm.service
状态:systemctl status php-fpm.service
  1. 查看是否启动成功
ps -ef | grep php-fpm

Nginx配置系统服务

[root@web46 system]# cd
[root@web46 ~]# cd /usr/lib/systemd/system
[root@web46 system]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx-The High-performance HTTP Server //描述服务
After=network.target remote-fs.target nss-lookup.target //描述服务类别
[Service]
Type=forking //后台运行的形式
PIDFile=/usr/local/nginx/logs/nginx.pid //PID文件的路径
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf //启动准备
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf //启动命令
ExecReload=/usr/local/nginx/sbin/nginx -s reload //重启命令
ExecStop=/usr/local/nginx/sbin/nginx -s stop //停止命令
ExecQuit=/usr/local/nginx/sbin/nginx -s quit //快速停止
PrivateTmp=true //给服务分配临时空间
[root@web46 system]# systemctl daemon-reload //在启动服务之前,需要先重载systemctl命令
[root@web46 system]# systemctl start nginx //启动nginx服务
[root@web46 system]# netstat -ntulp |grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 17839/nginx: master

配置nginx的systemctl命令_liuxe1990的博客-CSDN博客

发表评论