chkconfig和systemctl对比

centos7里面的取代sysv的新玩意Systemd,把我们杀得个措手不及,刚开始还以为是Linus觉得自己店做大了,可以开始欺客了。后来才知道始作俑者是Lennart Poettering,一个水平跟Linus差了十万八千里的人在干着本该linus干的事。在鲁班面前跟个小丑似的舞弄着石斧。

吐槽邮件、人身攻击、死亡威胁——Lennart Poettering,我只想说让这些来得更猛烈些吧。

Lennart Poettering的博文中首先强调的就是启动速度.
As mentioned, the central responsibility of an init system is
to bring up userspace. And a good init system does that
fast. Unfortunately, the traditional SysV init system was not
particularly fast.For a fast and efficient boot-up two things are crucial:
➤To start less
➤And to start more in parallel.
有病啊,谁在乎这么点启动速度!??服务器上电自检动不动就几分钟甚至十几分钟,我去在乎你这几秒钟的时间??我要的是稳定,要的是uptime 2000+ days 显然这个systemd肯定做不到。
吐槽完毕。
文本将chkconfig和systemctl做个对比。
命令写法比较:
/etc/init.d/sshd start
简单明了,逻辑清晰
systemctl restart sshd.service
虽然符合linux标准命令行格式(命令 选项 参数),但我实在不想记这么多东西啊。

查看一个服务是否开机启动

[root@disz ~]# chkconfig --list sshd
sshd           	0:off	1:off	2:on	3:on	4:on	5:on	6:off
[root@hqidi ~]#  systemctl list-unit-files -t service sshd.service
UNIT FILE    STATE  
sshd.service enabled

1 unit files listed.

重新加载配置文件

[root@disz ~]# /etc/init.d/sshd reload
Reloading sshd:                                            [  OK  ]
[root@hqidi ~]# systemctl reload sshd
[root@hqidi ~]# echo $?
0

condrestart选项挺有用,系统会测试新的配置文件是否有问题,若有问题,则不会重启,若没问题,则重启服务。

列出系统所有服务及状态

[root@disz ~]# chkconfig --list
abrt-ccpp      	0:off	1:off	2:off	3:off	4:off	5:off	6:off
abrtd          	0:off	1:off	2:off	3:off	4:off	5:off	6:off
acpid          	0:off	1:off	2:off	3:off	4:off	5:off	6:off
aegis          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
agentwatch     	0:off	1:off	2:on	3:on	4:on	5:on	6:off
aliyun-util    	0:off	1:off	2:on	3:on	4:on	5:on	6:off
atd            	0:off	1:off	2:off	3:off	4:off	5:off	6:off
auditd         	0:off	1:off	2:off	3:off	4:off	5:off	6:off
……略……
[root@hqidi ~]# systemctl list-units --type=service
  UNIT                               LOAD   ACTIVE SUB     DESCRIPTION
  abrt-ccpp.service                  loaded active exited  Install ABRT coredump hook
  abrt-oops.service                  loaded active running ABRT kernel log watcher
  abrt-xorg.service                  loaded active running ABRT Xorg log watcher
  abrtd.service                      loaded active running ABRT Automated Bug Reporting Tool
  alsa-state.service                 loaded active running Manage Sound Card State (restore and store)
  atd.service                        loaded active running Job spooling tools
  auditd.service                     loaded active running Security Auditing Service
  avahi-daemon.service               loaded active running Avahi mDNS/DNS-SD Stack
  blk-availability.service           loaded active exited  Availability of block devices
  chronyd.service                    loaded active running NTP client/server
  crond.service                      loaded active running Command Scheduler
  cups.service                       loaded active running CUPS Printing Service
  dbus.service                       loaded active running D-Bus System Message Bus
  firewalld.service                  loaded active running firewalld - dynamic firewall daemon
  getty@tty1.service                 loaded active running Getty on tty1
  gssproxy.service                   loaded active running GSSAPI Proxy Daemon
  iscsi-shutdown.service             loaded active exited  Logout off all iSCSI sessions on shutdown
● kdump.service                      loaded failed failed  Crash recovery kernel arming

取消服务的开机启动

[root@disz ~]# chkconfig --list postfix
postfix        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
[root@disz ~]# chkconfig postfix off
[root@disz ~]# chkconfig --list postfix
postfix        	0:off	1:off	2:off	3:off	4:off	5:off	6:off
[root@hqidi ~]# systemctl disable postfix.service
Removed symlink /etc/systemd/system/multi-user.target.wants/postfix.service.

设为开机启动

[root@disz ~]# chkconfig --level 3 postfix on
[root@disz ~]# chkconfig --list postfix
postfix        	0:off	1:off	2:off	3:on	4:off	5:off	6:off
[root@hqidi ~]# systemctl enable postfix.service
Created symlink from /etc/systemd/system/multi-user.target.wants/postfix.service to /usr/lib/systemd/system/postfix.service.

sysv

# 启动
/etc/init.d/httpd start
# 重启
/etc/init.d/httpd restart
# 关闭
/etc/init.d/httpd stop
# 状态查询
/etc/init.d/httpd status
# 加入开机启动
chkconfi --add httpd
# 删除开机启动 (对应windows下的 sc delete 服务名)
chkconfi --del httpd
# 设定开机启动
chkconfig httpd on
# 取消开机启动
chkconfig httpd off

Systemd

# 启动
systemctl start tomcat.service
# 重启
systemctl restart tomcat.service
# 关闭
systemctl stop tomcat.service
# 状态查询
systemctl status tomcat.service
# 加入开机启动
systemctl enable tomcat.service
# 取消开机启动
systemctl disable tomcat.service

原创文章,转载请注明: 转载自笛声

本文链接地址: chkconfig和systemctl对比

5 条评论

  • 阿柯 2017年5月12日 回复

    技术人才,没一篇是我能看得懂的。

    • dige 2017年5月12日 回复 作者

      谦虚了,肯定有您能看懂的,你的博客我常去,知道你的水平。

  • 施展 2017年5月12日 回复

    内容不错,不过我也没看懂~

    • dige 2017年5月12日 回复 作者

      那就是我书面表达的问题咯。

  • 布什 2017年7月29日 回复

    Lennart Poettering背离了linux设计原则的初衷,把简单的事情复杂化,所以这么令人讨厌

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Copyright © 2015-2024 笛声博客 All Rights Reserved     浙ICP备15036123号-1