systemctl 管理nginx
- 添加nginx.service
[root@localhost data]# cat /usr/lib/systemd/system/nginx.service
# /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target sshd-keygen.service
[Service]
Type=forking
EnvironmentFile=/etc/sysconfig/sshd
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
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
- 重新加载服务配置
systemctl daemon-reload
- 设置开机自动并测试启动
systemctl enable nginx
systemctl restart nginx
[root@localhost data]# netstat -tunlp |grep nginx
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4080/nginx: master
转载http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-part-two.html
- 脚本安装
脚本地址
wget http://8.210.62.122/nginx/scripts/install_ngix.sh
bash install_ngix.sh
查看状态
systemctl status nginx