一、系统基础(每天都敲)

1. 查看系统信息

uname -a        # 内核、系统版本
hostname        # 主机名
uptime          # 开机多久、负载高不高(运维第一命令)
who / w         # 谁在登录
last            # 登录历史

2. 资源监控(面试必考、日常必用)

top             # 实时进程(类似任务管理器)
htop            # 美化版 top(要先装)
free -h         # 看内存
df -h           # 看磁盘使用率
du -sh *        # 看当前目录哪个文件夹最大

3. 进程管理

ps aux          # 看所有进程
ps aux | grep nginx  # 过滤某个服务
kill -9 进程号   # 强制杀进程
pkill nginx     # 直接杀服务名
systemctl status nginx  # 看服务状态

二、文件操作(90% 时间都在干这个)

1. 目录 / 文件

ls              # 列表
ls -l           # 详细信息
ls -lh          # 带单位大小
ls -a           # 看隐藏文件

cd /path        # 进入目录
cd ..           # 返回上一级
pwd             # 显示当前在哪

mkdir test      # 新建文件夹
rm -rf file     # 删除文件/文件夹(慎用!)
cp file1 file2  # 复制
mv old new      # 移动/改名

2. 文件查看(运维神技)

cat file        # 看全部内容
less file       # 分页看(大日志必备)
tail -f log     # 实时刷新日志(最常用!)
head -20 file   # 看前20行
wc -l file      # 统计行数

3. 查找文件

find / -name nginx.conf    # 全局找文件
grep 'error' log.log       # 在文件里搜关键词

三、网络命令(DevOps 核心)

ip a            # 看本机 IP(你刚才用过)
ip route        # 看网关
ping ip         # 通不通
curl ip         # 访问网页/接口
wget url        # 下载文件

ss -tulnp       # 看端口占用(比 netstat 好用)
netstat -tulnp  # 老版本看端口

四、软件安装(Ubuntu/Debian)

apt update      # 更新源
apt install nginx  # 安装
apt remove nginx   # 卸载
apt search 关键词   # 搜索软件

CentOS 用:

yum install / dnf install

五、权限命令(部署网站必用)

chmod 755 file  # 改权限
chown www-data:www-data file  # 改所属用户(Nginx/PHP必备)
sudo            # 临时 root

六、服务管理(systemd 现代运维标准)

systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl enable nginx  # 开机自启
systemctl disable nginx
systemctl status nginx  # 看日志+状态
journalctl -u nginx     # 看完整日志

七、压缩 / 解压(部署必用)

tar -zxvf xxx.tar.gz   # 解压
tar -zcvf xxx.tar.gz dir  # 压缩
unzip xxx.zip          # 解压 zip

八、文本编辑(必会)

vim 文件名

i 进入编辑
ESC 退出编辑
:wq 保存退出
:q! 不保存退出

九、日志排查(真正运维能力)

tail -f /var/log/nginx/access.log  # 访问日志
tail -f /var/log/nginx/error.log   # 错误日志
dmesg           # 系统内核日志
journalctl -f   # 系统实时日志

十、磁盘清理(服务器卡慢必用)

df -h
du -sh /* | sort -rh
rm -rf /var/log/*old
apt autoremove

十一、防火墙命令

(1)ubuntu防火墙命令

1. 查看状态

ufw status
ufw status verbose

2. 开启 / 关闭 / 重启

ufw enable       # 开启防火墙
ufw disable      # 关闭
ufw reload       # 重载规则

3. 放行端口(最常用)

# 放行 80 端口(HTTP/Nginx)
ufw allow 80/tcp

# 放行 443 端口(HTTPS)
ufw allow 443/tcp

# 放行 SSH(22 端口)
ufw allow 22/tcp

# 放行某个服务名(系统自带别名)
ufw allow ssh
ufw allow http
ufw allow https

4. 删除规则

# 按端口删
ufw delete allow 80/tcp

# 按服务删
ufw delete allow ssh

5. 禁止端口

ufw deny 3306/tcp

6. 开机自启

systemctl enable ufw
systemctl disable ufw

(2)CentOS / RHEL 防火墙命令

工作服务器绝大多数是这个,必须会

1. 基本操作

systemctl start firewalld
systemctl stop firewalld
systemctl status firewalld
systemctl enable firewalld
systemctl disable firewalld

2. 查看规则

firewall-cmd --list-all
firewall-cmd --list-ports
firewall-cmd --list-services

3. 放行端口(临时,重启失效)

firewall-cmd --add-port=80/tcp
firewall-cmd --add-port=443/tcp
firewall-cmd --add-port=22/tcp

4. 永久放行(重启依然有效)

firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --add-port=443/tcp --permanent
firewall-cmd --add-service=http --permanent

5. 删规则

firewall-cmd --remove-port=80/tcp --permanent

6. 重载(改完必须执行)

firewall-cmd --reload

(3)最实用总结(运维只记这几句就够)

Ubuntu 日常用

ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
ufw status

CentOS 日常用

firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --add-port=443/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-all