CentOS网站服务器常用命令
发表日期:2019-07-17 06:37:41 文章编辑:admin 浏览次数:223
显示安装的系统版本
[root@VM_0_9_centos ~]# cat /etc/redhat-release [root@VM_0_9_centos ~]# cat /proc/version [root@VM_0_9_centos ~]# uname -r
显示系统是多少位的(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 ......
查看配置的环境变量
//查看配置的环境变量
[root@VM_0_9_centos ~]# env
查看当前用户的计划任务服务
// 查看当前用户的计划任务服务 [root@VM_0_9_centos ~]# crontab -l
查看所有网络接口的属性,包括IP地址
// 查看所有网络接口的属性,包括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的防火墙相关:
firewall-cmd --state (防火墙状态)
systemctl list-unit-files|grep firewalld.service(防火墙状态)
systemctl restart firewalld.service(关闭防火墙)
systemctl disable firewalld.service(禁止开机自动启动)
//centos7以下的防火墙相关:
service iptables stop(关闭防火墙centos7以下)
chkconfig iptables off(禁止开机自动启动)
内存/硬盘大小
//内存大小
[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
查看系统内存情况
[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:总计物理内存的大小 //used:已使用多大 //free:可用有多少 //Shared:多个进程共享的内存总额 //Buffers/cached:磁盘缓存的大小 //available:可用物理内存大小
//查看内存总量 grep MemTotal /proc/meminfo //查看空闲内存量 grep MemFree /proc/meminfo
CPU大小
//查看CPU相关参数 [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的详细信息。但是对于双核的cpu,在cpuinfo中会看到两个cpu。常常会让人误以为是两个单核的cpu。 //其实应该通过Physical Processor ID来区分单核和双核。而Physical Processor ID可以从cpuinfo或者dmesg中找到. flags 如果有 ht 说明支持超线程技术 判断物理CPU的个数可以查看physical id 的值,相同则为同一CPU
查看分区使用情况
// 查看所有分区 [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 //查看各分区使用情况 [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
查看指定目录的大小
//查看指定目录的大小,不指定时默认是当前目录 [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 // 查看系统所有用户 [root@VM_0_9_centos ~]# cut -d: -f1 /etc/group // 查看系统所有组
查看CPU信息的linux系统信息命令
//查看CPU信息的linux系统信息命令 [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:
查看系统运行/启动时间
//最清晰的查看方式 [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("系统已运行:%d天%d时%d分%d秒",run_days,run_hour,run_minute,run_second)}' 系统已运行:0天0时6分7秒 //who -b 查看最后一次系统启动的时间。 //who -r 查看当前系统运行时间 [root@VM_0_9_centos ~]# who -b system boot 2019-07-14 15:06 //系统上次启动时间 [root@VM_0_9_centos ~]# who -r run-level 3 2019-07-14 15:06 //last reboot可以看到Linux系统历史启动的时间。 重启一下操作系统后,然后 [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系统启动的时间 [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后表示系统到目前运行了多久时间,反过来推算系统重启时间 [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//第一数字即是系统已运行的时间266.50秒 //运用系统工具date即可算出系统启动时间 [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("系统已运行:%d天%d时%d分%d秒",run_days,run_hour,run_minute,run_second)}' 系统已运行: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 – :系统当前时间 up:服务器连续运行的时间,笔者见过有服务器连续运行一年以上,linux服务器还是非常稳定的。 user:当前有多少用户登录系统 load average:这个边有3个数值分别表示系统在前1分钟,5分钟,15分钟的工作负载,一般单核负载在3-5之间比较合适,经常在1以下,说明cpu利用率不高,在5以上,cpu会处于较高负载状态,会容易宕机。 第二行就是显示任务的数量情况,其中zombie要注意一下,这个是表示僵尸进程,出现了僵尸进程要注意下僵尸进程是如何产生的。如果不找到产生原因,即使杀死了,可能也会再次出现。 第三行表示cpu的运行情况,按下1可以显示每个核的运行情况。 第四行表示内存memory的使用情况。 第五行表示交换空间swap的使用情况。 下面显示的就是进程的运行状态了。每个表头表示的含义如下: PID:进程编号 USER:进程所属用户 PR/NI:Priority/Nice value进程执行的优先顺序 VIRT:Virtual Image (kb) 虚拟内存使用总额 RES:Resident size (kb) 常驻内存 SHR:Shared Mem size (kb) 共享内存 S:Process Status 进程状态 %CPU:cpu使用率 %MEM:内存使用率 TIME+:进程开始运行时使用cpu的总时间 COMMAND:进程运行的命令 在top状态下按f可以查看表头字段说明。
更多命令
1、uname -a //查看内核/操作系统/CPU信息的linux系统信息命令 2、head -n 1 /etc/issue //查看操作系统版本,是数字1不是字母L 3、hostname //查看计算机名的linux系统信息命令 4、lsusb -tv //列出所有USB设备的linux系统信息命令 5、lspci -tv //列出所有PCI设备 6、lsmod //列出加载的内核模块 7、cat /proc/loadavg // 查看系统负载磁盘和分区 8、mount | column -t // 查看挂接的分区状态 9、swapon -s // 查看所有交换分区 10、hdparm -i /dev/hda // 查看磁盘参数(仅适用于IDE设备) 11、dmesg | grep IDE // 查看启动时IDE设备检测状况网络 12、iptables -L // 查看防火墙设置 13、route –n // 查看路由表 14、netstat -lntp // 查看所有监听端口 15、netstat -antp // 查看所有已经建立的连接 16、netstat -s // 查看网络统计信息进程 17、ps -ef // 查看所有进程 18、chkconfig –list // 列出所有系统服务 19、chkconfig –list | grep on // 列出所有启动的系统服务程序 20、cat /proc/partitions //查看linux硬盘和分区信息的系统信息命令 21、cat /proc/meminfo //查看linux系统内存信息的linux系统命令 22、cat /proc/ioports //查看设备io端口 23、cat /proc/interrupts //查看中断 24、cat /proc/pci //查看pci设备的信息
标签: CentOS常用命令
如没特殊注明,文章均为宜兴博路网络原创,转载请注明来自https://www.boroad.net/news/wangzhansheji/2019/0717/199.html