chkconfig设置开机自启动的原理
开机自启动服务的原理
$sudo chkconfig --level sshd on #手动设置3级别的开机自启动
[leiyf@leiyangfeng ~]
#手动设置3级别的开机自启动,实质是在对应运行级别的目录rc3.d下创建一个sshd的启动脚本(/etc/init.d/sshd)的软连接S55sshd,如下:
$ls -l /etc/rc.d/rc3.d/S55sshd
lrwxrwxrwx. root root Oct : /etc/rc.d/rc3.d/S55sshd -> ../init.d/sshd
而设置3级别的开机关闭,如下:
$sudo chkconfig --level 3 sshd off
[leiyf@leiyangfeng ~]
$ls -l /etc/rc.d/rc3.d/K25sshd
lrwxrwxrwx. 1 root root 14 Oct 3 11:12 /etc/rc.d/rc3.d/K25sshd -> ../init.d/sshd
所以也可以通过修改软连接的方式,设置开机启动的方式,如下:
$chkconfig --list sshd
sshd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[leiyf@leiyangfeng ~]
$ls -l /etc/rc.d/rc3.d/ | grep sshd
lrwxrwxrwx. 1 root root 14 Oct 3 11:25 K25sshd -> ../init.d/sshd
[leiyf@leiyangfeng ~]
$sudo \rm -f /etc/rc.d/rc3.d/K25sshd ; sudo ln -s /etc/init.d/sshd /etc/rc.d/rc3.d/S55sshd
[leiyf@leiyangfeng ~]
$ls -l /etc/rc.d/rc3.d/S55sshd
lrwxrwxrwx. 1 root root 16 Oct 3 11:27 /etc/rc.d/rc3.d/S55sshd -> /etc/init.d/sshd
[leiyf@leiyangfeng ~]
$chkconfig --list sshd
sshd 0:off 1:off 2:off 3:on 4:off 5:off 6:off
其中K55(关闭),S55(开启),在/etc/init.d/sshd中设置的,如下:
$sed -n '/55/p' /etc/init.d/sshd
# chkconfig: 2345 55 25
将服务或者脚本添加到系统服务中
自建脚本内容,如下:
$sudo vim /etc/init.d/leiyf
#!/bin/bash
#
# leiyfd Start up the leiyf server daemon
#
# chkconfig: echo "Knowledge has no limit"
添加可执行权限
sudo chmod +x /etc/init.d/leiyf
添加到系统服务
$sudo chkconfig --add leiyf
此时可以看到在脚本leiyf中定义的2345级别到运行了,如下:
$sudo chkconfig --list leiyf
leiyf :off :off :on :on :on :on :off
关闭在3级别的开机启动,如下:
$sudo chkconfig --level leiyf off
[leiyf@leiyangfeng ~]
$sudo chkconfig --list leiyf
leiyf :off :off :on :off :on :on :off
可以看到创建了如下的软链接,链接的名称也是在脚本(leiyf)中,定义:# chkconfig: 2345 66 44的44,如下:
$ls -l /etc/rc.d/rc3.d/ | grep leiyf
lrwxrwxrwx. root root Oct : K44leiyf -> ../init.d/leiyf
开启在3级别的开机启动,也可以看到如下软链接:
$sudo chkconfig --level leiyf on
[leiyf@leiyangfeng ~]
$ls -l /etc/rc.d/rc3.d/ | grep leiyf
lrwxrwxrwx. root root Oct : S66leiyf -> ../init.d/leiyf
chkconfig设置开机自启动的原理的更多相关文章
- Linux服务器,服务管理--systemctl命令详解,设置开机自启动
Linux服务器,服务管理--systemctl命令详解,设置开机自启动 syetemclt就是service和chkconfig这两个命令的整合,在CentOS 7就开始被使用了. 摘要: syst ...
- CentOS 6下 Oracle11gR2 设置开机自启动
[1] 更改/etc/oratab # This file is used by ORACLE utilities. It is created by root.sh # and updated by ...
- CentOS7设置开机自启动命令大全
任务 旧指令 新指令 使某服务自动启动 chkconfig --level 3 httpd on systemctl enable httpd.service 使某服务不自 ...
- CentOS7设置开机自启动方式
方式一: # 在/etc/rc.d/rc.local文件中追加启动命令,该文件追加后,会随着机器自动后,自动运行文件中的命令 # vim /etc/rc.d/rc.local # 权限问题:在cent ...
- redis的安装与设置开机自启动
redis 的安装配置: 可以直接去官网下载((https://redis.io/download) 解压文件到指定目录下 tar zxvf redis-5.0.7.tar.gz -C /opt/ ...
- CentOS6设置开机自启动
1.把开机启动脚本(mysqld)copy到文件夹/etc/init.d 或 /etc/rc.d/init.d 中 2.将启动程序的命令添加到 /etc/rc.d/rc.local 文件中,比如: # ...
- Fedora 16设置开机自启动程序与Ubuntu的区别
Ubuntu设置开机自启动脚本的方法是:修改/etc/init.d/rc.local这个文件,添加需要启动的程序即可,相关函数如下: void SetSysAutoBoot() { ] = {}; ; ...
- linux_设置开机自启动程序脚本
设置开机自启动
- Ubuntu14.04设置开机自启动脚本
方法一.编辑rc.loacl脚本 Ubuntu开机之后会执行/etc/rc.local文件中的脚本,所以我们可以直接在/etc/rc.local中添加启动脚本.在 exit 0 前面添加好脚本代码, ...
随机推荐
- oracle 帐号scott被锁定 如何解锁
由于多次输入:账号 密码不对 oracle 帐号scott被锁定 如何解锁: 具体操作步骤如下:C:> sqlplus请输入用户名:sys输入口令:sys as sysdba //注意:在口令这 ...
- SqlServer数据库(可疑)的解决办法
当数据库发生这种操作故障时,可以按如下操作步骤可解决此方法, 打开数据库里的Sql 查询编辑器窗口,运行以下的命令. // 1.使用指定值强制重新配置:(1.0表示为真假) sp_configure ...
- 执行系统命令,subprocess使用说明
os.system('ls -l') #只执行命令,不能将结果赋予变量 os.system('mkdir test') #创建test目录 files = os.popen('ls -l').rea ...
- Spring学习---Spring中利用组件实现从FTP服务器上传/下载文件
FtpUtil.java import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundExcepti ...
- Linq to Entities,ADO.NET Entity Framework 模型优先
一.概念: Database First(数据库优先):存在的DB------------->生成Data Model .edmx文件 Model First(模型优先):Data Model ...
- codeforces 722E Research Rover
codeforces 722E Research Rover 题意 \(1e5*1e5\)的棋盘中有\(2000\)个坏点,初始给定一个值\(s(1<=s<=1e6)\).从棋盘左上角走到 ...
- windows server 2008/2012安装PostgreSQL过程及问题总结
今天第一次接触在Windows Server2008/2012 下安装PostgreSQL,遇到的问题总结如下: 1.首先,在安装的时候,我更改安装目录改为自定义的E盘,安装时报错:libintl.d ...
- python对列表中的字典进行排序
数据显示为: rows=[{'日期': '2018-09-04', '测试1': '50.00 %', '测试2': '100.00%'}, {'日期': '2018-09-05', '测试1': ' ...
- bzoj4037 [HAOI2015]数字串拆分
Description 你有一个长度为n的数字串.定义f(S)为将S拆分成若干个1~m的数的和的方案数,比如m=2时,f(4)=5,分别为4=1+1+1+1你可以将这个数字串分割成若干个数字(允许前导 ...
- 死磕salt系列-salt API 使用
启用salt-api 服务 这里简单的说明下,SaltStack官方支持三种REST API,分别是rest_cherry; rest_tonado和rest_wsgi, 本文选择使用rest_che ...