Centos7 安装postgresql 10并开通外网访问权限
一、获取最新yum源
输入 yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm -y
二、使用yum安装postgresql10
输入 yum install postgresql10-contrib postgresql10-server -y
出现以下文字则说明安装成功
三、初始化数据库
- 初始化数据库 /usr/pgsql-10/bin/postgresql-10-setup initdb
- 启动数据库 systemctl start postgresql-10
- 添加到开机启动 systemctl enable postgresql-10.service
四、配置数据库
- 切换用户 su - postgres
- 连接数据库 psql
- 设置数据库密码 ALTER USER postgres WITH PASSWORD ‘password’;
- 退出 \q
五、postgresql配置外网访问
- 编辑pg_hba.conf文件 vi /var/lib/pgsql/10/data/pg_hba.conf
翻到文件最后,将最后三行注释,并添加一行代码
host all all 0.0.0.0/0 md5
- 编辑postgresql.conf文件 vi /var/lib/pgsql/10/data/postgresql.conf
将listen_addresses修改为 listen_addresses = ‘*’
- 重启postgresql
systemctl restart postgresql-10
五、测试postgresql连接