Think Deep,Work Lean

linux之 dmstat vmstat iostat sar ss netstat vim nc

Posted on By zack

dstat

nc

  • 两台服务器不用ssh传输文件,直接nc指定端口,先接收端用nc监听一个端口;传输端直接往这个Ip的端口发就行

在接收端监听端口,并将端口的数据写入文件

root@default:/tmp# nc -l 8888 > /tmp.txt

在发送端往其端口上发送数据

➜  nc 192.168.33.10 8888 < /tmp/txt

成功后会自动断开连接

  • 测试远端服务器端口是否正常 ``` ➜ nc -vz 192.168.33.10 8888 found 0 associations found 1 connections: 1: flags=82<CONNECTED,PREFERRED> outif vboxnet3 src 192.168.33.1 port 51046 dst 192.168.33.10 port 8888 rank info not available TCP aux info available

Connection to 192.168.33.10 port 8888 [tcp/ddi-tcp-1] succeeded!

它分列出源Ip 源端口、目的Ip 目的端口

好了,这是常见的用法;来深入看下,如下为man的部份

NAME nc – arbitrary TCP and UDP connections and listens

SYNOPSIS nc [-46AcDCdhklnrtUuvz] [-b boundif] [-i interval] [-p source_port] [-s source_ip_address] [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [–apple-delegate-pid pid] [–apple-delegate-uuid uuid] [–apple-ext-bk-idle] [–apple-nowakefromsleep] [–apple-ecn mode] [hostname] [port[s]]

DESCRIPTION The nc (or netcat) utility is used for just about anything under the sun involving TCP or UDP. It can open TCP connec- tions, send UDP packets, listen on arbitrary TCP and UDP ports, do port scanning, and deal with both IPv4 and IPv6. Unlike telnet(1), nc scripts nicely, and separates error messages onto standard error instead of sending them to standard output, as telnet(1) does with some.

 Common uses include:

       o   simple TCP proxies
       o   shell-script based HTTP clients and servers
       o   network daemon testing
       o   a SOCKS or HTTP ProxyCommand for ssh(1)
       o   and much, much more

 The options are as follows:

 -4      Forces nc to use IPv4 addresses only.

 -6      Forces nc to use IPv6 addresses only.

 -A      Set SO_RECV_ANYIF on socket.

 -b boundif
         Specifies the interface to bind the socket to.

 -c      Send CRLF as line-ending

 -D      Enable debugging on the socket. ``` 其实我相信man出来的手册基本上已经把功能及使用已经介绍清楚,然而我们的坏毛病在于没有耐心看或是英文头疼,直接百度出来的拿来就用,很方便;然而弊端在于第二次用的时候还是不够熟练;现在我来翻译,静下心来看;

vmstat

root@qingcloud-firstbox:/pitrix/upgrade# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 1004540 184160 424824    0    0     3     2   84  169  0  0 99  0  0
  1. 第一列:procs r b分别表示进程当前读写速度
  2. 第二列:memory:内存相关(swpd cache buffer free)
    • swpd:
    • free:剩余内存
    • buff:buffer,内存等待写入磁盘的缓存文件
    • cache:磁盘写入内存的缓存文件
  3. 第三列:swap,交换分区,服务器会把磁盘部分空间当作内存使用,swap的si so读写速度,如果该项值较大,表明系统内存已经不够用了
  4. io: io读写速度,io是什么?

iostat

top

sar -n DEV 1

ss

netstat

vim

  • vim中 set ignorecase忽略大小写的查找
  • set noignorecase不忽略大小写的查找

先来贴几个最近收藏的图: