RHEL7下的systemd

systemd是Linux下的系统和服务管理器,兼容SysV和LSB的启动脚本。对于systemd有以下特性:支持并行化任务、同时采用socket和D-BUS总线式激活服务、按需启动相应的守护进程、利用Linux的cgroup监控进程、支持快照和系统恢复、维护挂载点和自动挂载点,各服务间基于依赖关系进行精密控制。

一、分析系统状态
1.输出激活的单元
[[email protected] ~]# systemctl
UNIT                                     LOAD                       ACTIVE SUB       DESCRIPTION
proc-sys...t_misc.automount     loaded active waiting   Arbitrary Executable File Fo
sys-devi...-sda-sda1.device      loaded active plugged   VMware_Virtual_S
sys-devi...-sda-sda2.device      loaded active plugged   LVM PV lv3Fxq-bu9J-pkq2-wMtN
sys-devi...block-sda.device loaded active plugged   VMware_Virtual_S
sys-devi...ooth-hci0.device loaded active plugged   /sys/devices/pci0000:00/0000
sys-devi...o16777736.device loaded active plugged   PRO/1000 MT Single Port Adap
sys-devi...block-sr0.device loaded active plugged   VMware_Virtual_SATA_CDRW_Dri
sys-devi...block-fd0.device loaded active plugged   /sys/devices/platform/floppy
sys-devi...tty-ttyS2.device loaded active plugged   /sys/devices/platform/serial
sys-devi...tty-ttyS3.device loaded active plugged   /sys/devices/platform/serial
sys-devi...tty-ttyS0.device loaded active plugged   /sys/devices/pnp0/00:09/tty/
sys-devi...tty-ttyS1.device loaded active plugged   /sys/devices/pnp0/00:0a/tty/
sys-devi...k-dm\x2d0.device loaded active plugged   /sys/devices/virtual/block/d
sys-devi...k-dm\x2d1.device loaded active plugged   /sys/devices/virtual/block/d
sys-module-configfs.device  loaded active plugged   /sys/module/configfs
sys-module-fuse.device      loaded active plugged   /sys/module/fuse
sys-subs...ices-hci0.device loaded active plugged   /sys/subsystem/bluetooth/dev
sys-subs...o16777736.device loaded active plugged   PRO/1000 MT Single Port Adap
-.mount                     loaded active mounted   /
boot.mount                  loaded active mounted   /boot
dev-hugepages.mount         loaded active mounted   Huge Pages File System
dev-mqueue.mount            loaded active mounted   POSIX Message Queue File Sys
proc-fs-nfsd.mount          loaded active mounted   RPC Pipe File System
run-user-1000-gvfs.mount    loaded active mounted   /run/user/1000/gvfs
sys-fs-f...onnections.mount loaded active mounted   FUSE Control File System
sys-kernel-config.mount     loaded active mounted   Configuration File System
sys-kernel-debug.mount      loaded active mounted   Debug File System
var-lib-...rpc_pipefs.mount loaded active mounted   RPC Pipe File System
brandbot.path               loaded active waiting   Flexible branding
cups.path                   loaded active waiting   CUPS Printer Service Spool
systemd-...rd-plymouth.path loaded active waiting   Forward Password Requests to
systemd-...ssword-wall.path loaded active waiting   Forward Password Requests to
session-1.scope             loaded active running   Session 1 of user admin
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
accounts-daemon.service     loaded active running   Accounts Service
alsa-state.service          loaded active running   Manage Sound Card State (res
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
bluetooth.service           loaded active running   Bluetooth service
chronyd.service             loaded active running   NTP client/server
colord.service              loaded active running   Manage, Install and Generate
crond.service               loaded active running   Command Scheduler
cups.service                loaded active running   CUPS Printing Service

[[email protected] ~]# systemctl list-units
UNIT                        LOAD   ACTIVE SUB       DESCRIPTION
proc-sys...t_misc.automount loaded active waiting   Arbitrary Executable File Fo
sys-devi...-sda-sda1.device loaded active plugged   VMware_Virtual_S
sys-devi...-sda-sda2.device loaded active plugged   LVM PV lv3Fxq-bu9J-pkq2-wMtN
sys-devi...block-sda.device loaded active plugged   VMware_Virtual_S
sys-devi...ooth-hci0.device loaded active plugged   /sys/devices/pci0000:00/0000
sys-devi...o16777736.device loaded active plugged   PRO/1000 MT Single Port Adap
sys-devi...block-sr0.device loaded active plugged   VMware_Virtual_SATA_CDRW_Dri
sys-devi...block-fd0.device loaded active plugged   /sys/devices/platform/floppy
sys-devi...tty-ttyS2.device loaded active plugged   /sys/devices/platform/serial
sys-devi...tty-ttyS3.device loaded active plugged   /sys/devices/platform/serial
sys-devi...tty-ttyS0.device loaded active plugged   /sys/devices/pnp0/00:09/tty/
sys-devi...tty-ttyS1.device loaded active plugged   /sys/devices/pnp0/00:0a/tty/
sys-devi...k-dm\x2d0.device loaded active plugged   /sys/devices/virtual/block/d
sys-devi...k-dm\x2d1.device loaded active plugged   /sys/devices/virtual/block/d
sys-module-configfs.device  loaded active plugged   /sys/module/configfs
sys-module-fuse.device      loaded active plugged   /sys/module/fuse

输出运行失败的单元
[[email protected] ~]# systemctl --failed
UNIT          LOAD   ACTIVE SUB    DESCRIPTION
rhnsd.service loaded failed failed LSB: Starts the Spacewalk Daemon

LOAD   = 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.

1 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use ‘systemctl list-unit-files‘.

所有可用的单元文件存放在/usr/lib/systemd/system/和/etc/systemd/system目录中,/etc/systemd/system中单元的优先级高于/usr/lib/systemd/system

[[email protected] ~]# ls /usr/lib/systemd/system/
abrt-ccpp.service                        packagekit-offline-update.service
abrtd.service                            paths.target
abrt-oops.service                        plymouth-halt.service
abrt-pstoreoops.service                  plymouth-kexec.service
abrt-vmcore.service                      plymouth-poweroff.service
abrt-xorg.service                        plymouth-quit.service
accounts-daemon.service                  plymouth-quit-wait.service
alsa-restore.service                     plymouth-read-write.service
alsa-state.service                       plymouth-reboot.service
alsa-store.service                       plymouth-start.service
anaconda-direct.service                  plymouth-switch-root.service
anaconda-noshell.service                 polkit.service
anaconda.service                         postfix.service
[email protected]                  poweroff.target
anaconda-sshd.service                    poweroff.target.wants
anaconda.target                          printer.target
anaconda.target.wants                    proc-fs-nfsd.mount
[email protected]                   proc-sys-fs-binfmt_misc.automount
arp-ethers.service                       proc-sys-fs-binfmt_misc.mount
atd.service                              psacct.service
auditd.service                           qemu-guest-agent.service
[email protected]                          quotaon.service
avahi-daemon.service                     radvd.service
avahi-daemon.socket                      rc-local.service
basic.target                             rdisc.service
basic.target.wants                       realmd.service
blk-availability.service                 reboot.target
bluetooth.service                        reboot.target.wants
bluetooth.target                         remote-fs-pre.target
brandbot.path                            remote-fs.target
brandbot.service                         rescue.service
brltty.service                           rescue.target
canberra-system-bootup.service           rhel-autorelabel-mark.service
canberra-system-shutdown-reboot.service  rhel-autorelabel.service
canberra-system-shutdown.service         rhel-configure.service
chronyd.service                          rhel-dmesg.service
chrony-wait.service                      rhel-domainname.service
colord.service                           rhel-import-state.service
[email protected]               rhel-loadmodules.service
console-getty.service                    rhel-readonly.service
console-shell.service                    rhsmcertd.service
cpupower.service                         rngd.service
crond.service                            rpcbind.service
cryptsetup.target                        rpcbind.socket
ctrl-alt-del.target                      rpcbind.target
cups-browsed.service                     rpcgssd.service
cups.path                                rpcidmapd.service
cups.service                             rpcsvcgssd.service
cups.socket                              rsyncd.service
dbus-org.freedesktop.hostname1.service   rsyncd.socket
dbus-org.freedesktop.locale1.service     rsyslog.service
dbus-org.freedesktop.login1.service      rtkit-daemon.service
dbus-org.freedesktop.machine1.service    runlevel0.target
dbus-org.freedesktop.timedate1.service   runlevel1.target
dbus.service                             runlevel1.target.wants
dbus.socket                              runlevel2.target
dbus.target.wants                        runlevel2.target.wants
debug-shell.service                      runlevel3.target
default.target                           runlevel3.target.wants
default.target.wants                     runlevel4.target
dev-hugepages.mount                      runlevel4.target.wants
dev-mqueue.mount                         runlevel5.target
dm-event.service                         runlevel5.target.wants
dm-event.socket                          runlevel6.target
dmraid-activation.service                saslauthd.service
dnsmasq.service                          [email protected]
dracut-cmdline.service                   shutdown.target
dracut-initqueue.service                 shutdown.target.wants
dracut-mount.service                     sigpwr.target
dracut-pre-mount.service                 sleep.target
dracut-pre-pivot.service                 -.slice
dracut-pre-trigger.service               slices.target
dracut-pre-udev.service                  smartcard.target
dracut-shutdown.service                  smartd.service
ebtables.service                         sockets.target
emergency.service                        sockets.target.wants
emergency.target                         sound.target
fcoe.service                             speech-dispatcherd.service
final.target                             spice-vdagentd.service
firewalld.service                        spice-vdagentd.target
firstboot-graphical.service              sshd-keygen.service
fprintd.service                          sshd.service
gdm.service                              [email protected]
[email protected]                           sshd.socket
getty.target                             suspend.target
graphical.target                         svnserve.service
graphical.target.wants                   swap.target
halt-local.service                       sys-fs-fuse-connections.mount
halt.target                              sysinit.target
halt.target.wants                        sysinit.target.wants
hibernate.target                         sys-kernel-config.mount
hybrid-sleep.target                      sys-kernel-debug.mount
hypervkvpd.service                       syslog.socket
hypervvssd.service                       syslog.target.wants
initial-setup-graphical.service          sysstat.service
initial-setup-text.service               systemd-ask-password-console.path
initrd-cleanup.service                   systemd-ask-password-console.service
initrd-fs.target                         systemd-ask-password-plymouth.path
initrd-parse-etc.service                 systemd-ask-password-plymouth.service
initrd-root-fs.target                    systemd-ask-password-wall.path
initrd-switch-root.service               systemd-ask-password-wall.service
initrd-switch-root.target                [email protected]
initrd-switch-root.target.wants          systemd-binfmt.service
initrd.target                            systemd-fsck-root.service
initrd.target.wants                      [email protected]
initrd-udevadm-cleanup-db.service        systemd-halt.service
instperf.service                         systemd-hibernate.service
ip6tables.service                        systemd-hostnamed.service
ipsec.service                            systemd-hybrid-sleep.service
iptables.service                         systemd-initctl.service
irqbalance.service                       systemd-initctl.socket
iscsid.service                           systemd-journald.service
iscsid.socket                            systemd-journald.socket
iscsi.service                            systemd-journal-flush.service
iscsiuio.service                         systemd-kexec.service
iscsiuio.socket                          systemd-localed.service
kdump.service                            systemd-logind.service
kexec.target                             systemd-machined.service
kexec.target.wants                       systemd-modules-load.service
kmod-static-nodes.service                [email protected]
kpatch.service                           systemd-poweroff.service
ksm.service                              systemd-quotacheck.service
ksmtuned.service                         systemd-random-seed.service
libstoragemgmt.service                   systemd-readahead-collect.service
libvirtd.service                         systemd-readahead-done.service
libvirt-guests.service                   systemd-readahead-done.timer
lldpad.service                           systemd-readahead-drop.service
local-fs-pre.target                      systemd-readahead-replay.service
local-fs.target                          systemd-reboot.service
local-fs.target.wants                    systemd-remount-fs.service
lvm2-lvmetad.service                     systemd-shutdownd.service
lvm2-lvmetad.socket                      systemd-shutdownd.socket
lvm2-monitor.service                     systemd-suspend.service
[email protected]                     systemd-sysctl.service
machine.slice                            systemd-timedated.service
mdmonitor.service                        systemd-tmpfiles-clean.service
[email protected]                           systemd-tmpfiles-clean.timer
messagebus.service                       systemd-tmpfiles-setup-dev.service
microcode.service                        systemd-tmpfiles-setup.service
ModemManager.service                     systemd-udevd-control.socket
multipathd.service                       systemd-udevd-kernel.socket
multi-user.target                        systemd-udevd.service
multi-user.target.wants                  systemd-udev-settle.service
netcf-transaction.service                systemd-udev-trigger.service
NetworkManager-dispatcher.service        systemd-update-utmp-runlevel.service
NetworkManager.service                   systemd-update-utmp.service
NetworkManager-wait-online.service       systemd-user-sessions.service
network-online.target                    systemd-vconsole-setup.service
network-online.target.wants              system.slice
network.target                           system-update.target
nfs-blkmap.service                       [email protected]
nfs-idmap.service                        timers.target
nfs-lock.service                         timers.target.wants
nfslock.service                          time-sync.target
nfs-mountd.service                       tmp.mount
nfs-rquotad.service                      tuned.service
nfs-secure-server.service                udisks2.service
nfs-secure.service                       umount.target
nfs-server.service                       upower.service
nfs.service                              usbmuxd.service
nfs.target                               user.slice
nfs.target.wants                         var-lib-nfs-rpc_pipefs.mount
nss-lookup.target                        virtlockd.service
nss-user-lookup.target                   virtlockd.socket
ntpdate.service                          vmtoolsd.service
numad.service                            [email protected]
oddjobd.service                          wpa_supplicant.service

[[email protected] ~]# ls /etc/systemd/system/
basic.target.wants                           display-manager.service
bluetooth.target.wants                       getty.target.wants
dbus-org.bluez.service                       graphical.target.wants
dbus-org.fedoraproject.FirewallD1.service    multi-user.target.wants
dbus-org.freedesktop.Avahi.service           nfs.target.wants
dbus-org.freedesktop.ModemManager1.service   printer.target.wants
dbus-org.freedesktop.NetworkManager.service  sockets.target.wants
dbus-org.freedesktop.nm-dispatcher.service   spice-vdagentd.target.wants
default.target                               sysinit.target.wants
default.target.wants                         system-update.target.wants

查看所有已安装的服务:
[[email protected] ~]# systemctl list-unit-files
UNIT FILE                                   STATE  
proc-sys-fs-binfmt_misc.automount           static 
dev-hugepages.mount                         static 
dev-mqueue.mount                            static 
proc-fs-nfsd.mount                          static 
proc-sys-fs-binfmt_misc.mount               static 
sys-fs-fuse-connections.mount               static 
sys-kernel-config.mount                     static 
sys-kernel-debug.mount                      static 
tmp.mount                                   disabled
var-lib-nfs-rpc_pipefs.mount                static 
brandbot.path                               disabled
cups.path                                   enabled
systemd-ask-password-console.path           static 
systemd-ask-password-plymouth.path          static 
systemd-ask-password-wall.path              static 
session-1.scope                             static 
session-5.scope                             static 
abrt-ccpp.service                           enabled
abrt-oops.service                           enabled
abrt-pstoreoops.service                     disabled

二、使用单元
     一个单元配置文件可以为:系统服务(.service)、挂载点(.mount)、sockets(.sockets)、系统设备、交换分区/文件、启动目标(target)、文件系统路径、由systemd管理的计时器。如果想了解详细的信息,可以使用man 5 systemd.unit

使用systemctl控制单元时,通常使用单元文件的全名,包括扩展名,例如sshd.service。但是有些单元可以在systemctl中使用简写方式
1.如果无扩展名,systemctl默认把扩展名当作.service.例如netcfg和netcfg.service是等价的。
2.挂载点会自动转化为相应的.mount单元。例如/home等价于home.mount
3.设备会自动转化为相应的.device单元,所以/dev/sda2等价于dev-sda2.device

1.查看单元的运行状态
[[email protected] ~]# systemctl status NetworkManager
NetworkManager.service - Network Manager
   Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled)
   Active: active (running) since Sun 2014-06-15 13:36:34 CST; 46min ago
 Main PID: 1078 (NetworkManager)
   CGroup: /system.slice/NetworkManager.service
           └─1078 /usr/sbin/NetworkManager --no-daemon

2.停止某个单元
[[email protected] ~]# systemctl stop NetworkManager

3.启动某个单元
[[email protected] ~]# systemctl start NetworkManager


4.重新启动某个单元

[[email protected] ~]# systemctl restart NetworkManager

5.让单元重新读取配置
[[email protected] ~]# systemctl reload NetworkManager

6.查看单元是否配置为自动启动
[[email protected] ~]# systemctl is-enabled NetworkManager
enabled

7.开机自动激活某个单元

(1)关闭NetworkManager单元
[[email protected] ~]# systemctl disable NetworkManager
rm ‘/etc/systemd/system/multi-user.target.wants/NetworkManager.service‘
rm ‘/etc/systemd/system/dbus-org.freedesktop.NetworkManager.service‘
rm ‘/etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service‘

(2)查看NetworkManager单元开机是否自动启动
[[email protected] ~]# systemctl is-enabled NetworkManager
disabled

(3)设置NetworkManager单元为开机自启动
[[email protected] ~]# systemctl enable NetworkManager
ln -s ‘/usr/lib/systemd/system/NetworkManager.service‘ ‘/etc/systemd/system/dbus-org.freedesktop.NetworkManager.service‘
ln -s ‘/usr/lib/systemd/system/NetworkManager.service‘ ‘/etc/systemd/system/multi-user.target.wants/NetworkManager.service‘
ln -s ‘/usr/lib/systemd/system/NetworkManager-dispatcher.service‘ ‘/etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service‘

(4)查看是否设置成功
[[email protected] ~]# systemctl is-enabled NetworkManager
enabled

8.重新载入systemd,扫描新的或有变动的单元
[[email protected] ~]# systemctl daemon-reload

RHEL7下的systemd,布布扣,bubuko.com

时间: 2024-10-16 02:09:16

RHEL7下的systemd的相关文章

RHEL7下Nginx虚拟主机配置(三)

RHEL7下Nginx虚拟主机配置 前面两节讲过安装和配置文件了,这里写出配置文件,大家根据内容修改配置文件就可以了. http { server{ listen    80; server_name   192.168.1.20; access_log        log/192.168.1.20 main; location / { index    index.html; root      /application/nginx/html/; } } server{ linsten  8

RHEL7下Nginx负载均衡配置(四)

RHEL7下Nginx负载均衡配置 前面两节讲过安装和配置文件了,这里写出配置文件,大家根据内容修改配置文件就可以了. http { upstream   myserver{ server 192.168.1.21:80 weight=2 max_fails=3 fail_timeout=20s; server 192.168.1.22:80 weight=3 max_fails=3 fail_timeout=20s; server 192.168.1.23:80 weight=4 max_fa

RHEL7下的Nginx的配置安装

RHEL7下的Nginx的配置安装 一.    安装前的准备 1.      建立RHEL的yum存储库 #vim /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/rhel/7/$basearch/ gpgcheck=0 enabled=1 2.      编译安装配置参数 --help#打印这个信息   --prefix=PATH#设置安装路径   --sbin-path

RHEL7下Nginx配置文件详解(二)

RHEL7下Nginx配置文件详解 全局配置 #user  nobody nobody;//指定Nginx进程运行用户以及用户组. worker_processes  1;//开启的进程数. #error_log  logs/error.log;//定义全局错误日志 #error_log  logs/error.log  notice; //定义全局错误日志 #error_log  logs/error.log  info; //定义全局错误日志 #pid        logs/nginx.p

RHEL7下PXE+NFS+Kickstart无人值守安装操作系统

1.配置yum源 vim /etc/yum.repos.d/development.repo [development] name=yum server baseurl=file:///mnt enabled=1 gpgcheck=0 2.挂载光盘 mount /dev/sr0 /mnt 3.安装相关软件包 yum install dhcp syslinux xinetd tftp-server 4.配置dhcp vim /etc/dhcp/dhcpd.conf 5.添加内容 subnet 19

apache-tomcat7 在rhel7下的安装记录

tomcat7官方下载地址:http://tomcat.apache.org/download-70.cgi 最新版本:7.0.73 安装tomcat之前需安装jdk 下载地址:http://www.oracle.com/technetwork/cn/java/javase/downloads/jdk8-downloads-2133151-zhs.html   #下载rpm包安装 安装jdk步骤: [[email protected] ~]# rpm -ivh  jdk-8u102-linux-

RHEL7下使用Nexus搭建Maven私服

写在前面 在之前使用ant的时候,工程中是通过建立一个lib目录来存放依赖的jar包,每建一个工程都要建立一个lib,需要将这些lib包不停的copy.最麻烦的是在我们是用svn对lib进行版本管理,就比如,如果有其中一个jar包升级,就需要把所有工程lib目录下的jar包更新,之后提交到svn上.同样的,之前管理多工程之间的依赖也比较麻烦,所以打算使用Maven对项目的jar包进行管理. 在网上查阅了一些资料,也加上平时的一些基本认知(之前比较小白),决定使用Maven + Nexus私服这个

CentOS 7下关于systemd的一些唠叨话一:systemd的优缺点

摘要 近年来,Linux 系统的 init 进程经历了两次重大的演进,传统的 sysvinit 已经逐渐淡出历史舞台,新的 UpStart 和 systemd 各有特点,越来越多的 Linux 发行版采纳了 systemd.本文简要介绍了这三种 init 系统的使用和原理,每个 Linux 系统管理员和系统软件开发者都应该了解它们,以便更好地管理系统和开发应用.本文是系列的第 3 部分,主要讲述 systemd 的特点和使用. CentOS/RHEL 7 systemd 目录[-] System

Centos7下的systemd管理

systemd简介 Systemd是由红帽公司的一名叫做Lennart Poettering的员工开发,systemd是Linux系统中最新的初始化系统(init),它主要的设计目的是克服Sys V 固有的缺点,提高系统的启动速度,systemd和upstart是竞争对手,ubantu上使用的是upstart的启动方式,centos7上使用systemd替换了Sys V,Systemd目录是要取代Unix时代依赖一直在使用的init系统,兼容SysV和LSB的启动脚本,而且能够在进程启动中更有效