SSH(Secure Shell)是构建高可靠性Linux系统运维架构的核心工具之一。以下是基于SSH的高可靠性SysOps架构设计方案:
# /etc/ssh/sshd_config 关键配置
Port 2222 # 修改默认端口
Protocol 2 # 仅使用SSHv2
PermitRootLogin no # 禁止root直接登录
MaxAuthTries 3 # 最大尝试次数
LoginGraceTime 1m # 登录宽限时间
AllowUsers sysadmin # 只允许特定用户
PasswordAuthentication no # 禁用密码认证
PubkeyAuthentication yes # 启用公钥认证
# 生成强密钥对
ssh-keygen -t ed25519 -a 100 -f ~/.ssh/admin_key
# 密钥分发
ssh-copy-id -i ~/.ssh/admin_key.pub user@server -p 2222
# Google Authenticator集成
sudo apt install libpam-google-authenticator
google-authenticator
# 在sshd_config中添加
ChallengeResponseAuthentication yes
AuthenticationMethods publickey,keyboard-interactive
# 并行执行命令工具
sudo apt install pdsh clusterssh
# 示例批量执行
pssh -h hosts.txt -l admin -i "sudo apt update"
#!/bin/bash
# 自动化部署脚本示例
for server in $(cat server_list); do
ssh -p 2222 -i ~/.ssh/admin_key admin@$server << 'EOF'
sudo apt update
sudo apt install -y nginx
sudo systemctl enable nginx
EOF
done
# 监控活跃SSH会话
watch -n 60 "netstat -tnpa | grep 'ESTABLISHED.*ssh'"
# 使用Prometheus + node_exporter监控SSH指标
# SSH健康检查脚本
check_ssh() {
if ! ssh -o ConnectTimeout=5 -q $1 exit; then
echo "$1: SSH不可达" | mail -s "SSH警报" admin@example.com
# 触发故障转移流程
fi
}
# 使用rsync over SSH进行加密备份
rsync -avz -e "ssh -p 2222 -i ~/.ssh/backup_key" /data backup@backup-server:/backups
通过以上架构设计,可以构建一个既安全又高可用的Linux系统运维环境,确保系统管理员能够可靠地访问和管理基础设施。