写给linux系统管理员看的systemd 第一部分 (systemd作者blog翻译过来的)

来源:互联网 发布:桌面办公软件 编辑:程序博客网 时间:2024/04/28 22:03

http://0pointer.de/blog/projects/systemd-for-admins-1.html


就像很多人知道的那样, systemd是新版本fedora(从F14开始)的init系统, 它也正在被一些其它的发行版所采用(例如, OpenSuse).

对系统管理员来说,systmed提供了许多新的特性,并在本质上改变和加强了系统管理过程.

这篇博客是系列文章的第一部分, 在接下来的几个月我打算差不多每周写一篇.

每篇文章我将尝试解释systemd的一个新的特性. 其实它的许多特性都很小很简单, 所以这个系列应该会使很多读者感兴趣. 

当然有时,我也会深挖systemd提供给你的一些伟大的新特性.


Verifying Bootup

传统的 linux系统在启动过程中, 你看到大量的短信息从你的屏幕上滚过.systemd中, 随着我们改进启动速度并使启动过程并行化, 这些信息的显示时间越来越短, 而且可读性也越来越差了, 就如同你在某些像Plymouth那样提供图像启动画面的启动程序中看到的那样.尽管它仍然提供了有用的相关性信息, 它在启动过程中记录了每个服务的开始,是否成功或失败(绿色[OK]代表成功,红色FAILED代表失败].

为了在提高机器启动速度并使启动过程并行执行的同时, 让启动的信息在运行时更友好,我们为systemd增加了一个新的特性,用来在启动时和运行时跟踪并记录每个服务是否启动成功, 是否以非0值退出, 是否超时, 是否非正常终止(被段错误信号或类似的东西), 只是在shell下简单的敲systemdctl, 你就能查询所有服务的状态, 无论是systemd的还是SysV/LSB的服务


[root@lambda] ~# systemctlUNIT                                          LOAD   ACTIVE       SUB          JOB             DESCRIPTIONdev-hugepages.automount                       loaded active       running                      Huge Pages File System Automount Pointdev-mqueue.automount                          loaded active       running                      POSIX Message Queue File System Automount Pointproc-sys-fs-binfmt_misc.automount             loaded active       waiting                      Arbitrary Executable File Formats File System Automount Pointsys-kernel-debug.automount                    loaded active       waiting                      Debug File System Automount Pointsys-kernel-security.automount                 loaded active       waiting                      Security File System Automount Pointsys-devices-pc...0000:02:00.0-net-eth0.device loaded active       plugged                      82573L Gigabit Ethernet Controller[...]sys-devices-virtual-tty-tty9.device           loaded active       plugged                      /sys/devices/virtual/tty/tty9-.mount                                       loaded active       mounted                      /boot.mount                                    loaded active       mounted                      /bootdev-hugepages.mount                           loaded active       mounted                      Huge Pages File Systemdev-mqueue.mount                              loaded active       mounted                      POSIX Message Queue File Systemhome.mount                                    loaded active       mounted                      /homeproc-sys-fs-binfmt_misc.mount                 loaded active       mounted                      Arbitrary Executable File Formats File Systemabrtd.service                                 loaded active       running                      ABRT Automated Bug Reporting Toolaccounts-daemon.service                       loaded active       running                      Accounts Serviceacpid.service                                 loaded active       running                      ACPI Event Daemonatd.service                                   loaded active       running                      Execution Queue Daemonauditd.service                                loaded active       running                      Security Auditing Serviceavahi-daemon.service                          loaded active       running                      Avahi mDNS/DNS-SD Stackbluetooth.service                             loaded active       running                      Bluetooth Managerconsole-kit-daemon.service                    loaded active       running                      Console Managercpuspeed.service                              loaded active       exited                       LSB: processor frequency scaling supportcrond.service                                 loaded active       running                      Command Schedulercups.service                                  loaded active       running                      CUPS Printing Servicedbus.service                                  loaded active       running                      D-Bus System Message Busgetty@tty2.service                            loaded active       running                      Getty on tty2getty@tty3.service                            loaded active       running                      Getty on tty3getty@tty4.service                            loaded active       running                      Getty on tty4getty@tty5.service                            loaded active       running                      Getty on tty5getty@tty6.service                            loaded active       running                      Getty on tty6haldaemon.service                             loaded active       running                      Hardware Managerhdapsd@sda.service                            loaded active       running                      sda shock protection daemonirqbalance.service                            loaded active       running                      LSB: start and stop irqbalance daemoniscsi.service                                 loaded active       exited                       LSB: Starts and stops login and scanning of iSCSI devices.iscsid.service                                loaded active       exited                       LSB: Starts and stops login iSCSI daemon.livesys-late.service                          loaded active       exited                       LSB: Late init script for live image.livesys.service                               loaded active       exited                       LSB: Init script for live image.lvm2-monitor.service                          loaded active       exited                       LSB: Monitoring of LVM2 mirrors, snapshots etc. using dmeventd or progress pollingmdmonitor.service                             loaded active       running                      LSB: Start and stop the MD software RAID monitormodem-manager.service                         loaded active       running                      Modem Managernetfs.service                                 loaded active       exited                       LSB: Mount and unmount network filesystems.NetworkManager.service                        loaded active       running                      Network Managerntpd.service                                  loaded maintenance  maintenance                  Network Time Servicepolkitd.service                               loaded active       running                      Policy Managerprefdm.service                                loaded active       running                      Display Managerrc-local.service                              loaded active       exited                       /etc/rc.local Compatibilityrpcbind.service                               loaded active       running                      RPC Portmapper Servicersyslog.service                               loaded active       running                      System Logging Servicertkit-daemon.service                          loaded active       running                      RealtimeKit Scheduling Policy Servicesendmail.service                              loaded active       running                      LSB: start and stop sendmailsshd@172.31.0.53:22-172.31.0.4:36368.service  loaded active       running                      SSH Per-Connection Serversysinit.service                               loaded active       running                      System Initializationsystemd-logger.service                        loaded active       running                      systemd Logging Daemonudev-post.service                             loaded active       exited                       LSB: Moves the generated persistent udev rules to /etc/udev/rules.dudisks.service                                loaded active       running                      Disk Managerupowerd.service                               loaded active       running                      Power Managerwpa_supplicant.service                        loaded active       running                      Wi-Fi Security Serviceavahi-daemon.socket                           loaded active       listening                    Avahi mDNS/DNS-SD Stack Activation Socketcups.socket                                   loaded active       listening                    CUPS Printing Service Socketsdbus.socket                                   loaded active       running                      dbus.socketrpcbind.socket                                loaded active       listening                    RPC Portmapper Socketsshd.socket                                   loaded active       listening                    sshd.socketsystemd-initctl.socket                        loaded active       listening                    systemd /dev/initctl Compatibility Socketsystemd-logger.socket                         loaded active       running                      systemd Logging Socketsystemd-shutdownd.socket                      loaded active       listening                    systemd Delayed Shutdown Socketdev-disk-by\x1...x1db22a\x1d870f1adf2732.swap loaded active       active                       /dev/disk/by-uuid/fd626ef7-34a4-4958-b22a-870f1adf2732basic.target                                  loaded active       active                       Basic Systembluetooth.target                              loaded active       active                       Bluetoothdbus.target                                   loaded active       active                       D-Busgetty.target                                  loaded active       active                       Login Promptsgraphical.target                              loaded active       active                       Graphical Interfacelocal-fs.target                               loaded active       active                       Local File Systemsmulti-user.target                             loaded active       active                       Multi-Usernetwork.target                                loaded active       active                       Networkremote-fs.target                              loaded active       active                       Remote File Systemssockets.target                                loaded active       active                       Socketsswap.target                                   loaded active       active                       Swapsysinit.target                                loaded active       active                       System InitializationLOAD   = Reflects whether the unit definition was properly loaded.ACTIVE = The high-level unit activation state, i.e. generalization of SUB.SUB    = The low-level unit activation state, values depend on unit type.JOB    = Pending job for the unit.221 units listed. Pass --all to see inactive units, too.[root@lambda] ~#


(我缩短了一些输出,移除了一些与此篇博客无关的行)

看一下ACTIVE列, 显示了一个服务(或者任何systemd维护的单元, 可以不只是服务,我们在后续文章中可以看到)的最基本的状态, 可能是active状态(比如: running), 可能是incative(比如: not running))也可能是其他状态.如果仔细看你会发现有一项标记为maintenance,红色高亮. 这提示你这个服务运行失败或者碰到其他问题.本例中是ntpd.现在让我们通过systemdctl status命令看看ntpd到底发生了什么. 

[root@lambda] ~# systemctl status ntpd.servicentpd.service - Network Time Service  Loaded: loaded (/etc/systemd/system/ntpd.service)  Active: maintenance    Main: 953 (code=exited, status=255)  CGroup: name=systemd:/systemd-1/ntpd.service[root@lambda] ~#

这告知我们NTPzai运行时终止了(它运行时的PID是953), 并告诉我们确切的出错条件:进程以状态码255退出.

以后的systmed版本中,我们计划把这种情况做成钩子,连接ABRT(自动bug报告工具). 这样,如果systemctl status告诉你一个服务崩溃了, 它将指示给你在ABRT中确切的崩溃dump内容


总结: 用systemctl和systemctl status作为传统SysV启动信息的代替工具, 更现代,更完备.system status不但能捕获更多的出错细节, 还能在提供启动错误信息的同时提供运行时错误信息

下周见



0 0