Linux 系统运维基础指南
目录
- 系统信息查看
- 用户与权限管理
- 进程管理
- 磁盘管理
- 网络配置
- 系统日志
- 常用运维命令
1. 系统信息查看
1.1 查看系统版本
1 2 3 4 5 6 7 8
| cat /etc/os-release cat /etc/redhat-release cat /etc/debian_version
uname -r uname -a
|
1.2 查看硬件信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| lscpu cat /proc/cpuinfo
free -h cat /proc/meminfo
lsblk df -h
lspci
lsusb
|
1.3 查看系统运行状态
1 2 3 4 5 6 7 8 9 10
| uptime
top htop
systemctl list-units --type=service systemctl list-unit-files --state=enabled
|
2. 用户与权限管理
2.1 用户管理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| useradd -m -s /bin/bash username passwd username
usermod -aG sudo username usermod -L username usermod -U username
userdel -r username
id username cat /etc/passwd cat /etc/shadow
|
2.2 组管理
1 2 3 4 5 6 7 8 9
| groupadd groupname
usermod -aG groupname username
getent group groupname cat /etc/group
|
2.3 权限管理
1 2 3 4 5 6 7 8 9 10 11 12
| chmod 755 filename chmod u+x filename chmod -R 755 directory/
chown user:group filename chown -R user:group directory/
ls -l stat filename
|
2.4 Sudo 配置
1 2 3 4 5 6 7 8
| visudo
username ALL=(ALL:ALL) ALL
username ALL=(ALL) NOPASSWD: ALL
|
3. 进程管理
3.1 查看进程
1 2 3 4 5 6 7 8 9 10 11
| ps aux ps -ef
ps aux | grep nginx pgrep nginx
top htop
|
3.2 进程控制
1 2 3 4 5 6 7 8 9
| kill PID kill -9 PID killall processname pkill processname
nice -n 10 command renice -n 10 -p PID
|
3.3 后台任务管理
1 2 3 4 5 6 7 8 9 10 11 12 13
| command &
jobs
Ctrl+Z bg fg
nohup command &
|
4. 磁盘管理
4.1 磁盘分区
1 2 3 4 5 6 7 8 9 10 11
| fdisk -l lsblk
fdisk /dev/sdb parted /dev/sdb
mkfs.ext4 /dev/sdb1 mkfs.xfs /dev/sdb1
|
4.2 挂载管理
1 2 3 4 5 6 7 8 9 10 11 12
| mount /dev/sdb1 /mnt/data
umount /mnt/data
df -h mount | grep sdb1
echo "/dev/sdb1 /mnt/data ext4 defaults 0 0" >> /etc/fstab
|
4.3 LVM 管理
1 2 3 4 5 6 7 8 9 10 11 12
| pvcreate /dev/sdb1
vgcreate vg_data /dev/sdb1
lvcreate -L 100G -n lv_data vg_data
lvextend -L +50G /dev/vg_data/lv_data resize2fs /dev/vg_data/lv_data
|
4.4 磁盘空间分析
1 2 3 4 5 6 7 8 9 10
| df -h df -i
du -sh /path du -h --max-depth=1 /path
find / -type f -size +100M
|
5. 网络配置
5.1 网络接口配置
1 2 3 4 5 6 7 8 9 10 11 12 13
| ip addr ifconfig
ip addr add 192.168.1.100/24 dev eth0 ip link set eth0 up
vi /etc/sysconfig/network-scripts/ifcfg-eth0
vi /etc/netplan/01-netcfg.yaml
|
5.2 路由配置
1 2 3 4 5 6 7 8 9
| ip route route -n
ip route add default via 192.168.1.1
ip route add 10.0.0.0/8 via 192.168.1.254
|
5.3 DNS 配置
1 2 3 4 5 6
| cat /etc/resolv.conf
echo "nameserver 8.8.8.8" >> /etc/resolv.conf echo "nameserver 8.8.4.4" >> /etc/resolv.conf
|
5.4 防火墙配置
1 2 3 4 5 6 7 8 9 10 11 12 13
| systemctl start firewalld firewall-cmd --add-port=80/tcp --permanent firewall-cmd --reload
ufw enable ufw allow 80/tcp ufw status
iptables -A INPUT -p tcp --dport 80 -j ACCEPT iptables-save > /etc/iptables/rules.v4
|
6. 系统日志
6.1 日志文件位置
1 2 3 4 5 6 7 8 9 10 11 12
| /var/log/messages /var/log/syslog
/var/log/secure /var/log/auth.log
/var/log/nginx/ /var/log/apache2/ /var/log/mysql/
|
6.2 日志查看命令
1 2 3 4 5 6 7 8 9 10
| tail -f /var/log/messages tail -100 /var/log/messages
grep "error" /var/log/messages journalctl -u nginx -f
logrotate -f /etc/logrotate.conf
|
6.3 systemd 日志
1 2 3 4 5 6 7 8 9 10 11 12
| journalctl journalctl -f journalctl -xe
journalctl -u nginx journalctl -u sshd
journalctl --since "2024-01-01" journalctl --since "1 hour ago"
|
7. 常用运维命令
7.1 系统维护
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| yum update -y apt update && apt upgrade -y
yum clean all apt clean
systemctl restart service systemctl reload service
systemctl status service
|
7.2 性能监控
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| top mpstat 1 5
free -h vmstat 1 5
iostat -x 1 5 iotop
iftop nethogs
|
7.3 故障排查
1 2 3 4 5 6 7 8 9 10 11 12 13
| ping host traceroute host telnet host port nc -zv host port
netstat -tulpn ss -tulpn lsof -i :80
strace -p PID
|
附录:常用快捷键
| 快捷键 |
功能 |
| Ctrl+C |
终止当前命令 |
| Ctrl+Z |
挂起当前命令 |
| Ctrl+D |
退出终端 |
| Ctrl+L |
清屏 |
| Ctrl+R |
搜索历史命令 |
| Tab |
自动补全 |
| Ctrl+A |
移动到行首 |
| Ctrl+E |
移动到行尾 |
文档版本: 1.0
最后更新: 2026-02-27
适用系统: CentOS/RHEL, Ubuntu/Debian