【常用命令】Linux相关命令

摘要:
[[TOC]]iostat-查看系统I/O状况-kDisplaystatisticsinkilobytespersecond-mDisplaystatisticsinmegabytespersecond.-dDisplaythedeviceutilizationreport.示例:[root@epic-phy-9-21~]#iostat-d-mLinux3.10.0-514.26.1.el7.x8

[[TOC]]

iostat - 查看系统I/O状况
  • -k Display statistics in kilobytes per second
  • -m Display statistics in megabytes per second.
  • -d Display the device utilization report.

示例:

[root@epic-phy-9-21 ~]# iostat -d -m
Linux 3.10.0-514.26.1.el7.x86_64 (epic-phy-9-21) 	12/15/2017 	_x86_64_	(32 CPU)

Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
sda             209.95         2.26         3.46   19564882   29937790
sdc               0.00         0.00         0.00          3          0
sde               0.00         0.00         0.00          3          0


sar (网络traffic)

说明:

sar - Collect, report, or save system activity information
-n { keyword [,...] | ALL }
              Report network statistics.

              Possible keywords are DEV, EDEV, NFS, NFSD, SOCK, IP, EIP, ICMP, EICMP, TCP, ETCP, UDP, SOCK6, IP6, EIP6, ICMP6, EICMP6 and UDP6.

              With the DEV keyword, statistics from the network devices are reported.  The following values are displayed:

示例:

// 每5s抽样一次,总共抽样2次
[root@epic-phy-9-21 ~]# sar -n DEV 5 2 | grep lo
Average:        IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
02:34:38 PM        lo    309.60    309.60    498.68    498.68      0.00      0.00      0.00
02:34:43 PM        lo   1241.20   1241.20    842.29    842.29      0.00      0.00      0.00
Average:           lo    775.40    775.40    670.48    670.48      0.00      0.00      0.00

top

查看每个CPU核是使用率

操作:按键1;

top - 10:23:11 up 100 days, 14 min,  5 users,  load average: 9.25, 9.17, 9.38
Tasks: 2002 total,  11 running, 1990 sleeping,   0 stopped,   1 zombie
%Cpu0  :  7.4 us,  0.7 sy,  0.0 ni, 92.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu1  :  3.0 us,  1.3 sy,  0.0 ni, 87.3 id,  8.3 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu2  : 67.3 us,  2.6 sy,  0.0 ni, 30.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu3  : 32.2 us,  1.3 sy,  0.0 ni, 66.4 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu4  : 34.3 us,  1.0 sy,  0.0 ni, 64.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st

线程角度来查看CPU消耗

操作:Shift+H

查看指定进程

top -p pid

byte转Mb、GB等

操作:Shift+e


awk

打印文件制定的列,并指定分隔符

  • $1: 第一列
  • -F: 指定分隔符
awk '{print $1}' -F "-" access.log 

筛选指定行,并打印指定列

awk '/google/{print $5,$6}' access.log 

查询length大于40的行,打印第3列

  • $0: 表示当前行
awk 'length($0)>40{print $3}' access.log

对内容进行格式化输出

awk '{line = sprintf ( "method:%s, response:%s", $3 , $7 ); print line}' access.log

将处理文本放在指定文件

awk -f testawk access.log

sed

替换文件中的item为items输出,文件内容不发生变化

sed 's/item/items/' test.properties

输出文件的12-16行

  • -n : 表示只输出指定行
sed -n '12,14p' test.properties

删除指定行输出,文件内容不发生变化

// 删除包含pool的行
sed '/pool/d' test.properties

在每行的行首插入文本

sed -e 'iThis is header of every line' test.properties

output:
This is header of every line
performance.indicator.graphite.item[1].key=pm_statistic_memory_used_size
This is header of every line
performance.indicator.graphite.item[1].targetQuery=aliasByNode(EPIC.pm.*.memory.memory.used, 2)
This is header of every line
performance.indicator.graphite.item[1].metricType=Gauge

在每行的行尾追加文本

 sed -e 'aend' test.properties

output:
performance.indicator.graphite.item[2].metricType=Gauge
end
performance.indicator.graphite.item[2].targetParamPattern=^(?<hostId>.*)$
end
performance.indicator.graphite.item[2].skipNullMax=8
end

对匹配的行进行替换

查找/pool/匹配的行,用poolnew对匹配的行进行替换

sed -e '/pool/cpoolnew' test.properties

tcpdump抓包工具
tcpdump -i any -A tcp port 2003 and host 192.168.46.32 -vvv 

参数解释:

  • -i: 表示网卡接口,如:eth0,当设置为any时,表示任一网卡;
  • -A: 以ASCII形式显示;
  • tcp port xxxudp port xxx等;
  • host xxx.xxx.xxx.xxx
  • -vvv: 多一个v就表示输出更详细一些;
  • and:多个判断条件直接的连接符;

nc命令

判断某端口是否打开

nc -zv ip host

示例:

[root@epic-phy-9-21 kubernetes]# kubectl exec epic-mgmt-4172821423-206kj -- nc -zv 172.30.29.13 8008

output:
172.30.29.13 (172.30.29.13:8008) open (当显示类似这条语句,表示该port打开)

telnet命令

判读某端口是否打开

telnet ip port

example:
telnet 192.168.3.42 2121

netstat 命令

查看某个端口是否被占用

netstat -anp | grep 8080

curl
  • -i: 包含header
  • -I: 仅仅包含Header
  • -H: 请求包含header信息
  • --request: 指定请求方法,默认是GET,可以是POST、PUT、DELETE等,一般不需要指定
  • -d: 使用post请求发送指定数据

Get方式请求token,包含header

curl -H "Content-Type:application/x-www-form-urlencoded" http://10.254.9.21:30111/v1/user/oauth/token?grant_type=password&username=epic&password=epic1234

POST方式请求token(多个-d将多个key-value分开)

curl -H "Content-Type:application/x-www-form-urlencoded" -d grant_type=password -d username=epic -d password=epic1234 http://10.254.9.21:30111/v1/user/oauth/token 

POST方式请求token(1个-d传递多个key-value)

curl -H "Content-Type:application/x-www-form-urlencoded" -d "grant_type=password&username=epic&password=epic1234" http://10.254.9.21:30111/v1/user/oauth/token

post方式请求(raw数据,json格式)

curl -H "Content-Type:application/json" -H "Authorization:Bearer 1429a901-9236-40eb-a53c-e6c7ef71fff6" -d '{
    "dateformat": "NUMERIC",
    "metrics": [
        {
            "resourceType": "splitter",
            "resourceId": "f8021c6606c7494b96d256a7c8951d89", 
            "metricItem": "splitter_realtime_cpu_avg_util_percent"
        }
    ]
}' --request POST http://192.168.29.222:8008/v2/pools/7b8f0f5e2fbb4d9aa2d5fd55466dsij2/performance/query

免责声明:文章转载自《【常用命令】Linux相关命令》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Linux上的ftp服务器 vsftpd 之配置满天飞--设置匿名用户访问(不弹出用户名密码框)以及其他用户可正常上传vs2015启动崩溃,wpfgfx_v0400.dll加载D3DCompiler_47.dll失败下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

zabbix监控磁盘IO

我这里有两种方法,感觉都不错。我这里主要是写一下监控的脚本。 1、使用iostat命令监控 1)首先打开配置文件的自定义脚本功能,然后编写脚本。 #!/bin/bash if [ $# -ne 1 ];then echo "Follow the script name with an argument" fi case $1 in...

Linux学习之iostat命令详解

我们可以用iostat 命令来监视系统输入/输出、设备负载,这通过观察与它们的平均传送速率相关的物理磁盘的活动时间 来实现。iostat 命令生成的报告可以用来更改系统配置,从而更好地平衡物理磁盘和适配器之间的输入/输出负载。当Linux系 统出现性能问题时,用iostat工具查看进程IO请求下发的数量、系统处理IO请求的耗时,进而分析进程与操作系统的交互...

Linux服务器性能查看分析调优

一 linux服务器性能查看 1.1 cpu性能查看 1、查看物理cpu个数: cat /proc/cpuinfo |grep "physical id"|sort|uniq|wc -l 2、查看每个物理cpu中的core个数: cat /proc/cpuinfo |grep "cpu cores"|wc -l 3、逻辑cpu的个数: cat /proc...

CSS之使用display:inline-block来布局及浮动和inline-block的区别作用

https://www.cnblogs.com/Ry-yuan/p/6848197.html css之display:inline-block布局 1.解释一下display的几个常用的属性值,inline , block, inline-block inline(行内元素): 使元素变成行内元素,拥有行内元素的特性,即可以与其他行内元素共享一行,不会...

浏览器、HTML、css 面试题

1.什么是盒模型 盒模型(内容(content),内边距(padding),边框(border),外边距(margin)),值得注意的是,块级元素可以设置宽高,内边距,边框,外边距 行内元素宽高自动,并排显示。 2.行内元素有哪些?块级元素有哪些? 空(void)元素有那些?行内元素和块级元素有什么区别? CSS规范规定,每个元素都有display属性,确...

CSS 公共样式摘自万能的度娘

global.css | reset.css(格式化样式) common.css(公共组件样式) layout.css(当前页面样式) 清除全站所有页面的浏览器默认样式,保证在初始样式在所有浏览器下一致。 common.css(公共组件样式) 一般一个网站所有页面头部、底部样式都是一致的,而且很长时间不会有大的改变,改变的大概就是产品、运营的经常需要添加、...