配置Centos 开机启动项

1. 进入/etc/systemd/system/(或 /lib/systemd/system/)目录
2.创建XXX.service

如:

vim nginx.service

文件内容:

# 服务的说明
[Unit]
Description=nginx service
#在network.target,auditd.service启动后才启动
After=network.target auditd.service

#服务运行参数的设置
[Service]
#是后台运行的形式
Type=forking
# 运行
ExecStart=/opt/nginx/sbin/nginx
# 重启
ExecReload=/opt/nginx/sbin/nginx -s reload
# 停止
ExecStop=/opt/nginx/sbin/nginx -s stop
# 表示给服务分配独立的临时空间
PrivateTmp=true

#运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
[Install]
WantedBy=multi-user.target
3. 加入开机自启动
 #设置开机启动
 systemctl enable nginx.service
 #取消开机启动
 systemctl disable nginx.service
4. 服务的启动/停止/刷新配置文件/查看状态
 systemctl start nginx.service  #启动nginx服务

 systemctl stop nginx.service          # 停止服务

 systemctl restart nginx.service     #  重新启动服务

 systemctl list-units --type=service    #查看所有已启动的服务

 systemctl status nginx.service         # 查看服务当前状态

 systemctl enable nginx.service          #设置开机自启动

 systemctl disable nginx.service        #停止开机自启动
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值