大数据全系列 教程
1869个小节阅读:467.7k
目录
408考研
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
1.进到系统服务添加路径:
xxxxxxxxxx
[root@node1 ~]# cd /usr/lib/systemd/system/
2.建立服务文件nginx.service
注意nginx 的安装路径保持一样: /usr/local/nginx/
xxxxxxxxxx
[root@node1 system]# vim nginx.service
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
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
[Install]
WantedBy=multi-user.target
[Unit]服务的说明
Description:服务的简单描述 After:依赖,仅当依赖的服务启动之后再启动自定义的服务单元
[Service]服务运行参数的设置 Type=forking是后台运行的形式 ExecStart为服务的具体运行命令 ExecReload为重启命令 ExecStop为停止命令 注意:启动、重启、停止命令全部要求使用绝对路径
[Install]服务安装的相关设置,可设置为多用户
3.添加执行权限
以755的权限保存在目录: /usr/lib/systemd/system
xxxxxxxxxx
[root@node1 system]# chmod +x nginx.service
4.设置开机自启动
可在任意目录下执行
xxxxxxxxxx
[root@node1 system]# systemctl enable nginx
[root@node1 system]# systemctl list-unit-files |grep nginx
nginx.service enabled
5.其他命令 以下以nginx 为例
xxxxxxxxxx
启动nginx服务: systemctl start nginx
停止开机自启动: systemctl disable nginx
查看服务当前状态: systemctl status nginx
重新启动服务: systemctl restart nginx
查看所有已启动的服务: systemctl list-units --type=service