自己写一个shell脚本
将写好的脚本(.sh文件)放到目录 /etc/profile.d/ 下,系统启动后就会自动执行该目录下的所有shell脚本。
通过chkconfig命令设置
编辑脚本
vi start-redis.sh
#!/bin/sh 告诉系统使用的shell,所以的shell脚本都是这样
#chkconfig: 35 20 80 分别代表运行级别,启动优先权,关闭优先权,此行代码必须
#description: redis server 自己随便发挥!!!,此行代码必须
# 脚本正式内容
nohup redis-server /home/hadoop/redis/redis.conf > /home/hadoop/redis/redis-server.log 2>&1 &
赋予脚本执行权限
chmod +x start-redis.sh
脚本移动到/etc/init.d/或者/etc/rc.d/init.d/目录下。(前者是后者的软连接)
mv start-redis.sh /etc/rc.d/init.d/
添加脚本到开机自动启动项目中。添加到chkconfig,开机自启动。
cd /etc/rc.d/init.d
chkconfig --add start-redis.sh
chkconfig start-redis.sh on
关闭开机启动
chkconfig start-redis.sh off
其他命令
# 6.从chkconfig管理中删除test.sh
[root@localhost ~]# chkconfig --del start-redis.sh
# 7.查看chkconfig管理
[root@localhost ~]# chkconfig --list start-redis.sh
本文档介绍了如何创建一个shell脚本并将其设置为Linux系统开机自动执行。步骤包括编写脚本、设置运行级别、赋予执行权限、移动脚本到指定目录以及使用chkconfig命令进行管理。此外,还提供了启用和禁用开机启动的命令,以及从chkconfig管理中删除脚本的指令。
1201

被折叠的 条评论
为什么被折叠?



