编译安装的nginx要使用/usr/local/nginx/sbin/nginx -s reload和/usr/local/nginx/sbin/nginx -s stop来重启和停止十分麻烦。现在我们来使用system来管理
[root@localhost ~]# vi /lib/systemd/system/nginx
##配置参数解释## [Unit] Description=nginx ##描述 After=network.target ##描述服务类别,网络服务模式 [Service] Type=forking ##后台运行形式 PIDFile=/usr/local/nginx/logs/nginx.pid ##PID文件位置 ,记录进程号 ExecStart=/usr/local/nginx/sbin/nginx ##启动服务脚本 ExecReload=/usr/bin/kill -s HUP $MAINPID ##根据PID(nginx进程号)重载配置 ExecStop=/usr/bin/kill -s QUIT $MAINPID ##根据PID(nginx进程号)终止进程 PrivateTmp=true [Install] WantedBy=multi-user.target
[root@localhost]# systemctl start nginx [root@localhost]# systemctl status nginx ● nginx.service - SYSV: nginx server Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled) Active: active (exited) since 二 2021-10-19 22:35:09 CST; 5min ago Docs: man:systemd-sysv-generator(8) Process: 1734 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=0/SUCCESS) 10月 19 22:35:07 localhost.localdomain systemd[1]: Starting SYSV: nginx server... 10月 19 22:35:07 localhost.localdomain nginx[1734]: nginx: [emerg] bind() to 0.0.0.0...) 10月 19 22:35:07 localhost.localdomain nginx[1734]: nginx: [emerg] bind() to 0.0.0.0...) 10月 19 22:35:08 localhost.localdomain nginx[1734]: nginx: [emerg] bind() to 0.0.0.0...) 10月 19 22:35:08 localhost.localdomain nginx[1734]: nginx: [emerg] bind() to 0.0.0.0...) 10月 19 22:35:09 localhost.localdomain nginx[1734]: nginx: [emerg] bind() to 0.0.0.0...) 10月 19 22:35:09 localhost.localdomain systemd[1]: Started SYSV: nginx server. 10月 19 22:35:09 localhost.localdomain nginx[1734]: nginx: [emerg] still could not b...) Hint: Some lines were ellipsized, use -l to show in full.
okk