dds实例连接失败怎么办-凯发k8国际娱乐官网入口
问题分析
主要从九个方面考虑:
- 排除数据库实例异常
例如:dds系统故障,实例状态异常,实例或表被锁定。
- (常见)使用正确的客户端连接方式
- 数据库安装包须从k8凯发官网下载并正确安装,请参见如何安装mongodb客户端。
- 建议使用4.0版本以上的mongodb客户端连接实例。
- 内网连接需要dds与ecs实例必须在同一区域、vpc内。
- 公网连接需要购买或使用已有eip,并对dds实例绑定该eip 。
- 使用正确的ssl方式安全连接
界面ssl开关开启和关闭,分别对应不用的连接命令。例如:
- 开关开启:./mongo --host<db_host>--port<db_port>-u<db_user>-p--authenticationdatabaseadmin--ssl --sslcafile<file_path> --sslallowinvalidhostnames
- 开关关闭:./mongo --host<db_host>--port<db_port>-u<db_user>-p --authenticationdatabase admin
- 排除连接命令错误
例如:连接地址错误、端口参数配置错误、用户名和密码错误、ssl方式下命令错误。
- (常见)排除网络不通
内网访问
- 确认ecs与dds是否在同一个区域、同一个vpc。
ecs与dds在不同vpc的场景,可以通过建立实现网络互通。
- 检查安全组规则。
- 安全组外访问安全组内的dds集群实例时,需要为安全组。
- 在ecs上测试是否可以正常连接到dds实例地址的端口。
公网访问
- 检查安全组规则。
- 安全组外访问安全组内的dds集群实例时,需要为安全组。
- 检查网络acl规则。
- 相同区域主机进行ping测试。
跨网段访问(配置ip映射)
通过内网连接副本集实例时,当客户端和副本集实例部署在不同网段时,且客户端所在的网段不在“192.168.0.0/16”,“172.16.0.0/24”和“10.0.0.0/8”时,需要进行跨网段访问配置,以实现网络互通。
- 确保在源端ecs网络与实例节点网络连通,如果网络不通,可以参考进行相关配置。
- 跨网段访问的操作请详见。
- 确认ecs与dds是否在同一个区域、同一个vpc。
- (常见)排除实例的连接数满的情况
实例连接数过多,可能会导致业务侧无法正常连接。
- (常见)排除磁盘满的情况
实例磁盘使用率过高会导致实例状态异常,无法正常连接实例。
- 排除cpu使用率飙升问题
cpu使用率很高或接近100%,会导致数据读写处理缓慢、无法获取连接、出现报错等,从而影响业务正常运行。
- 连接失败的常见报错
包含连接失败的常见报错,以及相应的解决方法。
排查思路
- 排除数据库实例异常
检查办法:请在控制台检查数据库实例状态是否为“正常”。
可能原因:dds系统故障,实例状态异常,实例或表被锁定等。
解决方法
- dds实例状态异常请及时联系运维人员协助处理。
- 系统故障、实例或表被锁定等,请尝试重启功能,详细操作请参考。
图1 查看实例状态
- 使用正确的客户端连接方式
建议使用4.0版本以上的mongodb客户端连接实例,安装客户端操作请参见如何安装mongodb客户端。
以集群为例:
- 内网连接实例的具体操作步骤,请参见通过内网连接集群实例。
- 公网连接实例的具体操作步骤,请参见通过公网连接集群实例。
表1 客户端连接方式 连接方式
使用场景
内网方式
系统默认提供内网ip地址。
当应用部署在ecs上,且该ecs与dds实例处于同一区域,同一vpc时,建议单独使用内网ip连接ecs与dds实例。
公网方式
不能通过内网ip地址访问dds实例时,使用公网访问,建议单独绑定弹性公网ip连接ecs(或公网主机)与dds实例。
用户需要购买弹性公网ip,请参见。
- 使用正确的ssl方式安全连接
- (推荐)ssl方式:实例连接管理页面的ssl开关开启,并且上传证书到ecs。
./mongo --host<db_host>--port<db_port>-u<db_user>-p--authenticationdatabaseadmin--ssl --sslcafile<file_path> --sslallowinvalidhostnames图2 ssl开启
- 普通方式:实例连接管理页面的ssl开关关闭。
./mongo --host<db_host>--port<db_port>-u<db_user>-p --authenticationdatabase admin
图3 ssl关闭
- (推荐)ssl方式:实例连接管理页面的ssl开关开启,并且上传证书到ecs。
- 排除连接命令错误
请获取正确的连接地址、端口参数配置、用户名和密码、ssl方式下命令,并重试连接实例。
ssl内网连接集群示例:./mongo mongodb://rwuser:
@<db_host>:<db_port>,<db_host>:<db_port>/test?authsource=admin --ssl --sslcafile <file_path> --sslallowinvalidhostnames - 连接地址
连接信息可在“实例管理”页的“连接地址”列获取。
图4 连接地址
- 数据库端口
目标实例的“连接管理”页面,“内网连接”页签的“数据库端口”。
- 用户名和密码
root管理员账号及其对应的密码,如若密码不正确或者忘记了密码,可通过来修改密码。
- 证书名称
ssl证书文件名,该文件需放在执行该命令的路径下。
ssl公网连接集群示例:./mongo mongodb://rwuser:
@<db_host>:<db_port>/test?authsource=admin --ssl --sslcafile <file_path> --sslallowinvalidhostnames - 连接地址
单击实例名称,在实例“连接管理”页面“公网连接”页签的公网连接地址处获取。
- 数据库端口
目标实例的“连接管理”页面,“公网连接”页签的“数据库端口”。
- 用户名和密码
root管理员账号及其对应的密码,如若密码不正确或者忘记了密码,可通过来修改密码。
- 证书名称
ssl证书文件名,该文件需放在执行该命令的路径下。
- 连接地址
- 排除网络不通
内网访问
- 检查ecs与dds是否在同一个区域、同一个vpc。
- 不同区域的云服务之间内网互不相通,无法访问实例。请就近选择靠近您业务的区域,可减少网络时延,提高访问速度。
- 不同vpc下,可以通过建立实现网络互通。
- 检查安全组规则。
安全组外访问安全组内的dds实例时,需要为安全组。
- 在ecs上测试是否可以正常连接到dds实例地址的端口。
telnet <实例地址> {8635}
- 可以通信,说明网络是正常的。
- 无法通信,请联系华为云客服协助解决。
公网访问
- 检查安全组规则。
安全组外访问安全组内的dds实例时,需要为安全组。
- 检查网络acl规则。
- 进入虚拟私有云列表。
- 检查eip绑定的网卡是否在网络acl关联的子网下。
- 查看网络acl当前是“开启”状态还是“关闭”状态。
若网络acl为“开启”状态,需要。
注意:网络acl的默认规则是丢弃所有出入方向的包,关闭“网络acl”后,其默认规则仍然生效。
- 相同区域主机进行ping测试。
如果在原ecs上没有ping通dds实例绑定的eip,请在相同区域的另一台ecs上去ping该eip,如果可以正常ping通,说明虚拟网络正常,请联系华为云客服协助解决。
跨网段访问(配置ip映射)
通过内网连接副本集实例时,当客户端和副本集实例部署在不同网段时,且客户端所在的网段不在“192.168.0.0/16”,“172.16.0.0/24”和“10.0.0.0/8”时,需要进行跨网段访问配置,以实现网络互通。
- 确保在源端ecs网络与实例节点网络连通,如果网络不通,可以参考进行相关配置。
- 跨网段访问的操作请详见。
- 检查ecs与dds是否在同一个区域、同一个vpc。
- 排除实例的连接数满的情况
- 查看实例的连接数是否已达上限,请参见如何查询及限制连接数。
若实例连接数已满请参见实例的连接数满怎么处理。
- 云监控服务目前可以监控数据库cpu、内存、磁盘、连接数等指标,并且设置告警策略,出现告警时可以提前识别风险。
- 查看实例的连接数是否已达上限,请参见如何查询及限制连接数。
- 排除磁盘满的情况
检查方法:磁盘空间使用率可通过管理控制台或云监控服务查看。
- 通过管理控制台查看
选择目标实例,单击实例名称,进入“基本信息”页面。在“存储空间”模块,查看磁盘使用率。
图5 存储空间
- 通过云监控服务查看
选择目标实例,单击“查看监控指标”,跳转到云监控页面,查看目标实例的磁盘使用量指标。
可能原因:当实例处于“磁盘空间满”状态时,需扩容至磁盘空间使用率小于80%才可使实例处于可用状态,使数据库恢复正常的写入操作。
凯发k8国际娱乐官网入口的解决方案:
- 随着业务数据的增加,原来申请的数据库磁盘容量可能会不足,建议用户扩容磁盘空间,确保磁盘空间足够。具体操作请参见扩容磁盘。
- 请及时处理过期数据文件。
- 云监控服务目前可以监控数据库cpu、内存、磁盘、连接数等指标,并且设置告警策略,出现告警时可以提前识别风险。
- 通过管理控制台查看
- 排除cpu使用率过高的情况
cpu使用率很高或接近100%,会导致数据读写处理缓慢、无法获取连接、出现报错等,从而影响业务正常运行。
凯发k8国际娱乐官网入口的解决方案:请参见如何排查dds实例cpu使用率高的问题。
- 连接失败的常见报错
- 连接失败,提示:network error while attempting to run command ‘ismaster’
使用如下命令连接dds实例时报错。
./mongo --host 192.168.168.182 --port 8635 -u rwuser -p xxxxxxxxxx --authenticationdatabase admin
图6 连接失败
具体处理方法请参见连接失败,提示:network error while attempting to run command ‘ismaster’。
- 连接失败,提示:no route to host以及connection attempt failed
使用如下命令连接dds实例时报错。
mongo --host 192.168.1.6 --port 8635 -u rwuser -p xxxxxxxxx --authenticationdatabase admin --ssl --sslcafile /root/ca.crt --sslallowinvalidhostnames
报错信息如下:
mongodb shell version v3.4.17 connecting to: mongodb://192.168.1.6:8635/ 2019-09-19t09:38:36.954 0800 w network [thread1] failed to connect to 192.168.1.6:8635, in(checking socket for error after poll), reason: no route to host 2019-09-19t09:38:36.954 0800 e query [thread1] error: couldn't connect to server 192.168.1.6:8635, connection attempt failed : connect@src/mongo/shell/mongo.js:240:13 @(connect):1:6 exception: connect failed
具体处理方法请参见连接失败,提示:no route to host以及connection attempt failed。
- 连接失败,提示:no route to host以及connection attempt failed
使用如下命令连接dds实例时报错。
mongo --host 192.168.168.116 --port 8635 -u rwuser -p xxxxxxxxx --authenticationdatabase admin --ssl --sslcafile /root/ca.crt --sslallowinvalidhostnames
报错信息如下:
mongodb shell version v3.4.17 connecting to: mongodb://192.168.168.116:8635/ 2019-09-19t09:39:24.306 0800 w network [thread1] the server certificate does not match the host name. hostname: 192.168.168.116 does not match cn: 172.16.2.65 mongodb server version: 4.0.3 warning: shell and server versions do not match 2019-09-19t09:39:24.329 0800 e query [thread1] error: authentication failed. : db.prototype._authorthrow@src/mongo/shell/db.js:1461:20 @(auth):6:1 @(auth):1:2 exception: login failed
具体处理方法请参见连接失败,提示:no route to host以及connection attempt failed。
- 连接失败,提示:couldn’t connect to server
使用如下命令连接dds实例时报错。
mongo --host 192.168.64.201 --port 8635 -u rwuser -p xxxxxxxxx --authenticationdatabase admin --ssl --sslcafile /root/ca.crt --sslallowinvalidhostnames
报错信息如下:
mongodb shell version v3.4.17 connecting to: mongodb://192.168.64.201:8635/ 2019-09-19t09:45:48.168 0800 w network [thread1] failed to connect to 192.168.64.201:8635 after 5000ms milliseconds, giving up. 2019-09-19t09:45:48.168 0800 e query [thread1] error: couldn't connect to server 192.168.64.201:8635, connection attempt failed : connect@src/mongo/shell/mongo.js:240:13 @(connect):1:6 exception: connect failed
具体处理方法请参见连接失败,提示:couldn’t connect to server。
- 连接失败,提示:cannot list multiple servers in url without ‘replicaset’ option
使用如下命令连接dds副本集实例时报错。
./mongo mongodb://rwuser:xxxxxxxxxxx@192.168.168.116:8635,192.168.200.147:8635/test?authsource=admin&replicaset=replica
报错信息如下:
failedtoparse: cannot list multiple servers in url without 'replicaset' option try 'mongo --help' for more information.
使用如下命令连接兼容mongodb 3.4版本的dds实例时报错。
mongo "mongodb://rwuser:xxxxxxxxx@192.168.95.167:8635,192.168.92.43:8635/test?authsource=admin"
报错信息如下:
failedtoparse: cannot list multiple servers in url without 'replicaset' option try 'mongo --help' for more information.
具体处理方法请参见。
- java驱动连接实例失败,提示:timeout while receiving message
使用java驱动连接dds实例时报错。
报错信息如下:
org.springframework.data.mongodb.uncategorizedmongodbexception: timeout while receiving message; nested exception is com.mongodb.mongosocketreadtimeoutexception: timeout while receiving message
具体处理方法请参见。
- 连接失败,提示:exception: login failed 以及 u_stringprep_prohibited_error
使用如下命令连接dds实例时报错。
./mongo "mongodb://rwuser:xxxxxx@192.168.0.45:8635,192.168.0.96:8635/test?authsource=admin&replicaset=replica"
报错信息如下:
mongodb shell version v4.0.3 connecting to: mongodb://192.168.0.45:8635,192.168.0.96:8635/test?authsource=admin&replicaset=replica 2021-11-05t05:52:53.717 0000 i network [js] starting new replica set monitor for replica/192.168.0.45:8635,192.168.0.96:8635 2021-11-05t05:52:53.718 0000 i network [replicasetmonitor-taskexecutor] successfully connected to 192.168.0.45:8635 (1 connections now open to 192.168.0.45:8635 with a 5 second timeout) 2021-11-05t05:52:53.718 0000 i network [js] successfully connected to 192.168.0.96:8635 (1 connections now open to 192.168.0.96:8635 with a 5 second timeout) implicit session: session { "id" : uuid("5945d2a5-8275-4e3c-b06f-632f062a2ead") } mongodb server version: 4.0.3 2021-11-05t05:52:53.722 0000 i network [js] marking host 192.168.0.96:8635 as failed :: caused by :: location50692: can't authenticate against replica set node 192.168.0.96:8635 :: caused by :: error preflighting normalization: u_stringprep_prohibited_error 2021-11-05t05:52:53.722 0000 i network [js] successfully connected to 192.168.0.45:8635 (1 connections now open to 192.168.0.45:8635 with a 0 second timeout) 2021-11-05t05:52:53.723 0000 i network [js] marking host 192.168.0.45:8635 as failed :: caused by :: location50692: can't authenticate against replica set node 192.168.0.45:8635 :: caused by :: error preflighting normalization: u_stringprep_prohibited_error 2021-11-05t05:52:53.724 0000 i network [js] marking host 192.168.0.96:8635 as failed :: caused by :: location50692: can't authenticate against replica set node 192.168.0.96:8635 :: caused by :: error preflighting normalization: u_stringprep_prohibited_error 2021-11-05t05:52:53.725 0000 i network [js] marking host 192.168.0.45:8635 as failed :: caused by :: location50692: can't authenticate against replica set node 192.168.0.45:8635 :: caused by :: error preflighting normalization: u_stringprep_prohibited_error 2021-11-05t05:52:53.725 0000 e query [js] error: can't authenticate against replica set node 192.168.0.45:8635 :: caused by :: error preflighting normalization: u_stringprep_prohibited_error : db.prototype._authorthrow@src/mongo/shell/db.js:1685:20 @(auth):6:1 @(auth):1:2 exception: login failed
具体处理方法请参见连接失败,提示:exception: login failed 以及 u_stringprep_prohibited_error。
- 连接失败,提示:network error while attempting to run command ‘ismaster’
- 如果上述方法均不能解决您的疑问,请联系华为云客服为您解答。
意见反馈
文档内容是否对您有帮助?
如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨
more