以下是CentOS服务配置的详细教程:
/usr/lib/systemd/system/或/etc/systemd/system/目录下,文件名以.service结尾。以创建Nginx服务为例,在/etc/systemd/system/目录下创建nginx.service文件,内容如下:
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload。systemctl start nginx。systemctl stop nginx。systemctl restart nginx。systemctl enable nginx。systemctl status nginx。