第1章 补充
1.1 chkconfig
#linux下面开机自启动软件在哪个目录 (假设现在是3运行级别)
[root@oldboyedu-40-nb ~]# ls -ld /etc/rc3.d /etc/rc.d/rc3.d rc3.d是rc.d/rc3.d的软连接
lrwxrwxrwx. 1 root root 10 Aug 10 18:36 /etc/rc3.d -> rc.d/rc3.d
drwxr-xr-x. 2 root root 4096 Aug 29 05:25 /etc/rc.d/rc3.d
#/etc/rc3.d 下面的内容 假设现在是3运行级别
软连接
[root@oldboyedu-40-nb rc3.d]# ls -l |grep ipt
lrwxrwxrwx 1 root root 18 Aug 29 05:25 K92iptables -> ../init.d/iptables
1.1.1 我们运行chkconfig iptables on chkconfig iptables off 在/etc/rc3.d 目录下面到底发生了什么?
[root@oldboyedu-40-nb rc3.d]# chkconfig iptables on
[root@oldboyedu-40-nb rc3.d]# chkconfig |grep ipt
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@oldboyedu-40-nb rc3.d]# ls -l /etc/rc3.d/ |grep ipt
lrwxrwxrwx 1 root root 18 Aug 30 12:03 S08iptables -> ../init.d/iptables
[root@oldboyedu-40-nb rc3.d]# chkconfig iptables off
[root@oldboyedu-40-nb rc3.d]# chkconfig |grep ipt
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@oldboyedu-40-nb rc3.d]# ls -l /etc/rc3.d/ |grep ipt
lrwxrwxrwx 1 root root 18 Aug 30 12:04 K92iptables -> ../init.d/iptables
#######我们运行
###chkconfig iptables on ====== 软连接变为 S08iptables -> /etc/init.d/iptables
###chkconfig iptables off ====== 软连接变为 K92iptables -> /etc/init.d/iptables
#####iptables 开机自启动 软连接 S开头 start
#####iptables 开机不自启动 软连接 K开头 kill
###验证
[root@oldboyedu-40-nb rc3.d]# chkconfig iptables off
[root@oldboyedu-40-nb rc3.d]# chkconfig |grep ipt
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@oldboyedu-40-nb rc3.d]# ls -l /etc/rc3.d/ |grep ipt
lrwxrwxrwx 1 root root 18 Aug 30 12:06 K92iptables -> ../init.d/iptables
[root@oldboyedu-40-nb rc3.d]# m -f /etc/rc3.d/K92iptables
[root@oldboyedu-40-nb rc3.d]# ln -s /etc/init.d/iptables /etc/rc3.d/S08iptables
[root@oldboyedu-40-nb rc3.d]# ls -l /etc/rc3.d/ |grep ipt
lrwxrwxrwx 1 root root 20 Aug 30 12:07 S08iptables -> /etc/init.d/iptables
[root@oldboyedu-40-nb rc3.d]# chkconfig |grep ipt
iptables 0:off 1:off 2:off 3:on 4:off 5:off 6:off
####chkconfig on /off 原理 或发生了什么 (理解结论 过程了解)
1.chkconfig 命令是在操作 /etc/rc运行级别.d /etc/rc3.d 下面软连接
2.
######开机自启动 chkconfig iptables on ====== 软连接变为 S08iptables -> /etc/init.d/iptables
######开机不自启动 chkconfig iptables off ====== 软连接变为 K92iptables -> /etc/init.d/iptables
1.2 linux下面如何让一个软件/命令开机自启动
- 把命令或脚本放入到 /etc/rc.local
- 通过chkconfig管理命令或脚本 让他开机自启动
如何让一个服务或命令通过chkconfig管理 管理的条件
###第一个里程碑-脚本必须放在/etc/init.d/目录下面
[root@oldboyedu-40-nb rc3.d]# echo "hostname" >/etc/init.d/oldboyd
[root@oldboyedu-40-nb rc3.d]# cat /etc/init.d/oldboyd
hostname
[root@oldboyedu-40-nb rc3.d]# /etc/init.d/oldboyd
-bash: /etc/init.d/oldboyd: Permission denied
[root@oldboyedu-40-nb rc3.d]# ls -l /etc/init.d/oldboyd
-rw-r--r-- 1 root root 9 Aug 30 12:22 /etc/init.d/oldboyd
###第二个里程碑-给这个脚本添加上 执行权限
#chmod +x /etc/init.d/oldboyd
# ls -l /etc/init.d/oldboyd
-rwxr-xr-x 1 root root 9 Aug 30 12:22 /etc/init.d/oldboyd
###第三个里程碑-运行脚本
#/etc/init.d/oldboyd
#oldboyedu-40-nb
###第四个里程碑-写出chkconfig格式
#chkconfig不支持 无法管理 oldboyd服务
# chkconfig: 2345 99 99
# 默认在哪几个运行级别启动 开机顺序 关机顺序
[root@oldboyedu-40-nb rc3.d]# cat /etc/init.d/oldboyd
# chkconfig: 2345 99 99
# description: print hostname
hostname
[root@oldboyedu-40-nb rc3.d]# ####第五个里程碑-添加到chkconfig管理
[root@oldboyedu-40-nb rc3.d]# chkconfig --add oldboyd
[root@oldboyedu-40-nb rc3.d]# ####6个-检查
[root@oldboyedu-40-nb rc3.d]# chkconfig |grep oldboyd
oldboyd 0:off 1:off 2:on 3:on
4:on 5:on 6:off
[root@oldboyedu-40-nb rc3.d]# ls -l /etc/rc3.d/|grep oldboy
lrwxrwxrwx 1 root root 17 Aug 30 12:39 S99oldboyd -> ../init.d/oldboyd
本博文中所使用的系统版本为: CentOS release 6.9 (Final) 内核版本为: 2.6.32-696.10.1.el6.x86_64 linux正在持续学习中,如有雷同请见谅!!!