Centos8设置开机启动服务

方法一:配置rc.local(不推荐)

直接修订文件/etc/rc.local,添加操作命令即可

方法二:chkconfig

新建脚本,开头加入以下代码

#!/bin/sh
#chkconfig:2345 80 90
#description:auto_run

将文件移到/etc/init.d目录下,chmod +x script.sh设置脚本权限

使用chkconfig命令将脚本添加到开机启动

chkconfig --add script.sh
chkconfig script.sh on

方法三:systemctl

  1. 新建脚本,例如,/tmp/mytest.sh,设置权限chmod +x /tmp/mytest.sh

  2. 进入目录/usr/lib/systemd/system,新建服务,例如mytest.service,编辑为如下形式:

    [Unit]
    Description=mytest for auto start
    Wants=network-online.target
    
    [Service]
    User=root
    Type=forking
    ExecStart=/usr/bin/bash /tmp/mytest.sh start
    ExecStop=/usr/bin/bash /tmp/mytest.sh stop
    
    [Install]
    WantedBy=multi-user.target
    
  3. 重新加载systemd配置systemctl daemon-reload

  4. 添加开机自启动systemctl enable mytest.service

  5. reboot重启验证

方法四:profile

直接将写好的脚本(.sh文件)放到目录/etc/profile.d/下。

参考资料:

https://blog.csdn.net/qq_36823799/article/details/117930664

https://www.cnblogs.com/hunttown/p/14872071.html

https://www.cnblogs.com/jingzaixin/p/12752373.html

posted @   TappaT  阅读(2675)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示