博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux下面如何让一个软件/命令开机自启动
阅读量:7199 次
发布时间:2019-06-29

本文共 3635 字,大约阅读时间需要 12 分钟。

第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]# \rm -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下面如何让一个软件/命令开机自启动

  1. 把命令或脚本放入到 /etc/rc.local
  2. 通过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正在持续学习中,如有雷同请见谅!!!

转载于:https://www.cnblogs.com/dzc-/p/7812921.html

你可能感兴趣的文章
跟我一起学docker(八)--Dockerfile
查看>>
做SEO,选择大于努力
查看>>
python web开发-flask调试模式
查看>>
3分钟看懂linux磁盘划分
查看>>
Linux-LAMP 默认页,虚拟主机
查看>>
Node.js 特点
查看>>
Linux-日志管理
查看>>
MySQL数据库系统
查看>>
Android Studio 提示帮助文档 一直显示:fetching documentation
查看>>
新 Terraform 提供商: F5 Networks, Nutanix, 腾讯云, Helm
查看>>
SpringBoot框架简介及搭建
查看>>
拯救 Java Code Style 强迫症
查看>>
PDF文档怎样在线合并?
查看>>
大侦探福老师——幽灵Crash谜踪案
查看>>
一个故事告诉你什么才是好的程序员
查看>>
python subprocess模块 监控子进程的2种方式 忙等待和立即返回同时设置子进程超时...
查看>>
Java 网络编程
查看>>
科略教育—《只有规则和制度,才能遏制人性的阴暗》
查看>>
IT兄弟连 JavaWeb教程 JSP语法
查看>>
C# DllImport的用法
查看>>