开发手册 欢迎您!
软件开发者资料库

Linux管理员 - 使用systemctl的资源管理

使用systemctl的Linux管理资源管理 - 从简单和简单的步骤学习Linux管理,从基本概念开始,包括CentOS概述,基本CentOS Linux命令,文件/文件夹管理,用户管理,配额管理,系统服务启动和停止,资源使用systemctl进行管理,使用crgoups进行资源管理,进程管理,防火墙设置,在CentOS Linux中配置PHP,使用CentOS Linux设置Python,在CentOS Linux上配置Ruby,为CentOS Linux设置Perl,安装和配置Open LDAP,创建SSL证书,安装Apache Web Server CentOS 7,在CentOS 7上安装MySQL,设置Postfix MTA和IMAP / POP3,安装匿名FTP,远程管理,CentOS中的流量监控,日志管理,备份和恢复,系统更新,Shell脚本,包管理,卷管理。

systemctl 是用于控制systemd的实用程序. systemctl为CentOS管理员提供了对systemd执行大量操作的能力,包括 :

  • 配置系统单位

  • 获取systemd untis的状态

  • 启动和停止服务

  • 启用/禁用运行时的systemd服务等.

systemctl 的命令语法非常基本,但可以与开关和选项纠缠在一起.我们将介绍管理CentOS Linux所需的 systemctl 最重要的功能.

Basic systemctl syntax: systemctl [OPTIONS] COMMAND [NAME]

以下是与 systemctl :

  • start

  • stop

  • restart

  • reload

  • 状态

  • is-active

  • list-units

  • 启用

  • 禁用

  • cat

  • show

我们已经讨论过开始停止重新加载重启使用systemctl启用禁用.让我们回顾一下剩下的常用命令.

status

以最简单的形式,status命令可用于查看系统状态整体;

[root@localhost rdc]# systemctl status  ● localhost.localdomain   State: running   Jobs: 0 queued  Failed: 0 units   Since: Thu 2017-01-19 19:14:37 EST; 4h 5min ago CGroup: /        ├─1 /usr/lib/systemd/systemd --switched-root --system --deserialize 21        ├─user.slice        │ └─user-1002.slice        │   └─session-1.scope        │     ├─2869 gdm-session-worker [pam/gdm-password]        │     ├─2881 /usr/bin/gnome-keyring-daemon --daemonize --login        │     ├─2888 gnome-session --session gnome-classic        │     ├─2895 dbus-launch --sh-syntax --exit-with-session

以上输出已经压缩.在现实世界中 systemctl状态将输出大约100行的treed进程状态.

假设我们要检查防火墙服务的状态 :

[root@localhost rdc]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2017-01-19 19:14:55 EST; 4h 12min ago  Docs: man:firewalld(1) Main PID: 825 (firewalld) CGroup: /system.slice/firewalld.service        └─825 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

如您所见,我们的防火墙服务目前处于活动状态且已经结束4小时.

list-units

list-units命令允许我们列出某种类型的所有单位.让我们检查由 systemd管理的套接字 :

[root@localhost]# systemctl list-units --type=socket UNIT                         LOAD     ACTIVE     SUB     DESCRIPTION     avahi-daemon.socket          loaded   active  running    Avahi mDNS/DNS-SD Stack Activation Socket cups.socket                  loaded   active  running    CUPS Printing Service Sockets dbus.socket                  loaded   active  running    D-Bus System Message Bus Socket dm-event.socket              loaded   active  listening  Device-mapper event daemon FIFOs iscsid.socket                loaded   active  listening  Open-iSCSI iscsid Socketiscsiuio.socket              loaded   active  listening  Open-iSCSI iscsiuio Socket lvm2-lvmetad.socket          loaded   active  running    LVM2 metadata daemon socket lvm2-lvmpolld.socket         loaded   active  listening  LVM2 poll daemon socket rpcbind.socket               loaded   active  listening  RPCbind Server Activation Socket systemd-initctl.socket       loaded   active  listening  /dev/initctl Compatibility Named Pipe systemd-journald.socket      loaded   active  running    Journal Socket systemd-shutdownd.socket     loaded   active  listening  Delayed Shutdown Socket systemd-udevd-control.socket loaded   active  running    udev Control Socket systemd-udevd-kernel.socket  loaded   active  running    udev Kernel Socket virtlockd.socket             loaded   active  listening  Virtual machine lock manager socket virtlogd.socket              loaded   active  listening  Virtual machine log manager socket

现在让我们检查当前正在运行的服务 :

[root@localhost rdc]# 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 accounts-daemon.service   loaded   active   running   Accounts Service 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

是活跃的

is-active 命令是systemctl命令的一个示例,用于返回单元的状态信息.

[root@localhost rdc]# systemctl is-active ksm.service active

cat

cat  systemctl cat .

[root@localhost]# systemctl cat firewalld # /usr/lib/systemd/system/firewalld.service[Unit] Description=firewalld - dynamic firewall daemon Before=network.target Before=libvirtd.service Before = NetworkManager.service After=dbus.service After=polkit.service Conflicts=iptables.service ip6tables.service ebtables.service ipset.service Documentation=man:firewalld(1)[Service] EnvironmentFile = -/etc/sysconfig/firewalld ExecStart = /usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS ExecReload = /bin/kill -HUP $MAINPID # supress to log debug and error output also to /var/log/messages StandardOutput = null StandardError = nullType = dbus BusName = org.fedoraproject.FirewallD1[Install] WantedBy = basic.target Alias = dbus-org.fedoraproject.FirewallD1.service[root@localhost]#

现在我们更详细地探讨了 systemd systemctl ,让我们用它来管理 cgroups 控制组中的资源