暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

1535.Linux 6、7、8对比及systemctl命令详解

原创 张鹏 2023-07-05
281

1535.Linux 6、7、8对比及systemctl命令详解
centos6 与centos7对比
sysvinit技术 VS systemd技术
网卡名称变更
centos7 与centos8对比
内核版本
网络时间同步
支持最大的文件
默认的网络数据包过滤
默认的数据库
默认版本的控制系统
编程语言版本
centos6 与centos7对比
sysvinit技术 VS systemd技术
systemd相对于sysvinit的对比

和 Sysvinit 兼容,降低迁移成本;
要优点:并行启动
d 为1的进程是systemd

centos6使用sysvinit技术操作命令:
#服务启动、重启、停止、状态
service httpd [start|restart|stop|status]
#服务开机启动查询
chkconfig list
#开启关闭服务开机启动
chkconfig httpd [on|off]

entos7使用systemd技术操作命令:
#服务启动、重启、停止、状态
systecmtl [start|restart|stop|status] httpd.service
#服务开机启动查询
systemctl list-unit-files --type=service
#开启关闭服务开机启动
systemctl [enable|disable] httpd.service

网卡名称变更
Linux 的网络接口名称为 的网络接口名称为 eth0 、eth1…

而CentOS7,是根据网卡的插槽命名的,如果想使用eth0,我们也是可以更改的,

在安装系统的时候配置:

修改内核选项, net.ifnames =0 biosdevname =0

8和7的区别对比分享

目录
红帽RHEL8与RHEL7的区别

  1. 红帽RHEL8和RHEL7功能区别对比
    1.1 默认的文件系统
    RHEL8与RHEL7都是采用XFS
    1.2 RHEL8与RHEL7的内核版本分别是多少
    关于内核版本,RHEL8和7的区别如下:
    RHEL8采用4.18.0-x
    RHEL7采用3.10-0-x
    1.3 内核代码名字
    关于内核代码,RHEL8和7的区别如下:
    RHEL8采用2019-05-07 (Kernel Version 4.18.0-80)
    RHE7采用2014-06-09 (Kernel Version 3.10.0-123)
    1.4 标准/默认的仓库频道
    关于仓库频道,RHEL8和7的区别如下:
    RHEL8
    Repo ID: rhel-8-for-x86_64-appstream-rpms
    Repo Name: Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)
    Repo ID: rhel-8-for-x86_64-baseos-rpms
    Repo Name: Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)
    RHEL7
    Repo ID: rhel-7-server-rpms
    Repo Name: Red Hat Enterprise Linux 7 Server (RPMs)

1.5 网络时间同步
关于网络时间同步,RHEL8和7的区别如下:
RHEL8
只使用Chronyd,不支持NTP部署。
RHEL7
Chronyd与NTP两者都支持
1.6 支持最大的文件
关于支持最大的文件,RHEL8和7的区别如下:
RHEL8
XFS文件系统支持的最大文件大小已从500 TiB增加到1024 TiB。
(此最大文件大小仅适用于64位机器。Red Hat Enterprise Linux不支持32位机器上的XFS.)
RHEL7
最大. (单独) 文件大小= 500TiB
最大. 文件系统大小 = 500TiB
1.7 软件包管理
关于软件包管理,RHEL8和7的区别如下:
红帽8
包管理由DNF (YUMv4)完成。
yum4基于DNF技术,yum4命令提供了与早期版本中使用的Yum v3的向后兼容性。yum命令只是到dnf的一个符号链接。
红帽7
yum基于3.0.x版本
1.8 最大支持的内存
关于最大支持的内存,RHEL8和7的区别如下:
红帽8
24TB,64位架构
红帽7:
只支持12TB
1.9 默认的网络数据包过滤
关于默认的网络数据包过滤,RHEL8和7的区别如下:
RHEL8使用nftables取代了iptables框架
nftables是默认的网络包过滤,它取代了以前的iptables框架。firewalld守护进程现在使用nftables作为默认后端。
这将取代以前使用的“iptables”、“ip6tables”、“arptables”和“ebtables”工具。“nftables”确实为IPv4和IPv6协议提供了一个单一的框架。
而RHEL7 firewalld守护进程使用iptables作为其默认后端。
1.10 默认的数据库
关于默认的数据库,RHEL8和7的区别如下:
RHEL8默认支持的数据库:
MySQL 8.0
MariaDB 10.3
PostgreSQL 10 and PostgreSQL 9.6
Redis 5.0
MariaDB是Red Hat Enterprise Linux 7中MySQL的默认实现
1.11 支持的硬件架构
关于支持的硬件架构,RHEL8和7的区别如下:
RHEL8支持以下硬件架构
AMD and Intel 64-bit architectures
The 64-bit ARM architecture
IBM Power Systems, Little Endian
IBM Z
RHEL7支持以下硬件架构:
64-bit AMD
64-bit Intel
IBM POWER7
IBM System z
1.12 可供安装的ISO镜像类型
关于可供安装的ISO镜像类型,RHEL8和7的区别如下:
RHEL 8可以使用以下类型的ISO镜像安装:
Binary(二进制) DVD ISO
Boot ISO
在RHEL7中,可以使用以下可用的ISO镜像进行安装:
Boot ISO
Binary(二进制) DVD ISO
Supplementary(追加的) Binary DVD
1.13 默认情况下的Cockpit web控制台的安装状态
关于默认情况下的Cockpit web控制台的安装状态,RHEL8和7的区别如下:
在RHEL8中,Cockpit是默认安装和可用的。这将在非最小模式下自动安装,并在防火墙中启用所需端口。
Cockpit提供了一个增强的框架,可以用来访问/编辑/更改许多系统设置。这提供了通过web接口的访问,可以使用浏览器访问url地址http://:9090进行管理。
在RHEL7系统中,Cockpit默认情况下没有安装,需要通过启用extra和optional存储库通道来安装。
1.14 默认虚拟机管理
关于默认虚拟机管理,RHEL8和7的区别如下:
在RHEL8系统中,默认情况下,它由Cockpit管理。如果需要,还可以安装virt-manager。
而在RHEL7系统中virt-manager将用于基于KVM的虚拟系统管理。
1.15 RMP版本的改进
关于RMP版本的改进,RHEL8和7的区别如下:
Red Hat Enterprise Linux 8是用RPM 4.14发布的。现在,RPM在开始安装之前验证整个包的内容。
这有很多改进,其中一些值得注意的功能是:
debuginfo包可以并行安装
支持弱依赖关系
支持丰富的或布尔依赖
支持封装文件超过4 GB的大小
支持文件触发器
构建在RHEL8上的包在压缩负载上使用一个新的SHA-256散列。
而Red Hat Enterprise Linux 7是用RPM 4.11发布的。在RHEL7上,RPM实用程序在解压时验证单个文件的有效负载内容。
1.16 CUPS日志
关于CUPS日志,RHEL8和7的区别如下:
RHEL8所有类型的CUPS日志都与来自其他程序的日志一起集中记录在systemd journald守护进程中。要访问CUPS日志,请使用“journalctl -u CUPS”命令。
而RHEL7系统上,CUPS日志被存储中 /var/log/cups directory.
nobody用户替换nfsnobody
rhel8系统上,nobody和nfsnobody用户和组合并到nobodyID(65534)中。
在Red Hat Enterprise Linux 7中,有:
ID为99的nobody用户和组
nfsnobody用户和组对的ID为65534,这也是默认的内核溢出ID。
1.17 默认版本的控制系统
关于默认版本的控制系统,RHEL8和7的区别如下:
RHEL 8提供以下版本控制系统:
Git 2.18
Mercurial 4.8
Subversion 1.10
并发版本系统(CVS)和版本控制系统(RCS)在RHEL8中都不可用。
而Red Hat Enterprise Linux 7与三个最流行的开源修订控制系统一起发布:Git、SVN和CVS。
1.18 编程语言版本
关于编程语言版本,RHEL8和7的区别如下:
RHEL8新版本编程语言
Python 3
PHP 7.2
Ruby 2.5
Node.js 10
而RHEL7支持以下编辑语言
Python 2 ( 2.7.X)
PHP 5.4
Ruby 2.0.0
1.19 关于容器技术的支持
关于容器技术的支持,RHEL8和7的区别如下:
Docker不包括在RHEL 8.0中。使用容器时,需要使用podman、buildah、skopeo和runc工具。
podman工具已经作为一个完全支持的特性发布了。
Docker和Docker Registry是Red Hat Enterprise Linux 7中的Extras订阅频道的一部分。
1.20 开发工具支持
关于开发工具支持,RHEL8和7的区别如下:
RHEL 8提供OpenJDK 11、OpenJDK 8、IcedTea-Web和各种Java工具,如Ant、Maven或Scala。
在RHEL7中,OpenJDK8用作默认的Java开发工具包(JDK),而Java 8用作默认的Java版本。
1.21 NFS配置对比
关于NFS配置对比,RHEL8和7的区别如下:
RHEL8的NFS配置文件是/etc/ NFS .conf。
当从RHEL7升级时,Red Hat Enterprise Linux 8尝试自动将所有选项从/etc/sysconfig/nfs转换为/etc/nfs。并不再支持NFS / UDP。
而RHEL7中,默认的NFS配置文件是/etc/sysconfig/ NFS
1.22 默认的显示服务器
关于默认的显示服务器,RHEL8和7的区别如下:
在RHEL 8中,Gnome display Manager使用的默认显示服务器是Wayland。
X.org服务器是RHEL 7中的默认显示服务器
2. RHEL8额外新功能新特性
2.1 elevator内核命令行参数被废弃
早期的RHEL版本中使用了elevator内核命令行参数来设置所有设备的磁盘调度程序。在RHEL 8中,该参数被弃用。
上游Linux内核已经取消了对elevator参数的支持,但是出于兼容性的原因,RHEL 8中仍然可以使用它。
2.2 网络脚本被废弃
在RHEL 8中,网络脚本在默认情况下不可用。有一个新版本的ifup和ifdown正在使用,这将需要NetworkManager守护进程运行,并在后端使用nmcli。
如果需要早期的网络脚本,则必须安装“network-scripts”包。
2.3 新内核支持5级paging
在早期版本中,有4级分页实现,可以处理48/46位虚拟/物理地址,并且物理总线上限为64TB。在即将推出的Intel处理器中,这些限制已经扩展到57/52位的虚拟/物理内存寻址,具有128 PiB的虚拟地址空间和4 PB的物理内存容量。
2.4 Anaconda支持RHEL 8中的系统目标
以前,Anaconda没有向订阅管理器提供系统用途信息。在Red Hat Enterprise Linux 8.0中,您可以在安装期间使用Anaconda的system purpose窗口或Kickstart的syspurpose命令设置系统的预期目标。
2.5 CodeReady Linux构建器仓库
有一个CodeReady Linux构建器存储库,可用于所有RHEL订阅。这为开发人员提供了额外的包。CodeReady Linux构建器存储库中包含的包不支持生产使用。
2.6 改进版本的OpenSSH
OpenSSH的版本是7.8p1,与早期版本相比有很多改进。其中一些是:
不再支持SSH version 1.
默认不开启DNS支持.
最小可接受RSA密钥大小设置为1024位.
移除 ‘Blowfish’, ‘CAST’, ‘RC4’ ciphers.
默认关闭DSA 公钥算法.
2.7 RHEL8中不支持数字用户名和组名
useradd和groupadd命令不允许用户名和组名完全由数字字符组成。这是RHEL7中不支持的特性,现在RHEL8完全不支持它。
2.8 默认情况下,securetty现在是禁用的
默认情况下禁用了securetty PAM模块,并且从RHEL8中删除了/etc/securetty文件。
2.9 改进的TCP网络栈
RHEL 8拥有TCP网络栈版本4.18,可以提供更高的性能、更好的可伸缩性和更稳定的性能。性能得到了提高,特别是在繁忙的TCP服务器与高进入连接速率。
除了新的TCP栈之外,还有两种新的TCP拥塞算法。在大多数情况下,BBR和NV可以提供比cubic更低的延迟和更好的吞吐量。
2.10 高可用性(HA)
在Red Hat Enterprise Linux 8中,pcs完全支持Corosync 3集群引擎和用于集群通信的Kronosnet (knet)网络抽象层。无法将集群节点从RHEL7就地升级到RHEL8。
2.11 lvmlockd取代了clvmd
用于管理共享存储逻辑卷的clvmd已被删除,取而代之的是lvmlockd(lvm lock 守护进程)

systemctl命令是系统服务管理器指令,它实际上将 service 和 chkconfig 这两个命令组合到一起。
任务 旧指令 新指令
使某服务自动启动 chkconfig --level 3 httpd on systemctl enable httpd.service
使某服务不自动启动 chkconfig --level 3 httpd off systemctl disable httpd.service
检查服务状态 service httpd status systemctl status httpd.service (服务详细信息) systemctl is-active httpd.service(仅显示是否 Active)
显示所有已启动的服务 chkconfig --list systemctl list-units --type=service
启动某服务 service httpd start systemctl start httpd.service
停止某服务 service httpd stop systemctl stop httpd.service
重启某服务 service httpd restart systemctl restart httpd.service

1.启动nfs服务 systemctl start nfs-server.service
2.设置开机自启动 systemctl enable nfs-server.service
3.停止开机自启动 systemctl disable nfs-server.service
4.查看服务当前状态 systemctl status nfs-server.service
5.重新启动某服务 systemctl restart nfs-server.service
6.查看所有已启动的服务 systemctl list -units --type=service
7.开启防火墙22端口 iptables -I INPUT -p tcp --dport 22 -j accept

如果仍然有问题,就可能是SELinux导致的 关闭SElinux:
修改/etc/selinux/config文件中的SELINUX=””为disabled,然后重启。

彻底关闭防火墙:
sudo systemctl status firewalld.service
sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service

简单总结
启动一个服务: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;echo $?
查看已启动的服务列表:systemctl list-unit-files|grep enabled
说明:启用服务就是在当前“runlevel”的配置文件目录/etc/systemd/system/multi-user.target.wants/里,建立/usr/lib/systemd/system里面对应服务配置文件的软链接;禁用服务就是删除此软链接。

Systemctl是一个systemd工具,主要负责控制systemd系统和服务管理器。
Systemd是一个系统管理守护进程、工具和库的集合,用于取代System V初始进程。Systemd的功能是用于集中管理和配置类UNIX系统。
在Linux生态系统中,Systemd被部署到了大多数的标准Linux发行版中,只有为数不多的几个发行版尚未部署。Systemd通常是所有其它守护进程的父进程,但并非总是如此。
本文旨在阐明在运行systemd的系统上“如何控制系统和服务”。
Systemd初体验和Systemctl基础

  1. 首先检查你的系统中是否安装有systemd并确定当前安装的版本

systemctl --version

systemd 215
+PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR
上例中很清楚地表明,我们安装了215版本的systemd。
2. 检查systemd和systemctl的二进制文件和库文件的安装位置

whereis systemd

systemd: /usr/lib/systemd /etc/systemd /usr/share/systemd /usr/share/man/man1/systemd.1.gz

whereis systemctl

systemctl: /usr/bin/systemctl /usr/share/man/man1/systemctl.1.gz
3. 检查systemd是否运行

ps -eaf | grep [s]ystemd

root 1 0 0 16:27 ? 00:00:00 /usr/lib/systemd/systemd --switched-root --system --deserialize 23
root 444 1 0 16:27 ? 00:00:00 /usr/lib/systemd/systemd-journald
root 469 1 0 16:27 ? 00:00:00 /usr/lib/systemd/systemd-udevd
root 555 1 0 16:27 ? 00:00:00 /usr/lib/systemd/systemd-logind
dbus 556 1 0 16:27 ? 00:00:00 /bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
注意:systemd是作为父进程(PID=1)运行的。在上面带(-e)参数的ps命令输出中,选择所有进程,(-a)选择除会话前导外的所有进程,并使用(-f)参数输出完整格式列表(即 -eaf)。
也请注意上例中后随的方括号和例子中剩余部分。方括号表达式是grep的字符类表达式的一部分。
4. 分析systemd启动进程

systemd-analyze

Startup finished in 487ms (kernel) + 2.776s (initrd) + 20.229s (userspace) = 23.493s
5. 分析启动时各个进程花费的时间

systemd-analyze blame

8.565s mariadb.service
7.991s webmin.service
6.095s postfix.service
4.311s httpd.service
3.926s firewalld.service
3.780s kdump.service
3.238s tuned.service
1.712s network.service
1.394s lvm2-monitor.service
1.126s systemd-logind.service

6. 分析启动时的关键链

systemd-analyze critical-chain

The time after the unit is active or started is printed after the “@” character.
The time the unit takes to start is printed after the “+” character.
multi-user.target @20.222s
└─mariadb.service @11.657s +8.565s
└─network.target @11.168s
└─network.service @9.456s +1.712s
└─NetworkManager.service @8.858s +596ms
└─firewalld.service @4.931s +3.926s
└─basic.target @4.916s
└─sockets.target @4.916s
└─dbus.socket @4.916s
└─sysinit.target @4.905s
└─systemd-update-utmp.service @4.864s +39ms
└─auditd.service @4.563s +301ms
└─systemd-tmpfiles-setup.service @4.485s +69ms
└─rhel-import-state.service @4.342s +142ms
└─local-fs.target @4.324s
└─boot.mount @4.286s +31ms
└─systemd-fsck@dev-disk-by\x2duuid-79f594ad\x2da332\x2d4730\x2dbb5f\x2d85d19608096
└─dev-disk-by\x2duuid-79f594ad\x2da332\x2d4730\x2dbb5f\x2d85d196080964.device @4
重要:Systemctl接受服务(.service),挂载点(.mount),套接口(.socket)和设备(.device)作为单元。
7. 列出所有可用单元

systemctl list-unit-files

UNIT FILE STATE
proc-sys-fs-binfmt_misc.automount static
dev-hugepages.mount static
dev-mqueue.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
brandbot.path disabled

8. 列出所有运行中单元

systemctl list-units

UNIT LOAD ACTIVE SUB DESCRIPTION
proc-sys-fs-binfmt_misc.automount loaded active waiting Arbitrary Executable File Formats File Syste
sys-devices-pc…0-1:0:0:0-block-sr0.device loaded active plugged VBOX_CD-ROM
sys-devices-pc…:00:03.0-net-enp0s3.device loaded active plugged PRO/1000 MT Desktop Adapter
sys-devices-pc…00:05.0-sound-card0.device loaded active plugged 82801AA AC’97 Audio Controller
sys-devices-pc…:0:0-block-sda-sda1.device loaded active plugged VBOX_HARDDISK
sys-devices-pc…:0:0-block-sda-sda2.device loaded active plugged LVM PV Qzyo3l-qYaL-uRUa-Cjuk-pljo-qKtX-VgBQ8
sys-devices-pc…0-2:0:0:0-block-sda.device loaded active plugged VBOX_HARDDISK
sys-devices-pl…erial8250-tty-ttyS0.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS0
sys-devices-pl…erial8250-tty-ttyS1.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS1
sys-devices-pl…erial8250-tty-ttyS2.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS2
sys-devices-pl…erial8250-tty-ttyS3.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS3
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

9. 列出所有失败单元

systemctl --failed

UNIT LOAD ACTIVE SUB DESCRIPTION
kdump.service loaded failed failed Crash recovery kernel arming
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’.
10. 检查某个单元(如 cron.service)是否启用

systemctl is-enabled crond.service

enabled
11. 检查某个单元或服务是否运行

systemctl status firewalld.service

firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled)
Active: active (running) since Tue 2015-04-28 16:27:55 IST; 34min ago
Main PID: 549 (firewalld)
CGroup: /system.slice/firewalld.service
└─549 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
Apr 28 16:27:51 tecmint systemd[1]: Starting firewalld - dynamic firewall daemon…
Apr 28 16:27:55 tecmint systemd[1]: Started firewalld - dynamic firewall daemon.
使用Systemctl控制并管理服务
12. 列出所有服务(包括启用的和禁用的)

systemctl list-unit-files --type=service

UNIT FILE STATE
arp-ethers.service disabled
auditd.service enabled
autovt@.service disabled
blk-availability.service disabled
brandbot.service static
collectd.service disabled
console-getty.service disabled
console-shell.service disabled
cpupower.service disabled
crond.service enabled
dbus-org.fedoraproject.FirewallD1.service enabled

13. Linux中如何启动、重启、停止、重载服务以及检查服务(如 httpd.service)状态

systemctl start httpd.service

systemctl restart httpd.service

systemctl stop httpd.service

systemctl reload httpd.service

systemctl status httpd.service

httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
Active: active (running) since Tue 2015-04-28 17:21:30 IST; 6s ago
Process: 2876 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
Main PID: 2881 (httpd)
Status: “Processing requests…”
CGroup: /system.slice/httpd.service
├─2881 /usr/sbin/httpd -DFOREGROUND
├─2884 /usr/sbin/httpd -DFOREGROUND
├─2885 /usr/sbin/httpd -DFOREGROUND
├─2886 /usr/sbin/httpd -DFOREGROUND
├─2887 /usr/sbin/httpd -DFOREGROUND
└─2888 /usr/sbin/httpd -DFOREGROUND
Apr 28 17:21:30 tecmint systemd[1]: Starting The Apache HTTP Server…
Apr 28 17:21:30 tecmint httpd[2881]: AH00558: httpd: Could not reliably determine the server’s fully q…ssage
Apr 28 17:21:30 tecmint systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
注意:当我们使用systemctl的start,restart,stop和reload命令时,我们不会从终端获取到任何输出内容,只有status命令可以打印输出。
14. 如何激活服务并在启动时启用或禁用服务(即系统启动时自动启动服务)

systemctl is-active httpd.service

systemctl enable httpd.service

systemctl disable httpd.service

  1. 如何屏蔽(让它不能启动)或显示服务(如 httpd.service)

systemctl mask httpd.service

ln -s ‘/dev/null’ ‘/etc/systemd/system/httpd.service’

systemctl unmask httpd.service

rm ‘/etc/systemd/system/httpd.service’
16. 使用systemctl命令杀死服务

systemctl kill httpd

systemctl status httpd

httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
Active: failed (Result: exit-code) since Tue 2015-04-28 18:01:42 IST; 28min ago
Main PID: 2881 (code=exited, status=0/SUCCESS)
Status: “Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec”
Apr 28 17:37:29 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti…bled.
Apr 28 17:37:29 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti…bled.
Apr 28 17:37:39 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti…bled.
Apr 28 17:37:39 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti…bled.
Apr 28 17:37:49 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti…bled.
Apr 28 17:37:49 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti…bled.
Apr 28 17:37:59 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti…bled.
Apr 28 17:37:59 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti…bled.
Apr 28 18:01:42 tecmint systemd[1]: httpd.service: control process exited, code=exited status=226
Apr 28 18:01:42 tecmint systemd[1]: Unit httpd.service entered failed state.
Hint: Some lines were ellipsized, use -l to show in full.
使用Systemctl控制并管理挂载点
17. 列出所有系统挂载点

systemctl list-unit-files --type=mount

UNIT FILE STATE
dev-hugepages.mount static
dev-mqueue.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
18. 挂载、卸载、重新挂载、重载系统挂载点并检查系统中挂载点状态

systemctl start tmp.mount

systemctl stop tmp.mount

systemctl restart tmp.mount

systemctl reload tmp.mount

systemctl status tmp.mount

tmp.mount - Temporary Directory
Loaded: loaded (/usr/lib/systemd/system/tmp.mount; disabled)
Active: active (mounted) since Tue 2015-04-28 17:46:06 IST; 2min 48s ago
Where: /tmp
What: tmpfs
Docs: man:hier(7)
http://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
Process: 3908 ExecMount=/bin/mount tmpfs /tmp -t tmpfs -o mode=1777,strictatime (code=exited, status=0/SUCCESS)
Apr 28 17:46:06 tecmint systemd[1]: Mounting Temporary Directory…
Apr 28 17:46:06 tecmint systemd[1]: tmp.mount: Directory /tmp to mount over is not empty, mounting anyway.
Apr 28 17:46:06 tecmint systemd[1]: Mounted Temporary Directory.
19. 在启动时激活、启用或禁用挂载点(系统启动时自动挂载)

systemctl is-active tmp.mount

systemctl enable tmp.mount

systemctl disable tmp.mount

  1. 在Linux中屏蔽(让它不能启用)或可见挂载点

systemctl mask tmp.mount

ln -s ‘/dev/null’ ‘/etc/systemd/system/tmp.mount’

systemctl unmask tmp.mount

rm ‘/etc/systemd/system/tmp.mount’
使用Systemctl控制并管理套接口
21. 列出所有可用系统套接口

systemctl list-unit-files --type=socket

UNIT FILE STATE
dbus.socket static
dm-event.socket enabled
lvm2-lvmetad.socket enabled
rsyncd.socket disabled
sshd.socket disabled
syslog.socket static
systemd-initctl.socket static
systemd-journald.socket static
systemd-shutdownd.socket static
systemd-udevd-control.socket static
systemd-udevd-kernel.socket static
11 unit files listed.
22. 在Linux中启动、重启、停止、重载套接口并检查其状态

systemctl start cups.socket

systemctl restart cups.socket

systemctl stop cups.socket

systemctl reload cups.socket

systemctl status cups.socket

cups.socket - CUPS Printing Service Sockets
Loaded: loaded (/usr/lib/systemd/system/cups.socket; enabled)
Active: active (listening) since Tue 2015-04-28 18:10:59 IST; 8s ago
Listen: /var/run/cups/cups.sock (Stream)
Apr 28 18:10:59 tecmint systemd[1]: Starting CUPS Printing Service Sockets.
Apr 28 18:10:59 tecmint systemd[1]: Listening on CUPS Printing Service Sockets.
23. 在启动时激活套接口,并启用或禁用它(系统启动时自启动)

systemctl is-active cups.socket

systemctl enable cups.socket

systemctl disable cups.socket

  1. 屏蔽(使它不能启动)或显示套接口

systemctl mask cups.socket

ln -s ‘/dev/null’ ‘/etc/systemd/system/cups.socket’

systemctl unmask cups.socket

rm ‘/etc/systemd/system/cups.socket’
服务的CPU利用率(分配额)
25. 获取当前某个服务的CPU分配额(如httpd)

systemctl show -p CPUShares httpd.service

CPUShares=1024
注意:各个服务的默认CPU分配份额=1024,你可以增加/减少某个进程的CPU分配份额。
26. 将某个服务(httpd.service)的CPU分配份额限制为2000 CPUShares/

systemctl set-property httpd.service CPUShares=2000

systemctl show -p CPUShares httpd.service

CPUShares=2000
注意:当你为某个服务设置CPUShares,会自动创建一个以服务名命名的目录(如 httpd.service),里面包含了一个名为90-CPUShares.conf的文件,该文件含有CPUShare限制信息,你可以通过以下方式查看该文件:

vi /etc/systemd/system/httpd.service.d/90-CPUShares.conf

[Service]
CPUShares=2000
27. 检查某个服务的所有配置细节

systemctl show httpd

Id=httpd.service
Names=httpd.service
Requires=basic.target
Wants=system.slice
WantedBy=multi-user.target
Conflicts=shutdown.target
Before=shutdown.target multi-user.target
After=network.target remote-fs.target nss-lookup.target systemd-journald.socket basic.target system.slice
Description=The Apache HTTP Server
LoadState=loaded
ActiveState=active
SubState=running
FragmentPath=/usr/lib/systemd/system/httpd.service

28. 分析某个服务(httpd)的关键链

systemd-analyze critical-chain httpd.service

The time after the unit is active or started is printed after the “@” character.
The time the unit takes to start is printed after the “+” character.
httpd.service +142ms
└─network.target @11.168s
└─network.service @9.456s +1.712s
└─NetworkManager.service @8.858s +596ms
└─firewalld.service @4.931s +3.926s
└─basic.target @4.916s
└─sockets.target @4.916s
└─dbus.socket @4.916s
└─sysinit.target @4.905s
└─systemd-update-utmp.service @4.864s +39ms
└─auditd.service @4.563s +301ms
└─systemd-tmpfiles-setup.service @4.485s +69ms
└─rhel-import-state.service @4.342s +142ms
└─local-fs.target @4.324s
└─boot.mount @4.286s +31ms
└─systemd-fsck@dev-disk-by\x2duuid-79f594ad\x2da332\x2d4730\x2dbb5f\x2d85d196080964.service @4.092s +149ms
└─dev-disk-by\x2duuid-79f594ad\x2da332\x2d4730\x2dbb5f\x2d85d196080964.device @4.092s
29. 获取某个服务(httpd)的依赖性列表

systemctl list-dependencies httpd.service

httpd.service
├─system.slice
└─basic.target
├─firewalld.service
├─microcode.service
├─rhel-autorelabel-mark.service
├─rhel-autorelabel.service
├─rhel-configure.service
├─rhel-dmesg.service
├─rhel-loadmodules.service
├─paths.target
├─slices.target
│ ├─-.slice
│ └─system.slice
├─sockets.target
│ ├─dbus.socket

30. 按等级列出控制组

systemd-cgls

├─1 /usr/lib/systemd/systemd --switched-root --system --deserialize 23
├─user.slice
│ └─user-0.slice
│ └─session-1.scope
│ ├─2498 sshd: root@pts/0
│ ├─2500 -bash
│ ├─4521 systemd-cgls
│ └─4522 systemd-cgls
└─system.slice
├─httpd.service
│ ├─4440 /usr/sbin/httpd -DFOREGROUND
│ ├─4442 /usr/sbin/httpd -DFOREGROUND
│ ├─4443 /usr/sbin/httpd -DFOREGROUND
│ ├─4444 /usr/sbin/httpd -DFOREGROUND
│ ├─4445 /usr/sbin/httpd -DFOREGROUND
│ └─4446 /usr/sbin/httpd -DFOREGROUND
├─polkit.service
│ └─721 /usr/lib/polkit-1/polkitd --no-debug

31. 按CPU、内存、输入和输出列出控制组

systemd-cgtop

Path Tasks %CPU Memory Input/s Output/s
/ 83 1.0 437.8M - -
/system.slice - 0.1 - - -
/system.slice/mariadb.service 2 0.1 - - -
/system.slice/tuned.service 1 0.0 - - -
/system.slice/httpd.service 6 0.0 - - -
/system.slice/NetworkManager.service 1 - - - -
/system.slice/atop.service 1 - - - -
/system.slice/atopacct.service 1 - - - -
/system.slice/auditd.service 1 - - - -
/system.slice/crond.service 1 - - - -
/system.slice/dbus.service 1 - - - -
/system.slice/firewalld.service 1 - - - -
/system.slice/lvm2-lvmetad.service 1 - - - -
/system.slice/polkit.service 1 - - - -
/system.slice/postfix.service 3 - - - -
/system.slice/rsyslog.service 1 - - - -
/system.slice/system-getty.slice/getty@tty1.service 1 - - - -
/system.slice/systemd-journald.service 1 - - - -
/system.slice/systemd-logind.service 1 - - - -
/system.slice/systemd-udevd.service 1 - - - -
/system.slice/webmin.service 1 - - - -
/user.slice/user-0.slice/session-1.scope 3 - - - -
控制系统运行等级
32. 启动系统救援模式

systemctl rescue

Broadcast message from root@tecmint on pts/0 (Wed 2015-04-29 11:31:18 IST):
The system is going down to rescue mode NOW!
33. 进入紧急模式

systemctl emergency

Welcome to emergency mode! After logging in, type “journalctl -xb” to view
system logs, “systemctl reboot” to reboot, “systemctl default” to try again
to boot into default mode.
34. 列出当前使用的运行等级

systemctl get-default

multi-user.target
35. 启动运行等级5,即图形模式

systemctl isolate runlevel5.target

systemctl isolate graphical.target

  1. 启动运行等级3,即多用户模式(命令行)

systemctl isolate runlevel3.target

systemctl isolate multiuser.target

  1. 设置多用户模式或图形模式为默认运行等级

systemctl set-default runlevel3.target

systemctl set-default runlevel5.target

  1. 重启、停止、挂起、休眠系统或使系统进入混合睡眠

systemctl reboot

systemctl halt

systemctl suspend

systemctl hibernate

systemctl hybrid-sleep

对于不知运行等级为何物的人,说明如下。
Runlevel 0 : 关闭系统
Runlevel 1 : 救援?维护模式
Runlevel 3 : 多用户,无图形系统
Runlevel 4 : 多用户,无图形系统
Runlevel 5 : 多用户,图形化系统
Runlevel 6 : 关闭并重启机器

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论