CentOS安裝,啓動,配置postgresql

1、首先卸載舊版本postgresql

yum remove postgresql*

2、然後開始安裝10版本

yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
yum install postgresql10
yum install postgresql10-server  (此時在/usr/下多了pgsql-10目錄)
初始化數據庫:
/usr/pgsql-10/bin/postgresql-10-setup initdb 
可選設置自動啓動:
systemctl enable postgresql-10
systemctl start postgresql-10

su - postgres -c "createuser -s odoo"
啓動服務:
service postgresql-10 initdb 
chkconfig postgresql-10 on

啓動可能出現的異常:could not open lock file "/tmp/.s.PGSQL.5432.lock":

解決方案:修改tmp權限,chown -R postgres:postgres /tmp

3、PostgreSQL 安裝完成後,會建立一下‘postgres’用戶,用於執行PostgreSQL,數據庫中也會建立一個’postgres’用戶,默認密碼爲自動生成,需要在系統中改一下。

修改postgres用戶密碼:

先切換到root 
然後passwd postgress 
接着輸入兩遍新密碼

4、修改postgres數據庫管理員密碼:

su - postgres 切換用戶,執行後提示符會變爲 ‘-bash-4.2$’,切換爲UNIX風格的bash 
psql -U postgres 登錄數據庫,執行後提示符變爲 ‘postgres=#’ 
ALTER USER postgres WITH PASSWORD ‘abc123’ 設置postgres用戶密碼 
\q 退出數據庫

5、切換到root配置一下遠程連接。 
開啓遠程訪問

vi /var/lib/pgsql/10/data/postgresql.conf 
修改#listen_addresses = ‘localhost’ 爲 listen_addresses=’*’ 
當然,此處‘*’也可以改爲任何你想開放的服務器IP

6、信任遠程連接

vi /var/lib/pgsql/10/data/pg_hba.conf 
修改如下內容,信任指定服務器連接 
# IPv4 local connections: 
host all all 127.0.0.1/32 trust 
host all all 192.168.1.2/32(需要連接的服務器IP) trust

配置後可能出現在遠程連接時,會報Error connecting to the server:致命錯誤:沒有用於主機“…”,用戶“…”,數據庫“…”,SSL關閉的pg_hba.conf記錄:

解決方案:

在文件末尾添上:

# TYPE DATABASE USER CIDR-ADDRESS METHOD
host    all             all              0.0.0.0/0              md5

7、遠程連接配置完成,由於系統原因,還需要在防火牆中打開相應的端口。

打開防火牆 
CentOS 防火牆中內置了PostgreSQL服務,配置文件位置在/usr/lib/firewalld/services/postgresql.xml,我們只需以服務方式將PostgreSQL服務開放即可。

firewall-cmd –add-service=postgresql –permanent 開放postgresql服務 
firewall-cmd –reload 重載防火牆

8、最後一步,不能忘記的,是重啓數據庫服務,使配置生效。

重啓PostgreSQL數據服務

systemctl restart postgresql-10.service

錯誤:

Job for postgresql-10.service failed because the control process exited with error code. See "systemctl status postgresql-10.service" and "journalctl -xe" for details

原因: 
數據庫安裝完後沒有進行初始化工作 
解決:

>/usr/pgsql-10/bin/postgresql-10-setup initdb

至此,PostgreSQL 10 在CentOS 7上完成基本安裝和配置。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章