0


Linux设置开机自启

文章目录

方法1:systemctl enable

启用 开机自动启动 的命令

  1. systemctl enable

关闭 开机自动启动 的命令

  1. systemctl disable

示例:设置MySQL开机自动启动

  1. systemctl enable mysqld

备注:该方法不是所有场景都能用

方法2:/etc/rc.local

  1. /etc/rc.local

  1. rc.d/rc.local

的软链

1、编辑文件

  1. vim /etc/rc.local

2、添加需要执行的内容

  1. date> /root/a.txt

3、添加可执行权限

  1. chmod777 /etc/rc.local

4、重启

  1. reboot

5、查看是否执行了开机自启命令

  1. cat a.txt

方法3:chkconfig

1、在

  1. /etc/init.d/

下创建可执行

  1. .sh

文件

  1. touch /etc/init.d/tmp.sh
  2. chmod777 /etc/init.d/tmp.sh
  3. vim /etc/init.d/tmp.sh

2、写入内容(

  1. #chkconfig

是必须的,3个参数代表:运行级别,启动优先权,关闭优先权)

  1. #!/bin/sh#chkconfig: 3 25 75date>> /root/t.txt

3、添加

  1. chkconfig--add /etc/init.d/tmp.sh

4、查看是否添加

  1. chkconfig

上面脚本内容设置了

  1. #chkconfig

的运行级别是

  1. 3

,所以

  1. 3

  1. on

其它是

  1. off

  1. --level levels
  2. Specifies the run levels an operation should pertain to.
  3. It is given as a string of numbers from 0 to 6.
  4. For example, --level35 specifies runlevels 3 and 5.

运行级别说明0关机1单用户【找回丢失的密码】 如果忘记root登陆密码,可以使用单用户登陆实现密码找回2多用户状态没有网络服务3多用户状态有网络服务4系统未使用保留给用户5图形界面6系统重启
5、重启验证

  1. reboot
  1. cat /root/t.txt

6、删除

  1. chkconfig--del /etc/init.d/tmp.sh

应用场景

CDH的工作节点重启后,服务会重启
然而有些服务不会重启,例如DolphinScheduler、Superset等
对此添加Superset开机自启

  1. chmod777 /etc/rc.local
  2. vim /etc/rc.local
  1. /home/yellow/bin/superset.sh start

爱的天灵灵

标签: linux bash 运维

本文转载自: https://blog.csdn.net/Yellow_python/article/details/125255531
版权归原作者 小基基o_O 所有, 如有侵权,请联系我们删除。

“Linux设置开机自启”的评论:

还没有评论