Skip to content

tingxin/nacos-on-aws

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nacos EKS 部署工具

在 AWS EKS 上快速部署 Nacos 集群的 CLI 工具。

注意:本项目强制使用外部 RDS/Aurora MySQL,不支持容器内 MySQL。

快速开始

方式 1: 创建新集群并部署 Nacos

# 1. 安装依赖
pip install -r requirements.txt

# 2. 配置(填入你的 RDS 端点)
cp config.yaml my-config.yaml
vim my-config.yaml

# 3. 创建集群
python3 nacos_eks_cli.py -c my-config.yaml create-eks

# 4. 部署 Nacos
python3 nacos_eks_cli.py -c my-config.yaml deploy-nacos

# 5. 获取访问地址
python3 nacos_eks_cli.py -c my-config.yaml status

方式 2: 在现有集群上部署 Nacos

# 1. 安装依赖
pip install -r requirements.txt

# 2. 配置(填入你的集群名称和 RDS 端点)
cp config.existing-cluster.yaml my-config.yaml
vim my-config.yaml

# 3. 测试 MySQL 连接
python3 test_mysql_connection.py -c my-config.yaml

# 4. 检查集群
python3 nacos_eks_cli.py -c my-config.yaml check-cluster

# 5. 部署 Nacos
python3 nacos_eks_cli.py -c my-config.yaml deploy-nacos

# 6. 获取访问地址
python3 nacos_eks_cli.py -c my-config.yaml status

配置文件

项目提供两个配置文件模板:

  1. config.yaml - 创建新集群

    • 从零开始创建 EKS 集群
    • 自动配置网络和节点组
    • 需要配置 RDS MySQL 端点
  2. config.existing-cluster.yaml - 使用现有集群

    • 在已有 EKS 集群上部署
    • 只需配置集群名称和 RDS 端点
    • 自动检查和安装必要组件

前置要求:准备 RDS MySQL

必须先准备好 RDS/Aurora MySQL 实例,包括:

  • RDS 端点地址
  • 数据库名称(如 nacos_config
  • 数据库用户和密码
  • 确保 RDS 与 EKS 在同一 VPC
  • 配置安全组允许 EKS 节点访问 RDS

主要命令

# 创建 EKS 集群
python3 nacos_eks_cli.py -c config.yaml create-eks

# 检查集群状态
python3 nacos_eks_cli.py -c config.yaml check-cluster

# 部署 Nacos
python3 nacos_eks_cli.py -c config.yaml deploy-nacos

# 查看状态
python3 nacos_eks_cli.py -c config.yaml status

# 扩缩容
python3 nacos_eks_cli.py -c config.yaml scale-nacos --replicas 5

# 卸载 Nacos
python3 nacos_eks_cli.py -c config.yaml uninstall-nacos

# 删除集群
python3 nacos_eks_cli.py -c config.yaml delete-eks

工具脚本

# 测试 MySQL 连接
python3 test_mysql_connection.py -c my-config.yaml

# 修复 EBS CSI 驱动问题
python3 fix_ebs_csi.py -c your-cluster -r ap-southeast-1 --fix

前置要求

  • Python 3.8+
  • AWS CLI(已配置凭证)
  • kubectl、eksctl、helm
  • RDS/Aurora MySQL 实例(必须提前准备好)

为什么强制使用外部 MySQL?

  1. 高可用性 - RDS/Aurora 提供自动故障转移和多可用区部署
  2. 自动备份 - 自动备份和时间点恢复
  3. 性能优化 - 更好的性能和可扩展性
  4. 运维简化 - AWS 管理数据库维护和更新
  5. 成本优化 - 无需为数据库 Pod 分配 EBS 存储和计算资源

文档

故障排查

1. 数据库连接问题

如果 Nacos Pod 报错 dataSource or tableName is null

# 使用诊断脚本
chmod +x diagnose_nacos.sh
./diagnose_nacos.sh nacos

# 重新部署
chmod +x redeploy_nacos.sh
./redeploy_nacos.sh config.yaml

详细说明:FIX_DATABASE_CONNECTION.md

2. 无法连接到 RDS

# 测试 MySQL 连接
python3 test_mysql_connection.py -c config.yaml

# 检查安全组
aws ec2 describe-security-groups --group-ids $RDS_SG

# 从 EKS 节点测试连接
kubectl run mysql-test --image=mysql:8.0 -it --rm --restart=Never -- \
  mysql -h $RDS_ENDPOINT -u nacos -p

3. EBS CSI 驱动问题

# 检查并修复
python3 fix_ebs_csi.py -c your-cluster -r ap-southeast-1 --fix

4. Nacos Pod 无法启动

# 查看日志
kubectl logs -n nacos nacos-0

# 查看前一个容器日志
kubectl logs -n nacos nacos-0 --previous

# 查看事件
kubectl describe pod -n nacos nacos-0

# 使用诊断脚本
./diagnose_nacos.sh nacos

许可证

MIT License

About

部署nacos的程序

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published