Linux系统连接

<p>本文主要介绍如何在Linux操作系统的ECS上安装PostgreSQL客户端,并通过PostgreSQL客户端访问RDS-PostgreSQL实例。</p> <p><span style="font-size:18px"><strong>前提条件</strong></span></p> <ol> <li>您已成功创建RDS-PostgreSQL实例,可参考<a href="https://pinganyun.com/ssr/help/database/RDS/Getting_Started.RDS_PostgreSQL.Create_RDS_PostgreSQL" target="_blank">创建RDS-PostgreSQL实例</a>。</li> <li>您已成功创建ECS,可参考<a href="https://pinganyun.com/ssr/help/database/RDS/Getting_Started.RDS_PostgreSQL.Create_ECS" target="_blank">创建ECS</a>,且实例处于运行中。</li> <li>您已成功开通白名单,可参考<a href="https://pinganyun.com/ssr/help/database/RDS/Getting_Started.RDS_PostgreSQL.Create_Whitelist" target="_blank">开通白名单</a>。</li> </ol> <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://pinganyun.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://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20191507142058-1696070097f8.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; vertical-align:top"> <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"> <tbody> <tr> <td style="background-color:#f7f8fa; vertical-align:top"> <p>[<em>postgresql</em>] &nbsp; //您可以根据实际情况自定义名称</p> <p><span style="font-family:Consolas">name=postgresql11-rhel-7-x86_64</span></p> <p><span style="font-family:Consolas">baseurl=<a href="http://yum.cloud.papub/postgresql/repos/yum/11/redhat/rhel-7-x86_64/">http://yum.cloud.papub/postgresql/repos/yum/11/redhat/rhel-7-x86_64/</a></span></p> <p><span style="font-family:Consolas">enabled=1&nbsp;</span></p> <p><span style="font-family:Consolas">gpgcheck=0</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; vertical-align:top"> <p><span style="font-family:Consolas">yum clean all &amp;&amp; yum makecache</span></p> </td> </tr> </tbody> </table> <p>5.&nbsp; 执行以下命令,屏蔽默认的PostgreSQL软件。</p> <table border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td style="background-color:#f7f8fa; vertical-align:top"> <p><span style="font-family:Consolas">yum -qy module disable postgresql</span></p> </td> </tr> </tbody> </table> <p>6.&nbsp; 执行以下命令,安装PostgreSQL客户端。</p> <table border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td style="background-color:#f7f8fa; vertical-align:top"> <p><span style="font-family:Consolas">yum install postgresql11</span></p> </td> </tr> </tbody> </table> <p>7.&nbsp; 执行以下命令,并输入密码,连接RDS-PostgreSQL实例。</p> <table border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td style="background-color:#f7f8fa; vertical-align:top"> <p>psql -h <em>Domain-name</em> -p <em>Port</em> -U <em>Postgresql_Account</em> -d postgres -W</p> </td> </tr> </tbody> </table> <p><img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20191507142058-1696070097f8.png" style="height:26px; margin:0px; width:65px" />:</p> <ul> <li>-h <em>Domain-Name</em>:RDS-PostgreSQL实例的<strong>访问域名</strong>,可参考<a href="https://pinganyun.com/ssr/help/database/RDS/User_Guide_RDS_PostgreSQL.Instance_Management.View_Instance.View_Common_Instance" target="_blank">查看实例基本信息</a>。</li> <li>-p<em> Port</em>:RDS-PostgreSQL实例的<strong>连接端口</strong>,可参考<a href="https://pinganyun.com/ssr/help/database/RDS/User_Guide_RDS_PostgreSQL.Instance_Management.View_Instance.View_Common_Instance">查看实例基本信息</a>。</li> <li>-U <em>Postgresql _Account</em>:创建的管理员名称,可参考<a href="https://pinganyun.com/ssr/help/database/RDS/User_Guide_RDS_PostgreSQL.Instance_Management.Create_Instance.Create_Common_Instance" target="_blank">创建常规实例</a>。</li> <li>-d postgres:需要连接的数据库名称,默认为postgres数据库。</li> <li>-W:强制输入密码,执行上述命令后,根据提示信息输入创建用户时设置的密码,可参考<a href="https://pinganyun.com/ssr/help/database/RDS/User_Guide_RDS_PostgreSQL.Instance_Management.Create_Instance.Create_Common_Instance">创建常规实例</a>。</li> </ul> <p><span style="font-size:18px"><strong>执行结果</strong></span></p> <p>成功连接RDS-PostgreSQL实例。&nbsp;&nbsp;</p> <p><img src="https://pcp-portal-sca.obs-cn-shenzhen.pinganyun.com/pcp-portal-sca/20191507142406-162c0ff29369.png" style="height:94px; width:644px" /></p>
以上内容是否解决了您的问题?
请补全提交信息!
咨询·建议

电话咨询

400-151-8800

邮件咨询

cloud@pingan.com

在线客服

工单支持

解决云产品相关技术问题