如今是资源共享的时代,同样也是知识分享的时代,假如你认为从本文能学到知识,请把知识与他人分享。
查看服务器的一些基本信息:
linux基础命令:http://cnblogs.com/mmzs/p/8406208.htm
Linux某些命令找不到/无法使用:http://www.cnblogs.com/mmzs/p/9043190.html
Linux之定时任务Crond使用:http://cnblogs.com/mmzs/p/8178487.html
Linux命令-基本操作和软件安装:http://cnblogs.com/mmzs/p/8183935.html
显示安装的系统版本
cat /etc/redhat-release
cat /proc/version
uname -r
显示系统是多少位的(32/64bit)
getconf LONG_BIT
查看所有安装的软件包
[root@VM_0_5_centos ~]# rpm -qa
libX11-devel-1.6.5-1.el7.x86_64
xmlrpc-c-client-1.32.5-1905.svn2451.el7.x86_64
setup-2.8.71-7.el7.noarch
gtk+-1.2.10-77.el7.x86_64
dhcp-libs-4.2.5-58.el7.centos.x86_64
langtable-data-0.0.31-3.el7.noarch
libXfixes-devel-5.0.3-1.el7.x86_64
查看配置的环境变量
[root@VM_0_5_centos ~]# env
查看当前用户的计划任务服务
[root@VM_0_5_centos ~]# crontab -l
查看所有网路插口的属性,包括IP地址
[root@VM_0_5_centos ~]# ifconfig
//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_5_centos ~]# cat /proc/meminfo |grep MemTotal
MemTotal: 1883616 kB
//硬碟大小
[root@VM_0_5_centos ~]# fdisk -l |grep Disk
Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Disk label type: dos
Disk identifier: 0x000c5e30
查看系统显存情况
[root@VM_0_5_centos ~]# free
total used free shared buff/cache available
Mem: 1883616 875260 67028 388 941328 574040
Swap: 0 0 0
//total:总计物理内存的大小
//used:已使用多大
//free:可用有多少
//Shared:多个进程共享的内存总额
//Buffers/cached:磁盘缓存的大小
//available:可用物理内存大小
查看显存总数
grep MemTotal /proc/meminfo
查看空闲显存量
grep MemFree /proc/meminfo
CPU大小
//查看CPU相关参数
[root@VM_0_5_centos ~]# cat /proc/cpuinfo
或
[root@VM_0_5_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_5_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_5_centos ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 50G 15G 33G 32% /
devtmpfs 911M 0 911M 0% /dev
tmpfs 920M 24K 920M 1% /dev/shm
tmpfs 920M 364K 920M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
tmpfs 184M 0 184M 0% /run/user/0
查看指定目录的大小
//查看指定目录的大小,不指定时默认是当前目录
[root@VM_0_5_centos ~]# du -sh /software/
2.1G /software/
查看用户信息
[root@VM_0_5_centos ~]# w
// 查看活动用户
[root@VM_0_5_centos ~]# id
// 查看指定用户信息
[root@VM_0_5_centos ~]# last
// 查看用户登录日志
[root@VM_0_5_centos ~]# cut -d: -f1 /etc/passwd
// 查看系统所有用户
[root@VM_0_5_centos ~]# cut -d: -f1 /etc/group
// 查看系统所有组
查看CPU信息的linux系统信息命令
//查看CPU信息的linux系统信息命令
[root@VM_0_5_centos ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 79
model name : Intel(R) Xeon(R) CPU E5-26xx v4
stepping : 1
microcode : 0x1
cpu MHz : 2394.446
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 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_5_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_5_centos ~]# who -b
system boot 2018-06-28 16:52 //系统上次启动时间
[root@VM_0_5_centos ~]# who -r
run-level 3 2018-06-28 16:52
//lastreboot可以看见Linux系统历史启动的时间。重启一下操作系统后linux软件中标麒麟linux,之后
[root@VM_0_5_centos ~]# last reboot
reboot system boot 3.10.0-693.el7.x Thu Jun 28 16:52 - 11:21 (3+18:29)
reboot system boot 3.10.0-693.el7.x Mon Jun 25 11:21 - 16:52 (3+05:30)
reboot system boot 3.10.0-693.el7.x Tue Jun 19 22:21 - 16:52 (8+18:31)
//假如只须要查看最后一次Linux系统启动的时间
[root@VM_0_5_centos ~]# last reboot | head -1
reboot system boot 3.10.0-693.el7.x Thu Jun 28 16:52 - 11:27 (3+18:35)
//w命令查看,up后表示系统到目前运行了多久时间,反过来推测系统重启时间
[root@VM_0_5_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_5_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_5_centos ~]# cat /proc/uptime
266.50 209.15//第一数字即是系统已运行的时间266.50秒
//运用系统工具date即可算出系统启动时间
[root@VM_0_5_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_5_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_5_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加载服务命令,笔者见过有服务器连续运行一年以上,linux服务器还是十分稳定的。
user:当前有多少用户登入系统
loadaverage:这个边有3个数值分别表示系统在前1分钟,5分钟,15分钟的工作负载linux加载服务命令,通常单核负载在3-5之间比较合适,常常在1以下,说明cpu借助率不高,在5以上,cpu会处于较高负载状态,会容易宕机。
第二行就是显示任务的数目情况,其中zombie要注意一下,这个是表示僵尸进程,出现了僵尸进程要注意下僵尸进程是怎样形成的。倘若不找到形成缘由,虽然杀害了,可能也会再度出现。
第三行表示cpu的运行情况,按下1可以显示每位核的运行情况。
第四行表示显存memory的使用情况。
第五行表示交换空间swap的使用情况。
下边显示的就是进程的运行状态了。每位表头表示的含意如下:
PID:进程编号
USER:进程所属用户
PR/NI:Priority/Nicevalue进程执行的优先次序
VIRT:VirtualImage(kb)虚拟显存使用支出
RES:Residentsize(kb)常驻显存
SHR:SharedMemsize(kb)共享显存
S:ProcessStatus进程状态
%CPU:cpu使用率
%MEM:显存使用率
TIME+:进程开始运行时使用cpu的总时间
COMMAND:进程运行的命令
在top状态下按f可以查看表头数组说明。