一、部署環(huán)境
| 配置名稱 | 配置詳情 |
|---|---|
| 系統(tǒng)配置 | CentOS Linux release 7.7.1908 (Core) |
| 數(shù)據(jù)庫版本 | postgresql10-10.20 |
| 操作用戶角色 | root |
二、下載安裝
postgres依賴包
下載地址:https://yum.postgresql.org/10/redhat/rhel-7-x86_64/repoview/postgresqldbserver10.group.html
postgresql10-10.20-1PGDG.rhel7.x86_64.rpm
postgresql10-libs-10.20-1PGDG.rhel7.x86_64.rpm
postgresql10-server-10.20-1PGDG.rhel7.x86_64.rpm
下載上面四個依賴包至本地。
libicu依賴包
下載地址:https://centos.pkgs.org/7/centos-x86_64/libicu-50.2-4.el7_7.x86_64.rpm.html
libicu-50.2-4.el7_7.x86_64.rpm
rpm安裝
rpm -ivh libicu-50.2-4.el7_7.x86_64.rpm
rpm -ivh postgresql10-libs-10.16-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql10-10.16-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql10-server-10.16-1PGDG.rhel7.x86_64.rpm
三、配置
1)初始化
初始化數(shù)據(jù)庫
/usr/pgsql-10/bin/postgresql-10-setup initdb
設(shè)置自啟動
systemctl enable postgresql-10.service #設(shè)置數(shù)據(jù)庫的開機啟動
systemctl start postgresql-10 #啟動數(shù)據(jù)庫
關(guān)閉防火墻
systemctl stop firewalld
systemctl disable firewalld
2)添加賬戶
切換用戶
su - postgres
進入psql
psql
添加用戶
ALTER USER postgres WITH PASSWORD 'postgres';
退出
\q
3) 設(shè)置配置文件
設(shè)置外部連接密碼訪問
vi /var/lib/pgsql/10/data/pg_hba.conf
內(nèi)容如下:
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
host all all 0.0.0.0/0 md5 #修改成這樣
修改監(jiān)聽端口
vi /var/lib/pgsql/10/data/postgresql.conf
找到 listen_addresses值給為*
重啟服務(wù)
systemctl restart postgresql-10