docker version:
Client:
Version: 17.09.0-ce
API version: 1.32
Go version: go1.8.3
Git commit: afdb6d4
Built: Tue Sep 26 22:41:23 2017
OS/Arch: linux/amd64
Server:
Version: 17.09.0-ce
API version: 1.32 (minimum version 1.12)
Go version: go1.8.3
Git commit: afdb6d4
Built: Tue Sep 26 22:42:49 2017
OS/Arch: linux/amd64
Experimental: false
牧场服务器版本:rancher/server:stable
OS:
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
立即使用Rancher服务器HA功能。使用AWS RDS Aurora cluster
准备数据库集群。
我可以通过AWS RDS
从Rancher服务器主机(AWS EC2
)连接群集IP(mysql cli
),但是使用此Rancher服务器安装命令似乎无法在数据库中创建表:
$ docker run -d --restart=unless-stopped -p 8080:8080 -p 9345:9345 rancher/server:stable --db-host [DB_CLUSTER_HOST] --db-port 3306 --db-user [USERNAME] --db-pass [PASSWORD] --db-name [DB_NAME] --advertise-address [CURRENT_IP]
从docker inspect
方式查看正在运行的Rancher服务器容器,参数设置正确:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f5b8ff32907c rancher/server:stable "/usr/bin/entry --..." 2 minutes ago Up 2 minutes 0.0.0.0:8080->8080/tcp, 3306/tcp, 0.0.0.0:9345->9345/tcp priceless_beaver
$ docker inspect f5b8
[
{
"Id": "f5b8ff32907c6e3158b424c7e2ba5b320763a5a5da807927a096d45ae700a30f",
"Created": "2017-12-06T04:41:08.498666156Z",
"Path": "/usr/bin/entry",
"Args": [
"--db-host",
"[DB_HOST]",
"--db-port",
"3306",
"--db-user",
"[DB_USER]",
"--db-pass",
"[DB_PASS]",
"--db-name",
"[DB_NAME]",
"--advertise-address",
"[CURRENT_IP]"
],
...
从容器日志中得到:
$ docker logs [CONTAINER_ID]
...
07:42:32.965 [main] ERROR i.c.p.a.sources.LazyJDBCSource - Failed to get connection to database, will retry for 5 minutes
07:42:40.061 [pollingConfigurationSource] ERROR i.c.p.a.sources.LazyJDBCSource - Failed to get connection to database, will retry for 5 minutes
07:42:47.077 [main] ERROR i.c.p.a.sources.LazyJDBCSource - Failed to get connection to database, will retry for 5 minutes
07:42:54.093 [pollingConfigurationSource] ERROR i.c.p.a.sources.LazyJDBCSource - Failed to get connection to database, will retry for 5 minutes
07:43:01.109 [main] ERROR i.c.p.a.sources.LazyJDBCSource - Failed to get connection to database, will retry for 5 minutes
07:43:08.125 [pollingConfigurationSource] ERROR i.c.p.a.sources.LazyJDBCSource - Failed to get connection to database, will retry for 5 minutes
07:43:15.213 [main] ERROR i.c.p.a.sources.LazyJDBCSource - Failed to get connection to database, will retry for 5 minutes
07:43:22.229 [pollingConfigurationSource] ERROR i.c.p.a.sources.LazyJDBCSource - Failed to get connection to database, will retry for 5 minutes
07:43:29.245 [main] ERROR i.c.p.a.sources.LazyJDBCSource - Failed to get connection to database, will retry for 5 minutes
07:43:36.261 [pollingConfigurationSource] ERROR i.c.p.a.sources.LazyJDBCSource - Failed to get connection to database, will retry for 5 minutes
07:43:43.277 [main] ERROR i.c.p.a.sources.LazyJDBCSource - Failed to get connection to database, will retry for 5 minutes
$ docker logs [CONTAINER_ID] -f
...
Caused by: java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=[CLUSTER_HOST])(port=3306)(type=master) : Connection timed out
at org.mariadb.jdbc.internal.util.ExceptionMapper.get(ExceptionMapper.java:137)
at org.mariadb.jdbc.internal.util.ExceptionMapper.getException(ExceptionMapper.java:101)
at org.mariadb.jdbc.internal.util.ExceptionMapper.throwException(ExceptionMapper.java:91)
at org.mariadb.jdbc.Driver.connect(Driver.java:109)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
... 102 common frames omitted
Caused by: org.mariadb.jdbc.internal.util.dao.QueryException: Could not connect to address=(host=[CLUSTER_HOST])(port=3306)(type=master) : Connection timed out
at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connectWithoutProxy(AbstractConnectProtocol.java:827)
at org.mariadb.jdbc.internal.util.Utils.retrieveProxy(Utils.java:469)
at org.mariadb.jdbc.Driver.connect(Driver.java:104)
... 106 common frames omitted
Caused by: java.net.ConnectException: Connection timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connect(AbstractConnectProtocol.java:371)
at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connectWithoutProxy(AbstractConnectProtocol.java:823)
... 108 common frames omitted
但为什么不能以这种方式连接数据库呢?