客户端连接

<p>本文主要介绍如何在ECS上安装MongoDB客户端,并通过MongoDB客户端以副本集的方式访问DDS实例。</p> <p><span style="font-size:18px"><strong>前提条件</strong></span></p> <p>1.&nbsp; 您已成功绑定账号与数据库,可参考<a href="/ssr/help/database/mongodb/Start.Binding_Account" target="_blank">授权账号与数据库权限</a>。</p> <p>2.&nbsp; 您已成功创建ECS,可参考<a href="/ssr/help/database/mongodb/Start.Create_ECS" target="_blank">创建ECS</a>,且实例处于运行中。</p> <p>3.&nbsp; 您已成功开通白名单,可参考<a href="/ssr/help/database/mongodb/Start.Create_Whitelist" target="_blank">开通白名单</a>。</p> <p>4.&nbsp;&nbsp;为保障鉴权成功,请安装与DDS实例版本相对应的Mongo Shell版本。</p> <p><span style="font-size:18px"><strong>注意事项</strong></span></p> <p>ECS的操作系统请选择CentOS 7.x、RedHat Linux 7.x、Oracle Linux 7.x及以上的版本。</p> <p><span style="font-size:18px"><strong>操作步骤</strong></span></p> <p>1.&nbsp; 登录ECS,可参考<a href="https://www.ocftcloud.com/ssr/help/compute/ecs/Quick_Start.Linux_Quick_Start.Login_Instance" target="_blank">登录Linux云主机</a>。</p> <p>2.&nbsp; 执行以下命令,打开<em>xxx</em>.repo文件。</p> <p><img src="https://obs-cn-shanghai.ocftcloud.com/pacloud/20192008112329-1295043998c6.png" style="height:26px; margin:0px; width:65px" />:<em>xxx</em>:文件名称,您可以根据实际情况自定义。</p> <table border="0" cellpadding="0" cellspacing="0" style="width:772px"> <tbody> <tr> <td style="background-color:#f7f8fa; vertical-align:top; width:768px"> <p><span style="font-family:Consolas">cd /etc/yum.repos.d</span></p> <p><span style="font-family:Consolas">vim xxx.repo</span></p> </td> </tr> </tbody> </table> <p>3.&nbsp;&nbsp;在<em>xxx</em>.repo文件中增加以下内容。</p> <table border="0" cellpadding="0" cellspacing="0" style="width:771px"> <tbody> <tr> <td style="background-color:#f7f8fa; vertical-align:top; width:767px"> <p>[<em>dds</em>] &nbsp; //您可以根据实际情况自定义名称 &nbsp;</p> <p><span style="font-family:Consolas">name=MongoDB Repository</span></p> <p><span style="font-family:Consolas">baseurl=http://yum.cloud.papub/mongodb/yum/el7-3.4/</span></p> <p><span style="font-family:Consolas">gpgcheck=0</span></p> <p><span style="font-family:Consolas">enabled=1</span></p> </td> </tr> </tbody> </table> <p>4.&nbsp;&nbsp;执行以下命令,更新yum源。</p> <table border="0" cellpadding="0" cellspacing="0" style="width:773px"> <tbody> <tr> <td style="background-color:#f7f8fa; vertical-align:top; width:769px"> <p><span style="font-family:Consolas">yum clean all &amp;&amp; yum makecache</span></p> </td> </tr> </tbody> </table> <p>5.&nbsp;&nbsp;执行以下命令,安装MongoDB客户端。</p> <table border="0" cellpadding="0" cellspacing="0" style="width:773px"> <tbody> <tr> <td style="background-color:#f7f8fa; vertical-align:top; width:769px"> <p><span style="font-family:Consolas">yum install mongodb-org-shell</span></p> </td> </tr> </tbody> </table> <p>6.&nbsp; 执行以下命令,连接DDS实例。</p> <table border="0" cellpadding="0" cellspacing="0" style="width:774px"> <tbody> <tr> <td style="background-color:#f7f8fa; vertical-align:top; width:770px"> <p><span style="font-family:Consolas">mongo &quot;mongodb://&lt;<em>Host-name</em>&gt;:&lt;<em>Port</em>&gt;/&lt;<em>Databases-name</em>&gt;?replicaSet=&lt;<em>ReplicaSet-name</em>&gt;&quot; -u&lt;<em>User-name</em>&gt; -p</span></p> </td> </tr> </tbody> </table> <p><img src="https://obs-cn-shanghai.ocftcloud.com/pacloud/20192008112329-1295043998c6.png" style="height:26px; margin:0px; width:65px" />:</p> <ul> <li>&lt;<em>Host-name</em>&gt;:DDS实例的访问域名,可参考<a href="/ssr/help/database/mongodb/Manual.Instance_Management.View_Instance.View_Common_Instance" target="_blank">查看实例基本信息</a>。</li> <li>&lt;<em>Port</em>&gt;:DDS实例的连接端口,可参考<a href="/ssr/help/database/mongodb/Manual.Instance_Management.View_Instance.View_Common_Instance" target="_blank">查看实例基本信息</a>。</li> <li>&lt;<em>Databases-name</em>&gt;:连接DDS实例的认证数据库,可参考<a href="/ssr/help/database/mongodb/Manual.Account.Create_Account" target="_blank">创建账号</a>。</li> <li>&lt;<em>ReplicaSet-name</em>&gt;:DDS副本集的名称,可参考<a href="/ssr/help/database/mongodb/Manual.Instance_Management.View_Instance.View_Common_Instance" target="_blank">查看实例基本信息</a>。</li> <li>&lt;<em>User-name</em>&gt;:连接DDS实例的账号名称,可参考<a href="/ssr/help/database/mongodb/Manual.Account.Create_Account" target="_blank">创建账号</a>。</li> </ul> <p>7.&nbsp; 输入创建账号时设置的密码。</p> <p><span style="font-size:18px"><strong>执行结果</strong></span></p> <p>成功连接DDS实例,且连接到的默认是主节点(Primary Node)。&nbsp; &nbsp;</p>
以上内容是否解决了您的问题?
请补全提交信息!
联系我们

电话咨询

400-151-8800

邮件咨询

fincloud@ocft.com

在线客服

工单支持

解决云产品相关技术问题