Centos 安装postgre sql

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 md5

IPv6 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
  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值