客户端连接
<p>本文主要介绍如何在ECS上安装MongoDB客户端,并通过MongoDB客户端以副本集的方式访问DDS实例。</p>
<p><strong><span style="font-size:18px">前提条件</span></strong></p>
<p>1. 您已成功绑定账号与数据库,可参考<a href="https://pinganyun.com/ssr/help/database/mongodb/Start.Binding_Account" target="_blank">授权账号与数据库权限</a>。</p>
<p>2. 您已成功创建ECS,可参考<a href="https://pinganyun.com/ssr/help/database/mongodb/Start.Create_ECS" target="_blank">创建ECS</a>,且实例处于运行中。</p>
<p>3. 您已成功开通白名单,可参考<a href="https://pinganyun.com/ssr/help/database/mongodb/Start.Create_Whitelist" target="_blank">开通白名单</a>。</p>
<p>4. 为保障鉴权成功,请安装与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. 登录ECS,可参考<a href="https://pinganyun.com/ssr/help/compute/ecs/Quick_Start.Linux_Quick_Start.Login_Instance" target="_blank">登录Linux云主机</a>。</p>
<p>2. 执行以下命令,打开<span style="font-family:Consolas"><em>xxx</em>.repo</span>文件。</p>
<p><img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/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. 在<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>] //您可以根据实际情况自定义名称 </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. 执行以下命令,更新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 && yum makecache</span></p>
</td>
</tr>
</tbody>
</table>
<p>5. 执行以下命令,安装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. 执行以下命令,连接DDS实例。</p>
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="background-color:#f7f8fa">
<p><span style="font-family:Consolas">mongo "mongodb://<<em>Host-name</em>>:<<em>Port</em>>/<<em>Databases-name</em>>?replicaSet=<<em>ReplicaSet-name</em>>" -u<<em>User-name</em>> -p</span></p>
</td>
</tr>
</tbody>
</table>
<p> <img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20192207094537-131c087f99b8.png" style="height:26px; margin:0px; width:65px" />:</p>
<p> <<em>Host-name</em>>:DDS实例的访问域名,可参考<a href="https://pinganyun.com/ssr/help/database/mongodb/Manual.Instance_Management.View_Instance.View_Common_Instance" target="_blank">查看实例基本信息</a>。</p>
<p> <<em>Port</em>>:DDS实例的连接端口,可参考<a href="https://pinganyun.com/ssr/help/database/mongodb/Manual.Instance_Management.View_Instance.View_Common_Instance" target="_blank">查看实例基本信息</a>。</p>
<p> <<em>Databases-name</em>>:连接DDS实例的认证数据库,可参考<a href="https://pinganyun.com/ssr/help/database/mongodb/Manual.Account.Create_Account" target="_blank">创建账号</a>。</p>
<p> <<em>ReplicaSet-name</em>>:DDS副本集的名称,可参考<a href="http://pinganyun.com/ssr/help/database/mongodb/Manual.Instance_Management.View_Instance.View_Common_Instance" target="_blank">查看实例基本信息</a>。</p>
<p> <<em>User-name</em>>:连接DDS实例的账号名称,可参考<a href="http://pinganyun.com/ssr/help/database/mongodb/Manual.Account.Create_Account" target="_blank">创建账号</a>。</p>
<p>7. 输入创建账号时设置的密码。</p>
<p><span style="font-size:18px"><strong>执行结果</strong></span></p>
<p>成功连接DDS实例,且连接到的默认是主节点(Primary Node)。 </p>
提交成功!非常感谢您的反馈,我们会继续努力做到更好!