Rocky Linux 8.5にPostgreSQL 14をインストールする

環境
1.OSバージョンの確認
# cat /etc/redhat-release
Rocky Linux release 8.5 (Green Obsidian)
PostgreSQL 14.2

1.リポジトリを追加します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

2.既存のモジュールを無効にします。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo dnf -qy module disable postgresql
# sudo dnf -qy module disable postgresql
# sudo dnf -qy module disable postgresql

3.dnfでpostgresql14をインストールします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo dnf install -y postgresql14-server
# sudo dnf install -y postgresql14-server
# sudo dnf install -y postgresql14-server

4.PostgreSQL 14初期化を行います

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
Initializing database ... OK
# sudo /usr/pgsql-14/bin/postgresql-14-setup initdb Initializing database ... OK
# sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
Initializing database ... OK

自動起動を行います

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo systemctl enable --now postgresql-14
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-14.service → /usr/lib/systemd/system/postgresql-14.service.
# sudo systemctl enable --now postgresql-14 Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-14.service → /usr/lib/systemd/system/postgresql-14.service.
# sudo systemctl enable --now postgresql-14
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-14.service → /usr/lib/systemd/system/postgresql-14.service.

5.postgresqlの起動、ステータスを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# systemctl status postgresql-14
● postgresql-14.service - PostgreSQL 14 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-14.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2022-03-30 15:15:52 EDT; 1min 24s ago
# systemctl status postgresql-14 ● postgresql-14.service - PostgreSQL 14 database server Loaded: loaded (/usr/lib/systemd/system/postgresql-14.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2022-03-30 15:15:52 EDT; 1min 24s ago
# systemctl status postgresql-14
● postgresql-14.service - PostgreSQL 14 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-14.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2022-03-30 15:15:52 EDT; 1min 24s ago

postgresqlを起動します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# systemctl start postgresql-14
# systemctl start postgresql-14
# systemctl start postgresql-14

6.管理者ユーザーのパスワードを設定します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo su - postgres
[postgres@localhost ~]$ psql -c "alter user postgres with password 'pwd123'"
ALTER ROLE
# sudo su - postgres [postgres@localhost ~]$ psql -c "alter user postgres with password 'pwd123'" ALTER ROLE
# sudo su - postgres
[postgres@localhost ~]$ psql -c "alter user postgres with password 'pwd123'"
ALTER ROLE

exitでログアウトを行います

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[postgres@localhost ~]$ exit
ログアウト
[postgres@localhost ~]$ exit ログアウト
[postgres@localhost ~]$ exit
ログアウト

7.外部接続許可を行います
(1).postgresql.confの編集

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo vi /var/lib/pgsql/14/data/postgresql.conf
# sudo vi /var/lib/pgsql/14/data/postgresql.conf
# sudo vi /var/lib/pgsql/14/data/postgresql.conf

60行目

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
修正前
#listen_addresses = 'localhost'
修正後
listen_addresses = '*'
修正前 #listen_addresses = 'localhost' 修正後 listen_addresses = '*'
修正前
#listen_addresses = 'localhost'
修正後
listen_addresses = '*'

64行目

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
修正前
#port = 5432
修正後
port = 5432
修正前 #port = 5432 修正後 port = 5432
修正前
#port = 5432
修正後
port = 5432

(2).pg_hba.confの編集
# sudo vi /var/lib/pgsql/14/data/pg_hba.conf
87行目

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
修正前
host all all 127.0.0.1/32 scram-sha-256
修正後
# host all all 127.0.0.1/32 scram-sha-256
host all all 192.168.0.0/16 scram-sha-256
修正前 host all all 127.0.0.1/32 scram-sha-256 修正後 # host all all 127.0.0.1/32 scram-sha-256 host all all 192.168.0.0/16 scram-sha-256
修正前
host all all 127.0.0.1/32 scram-sha-256
修正後
# host all all 127.0.0.1/32 scram-sha-256
host all all 192.168.0.0/16 scram-sha-256

(3).Firewallを許可します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo firewall-cmd --add-port=5432/tcp --zone=public --permanent
success
# sudo firewall-cmd --reload
success
# sudo firewall-cmd --add-port=5432/tcp --zone=public --permanent success # sudo firewall-cmd --reload success
# sudo firewall-cmd --add-port=5432/tcp --zone=public --permanent
success
# sudo firewall-cmd --reload
success

(4).PostgreSQLを再起動します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo systemctl restart postgresql-14
# sudo systemctl restart postgresql-14
# sudo systemctl restart postgresql-14

 

Rocky Linux 8

Posted by arkgame