参考文章:  《Linux 设置程序开机自启动 (命令systemctl 和 chkconfig用法区别比较)

http://blog.csdn.net/kenhins/article/details/74518978

最近看书发现  centos 中开机自启动的设置在不同版本中有所不同,发现如下:

其中,最大的一个不同是在 centos7中 chkconfig  命令会有如下提示:

注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。 要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。

这也就是说  在 centos7 中  chkconfig  命令与以前版本中 不同。

下面给出网上的一些资料:

centos 7 怎样设置开机自动启动,  如 httpd和mysqld 服务

systemctl enable httpd.service

systemctl enable mysqld.service

如果要取消开机自动启动apache和mysql,则用下面的命令

systemctl disable httpd.service
      
systemctl disable mysqld.service

在以前版本中的    centos   系统中 开机自动运行httpd服务好像不是上面的命令,而是
      
chkconfig –level 3 httpd on

任务 旧指令 新指令
使某服务自动启动 chkconfig –level 3 httpd on systemctl enable httpd.service
使某服务不自动启动 chkconfig –level 3 httpd off systemctl disable httpd.service
检查服务状态 service httpd status systemctl status httpd.service
显示所有已启动的服务 chkconfig –list systemctl list-units –type=service
启动某服务 service httpd start systemctl start httpd.service
停止某服务 service httpd stop systemctl stop httpd.service
重启某服务 service httpd restart systemctl restart httpd.service

systemctl 是系统服务管理器命令,它实际上将 service 和 chkconfig 这两个命令组合到一起。

在centos系统启动过程中,会根据  运行级别   执行   /etc/rcx.d/* (其中x为运行级别)。这里的文件实际上软链接到   /etc/init.d/   下的脚本文件。

systemctl 和  chkconfig  命令都是自动设置自启动项目的命令:

 systemctl 命令:
设置开机启动指令:systemctl enable tomcat
取消设置:systemctl disable tomcat
查看设置:systemctl list-unit-files
 chkconfig 命令:
使用chkconfig时需要注意,/etc/init.d/下有对应的脚本(这里就是tomcat),且该脚本头部包含如下注释以支持chkconfig,
注释表示在rc2|||.d下生成优先级96的启动脚本软链接,另外在rc0|.d下生成优先级04的停止脚本软链接:
#chkconfig: 设置开机启动指令: chkconfig --add tomcat
取消设置: chkconfig --del tomcat
查看设置: chkconfig

正常我们开机是使用 level5 的, 于是进入  rc5.d 目录中查看:

个人的感觉是在  Centos7 中  chkconfig 命令属于被替换的那种命令,  毕竟 chkconfig命令使用起来还是要比  systemctl 要复杂一些的。

而且  systemctl 提示会覆盖  chkconfig  命令的设置, 具体是什么意思不是很理解,有可能是说在systemctl 中设置过了 在 chkconfig 中进行命令是没有效果的,  比如我在systemctl 中设置  tomcat 不自启动,  但是在  chkconfig 中设置自启动,但是实际上 chkconfig 的设置是无效的,也就是说 systemctl 命令是真正执行的。

网上有网友发现以下事情:

先用systemctl设置开机启动,但是因为它是从/usr/lib/systemd/system/下的软链接到/etc/systemd/system/multi-user.target.wants,
而奇怪的是/usr/lib/systemd/system/tomcat这个文件中的环境配置是错误的。 为了防止其他不必要的麻烦,决定使用chkconfig,用chkconfig设置开机启动后重启机子,
发现tomcat未启动。orz。后来尝试把文件名tomcat改成test,执行chkconfig --add test后重启机子,发现tomcat启动了。

最新文章

  1. hashmap的底层实现
  2. [.NET领域驱动设计实战系列]专题八:DDD案例:网上书店分布式消息队列和分布式缓存的实现
  3. MEF入门之不求甚解,但力求简单能讲明白(五)
  4. linq中join的用法
  5. 解决MyEclipse吃内存以及卡死的方法
  6. Serialize Documents with the C# Driver
  7. Contest2037 - CSU Monthly 2013 Oct (problem D :CX and girls)
  8. VC++2010添加菜单
  9. [转]【基于zxing的编解码实战】精简Barcode Scanner篇
  10. [Angular 2] Dispatching Action with Payloads and type to Reducers
  11. ACM比赛(第三次D)
  12. Jquery显示和隐藏元素或设为只读(含Ligerui的控件禁用,实例说明)
  13. 开始 space viking 之旅
  14. poj-3898 Software Industry Revolution DP
  15. 结对项目https://github.com/bxoing1994/test/blob/master/源代码
  16. java版本DbhelperMysql
  17. window server 2012 II8 假陌生 碰到的问题
  18. as3 文本竖排效果实现
  19. BATJ面试必会之 Spring 篇(一)
  20. Chapter10(泛型算法)--C++Prime笔记

热门文章

  1. rest-framework框架的基本组件
  2. C# 复杂格式多级深度XML序列化反序列化
  3. SQL :模糊查询,转义字符
  4. appium问题解决
  5. 使用vux实现上拉刷新的总结
  6. OpenCV图像增强算法实现(直方图均衡化、拉普拉斯、Log、Gamma)
  7. 20145118 《Java程序设计》第5周学习总结 教材学习内容总结
  8. 20155201 实验四《Java面向对象程序设计》实验报告
  9. SDN前瞻 传统网络架构的危机:危机“四”起
  10. [转] VR-FORCES 介绍