《云计算》-安全策略-你必须要掌握的常用的系统监控命令合集

1 案例1:常用系统监控命令
1.1 问题

本案例要求熟悉查看Linux系统状态的常用命令,为进一步执行具体的监控任务做准备:

查看内存信息
查看交换分区信息
查看磁盘信息
查看CPU信息
查看网卡信息
查看端口信息
查看网络连接信息

     
     
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

1.2 方案

一般企业做监控的目的:实时报告系统状态,提前发现系统的问题。

监控的资源可以分为:共有数据(HTTP、FTP等)和私有数据(CPU、内存、进程数等)。

监控软件可以使用:系统自带的命令、Cacti监控系统、Nagios监控系统、Zabbix监控系统。
1.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:使用命令查看计算机状态数据

1)查看内存与交换分区信息

[root@svr5 ~]# free                                     //查看内存信息
              total        used        free      shared  buff/cache   available
Mem:       16166888     8017696      720016      106504     7429176     7731740
Swap:       4194300      218268     3976032
[root@svr5 ~]# free | awk '/Mem/{print $4}'                //查看剩余内存容量
720928
[root@svr5 ~]# swapon -s                                //查看交换分区信息
文件名                类型            大小        已用        权限
/dev/sda3             partition        4194300    218268    -1

     
     
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

步骤二:查看磁盘与CPU利用率

1)查看磁盘信息

[root@svr5 ~]# df                                     //查看所有磁盘的使用率
文件系统           1K-块      已用      可用         已用% 挂载点
/dev/sda2      476254208 116879624 335159084   26%         /
/dev/sda1         198174    133897     49737   73%         /boot
[root@svr5 ~]# df | awk '/\/$/{print $5}'            //查看根分区的利用率

     
     
  • 1
  • 2
  • 3
  • 4
  • 5

2)查看CPU平均负载

[root@svr5 ~]# uptime                             //查看CPU负载(1,5,15分钟)
 23:54:12 up 38 days, 14:54,  9 users,  load average: 0.00, 0.04, 0.05
[root@svr5 ~]# uptime |awk '{print $NF}'            //仅查看CPU的15分钟平均负载
0.05

     
     
  • 1
  • 2
  • 3
  • 4

步骤二:查看网卡信息、端口信息、网络连接信息

1)查看网卡信息

[root@svr5 ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.4.5  netmask 255.255.255.0  broadcast 172.25.0.255
        inet6 fe80::5054:ff:fe00:b  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:00:00:0b  txqueuelen 1000  (Ethernet)
        RX packets 62429  bytes 10612049 (10.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5674  bytes 4121143 (3.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[root@svr5 ~]# ifconfig eth0 |awk '/inet /{print $2}'        //查看IP地址信息
192.168.4.5
[root@svr5 ~]# ifconfig eth0 |awk '/RX p/{print $5}'        //网卡接受数据包流量
10625295
[root@svr5 ~]# ifconfig eth0 |awk '/TX p/{print $5}'        //网卡发送数据包流量
4130821

     
     
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

2)查看端口信息

[root@svr5 ~]# ss -ntulp                                //查看本机监听的所有端口
//-n以数字显示端口号
//-t显示tcp连接
//-u显示udp连接
//-p显示监听端口对应的程序名称

     
     
  • 1
  • 2
  • 3
  • 4
  • 5

3)查看网络连接信息

[root@svr5 ~]# ss -antup                                //查看所有的网络连接信息
//-a查看所有连接状态信息

     
     
  • 1
  • 2
                                </div>
            <link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-b6c3c6d139.css" rel="stylesheet">
                                            <div class="more-toolbox">
            <div class="left-toolbox">
                <ul class="toolbox-list">
                    
                    <li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
                        <use xlink:href="#csdnc-thumbsup"></use>
                    </svg><span class="name">点赞</span>
                    <span class="count"></span>
                    </a></li>
                    <li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;popu_824&quot;}"><svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-csdnc-Collection-G"></use>
                    </svg><span class="name">收藏</span></a></li>
                    <li class="tool-item tool-active is-share"><a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;1582594662_002&quot;}"><svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-csdnc-fenxiang"></use>
                    </svg>分享</a></li>
                    <!--打赏开始-->
                                            <!--打赏结束-->
                                            <li class="tool-item tool-more">
                        <a>
                        <svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
                        </a>
                        <ul class="more-box">
                            <li class="item"><a class="article-report">文章举报</a></li>
                        </ul>
                    </li>
                                        </ul>
            </div>
                        </div>
        <div class="person-messagebox">
            <div class="left-message"><a href="https://blog.csdn.net/xie_qi_chao">
                <img src="https://profile.csdnimg.cn/B/F/6/3_xie_qi_chao" class="avatar_pic" username="xie_qi_chao">
                                        <img src="https://g.csdnimg.cn/static/user-reg-year/1x/2.png" class="user-years">
                                </a></div>
            <div class="middle-message">
                                    <div class="title"><span class="tit"><a href="https://blog.csdn.net/xie_qi_chao" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}" target="_blank">解启超</a></span>
                                        </div>
                <div class="text"><span>发布了329 篇原创文章</span> · <span>获赞 52</span> · <span>访问量 3万+</span></div>
            </div>
                            <div class="right-message">
                                        <a href="https://im.csdn.net/im/main.html?userName=xie_qi_chao" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
                    </a>
                                                        <a class="btn btn-sm attented bt-button personal-watch" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}">已关注</a>
                                </div>
                        </div>
                </div>
</article>
发布了179 篇原创文章 · 获赞 180 · 访问量 7073

1 案例1:常用系统监控命令
1.1 问题

本案例要求熟悉查看Linux系统状态的常用命令,为进一步执行具体的监控任务做准备:

查看内存信息
查看交换分区信息
查看磁盘信息
查看CPU信息
查看网卡信息
查看端口信息
查看网络连接信息

  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

1.2 方案

一般企业做监控的目的:实时报告系统状态,提前发现系统的问题。

监控的资源可以分为:共有数据(HTTP、FTP等)和私有数据(CPU、内存、进程数等)。

监控软件可以使用:系统自带的命令、Cacti监控系统、Nagios监控系统、Zabbix监控系统。
1.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:使用命令查看计算机状态数据

1)查看内存与交换分区信息

[root@svr5 ~]# free                                     //查看内存信息
              total        used        free      shared  buff/cache   available
Mem:       16166888     8017696      720016      106504     7429176     7731740
Swap:       4194300      218268     3976032
[root@svr5 ~]# free | awk '/Mem/{print $4}'                //查看剩余内存容量
720928
[root@svr5 ~]# swapon -s                                //查看交换分区信息
文件名                类型            大小        已用        权限
/dev/sda3             partition        4194300    218268    -1

  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

步骤二:查看磁盘与CPU利用率

1)查看磁盘信息

[root@svr5 ~]# df                                     //查看所有磁盘的使用率
文件系统           1K-块      已用      可用         已用% 挂载点
/dev/sda2      476254208 116879624 335159084   26%         /
/dev/sda1         198174    133897     49737   73%         /boot
[root@svr5 ~]# df | awk '/\/$/{print $5}'            //查看根分区的利用率

  
  
  • 1
  • 2
  • 3
  • 4
  • 5

2)查看CPU平均负载

[root@svr5 ~]# uptime                             //查看CPU负载(1,5,15分钟)
 23:54:12 up 38 days, 14:54,  9 users,  load average: 0.00, 0.04, 0.05
[root@svr5 ~]# uptime |awk '{print $NF}'            //仅查看CPU的15分钟平均负载
0.05

  
  
  • 1
  • 2
  • 3
  • 4

步骤二:查看网卡信息、端口信息、网络连接信息

1)查看网卡信息

[root@svr5 ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.4.5  netmask 255.255.255.0  broadcast 172.25.0.255
        inet6 fe80::5054:ff:fe00:b  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:00:00:0b  txqueuelen 1000  (Ethernet)
        RX packets 62429  bytes 10612049 (10.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5674  bytes 4121143 (3.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[root@svr5 ~]# ifconfig eth0 |awk '/inet /{print $2}'        //查看IP地址信息
192.168.4.5
[root@svr5 ~]# ifconfig eth0 |awk '/RX p/{print $5}'        //网卡接受数据包流量
10625295
[root@svr5 ~]# ifconfig eth0 |awk '/TX p/{print $5}'        //网卡发送数据包流量
4130821

  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

2)查看端口信息

[root@svr5 ~]# ss -ntulp                                //查看本机监听的所有端口
//-n以数字显示端口号
//-t显示tcp连接
//-u显示udp连接
//-p显示监听端口对应的程序名称

  
  
  • 1
  • 2
  • 3
  • 4
  • 5

3)查看网络连接信息

[root@svr5 ~]# ss -antup                                //查看所有的网络连接信息
//-a查看所有连接状态信息

  
  
  • 1
  • 2
                                </div>
            <link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-b6c3c6d139.css" rel="stylesheet">
                                            <div class="more-toolbox">
            <div class="left-toolbox">
                <ul class="toolbox-list">
                    
                    <li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
                        <use xlink:href="#csdnc-thumbsup"></use>
                    </svg><span class="name">点赞</span>
                    <span class="count"></span>
                    </a></li>
                    <li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;popu_824&quot;}"><svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-csdnc-Collection-G"></use>
                    </svg><span class="name">收藏</span></a></li>
                    <li class="tool-item tool-active is-share"><a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;1582594662_002&quot;}"><svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-csdnc-fenxiang"></use>
                    </svg>分享</a></li>
                    <!--打赏开始-->
                                            <!--打赏结束-->
                                            <li class="tool-item tool-more">
                        <a>
                        <svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
                        </a>
                        <ul class="more-box">
                            <li class="item"><a class="article-report">文章举报</a></li>
                        </ul>
                    </li>
                                        </ul>
            </div>
                        </div>
        <div class="person-messagebox">
            <div class="left-message"><a href="https://blog.csdn.net/xie_qi_chao">
                <img src="https://profile.csdnimg.cn/B/F/6/3_xie_qi_chao" class="avatar_pic" username="xie_qi_chao">
                                        <img src="https://g.csdnimg.cn/static/user-reg-year/1x/2.png" class="user-years">
                                </a></div>
            <div class="middle-message">
                                    <div class="title"><span class="tit"><a href="https://blog.csdn.net/xie_qi_chao" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}" target="_blank">解启超</a></span>
                                        </div>
                <div class="text"><span>发布了329 篇原创文章</span> · <span>获赞 52</span> · <span>访问量 3万+</span></div>
            </div>
                            <div class="right-message">
                                        <a href="https://im.csdn.net/im/main.html?userName=xie_qi_chao" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
                    </a>
                                                        <a class="btn btn-sm attented bt-button personal-watch" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}">已关注</a>
                                </div>
                        </div>
                </div>
</article>

猜你喜欢

转载自blog.csdn.net/weixin_46575696/article/details/105040627
今日推荐