传统的Linux系统启动过程主要由著名的init进程(也被称为SysV init启动系统)处理,而基于init的启动系统被认为有效率不足的问题,systemd是Linux系统机器的另一种启动方式,宣称弥补了以传统Linux SysV init为基础的系统的缺点。
1、列出正在运行的服务
[[email protected] ~]# systemctl UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active waiting Arbitrary Executable File Formats File System Automount Point sys-devices-pci0000:00-0000:00:07.1-ata2-host1-target1:0:0-1:0:0:0-block-sr0.device loaded active plugged VMware_Virtual_IDE_CDROM_Drive CentOS_7_x86_64 sys-devices-pci0000:00-0000:00:10.0-host2-target2:0:0-2:0:0:0-block-sda-sda1.device loaded active plugged VMware_Virtual_S 1 sys-devices-pci0000:00-0000:00:10.0-host2-target2:0:0-2:0:0:0-block-sda-sda2.device loaded active plugged LVM PV CSeHGs-hdrA-6Y0N-jXVM-VA3R-3sSe-BraSga on /dev/sda2 2 sys-devices-pci0000:00-0000:00:10.0-host2-target2:0:0-2:0:0:0-block-sda.device loaded active plugged VMware_Virtual_S sys-devices-pci0000:00-0000:00:10.0-host2-target2:0:1-2:0:1:0-block-sdb.device loaded active plugged VMware_Virtual_S sys-devices-pci0000:00-0000:00:11.0-0000:02:01.0-net-ens33.device loaded active plugged 82545EM Gigabit Ethernet Controller (Copper) (PRO/1000 MT Single Port Adapter) sys-devices-pci0000:00-0000:00:11.0-0000:02:02.0-sound-card0.device loaded active plugged ES1371/ES1373 / Creative Labs CT2518 (Audio PCI 64V/128/5200 / Creative CT4810/ sys-devices-platform-serial8250-tty-ttyS1.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS1 sys-devices-platform-serial8250-tty-ttyS2.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS2 sys-devices-platform-serial8250-tty-ttyS3.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS3 sys-devices-pnp0-00:05-tty-ttyS0.device loaded active plugged /sys/devices/pnp0/00:05/tty/ttyS0 sys-devices-virtual-block-dm\x2d0.device loaded active plugged /sys/devices/virtual/block/dm-0 sys-devices-virtual-block-dm\x2d1.device loaded active plugged /sys/devices/virtual/block/dm-1 sys-module-configfs.device loaded active plugged /sys/module/configfs sys-subsystem-net-devices-ens33.device loaded active plugged 82545EM Gigabit Ethernet Controller (Copper) (PRO/1000 MT Single Port Adapter) -.mount loaded active mounted / boot.mount loaded active mounted /boot
2、树状结构显示正在运行的服务
[[email protected] ~]# systemd-cgls ├─1 /usr/lib/systemd/systemd --switched-root --system --deserialize 21 ├─user.slice │ └─user-0.slice │ └─session-1.scope │ ├─1649 sshd: [email protected]/0 │ ├─1967 -bash │ ├─2860 systemd-cgls │ └─2861 systemd-cgls └─system.slice ├─rsyslog.service │ └─1554 /usr/sbin/rsyslogd -n ├─umail_postgresql.service │ ├─1589 /usr/local/u-mail/service/pgsql-9.4/bin/postgres -D /usr/local/u-mail/service/pgsql-9.4/data/data │ ├─1672 postgres: logger process │ ├─1719 postgres: checkpointer process │ ├─1720 postgres: writer process │ ├─1721 postgres: wal writer process │ ├─1724 postgres: autovacuum launcher process │ └─1726 postgres: stats collector process ├─tuned.service │ └─1546 /usr/bin/python -Es /usr/sbin/tuned -l -P
3、systemctl常见操作命令
启动服务:systemctl start postfix.service
关闭服务:systemctl stop postfix.service
重启服务:systemctl restart postfix.service
查看服务状态:systemctl status postfix.service
开机启动服务:systemctl enable postfix.service
开机禁用服务:systemctl disable postfix.service
确认开机是否启动服务:systemctl is-enabled postfix.service
查看已启动的服务:systemctl list-unit-files|grep enabled
查看启动失败的服务:systemctl --failed
使用命令 systemctl is-enabled postfix.service返回的结果有enable、disable或static。static它是指对应的 Unit 文件中没有定义[Install]区域,因此无法配置为开机启动服务。
说明:启用服务是在当前“runlevel”的配置文件目录/etc/systemd/system/multi-user.target.wants/里,建立/usr/lib/systemd/system里面对应服务配置文件的软链接;禁用服务就是删除此软链接,添加服务就是添加软连接。
原文地址:http://blog.51cto.com/net881004/2054850