ubuntu查看系统信息命令
查看处理核信息
cat /proc/cpuinfo |grep “model name” && cat /proc/cpuinfo |grep “physical id”
Linux下可以在/proc/cpuinfo
中看到每个cpu的详细信息,包括型号、主频、内核信息等。此命令是在/proc/cpuinfo
文件下查看model name
和 physical id
;通过Physical Processor ID来区分单核和双核
通过/proc/cpuinfo
会列出类似如下的逻辑cpu信息,从下面可以看到三个核,然后列出每一个核的详细信息。其中processor : 0
表示虚拟cpu的id,model name : Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz
表示该逻辑cpu的主频,physical id : 0
表示物理cpu的id,cpu cores : 10
表示该物理cpu上的虚拟核数;逻辑CPU数量 = 物理cpu数量 x cpu cores
cat /proc/cpuinfo| grep “processor”| wc -1 #查看核数
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 79
model name : Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz
stepping : 1
microcode : 0xb000021
cpu MHz : 2199.914
cache size : 25600 KB
physical id : 0
siblings : 20
core id : 0
cpu cores : 10
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 20
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch arat epb pln pts dtherm intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local
bogomips : 4390.16
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 79
model name : Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz
stepping : 1
microcode : 0xb000021
cpu MHz : 2200.000
cache size : 25600 KB
physical id : 0
siblings : 20
core id : 1
cpu cores : 10
apicid : 2
initial apicid : 2
fpu : yes
fpu_exception : yes
cpuid level : 20
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch arat epb pln pts dtherm intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local
bogomips : 4390.16
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 2
vendor_id : GenuineIntel
cpu family : 6
model : 79
model name : Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz
stepping : 1
microcode : 0xb000021
cpu MHz : 2199.914
cache size : 25600 KB
physical id : 0
siblings : 20
core id : 2
cpu cores : 10
apicid : 4
initial apicid : 4
fpu : yes
fpu_exception : yes
cpuid level : 20
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch arat epb pln pts dtherm intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local
bogomips : 4390.16
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
查看内存交换区大小
显示内存使用量和交换区使用量
free -m # 以MB为单位显示内存使用量和交换区使用量
如下
total used free shared buff/cache available
Mem: 32012 21003 340 1769 10668 8642
Swap: 4095 0 4095
/proc/meminfo
cat /proc/meminfo |grep MemTotal
如下所示,包括服务器的总内存,可用内存,缓存缓冲区大小等信息
MemTotal: 263566308 kB
MemFree: 50457208 kB
MemAvailable: 151563588 kB
Buffers: 2640284 kB
Cached: 70216900 kB
SwapCached: 0 kB
Active: 137663572 kB
Inactive: 43680504 kB
Active(anon): 102379268 kB
Inactive(anon): 6269760 kB
Active(file): 35284304 kB
Inactive(file): 37410744 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 4194300 kB
SwapFree: 4194300 kB
Dirty: 142468 kB
Writeback: 0 kB
AnonPages: 108483892 kB
Mapped: 75956 kB
Shmem: 165160 kB
Slab: 29710900 kB
SReclaimable: 29295540 kB
SUnreclaim: 415360 kB
KernelStack: 59600 kB
PageTables: 255992 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 135977452 kB
Committed_AS: 134803444 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 706620 kB
VmallocChunk: 34224636092 kB
HardwareCorrupted: 0 kB
AnonHugePages: 4096 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 159616 kB
DirectMap2M: 6768640 kB
DirectMap1G: 263192576 kB
查看内存总量
grep MemTotal /proc/meminfo #
如下
MemTotal: 32781100 kB
查看空闲内存量
grep MemFree /proc/meminfo #
如下
MemFree: 349800 kB
查看交换区的信息
cat /proc/swaps :#查看所有swap分区的信息
该命令与swapon -s
显示信息一样
类似如下
Filename Type Size Used Priority
/dev/dm-1 partition 4194300 0 -1
Linux查看系统资源占用
查看内存使用量和交换区使用量
Linux的free命令以及cache与buffer的区别解决Linux buffer/cache内存占用过高的办法Linux查看系统资源占用总体内存占用的查看free
查看内存占用前五的进程ps auxw | head -1;ps auxw|sort -rn -k4|head -5
查看CPU占用前三的进程ps auxw|head -1;ps auxw|sort -rn -k3|head -3
查看系统整体的负载top
Linux下top命令详解Linux查看GPU信息和使用情况
Linux查看GPU信息和使用情况
linux 数据盘和系统盘的查看
硬盘和情况
使用fdisk -l
查看各硬盘情况,如下,Disk /dev/sdb
这样的表示硬盘,Device Boot
表示该硬盘下的分区
Disk /dev/sda: 31.9 GB, 31914982912 bytes, 62333951 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 /dev/sdb: 899.0 GB, 898999779328 bytes, 1755858944 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x000f3b27
Device Boot Start End Blocks Id System
/dev/sdb1 * 2048 2099199 1048576 83 Linux
/dev/sdb2 2099200 1755858943 876879872 8e Linux LVM
Disk /dev/sdm: 800.2 GB, 800166076416 bytes, 1562824368 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0xe1ce65d1
Device Boot Start End Blocks Id System
/dev/sdm1 2048 1562824367 781411160 83 Linux
Disk /dev/sdn: 800.2 GB, 800166076416 bytes, 1562824368 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0xd8a19f71
Device Boot Start End Blocks Id System
/dev/sdn1 2048 1562824367 781411160 83 Linux
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/sdc: 6001.2 GB, 6001175126016 bytes, 11721045168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: gpt
# Start End Size Type Name
1 2048 11721043967 5.5T Microsoft basic primary
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/sdd: 6001.2 GB, 6001175126016 bytes, 11721045168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: gpt
# Start End Size Type Name
1 2048 11721043967 5.5T Microsoft basic primary
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/sde: 6001.2 GB, 6001175126016 bytes, 11721045168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: gpt
# Start End Size Type Name
1 2048 11721043967 5.5T Microsoft basic primary
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/sdk: 6001.2 GB, 6001175126016 bytes, 11721045168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: gpt
# Start End Size Type Name
1 2048 11721043967 5.5T Microsoft basic primary
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/sdh: 6001.2 GB, 6001175126016 bytes, 11721045168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: gpt
# Start End Size Type Name
1 2048 11721043967 5.5T Microsoft basic primary
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/sdf: 6001.2 GB, 6001175126016 bytes, 11721045168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: gpt
# Start End Size Type Name
1 2048 11721043967 5.5T Microsoft basic primary
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/sdi: 6001.2 GB, 6001175126016 bytes, 11721045168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: gpt
# Start End Size Type Name
1 2048 11721043967 5.5T Microsoft basic primary
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/sdg: 6001.2 GB, 6001175126016 bytes, 11721045168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: gpt
# Start End Size Type Name
1 2048 11721043967 5.5T Microsoft basic primary
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/sdl: 6001.2 GB, 6001175126016 bytes, 11721045168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: gpt
# Start End Size Type Name
1 2048 11721043967 5.5T Microsoft basic primary
Disk /dev/mapper/cl-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mapper/cl-swap: 4294 MB, 4294967296 bytes, 8388608 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mapper/cl-home: 839.9 GB, 839938736128 bytes, 1640505344 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
磁盘分区及使用情况
使用df -h
来查看磁盘分区及使用情况,如下
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 50G 43G 8.0G 85% /
devtmpfs 126G 0 126G 0% /dev
tmpfs 126G 20K 126G 1% /dev/shm
tmpfs 126G 146M 126G 1% /run
tmpfs 126G 0 126G 0% /sys/fs/cgroup
/dev/sdm1 734G 690G 6.2G 100% /data11
/dev/sdn1 734G 690G 6.2G 100% /data12
/dev/sdc1 5.5T 2.8T 2.4T 55% /data03
/dev/sdi1 5.5T 2.8T 2.4T 55% /data07
/dev/sdg1 5.5T 2.8T 2.4T 54% /data05
/dev/sdd1 5.5T 2.9T 2.4T 55% /data01
/dev/sde1 5.5T 2.8T 2.4T 55% /data02
/dev/sdj1 5.5T 1.8T 3.5T 34% /data08
/dev/sdf1 5.5T 2.8T 2.4T 55% /data04
/dev/sdh1 5.5T 2.8T 2.4T 55% /data06
/dev/sdl1 5.5T 2.8T 2.4T 55% /data10
/dev/sdk1 5.5T 2.8T 2.4T 55% /data09
/dev/sdb1 1014M 139M 876M 14% /boot
/dev/mapper/cl-home 782G 35M 782G 1% /home
tmpfs 26G 0 26G 0% /run/user/0
上面的/为系统根目录,/boot,/home等是根目录下的子目录
/data11等则为对应的数据盘
查看系统负载磁盘和分区
cat /proc/loadavg
如下
0.74 0.72 0.67 1/3042 13900
查看磁盘损坏情况及修复
磁盘问题导致的Read-only file systemLinux fsck命令Linux umount命令mount –o remount,rw /Linux partprobe命令详解
fdisk -l 查看 分区,如果看不到分区,那肯定有问题
umount -v /dev/设备名 # 通过设备名卸载
fsck -a /dev/设备名 #修复
mount –o remount,rw /dev/设备名
partprobe /dev/sdb #查看分区是否有变化
查看磁盘参数(仅适用于IDE设备)
hdparm -i /dev/hda #
查看分区情况
cat /proc/partitions :#查看linux硬盘和分区信息的系统信息命令
如下:
major minor #blocks name
8 0 31166975 sda
8 16 877929472 sdb
8 17 1048576 sdb1
8 18 876879872 sdb2
8 192 781412184 sdm
8 193 781411160 sdm1
8 208 781412184 sdn
8 209 781411160 sdn1
8 32 5860522584 sdc
8 33 5860520960 sdc1
8 48 5860522584 sdd
8 49 5860520960 sdd1
8 64 5860522584 sde
8 65 5860520960 sde1
8 160 5860522584 sdk
8 161 5860520960 sdk1
8 112 5860522584 sdh
8 113 5860520960 sdh1
8 80 5860522584 sdf
8 81 5860520960 sdf1
8 128 5860522584 sdi
8 129 5860520960 sdi1
8 144 5860522584 sdj
8 145 5860520960 sdj1
8 96 5860522584 sdg
8 97 5860520960 sdg1
8 176 5860522584 sdl
8 177 5860520960 sdl1
253 0 52428800 dm-0
253 1 4194304 dm-1
253 2 820252672 dm-2
查看指定目录的大小
du -sh #
du -sh * | sort -n 统计当前文件夹(目录)大小,并按文件大小排序
# ls -lhs
总计 28G
15G -rw-r--r-- 1 root root 15G 06-04 14:35 all.txt
8.0K -rwx--x--x 1 root root 632 06-04 15:57 hash.pl
测试硬盘读写速度
dd if=/root/1Gb.file bs=64k | dd of=/dev/null
dd if=/dev/zero of=/root/1Gb.file bs=1024 count=1000000
通过上两个命令输出的执行时间,可以计算出测试硬盘的读/写速度
可以通过使用dd if=/dev/zero of=/file 来测试磁盘的纯写入性能
使用dd if=/file of=/dev/null 来测试磁盘的纯读取性能
使用dd if=/file1 of=/file2 来测试磁盘的读写性能
还可以用dd命令来备份、恢复或销毁磁盘数据
其他设备信息
lspci -tv # 列出所有PCI设备
lsusb -tv # 列出所有USB设备的linux系统信息命令
cat /proc/ioports :#查看设备io端口
cat /proc/interrupts :#查看中断
cat /proc/pci :#查看pci设备的信息
dmesg | grep IDE # 查看启动时IDE设备检测状况网络
网络相关
ifconfig # 查看所有网络接口的属性
iptables -L # 查看防火墙设置
route -n # 查看路由表
netstat -lntp # 查看所有监听端口
netstat -antp # 查看所有已经建立的连接
netstat -s # 查看网络统计信息进程
centos7中没有安装ifconfig命令的解决方法
有些时候最小化安装CentOS等Linux发行版的时候会默认不安装ifconfig等命令,这时候你进入终端,运行ifconfig命令就会出错.
可使用yum search ifconfig
来看这个这个功能在哪个包中,应该是net-tools.x86_64
利用yum install net-tools.x86_64
进行安装
linux系统查看端口占用情况
1、查看端口是否已经打开:
netstat -an | grep 端口号
2、查看端口是被哪个应用程序使用:
netstat -apn | grep 端口号
或者ps -ef | grep 端口号
或者lsof -i:端口号
lsof命令详解
#查看端口现在运行的情况
lsof -i:port #某个端口
lsof -i:port1-port2 #
lsof -i:1-1024 #查看端口1-1024运行情况
CentOS7 关闭防火墙
CentOS6关闭防火墙使用以下命令
//临时关闭
service iptables stop
//禁止开机启动
chkconfig iptables off
Centos7中不能如此使用,因为CentOS7版本后防火墙默认使用firewalld,CentOS7中关闭防火墙使用以下命令
//临时关闭
systemctl stop firewalld
//禁止开机启动
systemctl disable firewalld
屏幕会有如下揭示:
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Centos7防火墙配置rich-rule实现IP端口限制访问
进程相关
实时显示进程状态用户
top #
如下
top - 16:42:24 up 249 days, 7:40, 1 user, load average: 0.56, 0.60, 0.55
Tasks: 187 total, 1 running, 186 sleeping, 0 stopped, 0 zombie
%Cpu(s): 2.7 us, 1.3 sy, 0.0 ni, 95.5 id, 0.1 wa, 0.0 hi, 0.4 si, 0.0 st
KiB Mem : 32781100 total, 353340 free, 21516132 used, 10911628 buff/cache
KiB Swap: 4194300 total, 4194300 free, 0 used. 8833976 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
28973 kafka 20 0 7463808 1.224g 15500 S 14.3 3.9 1147:49 java
32343 storm 20 0 6549760 1.011g 19336 S 13.0 3.2 355:17.22 java
23583 root 20 0 8120272 1.072g 13660 S 6.0 3.4 242:56.69 java
查看所有进程
ps -ef #
如下
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 2018 ? 00:32:36 /usr/lib/systemd/systemd --syste
root 2 0 0 2018 ? 00:00:00 [kthreadd]
root 3 2 0 2018 ? 00:02:01 [ksoftirqd/0]
root 5 2 0 2018 ? 00:00:00 [kworker/0:0H]
ps -ef | grep xxx 命令
此命令表示查看相关进程。如
ps -ef|grep java
#结果为:digger 5350 5312 0 08:46 pts/2 00:00:00 grep --color=auto java
#对应字段:UID PID PPID C STIME TTY TIME CMD
#字段解释:进程所属用户ID 进程ID 父类进程ID CPU占用百分比 进程开始时间 终端位置 cpu时间 执行的命令
ps:将某个进程显示出来
-A 显示所有程序。
-e 此参数的效果和指定"A"参数相同。
-f 显示UID,PPIP,C与STIME栏位。
grep命令是查找
中间的|是管道命令 是指ps命令与grep同时执行
这条命令的意思是显示有关java有关的进程,包括java和grep java这两个甚至包括ps -ef本身,而grep是查找输出包含想要的字符串的行,也就是说grep java是在所有运行的进程中查找输出包含“java”字符串的输出行,这里面就包含java,和grep java两个进程。
杀死进程
centos下kill、killall、pkill命令区别老板:kill -9 的原理都不知道就敢在线上执行?
服务和软件相关
列出加载的内核模块
lsmod #
Module Size Used by
iptable_filter 12810 0
binfmt_misc 17468 1
dm_mirror 22135 0
dm_region_hash 20862 1 dm_mirror
dm_log 18411 2 dm_region_hash,dm_mirror
ipmi_ssif 23829 0
………………
列出所有系统服务
chkconfig --list #
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
activity-analyzer 0:off 1:off 2:off 3:on 4:on 5:on 6:off
ambari-agent 0:off 1:off 2:on 3:on 4:on 5:on 6:off
ambari-server 0:off 1:off 2:on 3:on 4:on 5:on 6:off
cloudResetPwdAgent 0:off 1:off 2:on 3:on 4:on 5:on 6:off
cloudResetPwdUpdateAgent 0:off 1:off 2:on 3:on 4:on 5:on 6:off
denyhosts 0:on 1:on 2:on 3:on 4:on 5:on 6:on
hst 0:off 1:off 2:off 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
uvp-monitor 0:off 1:off 2:on 3:on 4:on 5:on 6:off
列出所有启动的系统服务程序
chkconfig --list | grep on # 会红色突出显示上面的on的服务
查看所有安装的软件包
rpm -qa #
查看操作系统信息
查看版本当前操作系统内核信息
uname -a #
如下
Linux AAA.BBB.com 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
Linux查看当前操作系统版本信息
cat /proc/version #类似uname -r
如下
Linux version 3.10.0-514.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Tue Nov 22 16:42:41 UTC 2016
[r
Linux查看版本当前操作系统发行版信息
cat /etc/issue 或cat /etc/redhat-release
如下
CentOS Linux release 7.3.1611 (Core)
head -n 1 /etc/issue # 查看操作系统版本,是数字1不是字母L
列出所有版本信息
lsb_release -a 列出所有版本信息(适用于所有的linux,包括Redhat、SuSE、Debian等发行版,但是在debian下要安装lsb)
查看用户相关信息
查看系统运行时间、用户数、负载
uptime #
17:13:17 up 249 days, 8:11, 1 user, load average: 0.47, 0.59, 0.59
查看计算机名的linux系统信息命令
hostname #
查看活动用户
w #
如下
16:46:58 up 249 days, 7:44, 1 user, load average: 0.33, 0.47, 0.51
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 172.26.103.103 15:29 2.00s 0.03s 0.03s -bash
查看指定用户信息
id #
如下
uid=0(root) gid=0(root) groups=0(root)
查看用户登录日志
last #
查看系统所有用户
cut -d: -f1 /etc/passwd #
查看系统所有组
cut -d: -f1 /etc/group #
查看环境变量资源
env #
XDG_SESSION_ID=42878
HOSTNAME=XXXX.XX
TERM=vt100
SHELL=/bin/bash
HISTSIZE=1000
SSH_CLIENT=172.26.103.103 65121 22
QTDIR=/usr/lib64/qt-3.3
QTINC=/usr/lib64/qt-3.3/include
SSH_TTY=/dev/pts/0
QT_GRAPHICSSYSTEM_CHECKED=1
JRE_HOME=/data/java/jdk1.8.0_144/jre
………………
CentOS7.x系统根目录分区扩容
说明:系统版本为 Linux version 3.10.0-327.el7.x86_64
step1. 查看现有磁盘信息,可以看出根分区有45G
[root@DEV-CMDB-DB02 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos_mb--centos7-root 45G 9.8G 35G 23% /
devtmpfs 5.9G 0 5.9G 0% /dev
tmpfs 5.9G 84K 5.9G 1% /dev/shm
tmpfs 5.9G 8.9M 5.9G 1% /run
tmpfs 5.9G 0 5.9G 0% /sys/fs/cgroup
/dev/sda1 497M 142M 356M 29% /boot
tmpfs 1.2G 16K 1.2G 1% /run/user/42
tmpfs 1.2G 0 1.2G 0% /run/user/0
step2. 查看新增加的磁盘信息
[root@DEV-CMDB-DB02 ~]# fdisk -l
Disk /dev/sda: 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: 0x000e0945
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 104857599 51915776 8e Linux LVM
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 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 /dev/mapper/centos_mb--centos7-root: 47.7 GB, 47747956736 bytes, 93257728 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 /dev/mapper/centos_mb--centos7-swap: 5368 MB, 5368709120 bytes, 10485760 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
step3. 根据以上信息,对新增加的磁盘进行分区
[root@DEV-CMDB-DB02 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x232defba.
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 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 label type: dos
Disk identifier: 0x232defba
Device Boot Start End Blocks Id System
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-209715199, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): L
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 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 label type: dos
Disk identifier: 0x232defba
Device Boot Start End Blocks Id System
/dev/sdb1 2048 209715199 104856576 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
step4. 创建物理卷
[root@DEV-CMDB-DB02 ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
step5. 查看物理卷信息
[root@DEV-CMDB-DB02 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos_mb-centos7
PV Size 49.51 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 12674
Free PE 10
Allocated PE 12664
PV UUID 8WbgjB-T1Lf-kqUD-qPFw-UwJu-B9Lc-GAUTUB
"/dev/sdb1" is a new physical volume of "100.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 100.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID HOknRs-TnMy-wtfX-sGqD-5RK9-dk9q-ze13fj
[root@DEV-CMDB-DB02 ~]# vgdisplay
--- Volume group ---
VG Name centos_mb-centos7
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 49.51 GiB
PE Size 4.00 MiB
Total PE 12674
Alloc PE / Size 12664 / 49.47 GiB
Free PE / Size 10 / 40.00 MiB
VG UUID aN2D2P-Rk1y-wGFz-5l2I-5CcD-7s88-Z8czc7
step6. 将新增加的分区/dev/sdb1加入到根目录分区centos_mb-centos7中
[root@DEV-CMDB-DB02 ~]# vgextend centos_mb-centos7 /dev/sdb1
Volume group "centos_mb-centos7" successfully extended
step7. 重新查看卷组信息
[root@DEV-CMDB-DB02 ~]# vgdisplay
--- Volume group ---
VG Name centos_mb-centos7
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 149.50 GiB
PE Size 4.00 MiB
Total PE 38273
Alloc PE / Size 12664 / 49.47 GiB
Free PE / Size 25609 / 100.04 GiB
VG UUID aN2D2P-Rk1y-wGFz-5l2I-5CcD-7s88-Z8czc7
step9. 进行卷扩容
[root@DEV-CMDB-DB02 ~]# lvextend -l +100%FREE /dev/mapper/centos_mb--centos7-root
Size of logical volume centos_mb-centos7/root changed from 44.47 GiB (11384 extents) to 144.50 GiB (36993 extents).
Logical volume root successfully resized.
step10. 调整卷分区大小
[root@DEV-CMDB-DB02 ~]# xfs_growfs /dev/mapper/centos_mb--centos7-root
meta-data=/dev/mapper/centos_mb--centos7-root isize=256 agcount=4, agsize=2914304 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=11657216, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=5692, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 11657216 to 37880832
最后,查看磁盘信息可以看出根目录分区大小已成功扩容
[root@DEV-CMDB-DB02 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos_mb--centos7-root 145G 9.8G 135G 7% /
devtmpfs 5.9G 0 5.9G 0% /dev
tmpfs 5.9G 84K 5.9G 1% /dev/shm
tmpfs 5.9G 8.9M 5.9G 1% /run
tmpfs 5.9G 0 5.9G 0% /sys/fs/cgroup
/dev/sda1 497M 142M 356M 29% /boot
tmpfs 1.2G 16K 1.2G 1% /run/user/42
tmpfs 1.2G 0 1.2G 0% /run/user/0
挂载和卸载外部文件到linux系统
mount /dev/cdrom /mnt/cdrom
将/dev/cdrom
挂载到/mnt/cdrom
,而/dev/cdrom
会由管理员指向某个镜像文件或其他文件
或者直接将某个镜像文件挂到cdrom
mount /tmp/image.iso /mnt/cdrom
查看挂接的分区状态
mount | column -t #
centos7访问windows共享文件夹
在Linux下访问Windows共享文件夹linux访问windows共享文件夹的方法
yum install cifs-utils
mount -t cifs -o username=administrator,password=*** //192.168.1.41/sjy /mnt/smb/
sudo mount -t cifs -o username=XX-yy-XrayAlert,password='XXXXXXX' //172.XX.XX.XX/H1/XXX /root/XXX/
**Tips:**使用mount挂载的方法在系统重新启动后就会失效,如果希望开机时自动挂载,将下面设置加入/etc/fstab文件最后面就可以了。
//192.168.66.198/share /home/windows cifs defaults,username=share,password=share 0 2
其中/home/windows表示挂载点,就是上面windows目录的完整路径。
卸载
umount -l /mnt/Windows
Linux下关于/tmp目录的清理规则
Systemd 入门教程:命令篇
系统管理
systemctl
systemd-analyze
hostnamectl
localectl
timedatectl
loginctl
服务器性能优化的正确姿势