【备忘】在Cloud9上安装psql(客户端)
我希望能够连接到从Cloud9迁移到EC2的postgresql服务器。
我创建了一个PostgreSQL服务器:【初学者】【备忘】在EC2上安装了PostgreSQL 12.3,所以我希望能够通过Cloud9连接到psql客户端。
我被结构困住了。
由于Cloud9也是EC2,所以我以为可以按照创建postgresql服务器的方式来进行操作。然而……出乎意料的是,我AWS环境中的EC2和Cloud9的操作系统版本是不同的。
参考: Amazon Linux 属于哪一类发行版?
- Cloud9のOSバージョン確認
# cat /etc/system-release
Amazon Linux AMI release 2018.03
- EC2のOSバージョン確認
# cat /etc/system-release
Amazon Linux release 2 (Karoo)
使用repo安装
由于Amazon Linux 1似乎是基于RHEL6(Red Hat Enterprise Linux 6),因此可以通过在此处安装repo文件来实现。
https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-x86_64/
pgdg-redhat-repo-latest.noarch.rpm
下载repo文件。
在Cloud9的root用户下进行操作。
$ sudo su -
# wget --no-check-certificate https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-x86_64/pgdg-redhat-repo-latest.noarch.rpm
--2021-10-05 07:15:01-- https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Resolving download.postgresql.org (download.postgresql.org)... 217.196.149.55, 72.32.157.246, 147.75.85.69, ...
Connecting to download.postgresql.org (download.postgresql.org)|217.196.149.55|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6636 (6.5K) [application/x-redhat-package-manager]
Saving to: ‘pgdg-redhat-repo-latest.noarch.rpm’
pgdg-redhat-repo-late 100%[=========================>] 6.48K --.-KB/s in 0s
2021-10-05 07:15:02 (913 MB/s) - ‘pgdg-redhat-repo-latest.noarch.rpm’ saved [6636/6636]
安装repo文件
使用–nodeps选项安装.rpm文件,忽略对/etc/redhat-release文件的依赖关系,该.rpm文件是通过↑下载的。
# rpm -Uvh --nodeps ./pgdg-redhat-repo-latest.noarch.rpm
warning: ./pgdg-redhat-repo-latest.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:pgdg-redhat-repo-42.0-11 ################################# [100%]
当查看repolist时,可以发现该操作系统版本为RHEL/CentOS最新版本的PostgreSQL 12 – x86_64,导致安装失败。
# yum repolist
Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main | 2.1 kB 00:00:00
amzn-updates | 3.8 kB 00:00:00
https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-latest-x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below knowledge base article
https://access.redhat.com/articles/1320623
If above article doesn't help to resolve this issue please open a ticket with Red Hat Support.
https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-latest-x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.
repo id repo name status
amzn-main/latest amzn-main-Base 5,934
amzn-updates/latest amzn-updates-Base 6,428
epel/x86_64 Extra Packages for Enterprise Linux 6 - x86_64 12,581
hashicorp/latest/x86_64 Hashicorp Stable - x86_64 321
pgdg-common/latest/x86_64 PostgreSQL common RPMs for RHEL/CentOS latest - x86_64 326
pgdg10/latest/x86_64 PostgreSQL 10 for RHEL/CentOS latest - x86_64 980
pgdg11/latest/x86_64 PostgreSQL 11 for RHEL/CentOS latest - x86_64 1,080
pgdg12/latest/x86_64 PostgreSQL 12 for RHEL/CentOS latest - x86_64 659
pgdg95/latest/x86_64 PostgreSQL 9.5 for RHEL/CentOS latest - x86_64 0
pgdg96/latest/x86_64 PostgreSQL 9.6 for RHEL/CentOS latest - x86_64 942
repolist: 29,251
仓库编辑
如果继续这样,yum install 就无法成功,所以需要编辑 yum.repos.d 文件。
据说 $releasever 这个变量中会包含 RHEL 或 CentOS 的版本号(比如 7 或 8),但在 EC2 的 Amazon Linux 中,它会包含一个名为 system-release 的字符串,导致 yum install 无法成功。
参考:【CentOS7】如何获取 yum 的 $releasever、$basearch 和 $infra 值。
将其替换为 6 表示指的是 RHEL/CentOS 的版本 6,需要使用适用于 6 版本的二进制文件的路径。
# sed --in-place -e "s/\$releasever/6/g" /etc/yum.repos.d/pgdg-redhat-all.repo
已经升级到版本6。
# yum repolist
Loaded plugins: priorities, update-motd, upgrade-helper
1277 packages excluded due to repository priority protections
repo id repo name status
amzn-main/latest amzn-main-Base 5,934
amzn-updates/latest amzn-updates-Base 6,428
epel/x86_64 Extra Packages for Enterprise Linux 6 - x86_64 11,514+1,067
hashicorp/latest/x86_64 Hashicorp Stable - x86_64 321
pgdg-common/x86_64 PostgreSQL common RPMs for RHEL/CentOS 6 - x86_64 324+2
pgdg10/x86_64 PostgreSQL 10 for RHEL/CentOS 6 - x86_64 980
pgdg11/x86_64 PostgreSQL 11 for RHEL/CentOS 6 - x86_64 1,080
pgdg12/x86_64 PostgreSQL 12 for RHEL/CentOS 6 - x86_64 659
pgdg95/x86_64 PostgreSQL 9.5 for RHEL/CentOS 6 - x86_64 317+88
pgdg96/x86_64 PostgreSQL 9.6 for RHEL/CentOS 6 - x86_64 822+120
repolist: 28,379
yum installでエラーでハマる。
systemdが無いとエラーになるが、RHEL6ベースのAmazon Linux 1ではそりゃ無いよ。
どうも調べたらPostgresql9までしかRHEL6ベースには入らないっぽい
请确认存储库中是否有postgresql客户端版本9。
# yum search postgresql9|grep client
postgresql92.x86_64 : PostgreSQL client programs
: clients
: clients
postgresql93.x86_64 : PostgreSQL client programs
: clients
: clients
postgresql94.x86_64 : PostgreSQL client programs
: clients
: clients
postgresql95.x86_64 : PostgreSQL client programs
: clients
: clients
postgresql95-tcl.x86_64 : A Tcl client library for PostgreSQL
postgresql96.x86_64 : PostgreSQL client programs
: clients
: clients
postgresql96-tcl.x86_64 : A Tcl client library for PostgreSQL
安装最新版的PostgreSQL 9。
# yum install postgresql96.x86_64
Loaded plugins: priorities, update-motd, upgrade-helper
1277 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package postgresql96.x86_64 0:9.6.22-1.85.amzn1 will be installed
--> Processing Dependency: postgresql96-libs(x86-64) = 9.6.22-1.85.amzn1 for package: postgresql96-9.6.22-1.85.amzn1.x86_64
--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql96-9.6.22-1.85.amzn1.x86_64
--> Running transaction check
---> Package postgresql96-libs.x86_64 0:9.6.22-1.85.amzn1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================
Package Arch Version Repository Size
========================================================================================
Installing:
postgresql96 x86_64 9.6.22-1.85.amzn1 amzn-updates 4.3 M
Installing for dependencies:
postgresql96-libs x86_64 9.6.22-1.85.amzn1 amzn-updates 290 k
Transaction Summary
========================================================================================
Install 1 Package (+1 Dependent package)
Total download size: 4.6 M
Installed size: 17 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): postgresql96-libs-9.6.22-1.85.amzn1.x86_64.rpm | 290 kB 00:00:00
(2/2): postgresql96-9.6.22-1.85.amzn1.x86_64.rpm | 4.3 MB 00:00:00
----------------------------------------------------------------------------------------
Total 22 MB/s | 4.6 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 1 pre-existing rpmdb problem(s), 'yum check' output follows:
pgdg-redhat-repo-42.0-11.noarch has missing requires of /etc/redhat-release
Installing : postgresql96-libs-9.6.22-1.85.amzn1.x86_64 1/2
Installing : postgresql96-9.6.22-1.85.amzn1.x86_64 2/2
Verifying : postgresql96-libs-9.6.22-1.85.amzn1.x86_64 1/2
Verifying : postgresql96-9.6.22-1.85.amzn1.x86_64 2/2
Installed:
postgresql96.x86_64 0:9.6.22-1.85.amzn1
Dependency Installed:
postgresql96-libs.x86_64 0:9.6.22-1.85.amzn1
Complete!
- インストール確認
# psql -V
psql (PostgreSQL) 9.6.22