centOS7下实践查询版本/CPU/内存/硬盘容量等硬件信息

逃离我推掉我的手 2022-04-10 06:11 440阅读 0赞

https://www.cnblogs.com/zy-plan/p/8617202.html

1.系统

1.1版本

uname -a 能确认是64位还是32位,其它的信息不多

  1. [root@localhost ~]# uname -a
  2. Linux localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

more /etc/*release 可以看到更多信息

  1. [root@localhost ~]# more /etc/*release
  2. ::::::::::::::
  3. /etc/centos-release
  4. ::::::::::::::
  5. CentOS Linux release 7.2.1511 (Core)
  6. ::::::::::::::
  7. /etc/os-release
  8. ::::::::::::::
  9. NAME="CentOS Linux"
  10. VERSION="7 (Core)"
  11. ID="centos"
  12. ID_LIKE="rhel fedora"
  13. VERSION_ID="7"
  14. PRETTY_NAME="CentOS Linux 7 (Core)"
  15. ANSI_COLOR="0;31"
  16. CPE_NAME="cpe:/o:centos:centos:7"
  17. HOME_URL="https://www.centos.org/"
  18. BUG_REPORT_URL="https://bugs.centos.org/"
  19. CENTOS_MANTISBT_PROJECT="CentOS-7"
  20. CENTOS_MANTISBT_PROJECT_VERSION="7"
  21. REDHAT_SUPPORT_PRODUCT="centos"
  22. REDHAT_SUPPORT_PRODUCT_VERSION="7"
  23. ::::::::::::::
  24. /etc/redhat-release
  25. ::::::::::::::
  26. CentOS Linux release 7.2.1511 (Core)
  27. ::::::::::::::
  28. /etc/system-release
  29. ::::::::::::::
  30. CentOS Linux release 7.2.1511 (Core)

1.2核数

  1. cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
  2. [root@localhost ~]# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
  3. 1 Intel(R) Core(TM) i5-6300HQ CPU @ 2.30GHz

1个逻辑CPU,i5型等信息

  1. [root@localhost ~]# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
  2. 8 Intel(R) Xeon(R) CPU E7-4820 v2 @ 2.00GHz

8个逻辑CPU

cat /proc/cpuinfo | grep physical | uniq -c

  1. [root@localhost ~]# cat /proc/cpuinfo | grep physical | uniq -c
  2. 1 physical id : 0
  3. 1 address sizes : 42 bits physical, 48 bits virtual

实际上是一颗一核的CPU

  1. [root@localhost ~]# cat /proc/cpuinfo | grep physical | uniq -c
  2. 1 physical id : 0
  3. 1 address sizes : 40 bits physical, 48 bits virtual
  4. 1 physical id : 0
  5. 1 address sizes : 40 bits physical, 48 bits virtual
  6. 1 physical id : 0
  7. 1 address sizes : 40 bits physical, 48 bits virtual
  8. 1 physical id : 0
  9. 1 address sizes : 40 bits physical, 48 bits virtual
  10. 1 physical id : 0
  11. 1 address sizes : 40 bits physical, 48 bits virtual
  12. 1 physical id : 0
  13. 1 address sizes : 40 bits physical, 48 bits virtual
  14. 1 physical id : 0
  15. 1 address sizes : 40 bits physical, 48 bits virtual
  16. 1 physical id : 0
  17. 1 address sizes : 40 bits physical, 48 bits virtual

由8个1核的CPU组成8核

cat /proc/cpuinfo可以看到更为详细的信息

  1. [root@localhost ~]# cat /proc/cpuinfo
  2. processor : 0
  3. vendor_id : GenuineIntel
  4. cpu family : 6
  5. model : 94
  6. model name : Intel(R) Core(TM) i5-6300HQ CPU @ 2.30GHz
  7. stepping : 3
  8. microcode : 0x74
  9. cpu MHz : 2304.004
  10. cache size : 6144 KB
  11. physical id : 0
  12. siblings : 1
  13. core id : 0
  14. cpu cores : 1
  15. apicid : 0
  16. initial apicid : 0
  17. fpu : yes
  18. fpu_exception : yes
  19. cpuid level : 22
  20. wp : yes
  21. flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf 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 ida arat epb pln pts dtherm hwp hwp_noitfy hwp_act_window hwp_epp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 invpcid rtm rdseed adx smap xsaveopt xsavec xgetbv1 xsaves
  22. bogomips : 4608.00
  23. clflush size : 64
  24. cache_alignment : 64
  25. address sizes : 42 bits physical, 48 bits virtual
  26. power management:

1.3运行模式

getconf LONG_BIT CPU运行在多少位模式下

  1. [root@localhost ~]# getconf LONG_BIT
  2. 64

如果是32,说明当前CPU运行在32bit模式下, 但不代表CPU不支持64bit

cat /proc/cpuinfo | grep flags | grep ‘ lm ‘ | wc -l 是否支持64位

  1. [root@localhost ~]# cat /proc/cpuinfo | grep flags | grep ' lm ' | wc -l
  2. 1

结果大于0, 说明支持64bit计算. lm指long mode, 支持lm则是64bit

1.4计算机名

hostname

  1. [root@localhost ~]# hostname
  2. localhost.localdomain

1.5.查看环境变量

env

  1. [root@localhost ~]# env
  2. XDG_SESSION_ID=4
  3. HOSTNAME=localhost.localdomain
  4. SELINUX_ROLE_REQUESTED=
  5. TERM=vt100
  6. SHELL=/bin/bash
  7. HISTSIZE=1000
  8. SSH_CLIENT=192.168.174.1 58896 22
  9. SELINUX_USE_CURRENT_RANGE=
  10. SSH_TTY=/dev/pts/0
  11. USER=root

1.6系统允许多长时间了/负载数

uptime

  1. [root@localhost proc]# uptime
  2. 10:55:01 up 1:28, 2 users, load average: 0.00, 0.01, 0.05

1.当前时间10:55:01

2.系统运行了多少时间,1:28(1小时28分)

3.多少个用户,2 users

4.平均负载:0.00, 0.01, 0.05,最近1分钟、5分钟、15分钟系统的负载

直接查看平均负载情况 cat /proc/loadavg

  1. [root@localhost proc]# cat /proc/loadavg
  2. 0.00 0.01 0.05 4/524 7152

除了前3个数字表示平均进程数量外,后面的1个分数,分母表示系统进程总数,分子表示正在运行的进程数;最后一个数字表示最近运行的进程ID

2.资源

2.1内存

cat /proc/meminfo内存的详细信息

  1. [root@localhost proc]# cat /proc/meminfo
  2. MemTotal: 1001332 kB
  3. MemFree: 99592 kB
  4. MemAvailable: 420940 kB
  5. Buffers: 1064 kB
  6. Cached: 405292 kB
  7. SwapCached: 0 kB
  8. Active: 412548 kB
  9. Inactive: 250192 kB
  10. Active(anon): 205264 kB
  11. Inactive(anon): 58460 kB
  12. Active(file): 207284 kB
  13. Inactive(file): 191732 kB
  14. Unevictable: 0 kB
  15. Mlocked: 0 kB
  16. SwapTotal: 2097148 kB
  17. SwapFree: 2097140 kB
  18. Dirty: 0 kB
  19. Writeback: 0 kB
  20. AnonPages: 256416 kB
  21. Mapped: 103344 kB
  22. Shmem: 7340 kB
  23. Slab: 126408 kB
  24. SReclaimable: 69912 kB
  25. SUnreclaim: 56496 kB
  26. KernelStack: 10416 kB
  27. PageTables: 15520 kB
  28. NFS_Unstable: 0 kB
  29. Bounce: 0 kB
  30. WritebackTmp: 0 kB
  31. CommitLimit: 2597812 kB
  32. Committed_AS: 1578872 kB
  33. VmallocTotal: 34359738367 kB
  34. VmallocUsed: 170756 kB
  35. VmallocChunk: 34359564288 kB
  36. HardwareCorrupted: 0 kB
  37. AnonHugePages: 75776 kB
  38. HugePages_Total: 0
  39. HugePages_Free: 0
  40. HugePages_Rsvd: 0
  41. HugePages_Surp: 0
  42. Hugepagesize: 2048 kB
  43. DirectMap4k: 73600 kB
  44. DirectMap2M: 974848 kB
  45. DirectMap1G: 0 kB

MemTotal总内存,MemFree可用内存
free -m(-m,单位是m,如果是-g,单位是g)查看可用内存

  1. [root@localhost proc]# free -m
  2. total used free shared buff/cache available
  3. Mem: 977 360 97 7 520 411
  4. Swap: 2047 0 2047

空闲内存total-used=free+buff/cache

我们通过free命令查看机器空闲内存时,会发现free的值很小。这主要是因为,在linux中有这么一种思想,内存不用白不用,因此它尽可能的cache和buffer一些数据,以方便下次使用。但实际上这些内存也是可以立刻拿来使用的。

3.磁盘和分区

3.1查看各分区使用情况

df -h

  1. [root@localhost ~]# df -h
  2. Filesystem Size Used Avail Use% Mounted on
  3. /dev/mapper/centos-root 45G 22G 24G 48% /
  4. devtmpfs 906M 0 906M 0% /dev
  5. tmpfs 921M 96K 921M 1% /dev/shm
  6. tmpfs 921M 1004K 920M 1% /run
  7. tmpfs 921M 0 921M 0% /sys/fs/cgroup
  8. /dev/sda1 497M 195M 303M 40% /boot
  9. tmpfs 185M 0 185M 0% /run/user/1001
  10. tmpfs 185M 0 185M 0% /run/user/0
  11. [root@localhost ~]#

3.2查看指定目录的大小

du -sh <目录名>

  1. [root@localhost ~]# du -sh /root
  2. 1.2G /root

3.3查看所有分区

fdisk -l

  1. [root@localhost proc]# fdisk -l
  2. 磁盘 /dev/sda32.2 GB, 32212254720 字节,62914560 个扇区
  3. Units = 扇区 of 1 * 512 = 512 bytes
  4. 扇区大小(逻辑/物理):512 字节 / 512 字节
  5. I/O 大小(最小/最佳):512 字节 / 512 字节
  6. 磁盘标签类型:dos
  7. 磁盘标识符:0x000a0cd4
  8. 设备 Boot Start End Blocks Id System
  9. /dev/sda1 * 2048 1026047 512000 83 Linux
  10. /dev/sda2 1026048 62914559 30944256 8e Linux LVM
  11. 磁盘 /dev/mapper/centos-root29.5 GB, 29490151424 字节,57597952 个扇区
  12. Units = 扇区 of 1 * 512 = 512 bytes
  13. 扇区大小(逻辑/物理):512 字节 / 512 字节
  14. I/O 大小(最小/最佳):512 字节 / 512 字节
  15. 磁盘 /dev/mapper/centos-swap2147 MB, 2147483648 字节,4194304 个扇区
  16. Units = 扇区 of 1 * 512 = 512 bytes
  17. 扇区大小(逻辑/物理):512 字节 / 512 字节
  18. I/O 大小(最小/最佳):512 字节 / 512 字节
  19. 磁盘 /dev/mapper/centos-docker--poolmeta33 MB, 33554432 字节,65536 个扇区
  20. Units = 扇区 of 1 * 512 = 512 bytes
  21. 扇区大小(逻辑/物理):512 字节 / 512 字节
  22. I/O 大小(最小/最佳):512 字节 / 512 字节
  23. 磁盘 /dev/mapper/docker-253:0-101330881-pool107.4 GB, 107374182400 字节,209715200 个扇区
  24. Units = 扇区 of 1 * 512 = 512 bytes
  25. 扇区大小(逻辑/物理):512 字节 / 512 字节
  26. I/O 大小(最小/最佳):65536 字节 / 65536 字节

3.4查看所有交换分区

swapon -s

  1. [root@localhost proc]# swapon -s
  2. 文件名 类型 大小 已用 权限
  3. /dev/dm-1 partition 2097148 8 -1

4.网络

4.1查看所有网络接口的属性

ifconfig

  1. [root@localhost proc]# ifconfig
  2. docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
  3. inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
  4. ether 02:42:e1:b8:a5:4f txqueuelen 0 (Ethernet)
  5. RX packets 0 bytes 0 (0.0 B)
  6. RX errors 0 dropped 0 overruns 0 frame 0
  7. TX packets 0 bytes 0 (0.0 B)
  8. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  9. eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  10. inet 192.168.174.129 netmask 255.255.255.0 broadcast 192.168.174.255
  11. inet6 fe80::20c:29ff:fe50:b3b4 prefixlen 64 scopeid 0x20<link>
  12. ether 00:0c:29:50:b3:b4 txqueuelen 1000 (Ethernet)
  13. RX packets 28649 bytes 38411280 (36.6 MiB)
  14. RX errors 0 dropped 0 overruns 0 frame 0
  15. TX packets 8937 bytes 1226914 (1.1 MiB)
  16. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  17. lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
  18. inet 127.0.0.1 netmask 255.0.0.0
  19. inet6 ::1 prefixlen 128 scopeid 0x10<host>
  20. loop txqueuelen 0 (Local Loopback)
  21. RX packets 4 bytes 340 (340.0 B)
  22. RX errors 0 dropped 0 overruns 0 frame 0
  23. TX packets 4 bytes 340 (340.0 B)
  24. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  25. virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
  26. inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
  27. ether 00:00:00:00:00:00 txqueuelen 0 (Ethernet)
  28. RX packets 0 bytes 0 (0.0 B)
  29. RX errors 0 dropped 0 overruns 0 frame 0
  30. TX packets 0 bytes 0 (0.0 B)
  31. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

4.2 带宽

ethtool 网卡名

  1. [root@localhost php-tomcat-base]# ethtool ens192
  2. Settings for ens192:
  3. Supported ports: [ TP ]
  4. Supported link modes: 1000baseT/Full
  5. 10000baseT/Full
  6. Supported pause frame use: No
  7. Supports auto-negotiation: No
  8. Advertised link modes: Not reported
  9. Advertised pause frame use: No
  10. Advertised auto-negotiation: No
  11. Speed: 10000Mb/s
  12. Duplex: Full
  13. Port: Twisted Pair
  14. PHYAD: 0
  15. Transceiver: internal
  16. Auto-negotiation: off
  17. MDI-X: Unknown
  18. Supports Wake-on: uag
  19. Wake-on: d
  20. Link detected: yes

看Speed

4.3查看路由表

route -n

  1. [root@localhost proc]# route -n
  2. Kernel IP routing table
  3. Destination Gateway Genmask Flags Metric Ref Use Iface
  4. 0.0.0.0 192.168.174.2 0.0.0.0 UG 100 0 0 eth0
  5. 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
  6. 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
  7. 192.168.174.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
  8. [root@localhost proc]#

4.4查看所有监听端口

netstat -lntp

  1. [root@localhost ~]# netstat -lntp
  2. Active Internet connections (only servers)
  3. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  4. tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 743/rpcbind
  5. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1740/nginx: master
  6. tcp 0 0 0.0.0.0:81 0.0.0.0:* LISTEN 1740/nginx: master
  7. tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2194/dnsmasq
  8. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1543/sshd
  9. tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 12610/cupsd
  10. tcp 0 0 0.0.0.0:40536 0.0.0.0:* LISTEN 19964/rpc.statd
  11. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2133/master
  12. tcp6 0 0 :::111 :::* LISTEN 743/rpcbind
  13. tcp6 0 0 :::81 :::* LISTEN 1740/nginx: master
  14. tcp6 0 0 :::22 :::* LISTEN 1543/sshd
  15. tcp6 0 0 ::1:631 :::* LISTEN 12610/cupsd
  16. tcp6 0 0 ::1:25 :::* LISTEN 2133/master
  17. tcp6 0 0 :::35420 :::* LISTEN 19964/rpc.statd
  18. [root@localhost ~]#

4.5查看所有已经建立的连接

netstat -antp

  1. [root@localhost ~]# netstat -antp
  2. Active Internet connections (servers and established)
  3. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  4. tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 743/rpcbind
  5. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1740/nginx: master
  6. tcp 0 0 0.0.0.0:81 0.0.0.0:* LISTEN 1740/nginx: master
  7. tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2194/dnsmasq
  8. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1543/sshd
  9. tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 12610/cupsd
  10. tcp 0 0 0.0.0.0:40536 0.0.0.0:* LISTEN 19964/rpc.statd
  11. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2133/master
  12. tcp 0 0 172.31.4.233:22 121.34.147.13:57190 ESTABLISHED 29540/sshd: cavan [
  13. tcp 0 0 172.31.4.233:22 121.34.147.13:54544 ESTABLISHED 27077/sshd: cavan [
  14. tcp 0 96 172.31.4.233:22 219.137.32.66:60645 ESTABLISHED 30315/sshd: root@pt
  15. tcp 0 0 172.31.4.233:22 121.34.147.13:56319 ESTABLISHED 28703/sshd: cavan [
  16. tcp6 0 0 :::111 :::* LISTEN 743/rpcbind
  17. tcp6 0 0 :::81 :::* LISTEN 1740/nginx: master
  18. tcp6 0 0 :::22 :::* LISTEN 1543/sshd
  19. tcp6 0 0 ::1:631 :::* LISTEN 12610/cupsd
  20. tcp6 0 0 ::1:25 :::* LISTEN 2133/master
  21. tcp6 0 0 :::35420 :::* LISTEN 19964/rpc.statd
  22. [root@localhost ~]#

4.6 某端口使用情况

lsof -i:端口号

  1. [root@localhost mysql]# lsof -i:22
  2. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  3. sshd 1150 root 3u IPv4 18264 0t0 TCP *:ssh (LISTEN)
  4. sshd 1150 root 4u IPv6 18273 0t0 TCP *:ssh (LISTEN)
  5. sshd 2617 root 3u IPv4 20437 0t0 TCP localhost.localdomain:ssh->192.168.174.1:60426 (ESTABLISHED)
  6. [root@localhost mysql]#

或者

netstat -apn|grep 端口号

  1. [root@localhost mysql]# netstat -apn|grep 22
  2. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1150/sshd
  3. tcp 0 96 192.168.174.136:22 192.168.174.1:60426 ESTABLISHED 2617/sshd: root@pts
  4. tcp6 0 0 :::22 :::* LISTEN 1150/sshd

5.进程

5.1查看所有进程

ps -ef,使用ps -ef|gerp tomcat过滤

  1. [root@localhost ~]# ps -ef
  2. UID PID PPID C STIME TTY TIME CMD
  3. root 1 0 0 09:26 ? 00:00:03 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
  4. root 2 0 0 09:26 ? 00:00:00 [kthreadd]
  5. root 3 2 0 09:26 ? 00:00:00 [ksoftirqd/0]
  6. root 6 2 0 09:26 ? 00:00:00 [kworker/u256:0]
  7. root 7 2 0 09:26 ? 00:00:00 [migration/0]
  8. root 8 2 0 09:26 ? 00:00:00 [rcu_bh]
  9. root 9 2 0 09:26 ? 00:00:00 [rcuob/0]
  10. root 10 2 0 09:26 ? 00:00:00 [rcuob/1]
  11. root 11 2 0 09:26 ? 00:00:00 [rcuob/2]
  12. root 12 2 0 09:26 ? 00:00:00 [rcuob/3]
  13. root 13 2 0 09:26 ? 00:00:00 [rcuob/4]
  14. root 14 2 0 09:26 ? 00:00:00 [rcuob/5]
  15. root 15 2 0 09:26 ? 00:00:00 [rcuob/6]
  16. root 16 2

ps -aux可以看到进程占用CPU,内存情况

  1. [root@localhost ~]# ps -aux
  2. USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
  3. root 1 0.0 0.6 126124 6792 ? Ss 09:26 0:03 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
  4. root 2 0.0 0.0 0 0 ? S 09:26 0:00 [kthreadd]
  5. root 3 0.0 0.0 0 0 ? S 09:26 0:00 [ksoftirqd/0]
  6. root 6 0.0 0.0 0 0 ? S 09:26 0:00 [kworker/u256:0]
  7. root 7 0.0 0.0 0 0 ? S 09:26 0:00 [migration/0]
  8. root 8 0.0 0.0 0 0 ? S 09:26 0:00 [rcu_bh]
  9. root 9 0.0 0.0 0 0 ? S 09:26 0:00 [rcuob/0]
  10. root 10 0.

5.2实时显示进程状态

top

  1. [root@localhost ~]# top
  2. top - 11:29:02 up 2:02, 2 users, load average: 0.12, 0.04, 0.05
  3. Tasks: 408 total, 2 running, 406 sleeping, 0 stopped, 0 zombie
  4. %Cpu(s): 1.3 us, 0.3 sy, 0.0 ni, 98.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
  5. KiB Mem : 1001332 total, 92184 free, 370332 used, 538816 buff/cache
  6. KiB Swap: 2097148 total, 2097140 free, 8 used. 419124 avail Mem
  7. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  8. 3001 gdm 20 0 1419364 122996 45860 S 1.0 12.3 0:06.50 gnome-shell
  9. 276 root 20 0 0 0 0 S 0.3 0.0 0:09.72 kworker/0:1
  10. 3765 root 20 0 142864 5128 3876 S 0.3 0.5 0:00.77 sshd
  11. 7740 root 20 0 146452 2384 1432 R 0.3 0.2 0:00.17 top
  12. 1 root 20 0 126124 6792 3912 S 0.0 0.7 0:03.58 systemd
  13. 2 root 20 0 0 0 0 S 0.0 0.0 0:00.03 kthreadd
  14. 3 root 20 0 0 0 0 S 0.0 0.0 0:00.37 ksoftirqd/0
  15. 6 root 20 0 0 0 0 S 0.0 0.0 0:00.39 kworker/u256:0
  16. 7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
  17. 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
  18. 9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/0
  19. 10 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/1
  20. 11 root 20 0 0

6.用户

6.1查看活动用户

w

  1. [root@localhost ~]# w
  2. 11:32:36 up 72 days, 20:50, 3 users, load average: 0.00, 0.01, 0.05
  3. USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
  4. cavan pts/0 121.34.147.13 09:47 1:14m 0.17s 0.17s sshd: cavan [priv]
  5. root pts/1 219.137.32.66 11:19 4.00s 0.05s 0.00s w
  6. cavan pts/3 121.34.147.13 10:14 20:44 0.38s 0.11s vim Dockerfile
  7. [root@localhost ~]#

6.2查看指定用户的信息

id <用户名>

  1. [root@localhost ~]# id root
  2. uid=0(root) gid=0(root) groups=0(root)
  3. [root@localhost ~]# id cavan
  4. uid=1001(cavan) gid=1001(cavan) groups=1001(cavan)
  5. [root@localhost ~]#

6.3查看用户登录日志

last

  1. [root@localhost 1]# last
  2. root pts/0 192.168.174.1 Mon Oct 24 09:51 still logged in
  3. (unknown :0 :0 Mon Oct 24 09:27 still logged in
  4. reboot system boot 3.10.0-327.el7.x Mon Oct 24 09:26 - 11:35 (02:09)
  5. root pts/0 192.168.174.1 Fri Oct 21 09:41 - 18:44 (09:03)
  6. (unknown :0 :0 Fri Oct 21 09:15 - 18:44 (09:28)
  7. reboot system boot 3.10.0-327.el7.x Fri Oct 21 09:15 - 11:35 (3+02:20)
  8. root pts/1 192.168.174.1 Thu Oct 20 10:05 - 18:13 (08:08)
  9. root pts/0

6.4查看系统所有用户

cut -d: -f1 /etc/passwd

  1. [root@localhost ~]# cut -d: -f1 /etc/passwd
  2. root
  3. bin
  4. daemon
  5. adm
  6. lp
  7. sync
  8. shutdown
  9. halt
  10. mail
  11. operator
  12. games
  13. ftp
  14. nobody
  15. dbus
  16. polkitd
  17. abrt
  18. unbound
  19. colord
  20. usbmuxd
  21. ntp

http://www.linuxidc.com/Linux/2016-11/137550.htm

http://blog.csdn.net/dream\_broken/article/details/52883883

前言

记下CentOS 7查看系统版本及查看机器位数x86-64的方法,由于不经常使用Linux,每当使用的时候就是安装软件,安装软件的时候就要选择安装包平台,是32位的还是64位的。这时候突然发现不知道怎么查,于是百度。虽然轻而易举百度出来,但仍旧没有自己的笔记看起来舒服。所以,还是记录下来。

辨识标准

首先要清楚什么样标识是32位的,什么样的是64位的。

PC server X86 系列

I386—I686 都是32位

x86_6464位

查看位数命令

命令实在是不要太多,为了防止选择性障碍,一致选择第一种方式,后面的仅作为补充。
方法1:

  1. [root@linuxidc ~]# uname -a
  2. Linux linuxidc 3.10.0-327.18.2.el7.x86_64 #1 SMP Thu May 12 11:03:55 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

方法2:显示系统程序信息

  1. [root@linuxidc ~]# file /bin/ls
  2. /bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=aa7ff68f13de25936a098016243ce57c3c982e06, stripped

方法3:

  1. [root@linuxidc ~]# cat /proc/version
  2. Linux version 3.10.0-327.18.2.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) ) #1 SMP Thu May 12 11:03:55 UTC 2016

方法4:

(32位的系统中int类型和long类型一般都是4字节,64位的系统中int类型还是4字节的,但是long已变成了8字节inux系统中可用”getconf WORD_BIT”和
“getconf LONG_BIT”获得word和long的位数。64位系统中应该分别得到32和64。)

  1. [root@linuxidc ~]# getconf LONG_BIT
  2. 64

查看系统版本

方法1:《这个命令试过不好用》

  1. [root@linuxidc ~]# lsb_release -a
  2. LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
  3. Distributor ID: CentOS
  4. Description: CentOS Linux release 7.2.1511 (Core)
  5. Release: 7.2.1511
  6. Codename: Core

方法2:

  1. [root@linuxidc ~]# cat /etc/os-release
  2. NAME="CentOS Linux"
  3. VERSION="7 (Core)"
  4. ID="centos"
  5. ID_LIKE="rhel Fedora"
  6. VERSION_ID="7"
  7. PRETTY_NAME="CentOS Linux 7 (Core)"
  8. ANSI_COLOR="0;31"
  9. CPE_NAME="cpe:/o:centos:centos:7"
  10. HOME_URL="https://www.centos.org/"
  11. BUG_REPORT_URL="https://bugs.centos.org/"
  12. CENTOS_MANTISBT_PROJECT="CentOS-7"
  13. CENTOS_MANTISBT_PROJECT_VERSION="7"
  14. RedHat_SUPPORT_PRODUCT="centos"
  15. REDHAT_SUPPORT_PRODUCT_VERSION="7"

方法3:

  1. [root@linuxidc ~]# cat /etc/redhat-release
  2. CentOS Linux release 7.2.1511 (Core)

方法4:

  1. [root@linuxidc ~]# rpm -q centos-release
  2. centos-release-7-2.1511.el7.centos.2.10.x86_64

    方法5:查看系统版本

cat /etc/redhat-release

这里写图片描述

查看内核版本

方法1:

  1. [root@linuxidc ~]# cat /proc/version
  2. Linux version 3.10.0-327.18.2.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) ) #1 SMP Thu May 12 11:03:55 UTC 2016

方法2:

  1. [root@linuxidc ~]# uname -a
  1. Linux linuxidc 3.10.0-327.18.2.el7.x86_64 #1 SMP Thu May 12 11:03:55 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

更多CentOS相关信息见CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14

1.系统

1.1版本

uname -a 能确认是64位还是32位,其它的信息不多

[html] view plain copy

  1. [root@localhost ~]# uname -a
  2. Linux localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

    more /etc/*release 可以看到更多信息

[html] view plain copy

  1. [root@localhost ~]# more /etc/*release
  2. ::::::::::::::
  3. /etc/centos-release
  4. ::::::::::::::
  5. CentOS Linux release 7.2.1511 (Core)
  6. ::::::::::::::
  7. /etc/os-release
  8. ::::::::::::::
  9. NAME=”CentOS Linux”
  10. VERSION=”7 (Core)”
  11. ID=”centos”
  12. ID_LIKE=”rhel fedora”
  13. VERSION_ID=”7”
  14. PRETTY_NAME=”CentOS Linux 7 (Core)”
  15. ANSI_COLOR=”0;31”
  16. CPE_NAME=”cpe:/o:centos:centos:7”
  17. HOME_URL=”https://www.centos.org/“
  18. BUG_REPORT_URL=”https://bugs.centos.org/“
  19. CENTOS_MANTISBT_PROJECT=”CentOS-7”
  20. CENTOS_MANTISBT_PROJECT_VERSION=”7”
  21. REDHAT_SUPPORT_PRODUCT=”centos”
  22. REDHAT_SUPPORT_PRODUCT_VERSION=”7”
  23. ::::::::::::::
  24. /etc/redhat-release
  25. ::::::::::::::
  26. CentOS Linux release 7.2.1511 (Core)
  27. ::::::::::::::
  28. /etc/system-release
  29. ::::::::::::::
  30. CentOS Linux release 7.2.1511 (Core)

1.2核数

  1. cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
  2. \[html\] [view plain][] [copy][view plain]
  1. [root@localhost ~]# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
  2. 1 Intel(R) Core(TM) i5-6300HQ CPU @ 2.30GHz

    1个逻辑CPU,i5型等信息[html] view plain copy

  1. [root@localhost ~]# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
  2. 8 Intel(R) Xeon(R) CPU E7-4820 v2 @ 2.00GHz

    8个逻辑CPU

cat /proc/cpuinfo | grep physical | uniq -c

[html] view plain copy

  1. [root@localhost ~]# cat /proc/cpuinfo | grep physical | uniq -c
  2. 1 physical id : 0
  3. 1 address sizes : 42 bits physical, 48 bits virtual

    实际上是一颗一核的CPU[html] view plain copy

  1. [root@localhost ~]# cat /proc/cpuinfo | grep physical | uniq -c
  2. 1 physical id : 0
  3. 1 address sizes : 40 bits physical, 48 bits virtual
  4. 1 physical id : 0
  5. 1 address sizes : 40 bits physical, 48 bits virtual
  6. 1 physical id : 0
  7. 1 address sizes : 40 bits physical, 48 bits virtual
  8. 1 physical id : 0
  9. 1 address sizes : 40 bits physical, 48 bits virtual
  10. 1 physical id : 0
  11. 1 address sizes : 40 bits physical, 48 bits virtual
  12. 1 physical id : 0
  13. 1 address sizes : 40 bits physical, 48 bits virtual
  14. 1 physical id : 0
  15. 1 address sizes : 40 bits physical, 48 bits virtual
  16. 1 physical id : 0
  17. 1 address sizes : 40 bits physical, 48 bits virtual

    由8个1核的CPU组成8核

cat /proc/cpuinfo可以看到更为详细的信息

[html] view plain copy

  1. [root@localhost ~]# cat /proc/cpuinfo
  2. processor : 0
  3. vendor_id : GenuineIntel
  4. cpu family : 6
  5. model : 94
  6. model name : Intel(R) Core(TM) i5-6300HQ CPU @ 2.30GHz
  7. stepping : 3
  8. microcode : 0x74
  9. cpu MHz : 2304.004
  10. cache size : 6144 KB
  11. physical id : 0
  12. siblings : 1
  13. core id : 0
  14. cpu cores : 1
  15. apicid : 0
  16. initial apicid : 0
  17. fpu : yes
  18. fpu_exception : yes
  19. cpuid level : 22
  20. wp : yes
  21. flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf 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 ida arat epb pln pts dtherm hwp hwp_noitfy hwp_act_window hwp_epp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 invpcid rtm rdseed adx smap xsaveopt xsavec xgetbv1 xsaves
  22. bogomips : 4608.00
  23. clflush size : 64
  24. cache_alignment : 64
  25. address sizes : 42 bits physical, 48 bits virtual
  26. power management:

1.3运行模式

getconf LONG_BIT CPU运行在多少位模式下[html] view plain copy

  1. [root@localhost ~]# getconf LONG_BIT
  2. 64

如果是32,说明当前CPU运行在32bit模式下, 但不代表CPU不支持64bit

cat /proc/cpuinfo | grep flags | grep ‘ lm ‘ | wc -l 是否支持64位

[html] view plain copy

  1. [root@localhost ~]# cat /proc/cpuinfo | grep flags | grep ‘ lm ‘ | wc -l
  2. 1

结果大于0, 说明支持64bit计算. lm指long mode, 支持lm则是64bit

1.4计算机名

hostname

[html] view plain copy

  1. [root@localhost ~]# hostname
  2. localhost.localdomain

1.5.查看环境变量

env

[html] view plain copy

  1. [root@localhost ~]# env
  2. XDG_SESSION_ID=4
  3. HOSTNAME=localhost.localdomain
  4. SELINUX_ROLE_REQUESTED=
  5. TERM=vt100
  6. SHELL=/bin/bash
  7. HISTSIZE=1000
  8. SSH_CLIENT=192.168.174.1 58896 22
  9. SELINUX_USE_CURRENT_RANGE=
  10. SSH_TTY=/dev/pts/0
  11. USER=root

1.6系统允许多长时间了/负载数

uptime

[html] view plain copy

  1. [root@localhost proc]# uptime
  2. 10:55:01 up 1:28, 2 users, load average: 0.00, 0.01, 0.05

1.当前时间10:55:01

2.系统运行了多少时间,1:28(1小时28分)

3.多少个用户,2 users

4.平均负载:0.00, 0.01, 0.05,最近1分钟、5分钟、15分钟系统的负载

直接查看平均负载情况 cat /proc/loadavg

[html] view plain copy

  1. [root@localhost proc]# cat /proc/loadavg
  2. 0.00 0.01 0.05 4/524 7152

    除了前3个数字表示平均进程数量外,后面的1个分数,分母表示系统进程总数,分子表示正在运行的进程数;最后一个数字表示最近运行的进程ID

2.资源

2.1内存

cat /proc/meminfo内存的详细信息

[html] view plain copy

  1. [root@localhost proc]# cat /proc/meminfo
  2. MemTotal: 1001332 kB
  3. MemFree: 99592 kB
  4. MemAvailable: 420940 kB
  5. Buffers: 1064 kB
  6. Cached: 405292 kB
  7. SwapCached: 0 kB
  8. Active: 412548 kB
  9. Inactive: 250192 kB
  10. Active(anon): 205264 kB
  11. Inactive(anon): 58460 kB
  12. Active(file): 207284 kB
  13. Inactive(file): 191732 kB
  14. Unevictable: 0 kB
  15. Mlocked: 0 kB
  16. SwapTotal: 2097148 kB
  17. SwapFree: 2097140 kB
  18. Dirty: 0 kB
  19. Writeback: 0 kB
  20. AnonPages: 256416 kB
  21. Mapped: 103344 kB
  22. Shmem: 7340 kB
  23. Slab: 126408 kB
  24. SReclaimable: 69912 kB
  25. SUnreclaim: 56496 kB
  26. KernelStack: 10416 kB
  27. PageTables: 15520 kB
  28. NFS_Unstable: 0 kB
  29. Bounce: 0 kB
  30. WritebackTmp: 0 kB
  31. CommitLimit: 2597812 kB
  32. Committed_AS: 1578872 kB
  33. VmallocTotal: 34359738367 kB
  34. VmallocUsed: 170756 kB
  35. VmallocChunk: 34359564288 kB
  36. HardwareCorrupted: 0 kB
  37. AnonHugePages: 75776 kB
  38. HugePages_Total: 0
  39. HugePages_Free: 0
  40. HugePages_Rsvd: 0
  41. HugePages_Surp: 0
  42. Hugepagesize: 2048 kB
  43. DirectMap4k: 73600 kB
  44. DirectMap2M: 974848 kB
  45. DirectMap1G: 0 kB

    MemTotal总内存,MemFree可用内存
    free -m(-m,单位是m,如果是-g,单位是g)查看可用内存[html] view plain copy

  1. [root@localhost proc]# free -m
  2. total used free shared buff/cache available
  3. Mem: 977 360 97 7 520 411
  4. Swap: 2047 0 2047

    空闲内存total-used=free+buff/cache

我们通过free命令查看机器空闲内存时,会发现free的值很小。这主要是因为,在linux中有这么一种思想,内存不用白不用,因此它尽可能的cache和buffer一些数据,以方便下次使用。但实际上这些内存也是可以立刻拿来使用的。

3.磁盘和分区

3.1查看各分区使用情况

df -h

[html] view plain copy

  1. [root@localhost ~]# df -h
  2. Filesystem Size Used Avail Use% Mounted on
  3. /dev/mapper/centos-root 45G 22G 24G 48% /
  4. devtmpfs 906M 0 906M 0% /dev
  5. tmpfs 921M 96K 921M 1% /dev/shm
  6. tmpfs 921M 1004K 920M 1% /run
  7. tmpfs 921M 0 921M 0% /sys/fs/cgroup
  8. /dev/sda1 497M 195M 303M 40% /boot
  9. tmpfs 185M 0 185M 0% /run/user/1001
  10. tmpfs 185M 0 185M 0% /run/user/0
  11. [root@localhost ~]#

3.2查看指定目录的大小

du -sh <目录名>

[html] view plain copy

  1. [root@localhost ~]# du -sh /root
  2. 1.2G /root

3.3查看所有分区

fdisk -l

[html] view plain copy

  1. [root@localhost proc]# fdisk -l
  2. 磁盘 /dev/sda:32.2 GB, 32212254720 字节,62914560 个扇区
  3. Units = 扇区 of 1 * 512 = 512 bytes
  4. 扇区大小(逻辑/物理):512 字节 / 512 字节
  5. I/O 大小(最小/最佳):512 字节 / 512 字节
  6. 磁盘标签类型:dos
  7. 磁盘标识符:0x000a0cd4
  8. 设备 Boot Start End Blocks Id System
  9. /dev/sda1 * 2048 1026047 512000 83 Linux
  10. /dev/sda2 1026048 62914559 30944256 8e Linux LVM
  11. 磁盘 /dev/mapper/centos-root:29.5 GB, 29490151424 字节,57597952 个扇区
  12. Units = 扇区 of 1 * 512 = 512 bytes
  13. 扇区大小(逻辑/物理):512 字节 / 512 字节
  14. I/O 大小(最小/最佳):512 字节 / 512 字节
  15. 磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区
  16. Units = 扇区 of 1 * 512 = 512 bytes
  17. 扇区大小(逻辑/物理):512 字节 / 512 字节
  18. I/O 大小(最小/最佳):512 字节 / 512 字节
  19. 磁盘 /dev/mapper/centos-docker—poolmeta:33 MB, 33554432 字节,65536 个扇区
  20. Units = 扇区 of 1 * 512 = 512 bytes
  21. 扇区大小(逻辑/物理):512 字节 / 512 字节
  22. I/O 大小(最小/最佳):512 字节 / 512 字节
  23. 磁盘 /dev/mapper/docker-253:0-101330881-pool:107.4 GB, 107374182400 字节,209715200 个扇区
  24. Units = 扇区 of 1 * 512 = 512 bytes
  25. 扇区大小(逻辑/物理):512 字节 / 512 字节
  26. I/O 大小(最小/最佳):65536 字节 / 65536 字节

3.4查看所有交换分区

swapon -s

[html] view plain copy

  1. [root@localhost proc]# swapon -s
  2. 文件名 类型 大小 已用 权限
  3. /dev/dm-1 partition 2097148 8 -1

4.网络

4.1查看所有网络接口的属性

ifconfig

[html] view plain copy

  1. [root@localhost proc]# ifconfig
  2. docker0: flags=4099 mtu 1500
  3. inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
  4. ether 02:42:e1:b8:a5:4f txqueuelen 0 (Ethernet)
  5. RX packets 0 bytes 0 (0.0 B)
  6. RX errors 0 dropped 0 overruns 0 frame 0
  7. TX packets 0 bytes 0 (0.0 B)
  8. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  9. eth0: flags=4163 mtu 1500
  10. inet 192.168.174.129 netmask 255.255.255.0 broadcast 192.168.174.255
  11. inet6 fe80::20c:29ff:fe50:b3b4 prefixlen 64 scopeid 0x20
  12. ether 00:0c:29:50:b3:b4 txqueuelen 1000 (Ethernet)
  13. RX packets 28649 bytes 38411280 (36.6 MiB)
  14. RX errors 0 dropped 0 overruns 0 frame 0
  15. TX packets 8937 bytes 1226914 (1.1 MiB)
  16. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  17. lo: flags=73 mtu 65536
  18. inet 127.0.0.1 netmask 255.0.0.0
  19. inet6 ::1 prefixlen 128 scopeid 0x10
  20. loop txqueuelen 0 (Local Loopback)
  21. RX packets 4 bytes 340 (340.0 B)
  22. RX errors 0 dropped 0 overruns 0 frame 0
  23. TX packets 4 bytes 340 (340.0 B)
  24. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  25. virbr0: flags=4099 mtu 1500
  26. inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
  27. ether 00:00:00:00:00:00 txqueuelen 0 (Ethernet)
  28. RX packets 0 bytes 0 (0.0 B)
  29. RX errors 0 dropped 0 overruns 0 frame 0
  30. TX packets 0 bytes 0 (0.0 B)
  31. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

4.2 带宽

ethtool 网卡名
[plain] view plain copy

  1. [root@localhost php-tomcat-base]# ethtool ens192
  2. Settings for ens192:
  3. Supported ports: [ TP ]
  4. Supported link modes: 1000baseT/Full
  5. 10000baseT/Full
  6. Supported pause frame use: No
  7. Supports auto-negotiation: No
  8. Advertised link modes: Not reported
  9. Advertised pause frame use: No
  10. Advertised auto-negotiation: No
  11. Speed: 10000Mb/s
  12. Duplex: Full
  13. Port: Twisted Pair
  14. PHYAD: 0
  15. Transceiver: internal
  16. Auto-negotiation: off
  17. MDI-X: Unknown
  18. Supports Wake-on: uag
  19. Wake-on: d
  20. Link detected: yes

看Speed

4.3查看路由表

route -n

[html] view plain copy

  1. [root@localhost proc]# route -n
  2. Kernel IP routing table
  3. Destination Gateway Genmask Flags Metric Ref Use Iface
  4. 0.0.0.0 192.168.174.2 0.0.0.0 UG 100 0 0 eth0
  5. 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
  6. 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
  7. 192.168.174.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
  8. [root@localhost proc]#

4.4查看所有监听端口

netstat -lntp
[html] view plain copy

  1. [root@localhost ~]# netstat -lntp
  2. Active Internet connections (only servers)
  3. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  4. tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 743/rpcbind
  5. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1740/nginx: master
  6. tcp 0 0 0.0.0.0:81 0.0.0.0:* LISTEN 1740/nginx: master
  7. tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2194/dnsmasq
  8. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1543/sshd
  9. tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 12610/cupsd
  10. tcp 0 0 0.0.0.0:40536 0.0.0.0:* LISTEN 19964/rpc.statd
  11. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2133/master
  12. tcp6 0 0 :::111 :::* LISTEN 743/rpcbind
  13. tcp6 0 0 :::81 :::* LISTEN 1740/nginx: master
  14. tcp6 0 0 :::22 :::* LISTEN 1543/sshd
  15. tcp6 0 0 ::1:631 :::* LISTEN 12610/cupsd
  16. tcp6 0 0 ::1:25 :::* LISTEN 2133/master
  17. tcp6 0 0 :::35420 :::* LISTEN 19964/rpc.statd
  18. [root@localhost ~]#

4.5查看所有已经建立的连接

netstat -antp

[html] view plain copy

  1. [root@localhost ~]# netstat -antp
  2. Active Internet connections (servers and established)
  3. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  4. tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 743/rpcbind
  5. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1740/nginx: master
  6. tcp 0 0 0.0.0.0:81 0.0.0.0:* LISTEN 1740/nginx: master
  7. tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2194/dnsmasq
  8. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1543/sshd
  9. tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 12610/cupsd
  10. tcp 0 0 0.0.0.0:40536 0.0.0.0:* LISTEN 19964/rpc.statd
  11. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2133/master
  12. tcp 0 0 172.31.4.233:22 121.34.147.13:57190 ESTABLISHED 29540/sshd: cavan [
  13. tcp 0 0 172.31.4.233:22 121.34.147.13:54544 ESTABLISHED 27077/sshd: cavan [
  14. tcp 0 96 172.31.4.233:22 219.137.32.66:60645 ESTABLISHED 30315/sshd: root@pt
  15. tcp 0 0 172.31.4.233:22 121.34.147.13:56319 ESTABLISHED 28703/sshd: cavan [
  16. tcp6 0 0 :::111 :::* LISTEN 743/rpcbind
  17. tcp6 0 0 :::81 :::* LISTEN 1740/nginx: master
  18. tcp6 0 0 :::22 :::* LISTEN 1543/sshd
  19. tcp6 0 0 ::1:631 :::* LISTEN 12610/cupsd
  20. tcp6 0 0 ::1:25 :::* LISTEN 2133/master
  21. tcp6 0 0 :::35420 :::* LISTEN 19964/rpc.statd
  22. [root@localhost ~]#

4.6 某端口使用情况

lsof -i:端口号

[plain] view plain copy

  1. [root@localhost mysql]# lsof -i:22
  2. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  3. sshd 1150 root 3u IPv4 18264 0t0 TCP *:ssh (LISTEN)
  4. sshd 1150 root 4u IPv6 18273 0t0 TCP *:ssh (LISTEN)
  5. sshd 2617 root 3u IPv4 20437 0t0 TCP localhost.localdomain:ssh->192.168.174.1:60426 (ESTABLISHED)
  6. [root@localhost mysql]#

或者

netstat -apn|grep 端口号

[html] view plain copy

  1. [root@localhost mysql]# netstat -apn|grep 22
  2. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1150/sshd
  3. tcp 0 96 192.168.174.136:22 192.168.174.1:60426 ESTABLISHED 2617/sshd: root@pts
  4. tcp6 0 0 :::22 :::* LISTEN 1150/sshd

5.进程

5.1查看所有进程

ps -ef,使用ps -ef|gerp tomcat过滤

[html] view plain copy

  1. [root@localhost ~]# ps -ef
  2. UID PID PPID C STIME TTY TIME CMD
  3. root 1 0 0 09:26 ? 00:00:03 /usr/lib/systemd/systemd —switched-root —system —deserialize 21
  4. root 2 0 0 09:26 ? 00:00:00 [kthreadd]
  5. root 3 2 0 09:26 ? 00:00:00 [ksoftirqd/0]
  6. root 6 2 0 09:26 ? 00:00:00 [kworker/u256:0]
  7. root 7 2 0 09:26 ? 00:00:00 [migration/0]
  8. root 8 2 0 09:26 ? 00:00:00 [rcu_bh]
  9. root 9 2 0 09:26 ? 00:00:00 [rcuob/0]
  10. root 10 2 0 09:26 ? 00:00:00 [rcuob/1]
  11. root 11 2 0 09:26 ? 00:00:00 [rcuob/2]
  12. root 12 2 0 09:26 ? 00:00:00 [rcuob/3]
  13. root 13 2 0 09:26 ? 00:00:00 [rcuob/4]
  14. root 14 2 0 09:26 ? 00:00:00 [rcuob/5]
  15. root 15 2 0 09:26 ? 00:00:00 [rcuob/6]
  16. root 16 2

ps -aux可以看到进程占用CPU,内存情况

[html] view plain copy

  1. [root@localhost ~]# ps -aux
  2. USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
  3. root 1 0.0 0.6 126124 6792 ? Ss 09:26 0:03 /usr/lib/systemd/systemd —switched-root —system —deserialize 21
  4. root 2 0.0 0.0 0 0 ? S 09:26 0:00 [kthreadd]
  5. root 3 0.0 0.0 0 0 ? S 09:26 0:00 [ksoftirqd/0]
  6. root 6 0.0 0.0 0 0 ? S 09:26 0:00 [kworker/u256:0]
  7. root 7 0.0 0.0 0 0 ? S 09:26 0:00 [migration/0]
  8. root 8 0.0 0.0 0 0 ? S 09:26 0:00 [rcu_bh]
  9. root 9 0.0 0.0 0 0 ? S 09:26 0:00 [rcuob/0]
  10. root 10 0.

5.2实时显示进程状态

top

[html] view plain copy

  1. [root@localhost ~]# top
  2. top - 11:29:02 up 2:02, 2 users, load average: 0.12, 0.04, 0.05
  3. Tasks: 408 total, 2 running, 406 sleeping, 0 stopped, 0 zombie
  4. %Cpu(s): 1.3 us, 0.3 sy, 0.0 ni, 98.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
  5. KiB Mem : 1001332 total, 92184 free, 370332 used, 538816 buff/cache
  6. KiB Swap: 2097148 total, 2097140 free, 8 used. 419124 avail Mem
  7. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  8. 3001 gdm 20 0 1419364 122996 45860 S 1.0 12.3 0:06.50 gnome-shell
  9. 276 root 20 0 0 0 0 S 0.3 0.0 0:09.72 kworker/0:1
  10. 3765 root 20 0 142864 5128 3876 S 0.3 0.5 0:00.77 sshd
  11. 7740 root 20 0 146452 2384 1432 R 0.3 0.2 0:00.17 top
  12. 1 root 20 0 126124 6792 3912 S 0.0 0.7 0:03.58 systemd
  13. 2 root 20 0 0 0 0 S 0.0 0.0 0:00.03 kthreadd
  14. 3 root 20 0 0 0 0 S 0.0 0.0 0:00.37 ksoftirqd/0
  15. 6 root 20 0 0 0 0 S 0.0 0.0 0:00.39 kworker/u256:0
  16. 7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
  17. 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
  18. 9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/0
  19. 10 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/1
  20. 11 root 20 0 0

6.用户

6.1查看活动用户

w

[html] view plain copy

  1. [root@localhost ~]# w
  2. 11:32:36 up 72 days, 20:50, 3 users, load average: 0.00, 0.01, 0.05
  3. USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
  4. cavan pts/0 121.34.147.13 09:47 1:14m 0.17s 0.17s sshd: cavan [priv]
  5. root pts/1 219.137.32.66 11:19 4.00s 0.05s 0.00s w
  6. cavan pts/3 121.34.147.13 10:14 20:44 0.38s 0.11s vim Dockerfile
  7. [root@localhost ~]#

6.2查看指定用户的信息

id <用户名>

[html] view plain copy

  1. [root@localhost ~]# id root
  2. uid=0(root) gid=0(root) groups=0(root)
  3. [root@localhost ~]# id cavan
  4. uid=1001(cavan) gid=1001(cavan) groups=1001(cavan)
  5. [root@localhost ~]#

6.3查看用户登录日志

last

[html] view plain copy

  1. [root@localhost 1]# last
  2. root pts/0 192.168.174.1 Mon Oct 24 09:51 still logged in
  3. (unknown :0 :0 Mon Oct 24 09:27 still logged in
  4. reboot system boot 3.10.0-327.el7.x Mon Oct 24 09:26 - 11:35 (02:09)
  5. root pts/0 192.168.174.1 Fri Oct 21 09:41 - 18:44 (09:03)
  6. (unknown :0 :0 Fri Oct 21 09:15 - 18:44 (09:28)
  7. reboot system boot 3.10.0-327.el7.x Fri Oct 21 09:15 - 11:35 (3+02:20)
  8. root pts/1 192.168.174.1 Thu Oct 20 10:05 - 18:13 (08:08)
  9. root pts/0

6.4查看系统所有用户

cut -d: -f1 /etc/passwd

[html] view plain copy

  1. [root@localhost ~]# cut -d: -f1 /etc/passwd
  2. root
  3. bin
  4. daemon
  5. adm
  6. lp
  7. sync
  8. shutdown
  9. halt
  10. mail
  11. operator
  12. games
  13. ftp
  14. nobody
  15. dbus
  16. polkitd
  17. abrt
  18. unbound
  19. colord
  20. usbmuxd
  21. ntp

https://blog.csdn.net/u012841092/article/details/73920648

CentOS查看系统信息

一:查看CPU

more /proc/cpuinfo | grep “model name”

grep “model name” /proc/cpuinfo

如果觉得需要看的更加舒服

grep “model name” /proc/cpuinfo | cut -f2 -d:

20181228090402980

怎么样,linux的命令就要这样熟悉。

# 总核数 = 物理CPU个数 X 每颗物理CPU的核数
# 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数

# 查看物理CPU个数
cat /proc/cpuinfo| grep “physical id”| sort| uniq| wc -l

# 查看每个物理CPU中core的个数(即核数)
cat /proc/cpuinfo| grep “cpu cores”| uniq

# 查看逻辑CPU的个数
cat /proc/cpuinfo| grep “processor”| wc -l

二:查看内存

grep MemTotal /proc/meminfo

grep MemTotal /proc/meminfo | cut -f2 -d:

free -m |grep “Mem” | awk ‘{print $2}‘

三:查看cpu是32位还是64位

查看CPU位数(32 or 64)

#getconf LONG_BIT

#echo $HOSTTYPE

#uname -a

四:查看当前linux的版本

#more /etc/RedHat-release

  1. \#cat /etc/redhat-release

五:查看内核版本

#uname -r

#uname -a

六:查看当前时间

date

七:查看硬盘和分区

df -h

2018122809040332

fdisk -l

也可以查看分区

du -sh

可以看到全部占用的空间

du /etc -sh

可以看到这个目录的大小

八:查看安装的软件包

查看系统安装的时候装的软件包

cat -n /root/install.log

more /root/install.log | wc -l

查看现在已经安装了那些软件包

rpm -qa

rpm -qa | wc -l

yum list installed | wc -l

不过很奇怪,我通过rpm,和yum这两种方式查询的安装软件包,数量并不一样。没有找到原因。

九:查看键盘布局

cat /etc/sysconfig/keyboard

cat /etc/sysconfig/keyboard | grep KEYTABLE | cut -f2 -d=

十:查看selinux情况

sestatus

sestatus | cut -f2 -d:

cat /etc/sysconfig/selinux

十一:查看ip,mac地址

在ifcfg-eth0 文件里你可以看到mac,网关等信息。

ifconfig

cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep IPADDR

cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep IPADDR | cut -f2 -d=

ifconfig eth0 |grep “inet addr:” |awk ‘{print $2}‘|cut -c 6-

ifconfig | grep ‘inet addr:’| grep -v ‘127.0.0.1’ | cut -d: -f2 | awk ‘{ print $1}‘

查看网关

cat /etc/sysconfig/network

查看dns

cat /etc/resolv.conf

十二:查看默认语言

echo $LANG $LANGUAGE

cat /etc/sysconfig/i18n

十三:查看所属时区和是否使用UTC时间

cat /etc/sysconfig/clock

十四:查看主机名

hostname

cat /etc/sysconfig/network

修改主机名就是修改这个文件,同时最好也把host文件也修改

发表评论

表情:
评论列表 (有 0 条评论,440人围观)

还没有评论,来说两句吧...

相关阅读