在私有子网中的EC2实例上安装PostgreSQL作为备忘录

首先

最近我在学习关于AWS,打算在EC2环境中部署Django应用程序,所以在这里做个备忘录。这次是关于安装Postgres。

安装PostgreSQL

对于环境问题来说

・位于私有子网的EC2实例
・AmazonLinux2
・PostgreSQL13(安装此版本)

スクリーンショット 2022-02-01 21.44.00.png

2. 安装 PostgreSQL

参考 PostgreSQL 官方类似组织的网站,
像往常一样使用 yum 进行安装。

噢~輕而易舉。一邊這麼想著,首先檢查一下所需的包裝。

$ yum search postgresql
読み込んだプラグイン:extras_suggestions, langpacks, priorities, update-motd
Could not retrieve mirrorlist https://amazonlinux-2-repos-us-east-2.s3.dualstack.us-east-2.amazonaws.com/2/core/latest/x86_64/mirror.list error was
12: Timeout on https://amazonlinux-2-repos-us-east-2.s3.dualstack.us-east-2.amazonaws.com/2/core/latest/x86_64/mirror.list: (28, 'Failed to connect to amazonlinux-2-repos-us-east-2.s3.dualstack.us-east-2.amazonaws.com port 443 after 2701 ms: Connection timed out')


 One of the configured repositories failed (不明),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=<repoid> ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>
        or
            subscription-manager repos --disable=<repoid>

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: amzn2-core/2/x86_64

你遇到错误了吗!
而且,由于是私有子网,所以无法连接外部。

将公共子网中的服务器设置为代理服务器,通过代理进行yum安装似乎可行呢。
然而,在搜索了一下后,发现还有更好的方法呢。

在私有子网内使用yum命令。

根据AWS上的文章所说,在AmazonLinux上,yum仓库存储在S3上,通过设置VPC终端节点,可以在私有子网中直接进行通信。

按照上述的文章,完成设置后,使用yum命令成功了。

默认的PostgreSQL版本是9.x吗?

终于可以安装了!当我打算安装PostgreSQL时,检查版本时发现它是9.2.24。

$ yum info postgresql-server
読み込んだプラグイン:extras_suggestions, langpacks, priorities, update-motd
利用可能なパッケージ
名前                : postgresql-server
アーキテクチャー    : x86_64
バージョン          : 9.2.24
リリース            : 6.amzn2
容量                : 3.8 M
リポジトリー        : amzn2-core/2/x86_64
要約                : The programs needed to create and run a PostgreSQL server
URL                 : http://www.postgresql.org/
ライセンス          : PostgreSQL
説明                : PostgreSQL is an advanced Object-Relational database
                    : management system (DBMS). The postgresql-server package
                    : contains the programs needed to create and run a
                    : PostgreSQL server, which will in turn allow you to create
                    : and maintain PostgreSQL databases.

哦~ PostgreSQL13很不错啊!有一种直觉!
查了一下,发现amazon-linux-extras上有13版本。

$ sudo amazon-linux-extras 

       ~省略~
 41  postgresql11             available    [ =11  =stable ]
    ~省略~
 58  postgresql12             available    [ =stable ]
 59  postgresql13             available    [ =stable ]

所以,就这样准备。

$ sudo amazon-linux-extras install postgresql13
$ yum info postgresql-server
読み込んだプラグイン:extras_suggestions, langpacks, priorities, update-motd
利用可能なパッケージ
名前                : postgresql-server
アーキテクチャー    : x86_64
バージョン          : 13.3
リリース            : 2.amzn2.0.1
容量                : 5.4 M
リポジトリー        : amzn2extra-postgresql13/2/x86_64
要約                : The programs needed to create and run a PostgreSQL server
URL                 : http://www.postgresql.org/
ライセンス          : PostgreSQL
説明                : PostgreSQL is an advanced Object-Relational database
                    : management system (DBMS). The postgresql-server package
                    : contains the programs needed to create and run a
                    : PostgreSQL server, which will in turn allow you to create
                    : and maintain PostgreSQL databases.

满心期待地安装了PostgreSQL。

$ sudo yum install postgresql-server

完成了?

结构让我费了不少劲。

广告
将在 10 秒后关闭
bannerAds