Linux系统本身就有很多支持监控的命令,这些监控指令能够得到系统活动的当前状态,如果用好这些指令,能很容易的发现性能问题点。下面讨论的命令对于分析系统运行状态、调试服务来说是最基本的命令,能够解决:
- 找到系统瓶颈
- 硬盘-存储瓶颈
- CPU、内存瓶颈
- 网络瓶颈
本文主要依赖于这篇文章,但是不全依赖于该文讲解,可以看看原文,再看看本文。本文主要是将命令的常用选项拉出来做讲解。另外最重要的是在工作中有意识的使用这些命令,并且使用这些命令的某些高级功能,才能熟能生巧。
top - Process Activity Command
vmstat - System Activity, Hardware and System Information
vmstat:reports information about processes, memory, paging, block IO, traps, and cpu activity。从描述中可以看出来vmstat命令是获得系统的各种统计信息的。-m=slabinfo and pages、-s=event counters and memory stat、-d=disk stat、-f=fork numbers,支持delay和count参数。另外man一下vmstat,可以看到vmstat的集中命令行使用格式,这个也比较好理解。
w - Find Out Who Is Logged on And What They Are Doing
找出谁在登陆这台机器,直接用w参数就行,可能会用到的参数是-h,这个是不显示header,实际上就是不显示第一行信息,大家看看第一行信息是什么东西,有没有感觉很熟悉;没错,就是下面的uptime,也是top命令的第一行信息。
uptime - Tell How Long The System Has Been Running
系统运行状况,包括当前时间、运行时间、用户登录数、load情况,包括一分钟、五分钟、十五分钟时的load。
ps - Displays The Processes
Memory、buffer、swap space使用情况。能够用-b,-k,-m,-g来调整数据显示情况,-s表示延迟显示,-c表示显示多少次,一般这两个参数一起使用观看一段时间内的内存使用情况。
iostat - Average CPU Load, Disk Activity
iostat –c和-d参数分别使用,可以得到CPU、IO统计信息的设备的统计信息。
iostat -d interval count以interval执行iostat –d命令,执行count次,观察一段时间的io统计情况。实际上,统计信息来自于这四个文件/proc/stat、/proc/partitions、/proc/diskstats、/proc/uptime等。在/proc/文件下有很多系统的统计信息,其实可以直接从这里的文件里面找到这些信息。
sar - Collect, report, or save system activity information.
sar命令获得系统的运行信息,-b、-d、-u等参数能够得到系统的paging stat、block device stat、CPU Utilization。同样有interval和count参数供使用
mpstat - Multiprocessor Usage
mpstat –P参数表示选择那几个核心的CPU统计信息。默认是统计all的信息。如果使用mpstat –p ALL则表示统计all和各个cpu的统计。添加interval和count参数可以观察一段时间内的CPU运行情况,在这点上貌似确实比TOP好用
pmap - Process Memory Usage
pmap pid可以得到程序的Memory Used,这个得到的是MemoryMap,得到的貌似是应用用到的各个模块的地址,最后来个total信息。加上-x参数能够得到模块的加载区大小,默认是Kbyte。
netstat and ss - Network Statistics
这个命令可是个利器,根据man的描述Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships可见该命令的强大之处。-t=tcp、-u=udp、-w=raw、-l=listening、-n=numeric、-a=all、-p=pid、-a=all、-s=stat,其中-s的信息最全,能够得到TCP、UDP、LISTENING、IP、ICMP各种协议的统计信息。这个命令的熟练使用也是linux网络查问题的基本功之一。更详细的统计信息可以参看这里:http://www.thegeekstuff.com/2010/03/netstat-command-examples/或者man一下
ss命令为Display Linux TCP / UDP Network and Socket Information,这个更关注TCP、UDP以及Socket信息,参数和netstat类似。
iptraf - Real-time Network Statistics
这个命令没有用过,不好说用途,不过看文档的话,是IP LAN 监控信息。细节可以见这里:http://www.linuxcommand.org/man_pages/iptraf8.html
tcpdump - Detailed Network Traffic Analysis
这个又是个重量级的网络命令,及其好用,推荐各位好好的使用这个命令。这个命令可以作为终极的TCP/UDP命令网络监控,几乎能够解决所有的网络问题,包括调试、监控、统计等,凡是使用网络的地方,最后都要走这个命令查看。好吧,这个命令 太过重要,使用的太多反而不知道哪个参数最重要。看下这篇文章吧,多读几遍这个命令的参数,多在工作中使用这个命令,才能最快的掌握。入门可以看下这篇文章,再搜下这个命令的高级用法。
strace - trace system calls and signals
看看strace的man命令是怎么说的,trace system calls and signal,这个是指linux shell命令的执行流程。这个命令倒是新奇,能够观察命令的执行流程,大致得到shell命令和内核的交互方式。对于这个命令感兴趣的可以继续看下ltrace和ptrace,前者是library trace,后者是process trace。
mtr:a network diagnostic tool
mtr combines the function of traceroute and ping,是一种通过界面操作的网络诊断工具。其实这个命令相当于traceroute和ping命令的组合,可以通过界面的方式得到统计结果。统计的内容更多:LDRSNBAWVGJMXI这些参数各有不同的统计,参数太多不多做解释,反正是上面两个命令能统计到的这个命令都能统计,还是以一种连续的方式统计,更加直观。
其它关于网络命令的ifconfig、ethtool、iwconfig(无线网卡配置)等,大家可以自行学习。
最后还是那句话,多练习、多使用,熟能生巧才是 学习的正确方法。
分享到:
相关推荐
linux-sysadmin-course, Linux系统管理 101 linux-sysadmin-courseLinux系统管理 101这里 repo 包含课程的附加材料和演示文稿。它还包括所有 homeworks 。等级:两个测试,每个测试有 50个问题一个问题一点每个作业...
linux-sysadmin-interview-questions, Linux系统管理员/devops访谈问题集合 Linux系统管理员/devops面试问题linux系统管理员/devops访谈问题集合。 通过请求请求,问题或者电子邮件来提供免费的帮助。内容的 table...
A SysAdmin’s Essential Guide to Linux Workstation Security How to work from anywhere and keep your data, identity, and sanity By Konstantin Ryabitsev Director of IT Infrastructure Security at The ...
Every sysadmin should be familiar with the material covered in HackNotes Linux and Unix Security Portable Reference. For every vulnerability presented, the author provides common-sense uidelines ...
This book is a collection of recipes for the working Linux sysadmin–a set of stand-alone quick guides and tips that you can keep on your desk for easy reference. Hardcore in-depth manuals are great ...
Oracle EBS SYSADMIN -
Finally, he presents a full section on the powerful Git version control system, teaching skills you can use in Linux and many other environments. Access Linux systems, use GUIs, and work at the ...
oracle ebs sysadmin - 培训手册.pdf
Finally, he presents a full section on the powerful Git version control system, teaching skills you can use in Linux and many other environments. Access Linux systems, use GUIs, and work at the ...
sysadmin工具 我们用来管理橘子的工具和脚本 签出项目,运行“ npm install”,设置config.json(参考config.json.sample),运行“ node tools.js”以开始使用
ServerHealers SysAdmin工具>>选择选项。 注意:仅当您选择搜索查询时,扩展名才会出现在右键菜单中。 (IP /域名)所有其他时间它将被隐藏。 可用选项:★域详细信息1)域WhoIs查找2)进入DNS检查3)DNS传播...
Using both simple one-line commands and command sequences complex problems can be solved with ease, from text processing to backing up sysadmin tools. In this book, you’ll discover everything you ...
Using both simple one-line commands and command sequences complex problems can be solved with ease, from text processing to backing up sysadmin tools. In this book, you’ll discover everything you ...
Using both simple one-line commands and command sequences complex problems can be solved with ease, from text processing to backing up sysadmin tools. In this book, you’ll discover everything you ...
The Accidental SysAdmin Handbook, Second Edition looks at those commonalities and provides a general introduction to critical aspects associated with system administration. It further acts to provide ...
Using and Administering Linux vol2和vol3 高清文字版。最新版,适合想快速上手LInux的同学
Using both simple one-line commands and command sequences complex problems can be solved with ease, from text processing to backing up sysadmin tools. In this book, you’ll discover everything you ...
Rather than viewing the subject traditionally as a set of recipes for success or communications technologies for monitoring, Analytical Network and System Administration: provides models and ...