PostgreSQL安裝配置

一、前置準備

參考網站:

官網下載安裝方式:https://www.postgresql.org/download/linux/redhat/

安裝版本:PostgreSQL11

系統版本:CentOS7

二、開始安裝

1)通過yum進行安裝

yum install postgresql-server

2)初始化數據庫

postgresql-setup initdb

安裝完成。(操作真簡單- -、)

三、初期配置

1)啓動相關

#開機啓動
systemctl enable postgresql.service
#啓動
systemctl start postgresql.service
#重啓
systemctl restart postgresql.service
#查看狀態
systemctl status postgresql.service
#停止
systemctl stop postgresql.service

2)簡單配置

a,設置密碼

#切換用戶環境
su - postgres
#進入pgsql
psql -U postgres
#修改密碼
alter user postgres with password 'new password';
#退出
\q
#退出當前用戶
exit

b,修改配置文件

配置文件路徑:/var/lib/pgsql/data

修改postgresql.conf

#原配置
#listen_addresses = 'localhost'		# what IP address(es) to listen on;
↓
#修改後
listen_addresses = '*'		# what IP address(es) to listen on;

修改pg_hba.conf

#原配置
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            ident
# IPv6 local connections:
host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            ident
#host    replication     postgres        ::1/128                 ident

↓
#在最後追加一行
host    all     all        0.0.0.0/0                 md5

修改重啓之後就可以通過賬戶密碼進行遠程連接了。

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