作为一名合格的运维人员,为了更好的了解咱们的Linux服务器,您必须具备快速查看系统状态的能力,所以接下来咱们会逐个来学习下对于网卡网络、系统内核、系统负载、内存使用情况、当前登陆用户、历史登陆记录、命令执行记录以及救援诊断命令的使用方法,都是超级实用的。
ifconfig用于获取网卡配置与网络状态等信息:格式为"ifconfig [网络设备] [参数]"。
查看本机当前的网卡配置与网络状态等信息,咱们主要就是看每段开头的网卡名称、inet参数后面的IP地址、ether参数后面的物理mac地址以及RX、TX的接收与发送数据包的大小:
[root@linuxprobe ~]# ifconfigeno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.10.10 netmask 255.255.255.0 broadcast 192.168.10.255 inet6 fe80::20c:29ff:fec4:a409 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:c4:a4:09 txqueuelen 1000 (Ethernet) RX packets 36 bytes 3176 (3.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 38 bytes 4757 (4.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 0 (Local Loopback) RX packets 386 bytes 32780 (32.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 386 bytes 32780 (32.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
uname命令用于查看系统内核与系统版本等信息,格式为:“uname [-a]”。
一般咱们会固定搭配上-a参数来完整查看当前系统的内核名称、主机名、内核发行版本、节点名、系统时间、硬件名称、硬件平台、处理器类型以及操作系统名称等信息:
[root@linuxprobe ~]# uname -a Linux linuxprobe.com 3.10.0-123.el7.x86_64 #1 SMP Mon May 5 11:16:57 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux
顺便说下,如果您想查看系统详细版本信息就看redhat-release文件:
[root@linuxprobe ~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.0 (Maipo)
uptime命令用于查看系统的负载信息,格式为:“uptime”。
这个命令真的很棒,它可以为您显示当前系统时间、系统已运行时间、当前在线用户以及平均负载值等信息数据。平均负载值指的是最近1分钟、5分钟、15分钟的系统压力情况,负载值越低越好,尽量不要长期超过1。另外您还可以结合搭配用"watch -n 1 uptime"命令来每秒刷新一次来获得当前的系统负载情况。
[root@linuxprobe ~]# uptime 22:49:55 up 10 min, 2 users, load average: 0.01, 0.19, 0.18
free命令用于显示当前系统中内存的使用量信息,格式为:“free [-h]”。
为了保证Linux系统不会突然卡住宕机,因此内存使用量应该是运维人员时刻要关注的数据啦,咱们可以使用-h参数来以更人性化的样式为咱们展示出内存的实时使用量信息(真实的输出值中不包括中文注释部分):
[root@linuxprobe ~]# free -h
| 总计内存量 | 已用量 | 可用量 | 进程共享的内存量 | 磁盘缓存的内存量 | 缓存的内存量 | |
| total | used | free | shared | buffers | cached | |
| Mem: | 1.8G | 1.3G | 542M | 9.8M | 1.6M | 413M |
| -/+ buffers/cache: | 869M | 957M | ||||
| Swap: | 2.0G | 0B | 2.0G |
who命令用于查看当前登入主机的用户终端信息,格式为:"who [参数]"。
简单三个字母就可以快捷的显示出所有正在登陆着本机的用户名称以及他们正在开启的终端信息:
[root@linuxprobe ~]# who
| 登陆的用户名 | 终端设备 | 登陆到系统的时间 |
| root | :0 | 2016-08-24 17:52 (:0) |
| root | pts/0 | 2016-08-24 17:52 (:0) |
last命令用于查看所有系统的登入记录,格式为:"last [参数]"。
下面使用last命令看到的本机登陆信息,其实仅仅是调取了过往保存到系统中的日志文件罢了,篡改里面的文字其实也很简单,因此对于做“***”***行为审计时其实并不牢靠,只能仅供咱们参考而已:
[root@linuxprobe ~]# last root pts/0 :0 Mon Aug 24 17:52 still logged in root :0 :0 Mon Aug 24 17:52 still logged in (unknown :0 :0 Mon Aug 24 17:50 - 17:52 (00:02) reboot system boot 3.10.0-123.el7.x Tue Aug 25 01:49 - 18:17 (-7:-32) root pts/0 :0 Mon Aug 24 15:40 - 08:54 (7+17:14) root pts/0 :0 Fri Jul 10 10:49 - 15:37 (45+04:47) ………………省略部分登陆信息………………
history命令用于显示历史执行过的命令,格式为:“history [-c]”。
这条命令应该是我最喜欢的了,history命令默认会保存1000条执行过的命令,若要修改可直接编辑/etc/profile文件的HISTSIZE值。它能显示出当前用户在本地计算机中执行过的所有命令记录,您可以使用-c参数来清空里面的历史数据,还可以使用“!编码数字”的方式来重复执行某一次的命令:
[root@linuxprobe ~]# history 1 tar xzvf VMwareTools-9.9.0-2304977.tar.gz 2 cd vmware-tools-distrib/ 3 ls 4 ./vmware-install.pl -d 5 reboot 6 df -h 7 cd /run/media/ 8 ls 9 cd root/ 10 ls 11 cd VMware\ Tools/ 12 ls 13 cp VMwareTools-9.9.0-2304977.tar.gz /home 14 cd /home15 ls16 tar xzvf VMwareTools-9.9.0-2304977.tar.gz 17 cd vmware-tools-distrib/ 18 ls 19 ./vmware-install.pl -d 20 reboot 21 history [root@linuxprobe ~]# !15 anaconda-ks.cfg Documents initial-setup-ks.cfg Pictures Templates Desktop Downloads Music Public Videos
历史命令会被保存到用户家目录中的".bash_history"文件中。Linux系统中以点(.)开头的文件均代表隐藏文件,一般会是系统文件。
[root@linuxprobe ~]# cat ~/.bash_history
清空该用户在本机中执行过命令的历史记录:
[root@linuxprobe ~]# history -c
sosreport命令用于收集系统配置并诊断信息后输出结论文档,格式为:“sosreport”。
当咱们的Linux系统出现故障需要联系红帽厂商或其他技术支持时,大多数时候都要先使用这个SOS功能来简单收集计算机的状态和配置信息,以便让技术支持公司能够通过远程就解决了一些小问题,又或者让他们能对复杂问题能提前有些了解:
[root@linuxprobe ~]# sosreport sosreport (version 3.0) This command will collect diagnostic and configuration information from this Red Hat Enterprise Linux system and installed applications. An archive containing the collected information will be generated in /var/tmp and may be provided to a Red Hat support representative. Any information provided to Red Hat will be treated in accordance with the published support policies at: https://access.redhat.com/support/ The generated archive may contain data considered sensitive and its content should be reviewed by the originating organization before being passed to any third party. No changes will be made to system configuration. Press ENTER to continue, or CTRL-C to quit. 此处敲击回车来确认收集信息Please enter your first initial and last name [linuxprobe.com]:此处敲击回车,来确认主机名称。Please enter the case number that you are generating this report for: Running plugins. Please wait ... Running 70/70: yum... Creating compressed archive... Your sosreport has been generated and saved in:/var/tmp/sosreport-linuxprobe.com-20150905230631.tar.xzThe checksum is: 79436cdf791327040efde48c452c6322 //此压缩包文件和这段校验值就是要发送给对方的内容。Please send this file to your support representative.
转载于:https://blog.51cto.com/20169999/1867181

被折叠的 条评论
为什么被折叠?



