install-certbot.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/bash
  2. # Certbot 自动安装脚本
  3. # 支持 Debian/Ubuntu, CentOS/RHEL, Fedora
  4. echo "=== 检测系统类型 ==="
  5. if [ -f /etc/os-release ]; then
  6. . /etc/os-release
  7. echo "系统: $NAME"
  8. echo "版本: $VERSION"
  9. else
  10. echo "无法检测系统类型"
  11. exit 1
  12. fi
  13. echo ""
  14. echo "=== 开始安装 Certbot ==="
  15. # 检测包管理器并安装
  16. if command -v apt &> /dev/null; then
  17. echo "检测到 apt (Debian/Ubuntu)"
  18. sudo apt update
  19. sudo apt install certbot python3-certbot-nginx -y
  20. elif command -v yum &> /dev/null; then
  21. echo "检测到 yum (CentOS/RHEL)"
  22. # 安装 EPEL 仓库
  23. sudo yum install epel-release -y
  24. sudo yum install certbot python3-certbot-nginx -y
  25. elif command -v dnf &> /dev/null; then
  26. echo "检测到 dnf (Fedora/CentOS 8+)"
  27. sudo dnf install epel-release -y
  28. sudo dnf install certbot python3-certbot-nginx -y
  29. else
  30. echo "未检测到支持的包管理器"
  31. echo "尝试使用 pip 安装..."
  32. if command -v pip3 &> /dev/null; then
  33. sudo pip3 install certbot certbot-nginx
  34. else
  35. echo "错误: 无法安装 certbot"
  36. exit 1
  37. fi
  38. fi
  39. echo ""
  40. echo "=== 验证安装 ==="
  41. if command -v certbot &> /dev/null; then
  42. certbot --version
  43. echo ""
  44. echo "✅ Certbot 安装成功!"
  45. echo ""
  46. echo "下一步: 运行以下命令获取 SSL 证书"
  47. echo "sudo certbot --nginx -d aiorz.com -d www.aiorz.com"
  48. else
  49. echo "❌ Certbot 安装失败"
  50. exit 1
  51. fi