CentOS網(wǎng)站服務(wù)器常用命令
發(fā)表日期:2019-07-17 06:37:41?? 文章編輯:admin ?? 瀏覽次數(shù):255
顯示安裝的系統(tǒng)版本
[root@VM_0_9_centos ~]# cat /etc/redhat-release [root@VM_0_9_centos ~]# cat /proc/version [root@VM_0_9_centos ~]# uname -r
顯示系統(tǒng)是多少位的(32/64bit)
getconf LONG_BIT
查看所有安裝的軟件包
//查看所有安裝的軟件包 [root@VM_0_9_centos ~]# rpm -qa
initscripts-9.49.37-1.el7.x86_64
perl-Git-1.8.3.1-12.el7_4.noarch
gmp-devel-6.0.0-15.el7.x86_64
rpm-libs-4.11.3-17.el7.x86_64
uw-imap-devel-2007f-16.el7.x86_64
libreport-python-2.1.11-32.el7.centos.x86_64
glibc-2.17-196.el7_4.2.x86_64
libreport-web-2.1.11-32.el7.centos.x86_64
glibc-static-2.17-196.el7_4.2.x86_64
systemd-libs-219-30.el7_3.9.x86_64
libXfixes-5.0.3-1.el7.x86_64
libreport-plugin-rhtsupport-2.1.11-32.el7.centos.x86_64
libXdamage-devel-1.1.4-4.1.el7.x86_64
NetworkManager-libnm-1.4.0-20.el7_3.x86_64
lsscsi-0.27-3.el7.x86_64
libXxf86vm-1.1.4-1.el7.x86_64
gpgme-1.3.2-5.el7.x86_64 ......
查看配置的環(huán)境變量
//查看配置的環(huán)境變量
[root@VM_0_9_centos ~]# env
查看當(dāng)前用戶的計劃任務(wù)服務(wù)
// 查看當(dāng)前用戶的計劃任務(wù)服務(wù) [root@VM_0_9_centos ~]# crontab -l
查看所有網(wǎng)絡(luò)接口的屬性,包括IP地址
// 查看所有網(wǎng)絡(luò)接口的屬性,包括IP地址 [root@VM_0_9_centos ~]# ifconfig
eth0: flags=4163 mtu 1500
inet 172.17.0.9 netmask 255.xxx.xxx.0 broadcast 172.xxx.xxx.xxx
ether 52:54:00:53:4c:01 txqueuelen 1000 (Ethernet)
RX packets 3367917 bytes 244515787 (233.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4172603 bytes 4146596093 (3.8 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73 mtu 65536
inet 127.0.0.1 netmask xxx.0.0.0
loop txqueuelen 1 (Local Loopback)
RX packets 109 bytes 20839 (20.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 109 bytes 20839 (20.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
防火墻
//centos7的防火墻相關(guān):
firewall-cmd --state (防火墻狀態(tài))
systemctl list-unit-files|grep firewalld.service(防火墻狀態(tài))
systemctl restart firewalld.service(關(guān)閉防火墻)
systemctl disable firewalld.service(禁止開機自動啟動)
//centos7以下的防火墻相關(guān):
service iptables stop(關(guān)閉防火墻centos7以下)
chkconfig iptables off(禁止開機自動啟動)
內(nèi)存/硬盤大小
//內(nèi)存大小
[root@VM_0_9_centos ~]# cat /proc/meminfo |grep MemTotal
MemTotal: 1883616 kB
//硬盤大小
[root@VM_0_9_centos ~]# fdisk -l |grep Disk
Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Disk label type: dos
Disk identifier: 0x0005fc9a
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
查看系統(tǒng)內(nèi)存情況
[root@VM_0_9_centos ~]# free
total used free shared buff/cache available
Mem: 1016516 592152 81652 196 342712 266756
Swap: 1049596 106176 943420
//total:總計物理內(nèi)存的大小 //used:已使用多大 //free:可用有多少 //Shared:多個進(jìn)程共享的內(nèi)存總額 //Buffers/cached:磁盤緩存的大小 //available:可用物理內(nèi)存大小
//查看內(nèi)存總量 grep MemTotal /proc/meminfo //查看空閑內(nèi)存量 grep MemFree /proc/meminfo
CPU大小
//查看CPU相關(guān)參數(shù) [root@VM_0_9_centos ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-26xx v3
stepping : 2
microcode : 0x1
cpu MHz : 2294.686
cache size : 4096 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
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 ht syscall nx lm constant_tsc rep_good nopl 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 bmi1 avx2 bmi2 xsaveopt
bogomips : 4589.37
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management:
[root@VM_0_9_centos ~]# cat /proc/cpuinfo |grep "model name" && cat /proc/cpuinfo |grep "physical id" model name : Intel(R) Xeon(R) CPU E5-26xx v4 physical id : 0 //說明:Linux下可以在/proc/cpuinfo中看到每個cpu的詳細(xì)信息。但是對于雙核的cpu,在cpuinfo中會看到兩個cpu。常常會讓人誤以為是兩個單核的cpu。 //其實應(yīng)該通過Physical Processor ID來區(qū)分單核和雙核。而Physical Processor ID可以從cpuinfo或者dmesg中找到. flags 如果有 ht 說明支持超線程技術(shù) 判斷物理CPU的個數(shù)可以查看physical id 的值,相同則為同一CPU
查看分區(qū)使用情況
// 查看所有分區(qū) [root@VM_0_9_centos ~]# fdisk -l Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 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 label type: dos Disk identifier: 0x000c5e30 Device Boot Start End Blocks Id System /dev/vda1 * 2048 104857566 52427759+ 83 Linux //查看各分區(qū)使用情況 [root@VM_0_9_centos ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 50G 11G 36G 23% /
devtmpfs 487M 0 487M 0% /dev
tmpfs 497M 44K 497M 1% /dev/shm
tmpfs 497M 448K 496M 1% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
tmpfs 100M 0 100M 0% /run/user/0
查看指定目錄的大小
//查看指定目錄的大小,不指定時默認(rèn)是當(dāng)前目錄 [root@VM_0_9_centos ~]# du -sh /software/ 2.1G /software/
查看用戶信息
[root@VM_0_9_centos ~]# w // 查看活動用戶 [root@VM_0_9_centos ~]# id // 查看指定用戶信息 [root@VM_0_9_centos ~]# last // 查看用戶登錄日志 [root@VM_0_9_centos ~]# cut -d: -f1 /etc/passwd // 查看系統(tǒng)所有用戶 [root@VM_0_9_centos ~]# cut -d: -f1 /etc/group // 查看系統(tǒng)所有組
查看CPU信息的linux系統(tǒng)信息命令
//查看CPU信息的linux系統(tǒng)信息命令 [root@VM_0_9_centos ~]# cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 719 model name : Intel(R) Xeon(R) CPU xxxxxx stepping : 2 microcode : 0x1 cpu MHz : 2394.446 cache size : 4096 KB physical id : 0 siblings : 2 core id : 0 cpu cores : 2 apicid : 0 initial apicid : 0 fpu : yes fpu_exception : yes cpuid level : 14 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 ht syscall nx lm constant_tsc rep_good nopl 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 bmi1 avx2 bmi2 rdseed adx xsaveopt bogomips : 4788.89 clflush size : 64 cache_alignment : 64 address sizes : 40 bits physical, 48 bits virtual power management:
查看系統(tǒng)運行/啟動時間
//最清晰的查看方式 [root@VM_0_9_centos ~]# cat /proc/uptime| awk -F. '{run_days=$1 / 86400;run_hour=($1 % 86400)/3600;run_minute=($1 % 3600)/60;run_second=$1 % 60;printf("系統(tǒng)已運行:%d天%d時%d分%d秒",run_days,run_hour,run_minute,run_second)}' 系統(tǒng)已運行:0天0時6分7秒 //who -b 查看最后一次系統(tǒng)啟動的時間。 //who -r 查看當(dāng)前系統(tǒng)運行時間 [root@VM_0_9_centos ~]# who -b system boot 2019-07-14 15:06 //系統(tǒng)上次啟動時間 [root@VM_0_9_centos ~]# who -r run-level 3 2019-07-14 15:06 //last reboot可以看到Linux系統(tǒng)歷史啟動的時間。 重啟一下操作系統(tǒng)后,然后 [root@VM_0_9_centos ~]# last reboot
reboot system boot 3.10.0-514.26.2. Thu Jul 11 09:57 - 09:08 (2+23:11)
reboot system boot 3.10.0-514.26.2. Mon Jul 8 08:55 - 09:57 (3+01:01)
reboot system boot 3.10.0-514.26.2. Tue Jul 2 15:05 - 09:57 (8+18:51)
reboot system boot 3.10.0-514.26.2. Sun Jun 23 09:49 - 15:05 (9+05:15)
reboot system boot 3.10.0-514.26.2. Sat Jun 8 20:28 - 09:48 (14+13:20)
reboot system boot 3.10.0-514.26.2. Mon May 27 22:26 - 20:28 (11+22:02)
reboot system boot 3.10.0-514.26.2. Mon May 27 21:52 - 22:25 (00:33)
reboot system boot 3.10.0-514.26.2. Fri May 24 10:52 - 22:25 (3+11:33)
reboot system boot 3.10.0-514.26.2. Fri May 24 10:51 - 22:25 (3+11:34)
reboot system boot 3.10.0-514.26.2. Fri May 24 06:00 - 22:25 (3+16:25)
reboot system boot 3.10.0-514.26.2. Tue May 14 15:24 - 05:59 (9+14:34)
reboot system boot 3.10.0-514.26.2. Tue May 7 12:38 - 15:24 (7+02:46)
reboot system boot 3.10.0-514.26.2. Wed May 1 18:03 - 15:24 (12+21:21)
reboot system boot 3.10.0-514.26.2. Sun Dec 30 14:17 - 15:24 (135+01:07)
reboot system boot 3.10.0-514.26.2. Mon Jul 16 19:16 - 15:24 (301+20:08)
reboot system boot 3.10.0-514.26.2. Sat Jul 7 21:25 - 19:16 (8+21:50) //如果只需要查看最后一次Linux系統(tǒng)啟動的時間 [root@VM_0_9_centos ~]# last reboot | head -1
reboot system boot 3.10.0-514.26.2. Sat Jul 7 21:25 - 19:16 (8+21:50)
// w命令查看,up后表示系統(tǒng)到目前運行了多久時間,反過來推算系統(tǒng)重啟時間 [root@VM_0_9_centos ~]# w 11:30:35 up 3 days, 18:38, 1 user, load average: 78.52, 73.84, 72.60 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root pts/0 222.211.233.166 11:18 3.00s 0.02s 0.00s w //uptime 命令查看 [root@VM_0_9_centos ~]# uptime 11:33:18 up 3 days, 18:40, 1 user, load average: 71.31, 72.56, 72.30 //通過/proc/uptime查看 [root@VM_0_9_centos ~]# cat /proc/uptime 266.50 209.15//第一數(shù)字即是系統(tǒng)已運行的時間266.50秒 //運用系統(tǒng)工具date即可算出系統(tǒng)啟動時間 [root@VM_0_9_centos ~]# date -d "$(awk -F. '{print $1}' /proc/uptime) second ago" +"%Y-%m-%d %H:%M:%S" 2018-06-28 16:52:24 [root@VM_0_9_centos ~]# cat /proc/uptime| awk -F. '{run_days=$1 / 86400;run_hour=($1 % 86400)/3600;run_minute=($1 % 3600)/60;run_second=$1 % 60;printf("系統(tǒng)已運行:%d天%d時%d分%d秒",run_days,run_hour,run_minute,run_second)}' 系統(tǒng)已運行:0天0時6分7秒 //top命令 [root@VM_0_9_centos ~]# top top - 11:29:30 up 3 days, 18:37, 1 user, load average: 71.57, 72.68, 72.20 Tasks: 164 total, 70 running, 92 sleeping, 0 stopped, 2 zombie %Cpu(s): 13.0 us, 86.7 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 0.3 si, 0.0 st KiB Mem : 1883616 total, 75328 free, 804624 used, 1003664 buff/cache KiB Swap: 0 total, 0 free, 0 used. 642936 avail Mem //top命令說明 第一行說明: top – :系統(tǒng)當(dāng)前時間 up:服務(wù)器連續(xù)運行的時間,筆者見過有服務(wù)器連續(xù)運行一年以上,linux服務(wù)器還是非常穩(wěn)定的。 user:當(dāng)前有多少用戶登錄系統(tǒng) load average:這個邊有3個數(shù)值分別表示系統(tǒng)在前1分鐘,5分鐘,15分鐘的工作負(fù)載,一般單核負(fù)載在3-5之間比較合適,經(jīng)常在1以下,說明cpu利用率不高,在5以上,cpu會處于較高負(fù)載狀態(tài),會容易宕機。 第二行就是顯示任務(wù)的數(shù)量情況,其中zombie要注意一下,這個是表示僵尸進(jìn)程,出現(xiàn)了僵尸進(jìn)程要注意下僵尸進(jìn)程是如何產(chǎn)生的。如果不找到產(chǎn)生原因,即使殺死了,可能也會再次出現(xiàn)。 第三行表示cpu的運行情況,按下1可以顯示每個核的運行情況。 第四行表示內(nèi)存memory的使用情況。 第五行表示交換空間swap的使用情況。 下面顯示的就是進(jìn)程的運行狀態(tài)了。每個表頭表示的含義如下: PID:進(jìn)程編號 USER:進(jìn)程所屬用戶 PR/NI:Priority/Nice value進(jìn)程執(zhí)行的優(yōu)先順序 VIRT:Virtual Image (kb) 虛擬內(nèi)存使用總額 RES:Resident size (kb) 常駐內(nèi)存 SHR:Shared Mem size (kb) 共享內(nèi)存 S:Process Status 進(jìn)程狀態(tài) %CPU:cpu使用率 %MEM:內(nèi)存使用率 TIME+:進(jìn)程開始運行時使用cpu的總時間 COMMAND:進(jìn)程運行的命令 在top狀態(tài)下按f可以查看表頭字段說明。
更多命令
1、uname -a //查看內(nèi)核/操作系統(tǒng)/CPU信息的linux系統(tǒng)信息命令 2、head -n 1 /etc/issue //查看操作系統(tǒng)版本,是數(shù)字1不是字母L 3、hostname //查看計算機名的linux系統(tǒng)信息命令 4、lsusb -tv //列出所有USB設(shè)備的linux系統(tǒng)信息命令 5、lspci -tv //列出所有PCI設(shè)備 6、lsmod //列出加載的內(nèi)核模塊 7、cat /proc/loadavg // 查看系統(tǒng)負(fù)載磁盤和分區(qū) 8、mount | column -t // 查看掛接的分區(qū)狀態(tài) 9、swapon -s // 查看所有交換分區(qū) 10、hdparm -i /dev/hda // 查看磁盤參數(shù)(僅適用于IDE設(shè)備) 11、dmesg | grep IDE // 查看啟動時IDE設(shè)備檢測狀況網(wǎng)絡(luò) 12、iptables -L // 查看防火墻設(shè)置 13、route –n // 查看路由表 14、netstat -lntp // 查看所有監(jiān)聽端口 15、netstat -antp // 查看所有已經(jīng)建立的連接 16、netstat -s // 查看網(wǎng)絡(luò)統(tǒng)計信息進(jìn)程 17、ps -ef // 查看所有進(jìn)程 18、chkconfig –list // 列出所有系統(tǒng)服務(wù) 19、chkconfig –list | grep on // 列出所有啟動的系統(tǒng)服務(wù)程序 20、cat /proc/partitions //查看linux硬盤和分區(qū)信息的系統(tǒng)信息命令 21、cat /proc/meminfo //查看linux系統(tǒng)內(nèi)存信息的linux系統(tǒng)命令 22、cat /proc/ioports //查看設(shè)備io端口 23、cat /proc/interrupts //查看中斷 24、cat /proc/pci //查看pci設(shè)備的信息
標(biāo)簽: CentOS常用命令
如沒特殊注明,文章均為宜興博路網(wǎng)絡(luò)原創(chuàng),轉(zhuǎn)載請注明來自http://m.mabhome.com/news/wangzhansheji/2019/0717/199.html

