在 CentOS 7.x 上安裝 PostgreSQL Server

從剛開始學 GNU/Linux 用的就是 MySQL,一直到後來的 MariaDB,很少使用的 PostgreSQL,印象中只有 OpenNMS 才有特別使用到。

1. 安裝 PostgreSQL Server
# yum install postgresql-server postgresql-contrib

2. 初始化 PostgreSQL 資料庫
# /usr/bin/postgresql-setup initdb
Initializing database … OK[@more@]
3. 修改認證設定檔 /var/lib/pgsql/data/pg_hba.conf
# sed -i ‘/^local/s/peer$/md5/’ /var/lib/pgsql/data/pg_hba.conf

# sed -i ‘/^host/s/…..$/md5/’ /var/lib/pgsql/data/pg_hba.conf
# egrep ‘^local|^host’ /var/lib/pgsql/data/pg_hba.conf
local   all             all                                     md5
host    all             all             127.0.0.1/32            md5

host    all             all             ::1/128                 md5

4. 啟動 PostgreSQL Server
# systemctl start postgresql.service
# systemctl enable postgresql.service

5. 開啟防火牆設定
# firewall-cmd –permanent –add-service=postgresql
# firewall-cmd –reload

# iptables -A INPUT -p tcp –syn -m state –state NEW –dport 5432 -j ACCEPT