Skip to content

Linux Explore

lanzhiwang edited this page Sep 28, 2018 · 9 revisions

了解Linux服务器

CPU

$ cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l
$ cat /proc/cpuinfo | grep "cpu cores" | uniq
$ cat /proc/cpuinfo | grep "processor" | wc -l

内存

$ free -m
             total       used       free     shared    buffers     cached
Mem:         16049        394      15654          6          0         35
-/+ buffers/cache:        359      15689
Swap:            0          0          0
$
$ free
             total       used       free     shared    buffers     cached
Mem:      16434204     394772   16039432       6772        860      36076
-/+ buffers/cache:     357836   16076368
Swap:            0          0          0
$

硬盘

$ sudo fdisk -l

Disk /dev/vda: 42.9 GB, 42949672960 bytes
4 heads, 32 sectors/track, 655360 cylinders, total 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0007a9ec

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    83886079    41942016   83  Linux

Disk /dev/vdb: 107.4 GB, 107374182400 bytes
16 heads, 63 sectors/track, 208050 cylinders, total 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/vdb doesn't contain a valid partition table
$
$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            7.9G   12K  7.9G   1% /dev
tmpfs           1.6G  372K  1.6G   1% /run
/dev/vda1        40G  2.9G   35G   8% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none            7.9G     0  7.9G   0% /run/shm
none            100M     0  100M   0% /run/user
$
$ iostat -d -x -k 1 5
Linux 3.13.0-92-generic (mongos-01)     07/30/2016     _x86_64_    (4 CPU)

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
vda               0.02     5.20    6.05    6.49    95.99    45.69    22.59     0.21   16.38    0.42   31.25   7.18   9.00
vdb               0.02     0.00    0.15    0.00     0.69     0.00     9.08     0.00    0.37    0.37    0.00   0.37   0.01
$
$ du -sh /var/lib/mongodb/
699M    /var/lib/mongodb/
$
$ cd /
$ sudo du -cks * | sort -rn | head -n 3
du: cannot access ‘proc/4427/task/4427/fd/4’: No such file or directory
du: cannot access ‘proc/4427/task/4427/fdinfo/4’: No such file or directory
du: cannot access ‘proc/4427/fd/4’: No such file or directory
du: cannot access ‘proc/4427/fdinfo/4’: No such file or directory
^C
$ dd if=/dev/zero of=/swapfile bs=1024 count=65536
$ dd if=rhe140.img of=/dev/fd0 bs=10k
$ dd if=mtplinux-3.02.68-1-rhe14.i686 of=/dev/fd0 bs=10k
$ dd if=/dev/cdrom of=/root/cd1.iso
$ mkisofs

平均负载

$ uptime
 06:43:03 up 50 min,  1 user,  load average: 0.28, 0.37, 0.29
$
$ w
 06:43:06 up 50 min,  1 user,  load average: 0.26, 0.36, 0.29
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
ubuntu   pts/0    192.168.11.152   06:30    5.00s  0.05s  0.00s w
$
$ top
top - 06:43:14 up 51 min,  1 user,  load average: 0.24, 0.35, 0.29
Tasks: 120 total,   1 running, 119 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.4 us,  0.3 sy,  0.0 ni, 97.1 id,  2.3 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:  16434204 total,   399044 used, 16035160 free,     2244 buffers
KiB Swap:        0 total,        0 used,        0 free.    38196 cached Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                                                                                 
    1 root      20   0   33508   2844   1476 S   0.0  0.0   0:01.12 init                                                                                                                                                                                                     
    2 root      20   0       0      0      0 S   0.0  0.0   0:00.00 kthreadd                                                                                                                                                                                                 
    3 root      20   0       0      0      0 S   0.0  0.0   0:00.00 ksoftirqd/0                                                                                                                                                                                                                                                                                                                                                                                  
$

综合参数

$ vmstat 1 4
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0 16032004   4792  38312    0    0    30    11  122  357  0  0 97  2  0
$
$ uname -a
Linux mongos-01 3.13.0-92-generic #139-Ubuntu SMP Tue Jun 28 20:42:26 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
$
$ uname -r
3.13.0-92-generic
$
$ file /sbin/init
/sbin/init: ELF 64-bit LSB  shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=7a4c688d009fc1f06ffc692f5f42ab09e68582b2, stripped
$
$ ls -lF / | grep lib64
drwxr-xr-x   2 root root  4096 May 26 18:03 lib64/
$
$ lsb_release -a
No LSB modules are available.
Distributor ID:    Ubuntu
Description:    Ubuntu 14.04.4 LTS
Release:    14.04
Codename:    trusty
$
$ lsmod
Module                  Size  Used by
dm_crypt               23177  0
kvm_intel             143187  0
kvm                   455843  1 kvm_intel
serio_raw              13462  0
crct10dif_pclmul       14289  0
$
$ lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
$

Linux运维常见工具

  • dmesg
  • FIO
  • free
  • iostat
  • ipert
  • mpstat
  • nmon
  • pidstat
  • sar
  • top
  • uptime
  • vmstat
  • gdb
  • mtrace
  • strace
  • fdisk

Linux网络常见工具

  • ifconfig
  • ping
  • netstat
  • nslookup
  • dig
  • finger
  • lsof
  • 网络相关配置
    • 网卡
    • hostname
    • /etc/hosts
    • DNS

Linux进程相关信息

# ps -ef | grep python
root      6747     1  0 Sep06 ?        00:00:00 python manage.py runserver 0.0.0.0:8090
root      6751  6747  1 Sep06 ?        10:25:10 /usr/local/bin/python manage.py runserver 0.0.0.0:8090
# 
# ll /proc/6751
total 0
dr-xr-xr-x  2 root root 0 Sep 28 19:30 attr
-rw-r--r--  1 root root 0 Sep 28 19:30 autogroup
-r--------  1 root root 0 Sep 28 19:30 auxv
-r--r--r--  1 root root 0 Sep 28 19:30 cgroup
--w-------  1 root root 0 Sep 28 19:30 clear_refs
-r--r--r--  1 root root 0 Sep 28 19:21 cmdline
-rw-r--r--  1 root root 0 Sep 28 19:30 comm
-rw-r--r--  1 root root 0 Sep 28 19:30 coredump_filter
-r--r--r--  1 root root 0 Sep 28 19:30 cpuset
lrwxrwxrwx  1 root root 0 Sep 28 19:30 cwd -> /opt/pscms_appmonitor_staticanalysis/scanos_web
-r--------  1 root root 0 Sep 28 19:30 environ
lrwxrwxrwx  1 root root 0 Sep 28 19:30 exe -> /usr/local/bin/python2.7
dr-x------  2 root root 0 Sep 28 19:30 fd
dr-x------  2 root root 0 Sep 28 19:30 fdinfo
-r--------  1 root root 0 Sep 28 19:30 io
-rw-------  1 root root 0 Sep 28 19:30 limits
-rw-r--r--  1 root root 0 Sep 28 19:30 loginuid
-r--r--r--  1 root root 0 Sep 28 19:30 maps
-rw-------  1 root root 0 Sep 28 19:30 mem
-r--r--r--  1 root root 0 Sep 28 19:30 mountinfo
-r--r--r--  1 root root 0 Sep 28 19:30 mounts
-r--------  1 root root 0 Sep 28 19:30 mountstats
dr-xr-xr-x  6 root root 0 Sep 28 19:30 net
dr-x--x--x  2 root root 0 Sep 28 19:30 ns
-r--r--r--  1 root root 0 Sep 28 19:30 numa_maps
-rw-r--r--  1 root root 0 Sep 28 19:30 oom_adj
-r--r--r--  1 root root 0 Sep 28 19:30 oom_score
-rw-r--r--  1 root root 0 Sep 28 19:30 oom_score_adj
-r--r--r--  1 root root 0 Sep 28 19:30 pagemap
-r--r--r--  1 root root 0 Sep 28 19:30 personality
lrwxrwxrwx  1 root root 0 Sep 28 19:30 root -> /
-rw-r--r--  1 root root 0 Sep 28 19:30 sched
-r--r--r--  1 root root 0 Sep 28 19:30 schedstat
-r--r--r--  1 root root 0 Sep 28 19:30 sessionid
-r--r--r--  1 root root 0 Sep 28 19:30 smaps
-r--r--r--  1 root root 0 Sep 28 19:30 stack
-r--r--r--  1 root root 0 Sep 28 12:40 stat
-r--r--r--  1 root root 0 Sep 28 19:30 statm
-r--r--r--  1 root root 0 Sep 28 19:21 status
-r--r--r--  1 root root 0 Sep 28 19:30 syscall
dr-xr-xr-x 14 root root 0 Sep 28 19:30 task
-r--r--r--  1 root root 0 Sep 28 19:30 wchan
# 
Clone this wiki locally