#はじめに
最近AWSについて勉強中で、EC2環境にDjangoアプリをデプロイしようと思っているので、備忘で記載します。
今回はPostgresインストール。
#PostgreSQLのインストール
###1. 環境について
・プライベートサブネット内のEC2インスタンス
・AmazonLinux2
・PostgreSQL13(今回入れるやつ)
すごい端折ってるけど、大体こんな感じ。なんでS3書いたんだろう笑
###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
完了🙌
結構手こずった。