Centos7-开机自启动服务设置
方式一:
可以借助 /etc/rc.d/rc.local 文件做一个开机自启动服务的功能,我们测试一个开启自动同步服务器时间的功能
1、root看一下rc.local是否有执行权限,没有的话 chmod u+x /etc/rc.d/rc.local 添加执行权限
2、新建一个自己要启动命令的脚本文件 vim /usr/local/myscripts/test.sh
#! /bin/bash yum info ntp && ntpdate cn.ntp.org.cn
3、给这个文件添加执行权限 chmod u+x /usr/local/myscripts/test.sh
4、把这个脚本文件的路径添加到 rc.local 中
#!/bin/bash # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES # # It is highly advisable to create own systemd services or udev rules # to run scripts during boot instead of using this file. # # In contrast to previous versions due to parallel execution during boot # this script will NOT be run after all other services. # # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure # that this script will be executed during boot. touch /var/lock/subsys/local /usr/local/myscripts/test.sh
5、重启系统 reboot
方式二:
通过chkconfig来配置开启自启
1、一定要在 /etc/init.d 这个目录下新建一个文件 test2.sh
2、编辑 test2.sh 文件 vim test2.sh
#! /bin/bash #chkconfig 2345 88 89 #description:auto_run #开机自启动同步时间 yum info ntp && ntpdate cn.ntp.org.cn
3、给 test2.sh 添加权限 chmod u+x test2.sh
4、添加到服务 chkconfig --add /etc/init.d/test2.sh
参考:
分类:
Linux
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
2018-04-10 JVM-内存模型