[RHEL]-7-常用系统状态检测命令
引言
这篇文章介绍RHEL中最常用的几个系统状态检测命令,包括:网络状态、内存、主机名及其架构、系统负载及其用户登录状态等。
文章目录
- 0×1.查看网络状态
- 0×2.使用uname查看系统版本
- 0×3.使用uptime命令查看系统负载
- 0×4.使用free命令查看内存
- 0×5.查看登录终端记录
- 0×6.查看当前用户历史命令
- 0×7.使用sosreport命令生成诊断包
0×1.查看网络状态
RHEL6以前系统中最常用的查看网络状态的命令就是ifconfig,下面是这个命令的一些基本用法举例:
01 |
[[email protected] ~] # ifconfig |
02 |
#eno16777736为网卡的标识名称,inet后是这块网卡的IP地址,子网掩码,广播地址 |
03 |
eno16777736: ..省略部分输出 |
04 |
inet 192.168.1.106 netmask 255.255.255.0 broadcast 192.168.1.255 |
05 |
..省略部分输出 |
06 |
#ether后是这块网卡的MAC地址 |
07 |
ether 00:0c:29:78:31:59 txqueuelen 1000 (Ethernet) |
08 |
#RX packets为这块网卡接收到的数据量 |
09 |
RX packets 13099 bytes 14064504 (13.4 MiB) |
10 |
RX errors 0 dropped 0 overruns 0 frame 0 |
11 |
#TX packets为这块网卡发送的数据量 |
12 |
TX packets 1646 bytes 168262 (164.3 KiB) |
13 |
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
14 |
15 |
#系统默认的环回接口 |
16 |
lo: flags=73 ..省略部分输出 |
在RHEL6之前的版本中,有线网卡的网卡号一般为"eth"开头,无线网卡号一般为"wlan"开头,而RHEL7之后的版本中,"en" 前缀代表以太网,"wl"前缀代表无线网卡,"vir" 前缀代表虚拟接口。
ifconfig不仅能用来查看网卡信息,还能用来停用或启用网卡,给网卡配置临时的IP地址(重启失效);
请参考[[Linux实用命令]-12-网络配置浅析]
在RHEL7以上版本中,官方推荐使用ip命令查看和配置网络接口信息,下面是一些常用的ip命令举例;
● 查看IP地址及网卡信息(同ifconfig):
01 |
#可以简写成ip a |
02 |
[[email protected] ~] # ip addr |
03 |
1: lo: <LOOPBACK,UP,LOWER_UP> |
04 |
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 |
05 |
inet 127.0.0.1/8 scope host lo |
06 |
valid_lft forever preferred_lft forever |
07 |
inet6 ::1/128 scope host |
08 |
valid_lft forever preferred_lft forever |
09 |
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> |
10 |
#MAC地址 |
11 |
link/ether 00:0c:29:78:31:59 brd ff:ff:ff:ff:ff:ff |
12 |
#inet IP/子网掩码 brd 广播地址 |
13 |
inet 192.168.1.106/24 brd 192.168.1.255 scope global dynamic eno16777736 |
14 |
valid_lft 4333sec preferred_lft 4333sec |
15 |
inet6 fe80::20c:29ff:fe78:3159/64 scope |
16 |
17 |
#单独查看一块网卡 |
18 |
[[email protected] ~] # ip addr show eno16777736 |
19 |
2: eno16777736: |
20 |
ink/ether 00:0c:29:78:31:59 brd ff:ff:ff:ff:ff:ff |
21 |
inet 192.168.1.106/24 brd 192.168.1.255 scope global dynamic eno16777736 |
22 |
valid_lft 6655sec preferred_lft 6655sec |
23 |
inet6 fe80::20c:29ff:fe78:3159/64 scope link |
24 |
valid_lft forever preferred_lft forever |
● 查看网卡的接口数据收发统计信息(比ifconfig更详细)
01 |
[[email protected] ~] # ip -s link |
02 |
1: lo: |
03 |
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 |
04 |
RX: bytes packets errors dropped overrun mcast |
05 |
980 10 0 0 0 0 |
06 |
X: bytes packets errors dropped carrier collsns |
07 |
980 10 0 0 0 0 |
08 |
2: eno16777736: |
09 |
link/ether 00:0c:29:78:31:59 brd ff:ff:ff:ff:ff:ff |
10 |
#接收到的数据包统计 |
11 |
RX: bytes packets errors dropped overrun mcast |
12 |
9393834 6644 0 0 0 0 |
13 |
#发送出的数据包统计 |
14 |
TX: bytes packets errors dropped carrier collsns |
15 |
87120 1123 0 0 0 0 |
16 |
17 |
#单独查看一块网卡的数据统计信息 |
18 |
[[email protected] ~] # ip -s link show eno16777736 |
● 显示系统路由表,添加删除路由条目:
01 |
#显示当前路由表,第一条为默认路由,第二条为局域网路由 |
02 |
[[email protected] ~] # ip route show |
03 |
default via 192.168.1.1 dev eno16777736 proto static metric 1024 |
04 |
192.168.1.0/24 dev eno16777736 proto kernel scope link src 192.168.1.106 |
05 |
06 |
##删除路由条目 |
07 |
#删除默认路由 |
08 |
[[email protected] ~] # ip route del default via 192.168.1.1 |
09 |
10 |
#删除普通路由 |
11 |
[[email protected] ~] # ip route del 192.168.1.0/24 |
12 |
13 |
##添加路由条目 |
14 |
#添加一条默认路由(未知网段的数据发往192.168.1.1,设备号为eno16777736) |
15 |
[[email protected] ~] # ip route add default via 192.168.1.1 dev eno16777736 |
16 |
17 |
#添加一条普通路由(发往192.168.2.0/24网段的数据发往192.168.1.1,设备号为eno16777736) |
18 |
[[email protected] ~] # ip route add 192.168.2.0/24 via 192.168.1.1 dev eno16777736 |
● 查看ARP列表,绑定与删除ARP
01 |
#查看本地ARP缓存,命令可简写成ip nei |
02 |
[[email protected] ~] # ip neighbor |
03 |
192.168.1.1 dev eno16777736 lladdr ec:26:ca:01:e3:c2 DELAY |
04 |
05 |
#添加静态ARP绑定 |
06 |
[[email protected] ~] # ip nei add 192.168.1.23 lladdr 11:11:11:11:11:11 dev eno16777736 nud perm |
07 |
08 |
[[email protected] ~] # ip nei |
09 |
192.168.1.23 dev eno16777736 lladdr 11:11:11:11:11:11 PERMANENT |
10 |
192.168.1.1 dev eno16777736 lladdr ec:26:ca:01:e3:c2 REACHABLE |
11 |
12 |
#删除ARP条目(必须指定IP与对应的网卡地址) |
13 |
[[email protected] ~] # ip nei del 192.168.1.23 dev eno16777736 |
0×2.使用uname查看系统版本
当我们需要下载安装一些软件的时候,可能需要先了解自己系统的构架以及内核信息等,这个时候就可以用到uname命令,例如:
1 |
#这条命令只需要看下面注释的三个部分即可 |
2 |
[[email protected] ~] # uname -a |
3 |
Linux qingsword.com(机器名称) 3.10.0-123.el7(内核版本) .x86_64 #1 SMP Mon May 5 11:16:57 EDT 2014 x86_64 x86_64 x86_64(64位系统) GNU/Linux |
4 |
5 |
#除此之外,如果想查看RHEL的版本信息,可以查看下面这个文件中的内容 |
6 |
[[email protected] ~] # more /etc/redhat-release |
7 |
Red Hat Enterprise Linux Server release 7.0 (Maipo) |
0×3.使用uptime命令查看系统负载
系统负载除了可以使用top命令查看外,uptime命令能够将top命令输出中的第一行单独打印出来:
1 |
[[email protected] ~] # uptime |
2 |
00:51:25 up 9 min, 2 users , load average: 0.02, 0.52, 0.49 |
0×4.使用free命令查看内存
free命令能够将top命令输出中的4,5行单独的显示出来:
01 |
#默认以K为单位 |
02 |
[[email protected] ~] # free |
03 |
total used free shared buffers cached |
04 |
Mem: 1870784 1069868 800916 9836 924 279848 |
05 |
-/+ buffers/cache: 789096 1081688 |
06 |
Swap: 0 0 0 |
07 |
08 |
#以M为单位 |
09 |
[[email protected] ~] # free -m |
10 |
total used free shared buffers cached |
11 |
Mem: 1826 1044 782 9 0 273 |
12 |
-/+ buffers/cache: 770 1056 |
13 |
Swap: 0 0 0 |
14 |
15 |
#人性化输出 |
16 |
[[email protected] ~] # free -h |
17 |
total used free shared buffers cached |
18 |
Mem: 1.8G 1.0G 781M 9.6M 924K 273M |
19 |
-/+ buffers/cache: 771M 1.0G |
20 |
Swap: 0B 0B 0B |
0×5.查看登录终端记录
who命令可以查看当前登录的用户,last可以查看登录的历史记录:
1 |
#本例中:0为root登录的图形界面,pts/0为图形界面中打开的一个shell窗口 |
2 |
[[email protected] ~] # who |
3 |
root :0 2016-11-14 00:43 (:0) |
4 |
root pts/0 2016-11-14 00:45 (:0) |
5 |
6 |
#使用last命令可以查看所有系统的登入记录,这些记录是保存在文件中的,命令只是查看了文件中的内容,文件内容是可以被篡改的,所以用这条命令来判断系统有没有被非法登录过并不可取 |
7 |
[[email protected] ~] # last |
8 |
root pts/0 :0 Mon Nov 14 00:45 still logged in |
0×6.查看当前用户历史命令
history命令可以用于查看当前用户输入过的历史命令列表,并可以直接从历史列表中取出某条命令执行:
01 |
#查看历史命令列表中的最后三条记录 |
02 |
[[email protected] ~] # history | tail -n 3 |
03 |
154 history |
04 |
155 who |
05 |
156 history | tail -n 3 |
06 |
07 |
#重新执行第155条命令 |
08 |
[[email protected] ~] # !155 |
09 |
who |
10 |
root :0 2016-11-14 00:43 (:0) |
11 |
root pts/0 2016-11-14 00:45 (:0) |
12 |
13 |
#历史命令记录最多可以保存的条目数量是/etc/profile文件中的HISTSIZE变量决定的,我的系统中最多为1000条 |
14 |
[[email protected] ~] # more /etc/profile | grep HISTSIZE= |
15 |
HISTSIZE=1000 |
16 |
17 |
#暂时清空历史命令记录(重启后失效) |
18 |
[[email protected] ~] # history -c |
19 |
20 |
#要想真正清空当前用户的命令历史记录,需要清空当前用户家目录中的.bash_history文件中的所有数据 |
21 |
[[email protected] ~] # vim ~/.bash_history |
22 |
1000dd |
23 |
:wq |
0×7.使用sosreport命令生成诊断包
当我们遇到解决不了的问题时,红帽提供了一个sosreport命令用于收集并生成诊断消息,将收集到的诊断信息(一个压缩包)发送给红帽公司,他们会根据这个压缩包中提供的内容来判断问题的根源,将解决方案发送给你(收费服务):
1 |
#直接在终端中输入命令,默认三个回车后,开始收集系统信息 |
2 |
[[email protected] ~] # sosreport |
3 |
Your sosreport has been generated and saved in : |
4 |
#最后会生成一个tar归档,将这个压缩包发送给红帽技术支持即可 |
5 |
/var/tmp/sosreport-qingsword.com-20161114012652. tar .xz |
*转载请注明来自:晴刃(QingSword.COM)