Linux 运维
Linux 是服务器运维的基础。本文记录常用的 Linux 运维技巧。
uname -a # 内核版本cat /etc/os-release # 系统版本hostnamectl # 主机信息top # 实时进程htop # 增强版 topfree -h # 内存df -h # 磁盘du -sh /path # 目录大小Shell 脚本
Section titled “Shell 脚本”#!/bin/bashset -euo pipefail
# 变量DIR="/var/log"
# 循环for f in "$DIR"/*.log; do echo "处理: $f"done
# 条件if [ -f "$FILE" ]; then echo "文件存在"fi定时任务 (Cron)
Section titled “定时任务 (Cron)”crontab -e# 每天凌晨 2 点备份0 2 * * * /usr/local/bin/backup.shsystemd 服务
Section titled “systemd 服务”[Unit]Description=My ServiceAfter=network.target
[Service]Type=simpleExecStart=/usr/bin/myappRestart=always
[Install]WantedBy=multi-user.targetss -tlnpnetstat -tlnpss -slsof -i :80SSH 安全
Section titled “SSH 安全”# 修改端口Port 2222
# 禁用 root 登录PermitRootLogin no
# 禁用密码登录PasswordAuthentication no