Linux开机自动启动服务
2023-09-14 08:59:05 时间
当我们的Linux,关机后,或者重启后,有些服务需要人工启动才能有。为了解决这个问题,我找了一个办法,用一个脚本,开机启动想启动的服务。
方法一:(强烈推荐)
1、写一个脚本auto.sh
vim /hom/xxx/auto.sh
chmod +x auto.sh
auto.sh中
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #!/bin/sh 2 3 #auto.sh log 4 DIR=/var/log 5 LOGFILE=auto_start_log.txt 6 echo start system by rc.local `date "+%Y-%m-%d %H:%M:%S"` >> $DIR/$LOGFILE 7 8 # auto service 9 systemctl restart firewalld.service 10 echo `date "+%Y-%m-%d %H:%M:%S"` restart firewalld >> $DIR/$LOGFILE
2、添加开机启动项到rc.local
echo /hom/xxx/auto.sh >> /etc/rc.local
方法二:以下方法不好用,脚本会被执行2次。。。。额。。。
1 cd /etc/rc.d/init.d/ 进入该文件夹
2 vi auto.sh 编写脚本
3 chmod +x auto.sh 给脚本添加执行权限
4 chkconfig --add auto.sh 添加脚本至开机自启
5 chkconfig auto.sh on 开启
6 reboot 重启
参考:
https://blog.csdn.net/softwarenb/article/details/80275479
https://www.cnblogs.com/xianhaiyan/p/7650391.html
https://blog.csdn.net/jk110333/article/details/8590746/
cd /etc/rc.d/init.d/ 进入该文件夹vi auto.sh 编写脚本chmod +x auto.sh 给脚本添加执行权限chkconfig --add auto.sh 添加脚本至开机自启chkconfig auto.sh on 开启reboot 重启
相关文章
- 【Linux驱动】linux内核模块简介
- linux下的系统垃圾清理
- 【Linux】linux常用查看命令
- 利用putty软件连接虚拟机中linux操作系统
- linux下查看最消耗CPU、内存的进程
- Linux下出现Read-only file system的解决办法
- Linux下C结构体初始化[总结]
- 【学习总结】快速上手Linux玩转典型应用-第2章-linux简介
- Linux安装qt注意事项
- 【Linux 内核】调度器 ⑧ ( 进程优先级源码 includelinuxschedprio.h | 进程分类 | 实时进程 | 普通进程 | 进程优先级数值 | 0 ~ 99 实时进程 )
- Alpine Linux使用简介
- L79.linux命令每日一练 -- 第11章 Linux系统管理命令 -- sar和chkconfig
- L76.linux命令每日一练 -- 第11章 Linux系统管理命令 -- free和iftop
- L73.linux命令每日一练 -- 第十章 Linux网络管理命令 -- dig和host
- L64.linux命令每日一练 -- 第十章 Linux网络管理命令 -- ifconfig和ifup
- L59.linux命令每日一练 -- 第九章 Linux进程管理命令 -- killall和pkill
- L56.linux命令每日一练 -- 第八章 Linux磁盘与文件系统管理命令 -- swapoff和sync
- L43.linux命令每日一练 -- 第七章 Linux用户管理及用户信息查询命令 -- chage和chpasswd
- Linux系统磁盘在线扩容方案
- Parallels Desktop 13.3.1 新建虚拟机kali linux 配置网络桥接
- Linux之LIBRARY_PATH与LD_LIBRARY_PATH配置多个目录用法
- 【Linux 或Mac系统】自动生成项目结构目录并放在README.md文件中
- 嵌入式Linux系统中ARM汇编语言的使用方法
- Linux 配置NFS与autofs自动挂载