CentOS 7.1 - 恢复到旧的 top 和 service 功能

Vin*_*oia 3 top upgrade memory-usage systemd centos7

我最近安装了一个全新的 CentOS 7.1 服务器。我注意到与 CentOS 6.7 的一些差异,我希望有一种方法可以恢复对某些事物的旧观点。

例如:

问题 1: top

Top 命令以不同方式显示数据。例如:

新顶视图:

top - 00:27:45 up  4:58,  1 user,  load average: 0.08, 0.50, 0.89
Tasks: 155 total,   2 running, 153 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  1.1 sy,  0.0 ni, 98.9 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  4047624 total,  1938600 free,   853888 used,  1255136 buff/cache
KiB Swap:  4194300 total,  4194300 free,        0 used.  2860704 avail Mem
Run Code Online (Sandbox Code Playgroud)

旧顶视图:

top - 00:28:59 up 22:49,  1 user,  load average: 0.19, 0.21, 0.24
Tasks: 157 total,   1 running, 156 sleeping,   0 stopped,   0 zombie
Cpu(s): 17.9%us,  1.0%sy,  0.0%ni, 80.9%id,  0.2%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   4055052k total,  3456240k used,   598812k free,   584160k buffers
Swap:  4194296k total,   191184k used,  4003112k free,  1076124k cached
Run Code Online (Sandbox Code Playgroud)

有没有办法使用旧格式显示内存和统计信息?

问题 2:service命令

使用 Centos 6.7,如果我执行类似 的操作service httpd restart,它会给我一个OKFailure消息。CentOS 7.1 似乎没有这样做。

旧观点:

# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
Run Code Online (Sandbox Code Playgroud)

新观点:

# service httpd restart
Redirecting to /bin/systemctl restart  httpd.service
Run Code Online (Sandbox Code Playgroud)

有什么办法可以回到旧视图吗?我意识到这有点微不足道,但是很多时候服务还没有启动,或者由于某种原因不会停止。消息状态是一种很好的查看方式。

use*_*517 6

CentOS 7 是一个与 CentOS 6 截然不同的操作系统。与其想倒退,不如拥抱变化并向前迈进。如果不返回 C6,您就无法使用这些命令(或其他任何命令)倒退。

学会使用systemctl代替service;一旦肌肉记忆被重新学习,这同样容易。等到你必须工作时firewalld,这很“有趣”。

其他你会发现不同的东西。

默认情况下未安装net-tools提供netstatifconfig等的包,它已被iproute ssip等中的工具取代。

您习惯检查的许多日志不在 /var/log 中,您需要启用 rsyslog 才能访问它们或使用 journalctl。

哦,还有 hostnamectl 和……还有……

  • 或者带着脾气暴躁的表情和对 Lennart Poettering(systemd 家伙)充满厌恶的心坐在那里,并尽可能长时间地继续使用 C6,就像我一样。 (3认同)
  • 叉子 !MadHatterOS ;) (3认同)

Wil*_*ill 6

问题 1

尝试使用top -M

-M : Detect memory units
        Show memory units (k/M/G) and display floating point values in the
        memory summary.
Run Code Online (Sandbox Code Playgroud)

KiB是代表1000字节的SI单位,其中KB代表1024字节。

就我个人而言,我总是安装htop和使用它,因为我发现它更具可读性、信息量更大、功能更强大。

此外,free -k(千字节)、free -m(兆字节)或free -g(千兆字节)还将提供您要查找的内存使用信息。

编辑:在进一步的调查,top -M可在CentOS 7.不工作这里有一个很好的答案与一些替代方法,并替代tophtop

问题2

CentOS的7取代传统sysvinitsystemd。这是一个重要但必要的更改,因为sysvinit已经过时了,解决其缺陷对开发人员和管理员来说可能是一场斗争。Ubuntu、Debian、RHEL、SUSE 和几乎所有其他主要的 Linux 发行版也已切换到systemd.

systemd在这些发行版上与服务交互的正确方法是使用以下systemctl命令:

restart NAME...
   Restart one or more units specified on the command line. If the units are not running
   yet, they will be started.
Run Code Online (Sandbox Code Playgroud)

所以,在你的情况下:

systemctl restart httpd
Run Code Online (Sandbox Code Playgroud)

Usingsystemctl将显示您正在寻找的成功或失败的指示(并返回适当的退出代码)。

正如@Iian所说,拥抱这些变化,因为每个主要的 Linux 发行版都已经发生了同样的变化。

  • 实际上,[KiB](https://en.wikipedia.org/wiki/Kibibyte) 是 1024 字节的单位,而 [KB](h​​ttps://en.wikipedia.org/wiki/Kilobyte) 是 1000 字节(与 SI 定义保持一致,kilo=1000)。 (3认同)