0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AWSのEC2(RHEL9)に Postgres を立て、Apache NiFiで接続

Posted at

この記事について

インフラが超苦手なエンジニアが、AWSのEC2に Postgres を立て、そのあとに Apache NiFi (をラップした Cloudera の製品である Cloudera Data Flow)でクエリかけられるようにするまでの全手順をメモしたものです。

Postgres をたてる手順は詳細にメモしていますが、Apache NiFi の部分はかなり端折っています。

手順

EC2をたてる

  • パブリックアクセスが可能なVPCの中で
  • t2.medium
  • RHEL9
  • SGの設定で、自分のPCからのSSH(ポート20)と5432を開放しておく

Postgresをインストール

こちらの手順を実施。(ルートで)

テストデータを入れる

こちらの手順を実行
※途中で unzip コマンドを実行するが、デフォでは入っていなかったのでまず yum install unzip をやってから⏬を実施

通信を通す

こちらの手順を実施。

👆のとおりだが、初心者(のわたし)向けにもう少し詳しいメモを残します。

postgresql.conf の編集

Vimで /var/lib/pgsql/data/postgresql.conf を開く

vi /var/lib/pgsql/data/postgresql.conf

/listenで検索して、listen_address と port を以下のように編集しコメントを外す

image.png

※本来は listen_address はもう少し粒度細かく設定すべきだろうけども、今回は検証目的なので全開放。

pg_hba.conf の編集

pg_hba.conf のパスを確認

find / -name pg_hba.conf

Vim で pg_hba.conf を開く

vi /var/lib/pgsql/data/pg_hba.conf

最後の行にこれを追加(md5メソッドを全開放)

host    all             all             0.0.0.0/0               md5

サービスを再起動

systemctl restart postgresql.service

postgres のパスワードの設定

ルートのままで

しかるべきディレクトリに移動して・・・

cd /var/lib/pgsql/

パスワード変更のコマンドをたたく

sudo -u postgres psql -c "alter user postgres password 'postgres';"

ALTER ROLE と返って来ればOK

Apache NiFi でクエリ

ExecuteSQLプロセッサのプロパティ設定
(Database Connection Pool と SQL select query 以外はデフォルト)

image.png

PostgreSQLConnectionPoolの中身

image.png

以上で、クエリをかけることができました!

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?