linux配置nginx.service服务并开机启动
systemctl is-enable nginx.service查询是否开机启动nginx服务。systemctl disable nginx.service禁止开机启动nginx服务。systemctl start nginx.service启动nginx服务。systemctl enable nginx.service开机启动nginx服务。1、先安装nginx。
1、先安装nginx
2、进入/usr/lib/systemd/system目录下,编写nginx.service文件:
[Unit] //服务说明
Description=nginx - high performance web server //服务描述
After=network.target remote-fs.target nss-lookup.target //服务类别
[Service] //服务
PIDFile=/run/nginx.pid
Type=forking //类型,forking代表后台运行
ExecStart=/usr/local/nginx/nginx -c /usr/local/nginx/nginx.conf //启动命令
ExecReload=/usr/local/nginx/nginx -s reload //重启命令
ExecStop=/usr/local/nginx/nginx -s stop //停止命令
ExecStart=/usr/local/nginx/nginx -s start
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
//PrivateTmp:true表示给服务分配独立的空间
[Install] //服务安装的相关设置,设置为多用户
WantedBy=multi-user.target
3、设置开机启动
systemctl enable nginx.service |
结果
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
执行3后,会在/etc/systemd/system/multi-user.target.wants/目录下生成nginx.service的软链接,multi-user.target.wants目录对应2步骤的WantedBy制定的运行级别,此时可以执行相关命令操作nginx服务:
systemctl enable nginx.service 开机启动nginx服务
systemctl disable nginx.service 禁止开机启动nginx服务
systemctl is-enable nginx.service 查询是否开机启动nginx服务
systemctl start nginx.service 启动nginx服务
systemctl stop nginx.service 停止nginx服务
systemctl reload nginx.service 重新加载nginx服务
systemctl status nginx.service 查看nginx服务状态
更多推荐
所有评论(0)