Linux及AIX常用命令

Linux及AIX常用命令

公共篇

  • vi编辑器常用快捷键

    • i --在光标所在位置前插入

    • a --在光标所在位置后插入

    • o --在光标所在行的下一行行首位置插入

    • x --删除光标所在位置字符

    • nx --从当前光标处往后删除n个字符

    • u --撤销最近一次修改

    • gg --将光标移动到首行首列

    • dd --删除光标所在行

    • dG --删除光标所在行(包含光标所在行)之后所有内容

    • ggdG --删除文件全部内容

    • /pattern --从光标开始处向文件尾搜索pattern

    • ?pattern --从光标开始处向文件头搜索pattern

    • :w --保存当前修改内容

    • :e! --放弃所有修改,从上次保存开始处再编辑

    • :wq --保存并退出

    • :q! --不保存退出

    • :set ff=unix --将文件编码格式修改为unix

  • cat

    语法格式:

      cat [-AbeEnstTuv] [--help] [--version] fileName
    

    常用参数:

    • -n     --由1开始对所有输出的行数编号
      [root@db2 yonder]# cat -n test.sh 
          1	This is the world
          2	A beautiful world
          3	
          4	
          5	Hi,world
      
    • -b     --和-n相似,只不过对于空白行不编号
      [root@db2 yonder]# cat -b test.sh 
          1	This is the world
          2	A beautiful world
      
      
          3	Hi,world
      
    • -s     --当遇到有连续两行以上的空白行,就代换为一行的空白行
      [root@db2 yonder]# cat -s test.sh 
      This is the world
      A beautiful world
      
      Hi,world
      
    • -E     --在每行结束处显示$
      This is the world$
      A beautiful world$
      $
      $
      Hi,world$
      
  • more

    语法格式:

      more [-dlfpcsu] [-num] [+/pattern] [+linenum] [fileNames..]
    

    常用参数:

    • -num     --每次显示的行数
      [root@db2 yonder]# more -1 test.sh 
      This is the world
      
    • +num     --从第num行开始显示
      [root@db2 yonder]# more +3 test.sh 
      
      
      Hi,world
      
    • -+/pattern     --在每个文档显示前搜寻该字串(pattern),然后从该字串之后开始显示
      [root@db2 yonder]# more +/Hi test.sh 
      
      ...skipping
      
      
      Hi,world
      
    • -s     --当遇到有连续两行以上的空白行,就代换为一行的空白行
      [root@db2 yonder]# more -s test.sh 
      This is the world
      A beautiful world
      
      Hi,world
      

    常用操作命令

    • Enter 向下n行,需要定义。默认为1行

    • Ctrl+F 或者 空格 向下滚动一屏

    • Ctrl+B 返回上一屏

    • = 输出当前行的行号

    • :f 输出文件名和当前行的行号

    • V 调用vi编辑器

    • !命令 调用Shell,并执行命令

    • q 退出more

  • head
    语法格式:

      head [-cnqv] [-num] [--help] [--version] fileName
    

    常用参数:

    • -num     --查看文件前num行内容
      [root@db2 yonder]# head -1 test.sh 
      This is the world
      
    • -n num     --查看文件前num行内容
      [root@db2 yonder]# head -n 1 test.sh 
      This is the world
      
    • -n -num     --不显示最后num行
      [root@db2 yonder]# head -n -1 test.sh
      This is the world
      A beautiful world
      
      
      
  • tail
    语法格式:

      tail [-cnqvfs] [-num] fileName
    

    常用参数

    • -num     --查看文件最后num行内容

      [root@db2 yonder]# tail -1 test.sh
      Hi,world
      
    • -n num     --查看文件前num行内容

      [root@db2 yonder]# tail -n 1 test.sh
      Hi,world
      
    • -f     --实时读取文件内容

      [root@db2 yonder]# tail -f test.sh
      This is the world
      A beautiful world
      
      
      Hi,world
      
  • awk

    语法格式:

      awk [选项参数] 'script' fileName
    

    常用参数

    • -F     --用指定分隔符分割文件
      [root@db2 yonder]# awk -F" " '{print $1}' test.sh 
      This
      A
      
      
      Hi,world
      
      在这里,使用空格作为分割符并打印出分割之后的第一个域,如果使用空格作为分隔符,-F" "可以省略,如:
      [root@db2 yonder]# awk '{print $1}' test.sh 
      This
      A
      
      
      Hi,world
      
    • -v var=Value     --为变量赋值
      [root@db2 yonder]# awk -v var=1234 '{print var$1}' test.sh 
      1234This
      1234A
      1234
      1234
      1234Hi,world
      

    awk 命令的功能相当强大,并且有很多自己的内建变量,这里只是写出日常处理文件的一个常用参数,如果想了解更多功能,可以在网上查找相关材料,例如:

    • awk '{if ($1~/(aaa|bbb)/)} {print $1}'     --检索首列包含有aaa、bbb字符串的行

    • awk '{if(NR%8!=0)ORS=",";else ORS="\n";print}'     --检每8行变成1行

    • awk '{for(i=1;i<=NF;i++){print $i}}'     --遍历输出

    • awk 'BEGIN{FS=""}{for(i=1;i<=NF;i++){if($i ~ /[[:digit:]]/){str=$i;str1=(str1 str)}}print str1}'     --提取阿拉伯数字

    • awk 'BEGIN{FS=""}{for(i=1;i<=NF;i++){if($i ~ /[^0-9]/){str=$i;str1=(str1 str)}}print str1}'     --提取非阿拉伯数字

    • awk 'BEGIN{FS=""}{for(i=1;i<=NF;i++){if($i ~ /[[:lower:]]/){str=$i;str1=(str1 str)}}print str1}'     --提取小写字母

    • awk 'BEGIN{FS=""}{for(i=1;i<=NF;i++){if($i ~ /[[:upper:]]/){str=$i;str1=(str1 str)}}print str1}'     --提取大写字母

    • awk 'BEGIN{FS=""}{for(i=1;i<=NF;i++){if($i ~ /[[:alpha:]]/){str=$i;str1=(str1 str)}}print str1}'     --提取字母,不区分大小写

  • sed

    语法格式:

      sed [-hnV][-e<script>][-f<script文件>] fileName
    

    常用参数:

    • -e     --以指定动作来处理输入的文本文件

      [root@db2 yonder]# sed -e 3a\Wow,World test.sh 
      This is the world
      A beautiful world
      
      Wow,World
      
      Hi,world
      
    • -n     --显示指定动作处理后的结果

      • 打印文件1-2行
        [root@db2 yonder]# sed -n '1,2p' test.sh 
        This is the world
        A beautiful world
        
      • 打印文件最后一行
        [root@db2 yonder]# sed -n '$p' test.sh 
        Hi,world
        

    常见案例:

    • sed '1,2d'     --删除文件1,2行
      [root@db2 yonder]# sed '1,2d' test.sh 
      
      
      Hi,world
      
    • sed '2d'     --删除文件第2行
      [root@db2 yonder]# sed '2d' test.sh 
      This is the world
      
      
      Hi,world
      
    • sed '/[1]*$/d'     --删除空行
      [root@db2 yonder]# sed  '/^[[:space:]]*$/d' test.sh 
      This is the world
      A beautiful world
      Hi,world
      
    • sed 's/" "//g'     --删除空格
      [root@db2 yonder]# sed 's/ //g' test.sh 
      Thisistheworld
      Abeautifulworld
      
      
      Hi,world
      

    想了解更多功能,可以在网上查找相关材料。

  • grep     --用于查找文件里符合条件的字符串

    语法格式:

      grep [-abcEFGhHilLnqrsvVwxy] filename
    

    常用参数:

    • -n <pattern>     --查找含有关键字pattern的行,并打印行号
      [root@db2 yonder]# grep -n Hi test.sh 
      5:Hi,world
      
    • -v <pattern>     --查找不带关键字pattern的行
      [root@db2 yonder]# grep -v Hi test.sh 
      This is the world
      A beautiful world
      
      
      
    • -c <pattern>     --查找含有关键字pattern的行数
      [root@db2 yonder]# grep -c world test.sh 
      3
      
    • E <pattern1|pattern2>     --查找含有关键字pattern1或者pattern2的行
      [root@db2 yonder]# grep -E "Hi|world" test.sh 
      This is the world
      A beautiful world
      Hi,world
      
    • -i <pattern>     --查找含有关键字pattern的行,不匹配大小写
      [root@db2 yonder]# grep -i world test.sh 
      This is the world
      A beautiful world
      Hi,world
      
    • w <pattern>     --查找含有关键字pattern的行,全词匹配
      [root@db2 yonder]# grep -w world test.sh 
      This is the world
      A beautiful world
      Hi,world
      
  • tr     --用于转换或删除文件中的字符

    • tr [a-z] [A-Z]     --将小写字母替换成大写字母
      [root@db2 yonder]# cat test.sh | tr [a-z] [A-Z]
      THIS IS THE WORLD
      A BEAUTIFUL WORLD
      
      
      HI,WORLD
      
    • tr <pattern1> <pattern2>     --将pattern1替换成pattern2
      [root@db2 yonder]# cat test.sh | tr i I
      ThIs Is the world
      A beautIful world
      
      
      HI,world
      
  • xargs     --是给命令传递参数的一个过滤器,也是组合多个命令的一个工具,用于给类似于ls这种不支持管道符“|”传递参数的命令传递参数

    [root@db2 yonder]# find ./ -type f 
    ./.bashrc
    ./.bash_logout
    ./.bash_profile
    ./test.sh
    ./.bash_history
    [root@db2 yonder]# find ./ -type f | ls -lrt
    total 4
    -rwxr-xr-x 1 root root 47 Mar 12 10:37 test.sh
    [root@db2 yonder]# find ./ -type f | xargs ls -lrt
    -rw-r--r--. 1 yonder yonder 124 Feb 15  2017 ./.bashrc
    -rw-r--r--. 1 yonder yonder 176 Feb 15  2017 ./.bash_profile
    -rw-r--r--. 1 yonder yonder  18 Feb 15  2017 ./.bash_logout
    -rw-------. 1 yonder yonder   5 Jan  9 01:01 ./.bash_history
    -rwxr-xr-x  1 root   root    47 Mar 12 10:37 ./test.sh
    
  • chmod     --更改文件权限

    [root@db2 yonder]# ls -lrt
    total 4
    -rw-r--r-- 1 root root 47 Mar 12 10:37 test.sh
    [root@db2 yonder]# chmod u+x test.sh 
    [root@db2 yonder]# ls -lrt
    total 4
    -rwxr--r-- 1 root root 47 Mar 12 10:37 test.sh
    

    u 表示该文件的拥有者,g 表示与该文件的拥有者属于同一个群体(group)者,o 表示其他以外的人,a 表示这三者皆是。

    + 表示增加权限、- 表示取消权限、= 表示唯一设定权限。

    r 表示可读取,w 表示可写入,x 表示可执行,X 表示只有当该文件是个子目录或者该文件已经被设定过为可执行。

    此外chmod也可以用数字来表示权限,其语法格式为chmod abc file,其中abc各为一个数字,分别表示User、Group、及Other的权限,r=4,w=2,x=1。

    若要rwx属性则4+2+1=7;

    若要rw-属性则4+2=6;

    若要r-x属性则4+1=5,例如:

    [root@db2 yonder]# chmod 755 test.sh 
    [root@db2 yonder]# ls -lrt
    total 4
    -rwxr-xr-x 1 root root 47 Mar 12 10:37 test.sh
    
  • chgrp     --更改文件或目录的属组

    [root@db2 yonder]# ls -lrt
    total 4
    -rw-r--r-- 1 root root 47 Mar 12 10:37 test.sh
    [root@db2 yonder]# chgrp yonder test.sh
    [root@db2 yonder]# ls -lrt
    total 4
    -rw-r--r-- 1 root yonder 47 Mar 12 10:37 test.sh
    

    如果需要指定目录下的所有文件及子目录一并处理,可使用-R参数

  • chown     --更改文件或目录的属主或属组

    [root@db2 yonder]# ls -lrt
    total 4
    -rw-r--r-- 1 root yonder 47 Mar 12 10:37 test.sh
    [root@db2 yonder]# chown yonder test.sh
    [root@db2 yonder]# ls -lrt
    total 4
    -rw-r--r-- 1 yonder yonder 47 Mar 12 10:37 test.sh
    [root@db2 yonder]# chown root:root test.sh
    [root@db2 yonder]# ls -lrt
    total 4
    -rw-r--r-- 1 root root 47 Mar 12 10:37 test.sh
    

    如果需要指定目录下的所有文件及子目录一并处理,可使用-R参数

  • hostname     --查看主机名

    server01:root:/>hostname
    server01
    
  • w     --查看联机用户

    server01:root:/>w
    04:27AM   up 138 days,   4:08,  1 user,  load average: 1.05, 1.09, 1.21
    User     tty          login@       idle      JCPU      PCPU what
    root     pts/2       04:26AM          0         0         0 w
    
  • uptime     --系统运行时间

    server01:root:/>uptime
    04:29AM   up 138 days,   4:11,  1 user,  load average: 1.33, 1.21, 1.24
    
  • ps

    • ps -ef     --查看进程信息
      server01:root:/tmp>ps -ef 
      UID      PID     PPID   C    STIME    TTY  TIME CMD
      root        1        0   0   Oct 26      -  0:36 /etc/init
      root  1704116        1   0   Oct 26      -  0:00 /usr/ccs/bin/shlap64
      root  1966202        1   0   Oct 26      -  0:00 /usr/dt/bin/dtlogin -daemon
      root  2031868        1   0   Oct 26      - 55:31 /usr/sbin/syncd 60
      root  2293934        1   0   Oct 26      -  0:00 /usr/lib/errdemon
      root  2621662        1   0   Oct 26      -  0:00 /usr/sbin/srcmstr
      root  2818262  2621662   0   Oct 26      -  0:00 /usr/sbin/portmap
      root  2949246  2621662   0   Oct 26      -  0:02 /usr/sbin/syslogd
      ...
      
    • ps aux     --查看进程对CPU,Memory的使用情况
      USER          PID %CPU %MEM   SZ  RSS    TTY STAT    STIME  TIME COMMAND
      root      1048608  6.2  0.0  448  448      - A      Oct 26 48917:36 wait
      root      1114146  6.2  0.0  448  448      - A      Oct 26 48917:31 wait
      root       983070  6.2  0.0  448  448      - A      Oct 26 48909:05 wait
      root       131076  6.1  0.0  448  448      - A      Oct 26 48570:53 wait
      oracle    8781944  0.0  2.0 195280 87764      - A      Oct 26 210:47 ora_dia0_devdb
      root      7536756  0.0  0.0  788  824      - A      Feb 22 26:50 sh test.sh 
      root      9175224  0.0  0.0  788  824      - A      Feb 22 26:46 sh test.sh 
      oracle    7078078  0.0  2.0 191148 83632      - A      Oct 26 68:40 ora_mmnl_devdb
      ...
      
  • netstat

    • netstat -an     --查看端口信息
      [root@db2 ~]# netstat -an
      Active Internet connections (servers and established)
      Proto Recv-Q Send-Q Local Address               Foreign Address             State      
      tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
      tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      
      tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      
      tcp        0      0 127.0.0.1:6010              0.0.0.0:*                   LISTEN      
      tcp        0      0 127.0.0.1:6011              0.0.0.0:*                   LISTEN      
      tcp        0      0 127.0.0.1:6012              0.0.0.0:*                   LISTEN      
      tcp        0      0 172.29.30.43:22             172.29.30.187:58117         ESTABLISHED 
      tcp        0     52 172.29.30.43:22             172.29.30.164:51475         ESTABLISHED 
      tcp        0      0 172.29.30.43:22             172.29.30.187:56622         ESTABLISHED 
      tcp        0      0 172.29.30.43:22             172.29.30.187:58115         ESTABLISHED 
      tcp        0      0 172.29.30.43:22             172.29.30.187:56621         ESTABLISHED 
      tcp        0      0 :::50000                    :::*                        LISTEN  
      ...    
      
    • netstat -rn     --查看路由信息
      [root@db2 ~]# netstat -rn
      Kernel IP routing table
      Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
      192.168.193.0   0.0.0.0         255.255.255.0   U         0 0          0 eth1
      172.29.30.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
      169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
      169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth1
      0.0.0.0         192.168.193.2   0.0.0.0         UG        0 0          0 eth1
      

AIX篇

  • ifconfig -a     --查看IP地址

    server01:root:/>ifconfig -a
    en0: flags=1e084863,480<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),CHAIN>
            inet 172.29.13.201 netmask 0xffffff00 broadcast 172.29.13.255
            tcp_sendspace 262144 tcp_recvspace 262144 rfc1323 1
    lo0: flags=e08084b,c0<UP,BROADCAST,LOOPBACK,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,LARGESEND,CHAIN>
            inet 127.0.0.1 netmask 0xff000000 broadcast 127.255.255.255
            inet6 ::1%1/0
            tcp_sendspace 131072 tcp_recvspace 131072 rfc1323 1
    
  • ps -ef|grep defunc     --查看僵尸进程

    server01:root:/>ps -ef|grep defunc
    
  • prtconf     --查看设备信息

    server01:root:/>prtconf
    System Model: IBM,8231-E2B
    Machine Serial Number: 064A6DR
    Processor Type: PowerPC_POWER7
    Processor Implementation Mode: POWER 7
    Processor Version: PV_7_Compat
    Number Of Processors: 1
    Processor Clock Speed: 3000 MHz
    CPU Type: 64-bit
    Kernel Type: 64-bit
    LPAR Info: 2 server01
    Memory Size: 4096 MB
    Good Memory Size: 4096 MB
    Platform Firmware level: AL730_066
    Firmware Version: IBM,AL730_066
    Console Login: enable
    Auto Restart: true
    Full Core: false
    NX Crypto Acceleration: Not Capable
    ...
    
  • cat /etc/security/user     --查看密码策略

    server01:root:/>cat /etc/security/user
    default:
        admin = false
        login = true
        su = true
        daemon = true
        rlogin = true
        sugroups = ALL
        admgroups =
        ttys = ALL
        auth1 = SYSTEM
        auth2 = NONE
        tpath = nosak
        umask = 022
        expires = 0
        SYSTEM = "compat"
        logintimes = 
        pwdwarntime = 0
        account_locked = false
        loginretries = 0
        histexpire = 0
        histsize = 0
        minage = 0
        maxage = 0
        maxexpired = -1
        minalpha = 0
        minother = 0
        minlen = 0
        mindiff = 0
        maxrepeats = 8
        minloweralpha = 0
        minupperalpha  = 0
        mindigit = 0
        minspecialchar = 0
        dictionlist =
        pwdchecks =
        default_roles =
    
  • ps aux | sed 1d | sort -rn +3 | head -10     --查看CPU使用率前十进程

    server01:root:/tmp>ps aux | sed 1d | sort -rn +3| head -10
    oracle    4784274  0.0  3.0 228428 120912      - A      Oct 26  4:27 ora_dbw0_devdb
    root      6553840  0.0  2.0 87548 87616      - A      Oct 26 49:36 /var/opt/tivol
    oracle   15859940  0.0  2.0 190688 83172      - A      Oct 26  2:20 ora_smco_devdb
    oracle   10682396  0.0  2.0 190820 83304      - A    04:21:03  0:00 ora_w000_devdb
    oracle   10158134  0.0  2.0 190864 83348      - A      Oct 26  0:29 ora_q001_devdb
    oracle    9699374  0.0  2.0 197164 89648      - A      Oct 26 20:12 ora_mmon_devdb
    oracle    9502800  0.0  2.0 192476 84960      - A      Oct 26 21:40 ora_ckpt_devdb
    oracle    9371784  0.0  2.0 206376 98860      - A      Oct 26  3:05 ora_lgwr_devdb
    oracle    9044016  0.0  2.0 190740 83224      - A      Oct 26  0:42 ora_qmnc_devdb
    oracle    8978490  0.0  2.0 190700 83184      - A      Oct 26  2:04 ora_mman_devdb
    
  • ps aux | sed 1d | sort -rn +4 | head -10     --查看Memory使用率前十进程

    server01:root:/tmp>ps aux | sed 1d | sort -rn +4 | head -10
    oracle    4784274  0.0  3.0 228428 120912      - A      Oct 26  4:27 ora_dbw0_devdb
    oracle    9371784  0.0  2.0 206376 98860      - A      Oct 26  3:05 ora_lgwr_devdb
    oracle    6947040  0.0  2.0 198092 90576      - A      Oct 26  4:13 ora_smon_devdb
    oracle    9699374  0.0  2.0 197164 89648      - A      Oct 26 20:12 ora_mmon_devdb
    oracle    6815908  0.0  2.0 196540 89024      - A      Oct 26 15:27 ora_cjq0_devdb
    oracle    4587590  0.0  2.0 195884 88368      - A      Oct 26 13:40 ora_pmon_devdb
    oracle    8781944  0.0  2.0 195280 87764      - A      Oct 26 210:48 ora_dia0_devdb
    oracle    8061182  0.0  2.0 194076 86560      - A      Oct 26  0:48 ora_q000_devdb
    oracle    9502800  0.0  2.0 192476 84960      - A      Oct 26 21:40 ora_ckpt_devdb
    oracle    8650848  0.0  2.0 191900 84384      - A      Oct 26 11:38 ora_dbrm_devdb
    
  • rmsock <PCB/ADDR> tcpcb/inpcb     --查看端口被哪个进程占用,如果是TCP连接则使用tcpcb,如果是udp连接则使用inpcb

    • 查看被占用套接字的PCB/ADDR:
      server01:root:/tmp>netstat -Aan | grep 21
      f1000e0000d4b3b8 tcp        0      0  *.21                  *.*                   LISTEN
      
    • 查看端口的进程ID
      server01:root:/tmp>rmsock f1000e0000d4b3b8 tcpcb
      The socket 0xf1000e0000d4b008 is being held by proccess 3801204 (inetd).    
      
    • 查看进程详细信息
      server01:root:/tmp>ps -ef | grep 3801204 | grep -v grep
      root  3801204  2621662   0   Oct 26      -  0:00 /usr/sbin/inetd  
      
  • netstat -Aan | grep tcp | awk '{print $1}' | while read line; do echo "$line $(rmsock $line tcpcb | awk '{print $(NF-1)}')";done | grep <ProcessID>     --通过进程,反查进程使用的端口

    • 查看进程的ProcessID
      server01:root:/>ps -ef | grep tnslsnr | grep -v grep
      oracle 13828322  1   0   Dec 19  -  1:24 /opt/oracle/product/11.2.0/database/bin/tnslsnr LISTENER -inherit
      
    • 查看进程的PCB/ADDR
      server01:root:/>netstat -Aan | grep tcp | awk '{print $1}' | while read line; do echo "$line $(rmsock $line tcpcb | awk '{print $(NF-1)}')";done | grep 13828322
      f1000e0000e263b8 13828322
      
    • 查看进程占用的端口号
      server01:root:/>netstat -Aan | grep f1000e0000e263b8
      f1000e0000e263b8 tcp        0      0  *.1521       *.*            LISTEN
      
  • lsattr -El sys0 -a maxuproc     --查看用户最大进程数

    server01:root:/>lsattr -El sys0 -a maxuproc
    maxuproc 128 Maximum number of PROCESSES allowed per user True
    
  • chdev -l sys0 -a maxuproc=500     --修改用户最大进程数为500

    server01:root:/>chdev -l sys0 -a maxuproc=500
    sys0 changed
    server01:root:/>lsattr -El sys0 -a maxuproc
    maxuproc 500 Maximum number of PROCESSES allowed per user True
    

    说明:如果当前进程总数达到了最大进程数,会导致应用启动失败或者SSH连接失败等问题。

Linux篇

  • ifconfig     --查看IP地址

    [root@db2 ~]# ifconfig
    eth0      Link encap:Ethernet  HWaddr 00:0C:29:17:2D:76  
            inet addr:172.29.30.43  Bcast:172.29.30.255  Mask:255.255.255.0
            inet6 addr: fe80::20c:29ff:fe17:2d76/64 Scope:Link
            UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
            RX packets:222641 errors:0 dropped:0 overruns:0 frame:0
            TX packets:47446 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:1000 
            RX bytes:78662786 (75.0 MiB)  TX bytes:62359695 (59.4 MiB)
    
    eth1      Link encap:Ethernet  HWaddr 00:0C:29:17:2D:80  
            inet addr:192.168.193.182  Bcast:192.168.193.255  Mask:255.255.255.0
            inet6 addr: fe80::20c:29ff:fe17:2d80/64 Scope:Link
            UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
            RX packets:2752 errors:0 dropped:0 overruns:0 frame:0
            TX packets:374 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:1000 
            RX bytes:533961 (521.4 KiB)  TX bytes:24175 (23.6 KiB)
    
  • cat /proc/cpuinfo     --查看CPU信息

    [root@db2 ~]# cat /proc/cpuinfo
    processor	: 0
    vendor_id	: GenuineIntel
    cpu family	: 6
    model		: 142
    model name	: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
    stepping	: 10
    microcode	: 150
    cpu MHz		: 1800.004
    cache size	: 6144 KB
    physical id	: 0
    siblings	: 1
    core id		: 0
    cpu cores	: 1
    apicid		: 0
    initial apicid	: 0
    fpu		: yes
    fpu_exception	: yes
    cpuid level	: 22
    wp		: yes
    flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc up arch_perfmon xtopology ts
    c_reliable nonstop_tsc unfair_spinlock eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch arat xsaveopt invpcid_single ssbd pti ibrs ibpb stibp fsgsbase bmi1 avx2 smep bmi2 invpcid rdseed adx flush_l1d arch_capabilitiesbogomips	: 3600.00
    clflush size	: 64
    cache_alignment	: 64
    address sizes	: 43 bits physical, 48 bits virtual
    power management:
    
  • cat /proc/meminfo     --查看内存信息

    [root@db2 ~]# cat /proc/meminfo
    MemTotal:        1905132 kB
    MemFree:          685744 kB
    Buffers:          118808 kB
    Cached:           520408 kB
    SwapCached:            0 kB
    Active:           699232 kB
    Inactive:         381960 kB
    Active(anon):     442376 kB
    Inactive(anon):    48952 kB
    Active(file):     256856 kB
    Inactive(file):   333008 kB
    Unevictable:           0 kB
    Mlocked:               0 kB
    SwapTotal:       2097148 kB
    SwapFree:        2097148 kB
    Dirty:                 0 kB
    Writeback:             0 kB
    AnonPages:        441992 kB
    Mapped:           129992 kB
    Shmem:             49356 kB
    Slab:              54044 kB
    SReclaimable:      22900 kB
    SUnreclaim:        31144 kB
    ...
    
  • cat /etc/issue     --查看操作系统版本

    [root@db2 ~]# cat /etc/issue
    Red Hat Enterprise Linux Server release 6.9 (Santiago)
    Kernel \r on an \m
    
  • cat /etc/pam.d/system-auth     --查看密码策略

    [root@db2 ~]# cat /etc/pam.d/system-auth
    #%PAM-1.0
    # This file is auto-generated.
    # User changes will be destroyed the next time authconfig is run.
    auth        required      pam_env.so
    auth        sufficient    pam_fprintd.so
    auth        sufficient    pam_unix.so nullok try_first_pass
    auth        requisite     pam_succeed_if.so uid >= 500 quiet
    auth        required      pam_deny.so
    account     required      pam_unix.so
    account     sufficient    pam_localuser.so
    account     sufficient    pam_succeed_if.so uid < 500 quiet
    account     required      pam_permit.so
    password    requisite     pam_cracklib.so try_first_pass retry=3 type=
    password    sufficient    pam_unix.so md5 shadow nullok try_first_pass use_authtok
    password    required      pam_deny.so
    session     optional      pam_keyinit.so revoke
    session     required      pam_limits.so
    session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
    session     required      pam_unix.so
    
  • ps aux |sed 1d |sort -rn +2 -3| head -10     --查看CPU使用率前十进程

    [root@oracle yonder]# ps aux |sed 1d |sort -rn +2 -3| head -10
    oracle    40298  0.6  0.3 1786320 12844 ?       Ss   Mar09   1:01 ora_vkrm_orcl
    oracle    10578  0.6  0.3 1786320 12676 ?       Ss   Mar08  11:03 ora_vktm_orcl
    root          9  0.2  0.0      0     0 ?        S    Mar08   3:36 [rcu_sched]
    root       8564  0.2  0.1 246292  6744 ?        Ss   Mar08   4:24 /usr/bin/vmtoolsd
    root      43006  0.1  0.0      0     0 ?        S    00:37   0:00 [kworker/0:0]
    root       4137  0.1  0.0      0     0 ?        S    Mar08   3:08 [xfsaild/sda3]
    rtkit      8555  0.0  0.0 198792  1804 ?        SNsl Mar08   0:11 /usr/libexec/rtkit-daemon
    rpc        8550  0.0  0.0  73648  1380 ?        Ss   Mar08   0:01 /sbin/rpcbind -w
    root       9855  0.0  0.0  78560  3356 ?        Ss   Mar08   0:03 /usr/sbin/wpa_supplicant 
    root       9854  0.0  0.1 410428  5296 ?        Ssl  Mar08   0:03 /usr/libexec/packagekitd
    
  • ps aux |sed 1d |sort -rn +3 -4| head -10     --查看Memory使用率前十进程

    [root@oracle yonder]# ps aux |sed 1d |sort -rn +3 -4| head -10
    oracle    10592  0.0  7.3 1786320 283348 ?      Ss   Mar08   0:11 ora_mman_orcl
    oracle    10594  0.0  6.5 1792588 251372 ?      Ss   Mar08   0:31 ora_dbw0_orcl
    oracle    10600  0.0  4.5 1793000 174612 ?      Ss   Mar08   0:13 ora_smon_orcl
    gdm        9772  0.0  3.9 3240488 150796 ?      Sl   Mar08   1:21 /usr/bin/gnome-shell
    oracle    40672  0.0  3.4 1845544 134080 ?      Ss   Mar09   0:08 oracleorcl (LOCAL=NO)
    oracle    10604  0.0  2.8 1792256 110148 ?      Ss   Mar08   0:39 ora_mmon_orcl
    oracle    10670  0.0  2.4 1793040 93496 ?       Ss   Mar08   0:33 ora_cjq0_orcl
    oracle    40674  0.0  2.3 1827488 92228 ?       Ss   Mar09   0:02 oracleorcl (LOCAL=NO)
    oracle    10678  0.0  1.3 1791816 50968 ?       Ss   Mar08   0:04 ora_q000_orcl
    oracle    43065  0.5  0.9 1787360 35972 ?       Ss   00:38   0:00 ora_j000_orcl
    
  • netstat -anp     --通过端口号查看进程或通过进程查看端口号

    • 查看进程ID
      [root@oracle yonder]# netstat -anp | grep 1521
      tcp6       0      0 :::1521      :::*        LISTEN      10383/tnslsnr  
      
    • 查看进程详细信息
      [root@oracle yonder]# ps -ef | grep 10383 | grep -v grep
      oracle  10383  1  0 Mar08 ?   00:00:20 /data/oracle/product/11.2.0/db_1/bin/tnslsnr LISTENER -inherit 
      

    注:如果需要通过进程反查端口号,只需要将以上两步骤执行顺序改变即可

  • ulimit -a     --查看用户最大进程数及用户最大打开文件数

    [root@oracle yonder]# ulimit -a
    core file size          (blocks, -c) 0
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 0
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 14960
    max locked memory       (kbytes, -l) 64
    max memory size         (kbytes, -m) unlimited
    open files                      (-n) 1024
    pipe size            (512 bytes, -p) 8
    POSIX message queues     (bytes, -q) 819200
    real-time priority              (-r) 0
    stack size              (kbytes, -s) 8192
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) 14960
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited
    

    可见 max user processes (-u) 14960   即:当前用户最大进程数为14960

         open files (-n) 1024   即:当前用户最大打开文件数为1024

    root账号下ulimit -a出现的max user processes的值默认是/proc/sys/kernel/threads-max的一半,即系统线程数的一半:

    [root@oracle ~]# whoami
    root
    [root@oracle ~]# ulimit -a | grep "max user processes"
    max user processes              (-u) 14960
    [root@oracle ~]# cat /proc/sys/kernel/threads-max
    29920
    

    普通账号下ulimit -a出现的max user processes的值默认是/etc/security/limits.d/20-nproc.conf(centos6 是90-nproc.conf)中的值:

    [root@oracle ~]# su - yonder
    [yonder@oracle ~]$ whoami
    yonder
    Last login: Mon Mar  9 19:43:05 PDT 2020 on pts/0
    [yonder@oracle ~]$ ulimit -a | grep "max user processes"
    max user processes              (-u) 4096
    [yonder@oracle ~]$ cat /etc/security/limits.d/20-nproc.conf
    # Default limit for number of user's processes to prevent
    # accidental fork bombs.
    # See rhbz #432903 for reasoning.
    *          soft    nproc     4096
    root       soft    nproc     unlimited
    
  • vi /etc/security/limits.conf     --修改用户最大进程数

    为yonder用户设置最大进程数:

    [root@oracle ~]# vi /etc/security/limits.conf
    yonder soft nproc 16384
    yonder hard nproc 16384
    
  • vi /etc/security/limits.conf     --修改用户最大打开文件数

    为yonder用户设置最大进程数:

    [root@oracle ~]# vi /etc/security/limits.conf
    yonder soft nofile 65536
    yonder hard nofile 65536
    

  1. [:space:] ↩︎

posted @ 2020-07-08 10:49  拾荒者-B  阅读(722)  评论(0)    收藏  举报