Linux·常用命令

版权声明:知识需要共享与交流 https://blog.csdn.net/weixin_43450987/article/details/85373253

一、查看Linux查看版本信息
1、# cat /proc/version (Linux查看当前操作系统版本信息)

  Linux version 2.4.20-8 ([email protected])
  (gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) #1 Thu Mar 13 17:54:28 EST 2003

2、# uname -a (Linux查看版本当前操作系统内核信息)

Linux localhost.localdomain 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 athlon i386 GNU/Linux
  
  3、# cat /etc/issue 或cat /etc/redhat-release(Linux查看版本当前操作系统发行版信息)

Red Hat Linux release 9 (Shrike)

4、# cat /proc/cpuinfo (Linux查看cpu相关信息,包括型号、主频、内核信息等)

processor : 0
vendor_id : AuthenticAMD
  cpu family : 15
  model : 1
  model name : AMD A4-3300M APU with Radeon™ HD Graphics
  stepping : 0
  cpu MHz : 1896.236
  cache size : 1024 KB
  fdiv_bug : no
  hlt_bug : no
  f00f_bug : no
  coma_bug : no
  fpu : yes
  fpu_exception : yes
  cpuid level : 6
  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 syscall mmxext lm 3dnowext 3dnow
  bogomips : 3774.87

5、# getconf LONG_BIT (Linux查看版本说明当前CPU运行在32bit模式下, 但不代表CPU不支持64bit)

32
  
6、#lsb_release -a

LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.4.1708 (Core)
Release: 7.4.1708
Codename: Core
二、查看cpu信息
1、查看CPU信息
总核数 = 物理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

查看CPU信息(型号)
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c

查看CPU的负载
top
平均负载是指上一分钟同时处于就绪状态的平均进程数。在CPU中可以理解为CPU可以并行处理的任务数量,就是CPU个数X核数。
如果CPU Load等于CPU个数乘以核数,那么就说CPU正好满负载,再多一点,可能就要出问题了,有些任务不能被及时分配处理器,那要保证性能的话,最好要小于CPU个数X核数X0.7。
Load Average是指CPU的Load。它所包含的信息是在一段时间内CPU正在处理及等待CPU处理的进程数之和的统计信息,也就是CPU使用队列的长度的统计信息。
Load Average的值应该小于CPU个数X核数X0.7,Load Average会有3个状态平均值,分别是1分钟、5分钟和15分钟平均Load。

三、查看内存信息
1)、cat /proc/meminfo
2)、free 命令
total used free shared buffers cached
Mem: 65973912 32496232 33477680 0 906932 6452984
-/+ buffers/cache: 25136316 40837596
Swap: 41943032 13204 41929828
一些简单的计算方法:
物理已用内存 = 实际已用内存 - 缓冲 - 缓存

物理空闲内存 = 总物理内存 - 实际已用内存 + 缓冲 + 缓存

应用程序可用空闲内存 = 总物理内存 - 实际已用内存

应用程序已用内存 = 实际已用内存 - 缓冲 - 缓存

四、查看磁盘信息
1)fdisk -l
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x0008d73a

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83884031 41940992 83 Linux
2)iostat -x 10 查看磁盘IO的性能
[root@xdpp02 bin]# iostat -x 10
Linux 2.6.32-358.el6.x86_64 (xdpp02) 11/30/2016 x86_64 (16 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
3.86 0.00 0.17 0.06 0.00 95.90
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
sda 0.77 84.89 0.62 3.11 15.72 703.97 193.03 0.12 31.10 2.86 1.07
dm-0 0.00 0.00 0.15 0.22 2.93 1.78 12.75 0.00 12.42 3.77 0.14
dm-1 0.00 0.00 0.09 0.10 0.75 0.83 8.00 0.00 14.53 0.28 0.01
dm-2 0.00 0.00 0.00 0.57 0.03 4.52 8.00 0.01 22.24 4.84 0.28
dm-3 0.00 0.00 0.01 3.10 1.58 24.82 8.48 0.03 11.16 1.05 0.33
dm-4 0.00 0.00 0.03 0.00 0.27 0.00 8.00 0.00 0.52 0.10 0.00
dm-5 0.00 0.00 1.11 84.00 10.11 672.02 8.01 3.62 42.54 0.07 0.61

CentOS7使用firewalld打开关闭防火墙与端口
1、firewalld的基本使用
启动: systemctl start firewalld
关闭: systemctl stop firewalld
查看状态: systemctl status firewalld
开机禁用 : systemctl disable firewalld
开机启用 : systemctl enable firewalld

2.systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。
启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed

3.配置firewalld-cmd

查看版本: firewall-cmd --version
查看帮助: firewall-cmd --help
显示状态: firewall-cmd --state
查看所有打开的端口: firewall-cmd --zone=public --list-ports
更新防火墙规则: firewall-cmd --reload
查看区域信息: firewall-cmd --get-active-zones
查看指定接口所属区域: firewall-cmd --get-zone-of-interface=eth0
拒绝所有包:firewall-cmd --panic-on
取消拒绝状态: firewall-cmd --panic-off
查看是否拒绝: firewall-cmd --query-panic

那怎么开启一个端口呢
添加
firewall-cmd --zone=public --add-port=80/tcp --permanent (–permanent永久生效,没有此参数重启后失效)
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone= public --query-port=80/tcp
删除
firewall-cmd --zone= public --remove-port=80/tcp --permanent

ifconfig
yum install net-tools
我当时忘记截图了,不过中间会出来一个 y/n ,输入y即可

lsof
yum install lsof
没截图,就输入就可以了。(查看端口号)

centos7 关闭firewall安装iptables并配置
一、配置防火墙,开启80端口、3306端口
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。
1、关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动

2、安装iptables防火墙
yum install iptables-services #安装
vi /etc/sysconfig/iptables #编辑防火墙配置文件
#Firewall configuration written by system-config-firewall
#Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2181 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
:wq! #保存退出
systemctl restart iptables.service #最后重启防火墙使配置生效
systemctl enable iptables.service #设置防火墙开机启动
二、关闭SELINUX
vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq! #保存退出
setenforce 0 #使配置立即生效

猜你喜欢

转载自blog.csdn.net/weixin_43450987/article/details/85373253