我尝试在ECS中申请午餐。
在我的本地docker环境中午餐时没有问题。
但是由于rds连接问题,无法在ECS中访问api服务器。
我在api服务器和mysql中为数据库使用golang。
我在main.go中致电db.go
func main() {
db := db.NewDatabase(os.Getenv("MYSQL_USER"), os.Getenv("MYSQL_PASSWORD"), os.Getenv("MYSQL_HOST"))
连接到rds数据库时发生错误
func NewDatabase(user, password, host string) *Database {
db, err := sql.Open("mysql", user+":"+password+"@tcp("+host+":3306)/article")
if err != nil {
panic(err.Error())
}
err = db.Ping()
// error occurs here
if err != nil {
panic(err.Error())
}
我将它部署到有弹性的beantalk中。
我检查了环境变量的设置是否正确。
这是完整的源代码:
https://github.com/jpskgc/article
我希望弹性豆没有错误。
但是实际不是。
我想知道解决方法。
这是弹性beantalk中的错误日志。
-------------------------------------
/var/log/containers/server-4c66c8d1848a-stdouterr.log
-------------------------------------
panic: dial tcp 172.31.26.91:3306: connect: connection timed out
goroutine 1 [running]:
article/api/db.NewDatabase(0xc00002401b, 0x4, 0xc00002a00f, 0xb, 0xc00002800b, 0x3c, 0xdb94f2)
/app/db/db.go:20 +0x3bc
main.main()
/app/main.go:18 +0xee
答案 0 :(得分:0)
“连接超时”表示存在防火墙限制,您还可以检查mysql白名单,该白名单应具有ECS的IP。