北京二锅头 2025-04-01 07:15 广东
在服务器上,有些操作一旦执行,职业生涯可能就此终结。
一、禁忌操作TOP10
# 优雅关机shutdown -h now# 重启前同步数据sync; sync; sync
# 设置危险命令别名保护alias rm='rm -i'alias chmod='echo "[WARNING] 禁止直接操作!请联系架构师"'
iptables-save > /backup/iptables_$(date +%F).rulessudo -u appuser ./deploy.sh-- 操作前必做CREATE TABLE backup_table LIKE original_table;INSERT INTO backup_table SELECT * FROM original_table;
# 禁用密码登录sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config# 启用密钥登录ssh-copy-id -i ~/.ssh/id_rsa.pub user@server
# 配置logrotate每日切割vim /etc/logrotate.d/nginx/var/log/nginx/*.log {dailyrotate 30compressmissingoknotifempty}
# 修改默认端口vim /etc/redis.confport 6380# 绑定内网IPbind 10.0.0.1
# 变更时实时监控watch -n 1 "netstat -ant | grep ESTABLISHED | wc -l"# 关键指标基线:- CPU使用率突增50%- 内存消耗持续上涨- 磁盘IO延迟>100ms
# 安全更新流程yum update --security -y# 内核更新后必须重启reboot
二、灾难自救指南
# 立即卸载分区防止覆盖umount /dev/sdb1# 使用extundelete恢复extundelete /dev/sdb1 --restore-file /home/data.txt
-- 闪回查询(MySQL 8.0+)SELECT * FROM table AS OF TIMESTAMP '2024-01-01 12:00:00';-- 生成补偿SQLFLASHBACK TABLE table TO TIMESTAMP '2024-01-01 12:00:00';
# 立即断网ifconfig eth0 down# 备份加密文件供后续分析tar -czvf ransom_evidence.tar.gz /tmp/*.encrypted# 使用chkrootkit排查后门chkrootkit -q
