1.添加PostgreSQL Yum存盤庫
sudo yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
2.安裝PostgreSQL Server和客戶端軟體包
sudo yum -y install postgresql11-server postgresql11
3.初始化資料庫并啟用自動啟動
# 初始化
sudo /usr/pgsql-11/bin/postgresql-11-setup initdb
# 啟動
sudo systemctl start postgresql-11
# 設定開機自啟動
sudo systemctl enable postgresql-11
# 下面這兩個配置是關于防火墻的(我沒有用到)
sudo firewall-cmd --add-service=postgresql --permanent
sudo firewall-cmd --reload
4.啟用遠程訪問PostgreSQL(作用是可以通過公網連接你的資料庫,前提是你有公網ip)
# 我的路徑是這樣的
vi /var/lib/pgsql/11/data/postgresql.conf
# 修改
listen_addresses = '*'
# 我的路徑是這樣的
sudo vim /var/lib/pgsql/11/data/pg_hba.conf
# 修改
host all all 127.0.0.1/32 md5
# 添加
host all all 0.0.0.0/0 trust
# 重啟
sudo systemctl restart postgresql-11
5.設定PostgreSQL管理員用戶的密碼(一定要按照這種格式配置用戶名和密碼)
sudo su - postgres
psql -c "alter user 用戶名 with password '密碼'"
需要注意,如果是云服務器,需要打開對應埠,我就吃了這個虧,折騰了很長時間,
最后,如果問題,請留言,
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/143446.html
標籤:Linux
