客户端连接

<p>本文主要介绍如何在ECS上安装MongoDB客户端,并通过MongoDB客户端以副本集的方式访问DDS实例。</p> <p><strong><span style="font-size:18px">前提条件</span></strong></p> <p>1.&nbsp; 您已成功绑定账号与数据库,可参考<a href="https://pinganyun.com/ssr/help/database/mongodb/Start.Binding_Account" target="_blank">授权账号与数据库权限</a>。</p> <p>2.&nbsp; 您已成功创建ECS,可参考<a href="https://pinganyun.com/ssr/help/database/mongodb/Start.Create_ECS" target="_blank">创建ECS</a>,且实例处于运行中。</p> <p>3.&nbsp; 您已成功开通白名单,可参考<a href="https://pinganyun.com/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><strong><span style="font-size:18px">操作步骤</span></strong></p> <p>1.&nbsp; 登录ECS,可参考<a href="https://pinganyun.com/ssr/help/compute/ecs/Quick_Start.Linux_Quick_Start.Login_Instance" target="_blank">登录Linux云主机</a>。</p> <p>2.&nbsp; 执行以下命令,打开<span style="font-family:Consolas"><em>xxx</em>.repo</span>文件。</p> <p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20192207094537-131c087f99b8.png" style="height:26px; margin:0px; width:65px" />:<em>xxx</em>:文件名称,您可以根据实际情况自定义。</p> <table border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td style="background-color:#f7f8fa"> <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; 在<span style="font-family:Consolas"><em>xxx</em>.repo</span>文件中增加以下内容。</p> <table border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td style="background-color:#f7f8fa"> <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"> <tbody> <tr> <td style="background-color:#f7f8fa"> <p><span style="font-family:Consolas">yum clean all &amp;&amp; yum makecache</span></p> </td> </tr> </tbody> </table> <p>5.&nbsp; 执行以下命令,安装MongoDB客户端。</p> <table border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td style="background-color:#f7f8fa"> <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"> <tbody> <tr> <td style="background-color:#f7f8fa"> <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>&nbsp; &nbsp;&nbsp;<img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20192207094537-131c087f99b8.png" style="height:26px; margin:0px; width:65px" />:</p> <p>&nbsp; &nbsp; &lt;<em>Host-name</em>&gt;:DDS实例的访问域名,可参考<a href="https://pinganyun.com/ssr/help/database/mongodb/Manual.Instance_Management.View_Instance.View_Common_Instance" target="_blank">查看实例基本信息</a>。</p> <p>&nbsp; &nbsp; &lt;<em>Port</em>&gt;:DDS实例的连接端口,可参考<a href="https://pinganyun.com/ssr/help/database/mongodb/Manual.Instance_Management.View_Instance.View_Common_Instance" target="_blank">查看实例基本信息</a>。</p> <p>&nbsp; &nbsp; &lt;<em>Databases-name</em>&gt;:连接DDS实例的认证数据库,可参考<a href="https://pinganyun.com/ssr/help/database/mongodb/Manual.Account.Create_Account" target="_blank">创建账号</a>。</p> <p>&nbsp; &nbsp; &lt;<em>ReplicaSet-name</em>&gt;:DDS副本集的名称,可参考<a href="http://pinganyun.com/ssr/help/database/mongodb/Manual.Instance_Management.View_Instance.View_Common_Instance" target="_blank">查看实例基本信息</a>。</p> <p>&nbsp; &nbsp; &lt;<em>User-name</em>&gt;:连接DDS实例的账号名称,可参考<a href="http://pinganyun.com/ssr/help/database/mongodb/Manual.Account.Create_Account" target="_blank">创建账号</a>。</p> <p>7.&nbsp; 输入创建账号时设置的密码。</p> <p><span style="font-size:18px"><strong>执行结果</strong></span></p> <p>成功连接DDS实例,且连接到的默认是主节点(Primary Node)。&nbsp;&nbsp;</p>
以上内容是否解决了您的问题?
请补全提交信息!
咨询·建议

电话咨询 - 7x24 小时

400-151-8800

邮件咨询

cloud@pingan.com

在线客服

7x24 小时,急速解答

工单支持

解决云产品相关技术问题