Centos 安装postgre sql
通过yum 安装
通过官网提供方式安装:https://www.postgresql.org/download/linux/redhat/
1.下载postgresql 安装源
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
2.安装
yum install -y postgresql11-server
3.初始化db
/usr/pgsql-11/bin/postgresql-11-setup initdb
4.设置自动启动并且启动postgresql
sudo systemctl enable postgresql-11
sudo systemctl start postgresql-11
5. 修改postgres sql
使用postgres用户登录(PostgresSQL安装后会自动创建postgres用户,无密码)
su postgres
psql
alter user postgres with password '你的密码';
exit
6. 修改配置,使用可以远程连接
首先配置postgresql.conf文件,开放PG网络访问端口。
vi /var/lib/pgsql/11/data/postgresql.conf
修改listen_addresses的值为‘*’:listen_addresses 被注释 需要关闭注释
listen_addresses = ‘*’ # what IP address(es) to listen on;
其次配置pg_hba.conf文件,细粒度控制PG服务访问和PG主从复制的IP段
vi /var/lib/pgsql/11/data/pg_hba.conf
重点关注下面配置行尾部是“md5”的配置项的修改
“local” is for Unix domain socket connections only
local all all md5
IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 192.168.83.0/16 md5IPv6 local connections:
host all all ::1/128 ident
Allow replication connections from localhost, by a user with the
replication privilege.
local replication all md5
host replication all 127.0.0.1/32 md5
host replication all 192.168.83.0/24 md5
host replication all ::1/128 ident
重启服务
systemctl restart postgresql-11.service
::1/128 ident
重启服务
systemctl restart postgresql-11.service