

适用对象:Linux 服务器运维工程师 / 网络工程师 / IT 运维人员 适用环境:CentOS / Rocky / AlmaLinux / Ubuntu / Debian(命令通用,个别差异已说明)
uname -a # 查看内核信息
cat /etc/os-release # 查看系统版本
hostnamectl # 主机名与系统信息
uptime # 运行时间、负载
lscpu
cat /proc/cpuinfo
mpstat -P ALL
free -h
cat /proc/meminfo
top / htop
df -hT
lsblk
mount | column -t
findmnt
ls -lh
cd /path
pwd
touch file
mkdir -p dir/subdir
cp -a src dst
mv old new
rm -rf dir
find / -name "*.log"
du -sh *
wc -l file
stat file
chmod 755 file
chmod -R 644 dir
chown user:user file
id username
权限速记:
useradd username
passwd username
usermod -aG wheel username
userdel -r username
su - username
whoami
who
last
sudo 配置:
visudo
username ALL=(ALL) NOPASSWD:ALL
ps aux
ps -ef | grep nginx
top
htop
kill PID
kill -9 PID
pkill nginx
systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl status nginx
systemctl enable nginx
systemctl disable nginx
systemctl list-units --type=service
ip a
ip route
nmcli device status
ss -lntup
netstat -lntup
lsof -i:80
ping 8.8.8.8
traceroute www.baidu.com
curl -I http://127.0.0.1
tcpdump -i eth0 -nn port 80
tcpdump -i any host 1.1.1.1
fdisk -l
parted /dev/sdb
mkfs.ext4 /dev/sdb1
fsck -y /dev/sdb1
pvcreate /dev/sdb
vgcreate vgdata /dev/sdb
lvcreate -L 10G -n lvdata vgdata
lvextend -L +5G /dev/vgdata/lvdata
resize2fs /dev/vgdata/lvdata
journalctl -xe
journalctl -u nginx
journalctl --since "1 hour ago"
/var/log/messages
/var/log/secure
/var/log/syslog
/var/log/nginx/
/var/log/audit/audit.log
tail -f /var/log/messages
tail -n 100 file.log
yum install nginx
dnf install httpd
yum remove nginx
yum list installed
yum provides */netstat
apt update
apt install nginx
apt remove nginx
apt list --installed
firewall-cmd --state
firewall-cmd --list-all
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
iptables -L -n
iptables -F
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
getenforce
setenforce 0
semanage port -l
crontab -e
crontab -l
示例:
0 2 * * * /usr/bin/backup.sh
at 23:00
atq
atrm 1
top / htop
iostat -x 1
vmstat 1
sar -u 1
free -h
df -h
排障口诀:
负载 → CPU → 内存 → 磁盘 → 网络 → 应用 → 日志
# 找出占用 80 端口的进程
ss -lntup | grep :80
# 找出大文件
find / -type f -size +1G
# 查看最近登录失败
lastb
# 一键查看服务器健康
uptime && free -h && df -h