centos7联网安装pg10

官网地址

https://www.postgresql.org/download/linux/redhat/

centos7联网安装pg10_第1张图片
image.png

安装步骤

建议使用root用户安装:

  1. 安装rpm仓库
yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
  1. 安装客户端
yum install postgresql10
  1. 安装服务端
yum install postgresql10-server
  1. 修改数据盘路径
#查看较大的磁盘分区,本例放在/mnt
df -lh
#创建数据目录
sudo mkdir /mnt/pgdata
sudo chown -R postgres:postgres /mnt/pgdata
sudo chmod 700 /home/pgdata

vim /usr/lib/systemd/system/postgresql-10.service
修改为刚建的目录

  1. 初始化及自启动
/usr/pgsql-10/bin/postgresql-10-setup initdb
systemctl enable postgresql-10
systemctl start postgresql-10

设置访问权限

修改配置文件

vim /home/pgdata/postgresql.conf 
改listen_addresses = 'localhost'的localhost为*,去掉前面的#(注释)

vim /home/pgdata/pg_hba.conf ## IPv4 local connections:添加一行
## 允许任务用户、任意IP以md5加密密码方式访问
host    all             all             0.0.0.0/0            md5

修改密码(默认无密码)

su postgres
psql
ALTER USER postgres WITH PASSWORD '新密码';   
--必须以分号结束,成功执行后会出现ALTER ROLE
\q #退出
exit

重启

systemctl restart postgresql-10
或
/usr/pgsql-10/bin/pg_ctl -p 5432 restart

你可能感兴趣的:(centos7联网安装pg10)