<p>1.建立服务文件</p><p>文件路径</p><p>vim /usr/lib/systemd/system/nginx.service</p><p>服务文件内容</p><p>1.nginx.service</p><p>[Unit]</p><p>Description=nginx - high performance web server</p><p>After=network.target remote-fs.target nss-lookup.target</p><p></p><p>[Service]</p><p>Type=forking</p><p>ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf</p><p>ExecReload=/usr/local/nginx/sbin/nginx -s reload</p><p>ExecStop=/usr/local/nginx/sbin/nginx -s stop</p><p></p><p>[Install]</p><p>WantedBy=multi-user.target</p><p>2.MySQL.service</p><p>[Unit]</p><p>Description=mysql</p><p>After=network.target remote-fs.target nss-lookup.target</p><p></p><p>[Service]</p><p>Type=forking</p><p>ExecStart=/usr/local/mysql/support-files/mysql.server start</p><p>#ExecReload=/usr/local/mysql/support-files/mysql.server restart</p><p>#ExecStop=/usr/local/mysql/support-files/mysql.server stop</p><p>#PrivateTmp=true</p><p></p><p>[Install]</p><p>WantedBy=multi-user.target</p><p>3.PHP-fpm.service</p><p>[Unit]</p><p>Description=php</p><p>After=network.target remote-fs.target nss-lookup.target</p><p></p><p>[Service]</p><p>Type=forking</p><p>ExecStart=/usr/local/php/sbin/php-fpm</p><p></p><p>[Install]</p><p>WantedBy=multi-user.target</p><p>4.Redis.service</p><p>[Unit]</p><p>Description=Redis</p><p>After=network.target remote-fs.target nss-lookup.target</p><p></p><p>[Service]</p><p>Type=forking</p><p>ExecStart=/usr/local/bin/redis-server /etc/redis.conf</p><p>ExecStop=kill -INT `cat /tmp/redis.pid`</p><p>User=www</p><p>Group=www</p><p></p><p>[Install]</p><p>WantedBy=multi-user.target</p><p>5.supervisord.service</p><p>[Unit]</p><p>Description=Process Monitoring and Control Daemon</p><p>After=rc-local.service</p><p></p><p>[Service]</p><p>Type=forking</p><p>ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf</p><p>SysVStartPriority=99</p><p></p><p>[Install]</p><p>WantedBy=multi-user.target</p><p>文件内容解释</p><p>[Unit]:服务的说明</p><p>Description:描述服务</p><p>After:描述服务类别</p><p>[Service]服务运行参数的设置</p><p>Type=forking是后台运行的形式</p><p>ExecStart为服务的具体运行命令</p><p>ExecReload为重启命令</p><p>ExecStop为停止命令</p><p>PrivateTmp=True表示给服务分配独立的临时空间</p><p>注意:启动、重启、停止命令全部要求使用绝对路径</p><p>[Install]服务安装的相关设置,可设置为多用户</p><p>2.保存目录</p><p>以754的权限保存在目录:</p><p>/usr/lib/systemd/system</p><p>3.设置开机自启动</p><p>任意目录下执行</p><p>systemctl enable nginx.service</p><p>4.其他命令</p><p>启动nginx服务</p><p>systemctl start nginx.service</p><p>设置开机自启动</p><p>systemctl enable nginx.service</p><p>停止开机自启动</p><p>systemctl disable nginx.service</p><p>查看服务当前状态</p><p>systemctl status nginx.service</p><p>重新启动服务</p><p>systemctl restart nginx.service</p><p>查看所有已启动的服务</p><p>systemctl list-units --type=service</p>
返回顶部 留言