- 安裝rpm文件
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
- 安裝PostgreSQL
sudo yum install -y --nogpgcheck postgresql14-server
- 初始化數(shù)
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
- 設(shè)備開機(jī)啟動
sudo systemctl enable postgresql-14
- 啟動PostgreSQL服務(wù)
sudo systemctl start postgresql-14
- 設(shè)置數(shù)據(jù)庫密碼
數(shù)據(jù)庫安裝后膛壹,默認(rèn)創(chuàng)建賬號postgres
使用postgres賬號身份操作
su - postgres
- 使用postgres賬號登錄數(shù)據(jù)庫
psql -U postgres
- 設(shè)置密碼
alter user postgres with password '123456'
- 退出
\q #退出數(shù)據(jù)庫
exit #退出postgres賬號
- 開啟遠(yuǎn)程訪問
對所有IP開放訪問
打開postgresql.conf文件
vi /var/lib/pgsql/14/data/postgresql.conf
- 修改listen_address配置(對所有IP開發(fā)訪問)
listen_address = '*'
增加信任連接
打開pg_hba.conf文件
vi /var/lib/pgsql/14/data/pg_hba.conf
- 增加新人連接配置
# IPv4 local connections:
host all all 0.0.0.0/0 trust
- 重啟服務(wù)
systemctl restart postgresql-14
- 添加防火墻端口號
- 添加端口號
firewall-cmd --zone=public --add-port=5432/tcp --permanent
- 重載防火墻立即生效
firewall-cmd --reload