Centos7下安装postgresql-9.5
2016-12-21 17:42
357 查看
1.添加RPM
yum install https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm
2.安装PostgreSQL 9.5
yum install postgresql95-server postgresql95-contrib
3.初始化数据库
/usr/pgsql-9.5/bin/postgresql95-setup initdb
![](http://upload-images.jianshu.io/upload_images/2167535-e57b338fc4b2ec22.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
4.设置开机自启动
systemctl enable postgresql-9.5.service
5.启动服务
systemctl start postgresql-9.5.service
![](http://upload-images.jianshu.io/upload_images/2167535-b2fde93d27e8c9b0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
自此,PostgreSQL 9.5 安装完成,此过程中注意安装权限,我在安装过程中一直使用的是root用户进行的安装。
接下来,进行一下简单的配置。
PostgreSQL 安装完成后,会建立一下‘postgres’用户,用于执行PostgreSQL,数据库中也会建立一个'postgres'用户,默认密码为自动生成,需要在系统中改一下。
6.修改用户密码
su - postgres 切换用户,执行后提示符会变为 '-bash-4.2$'
psql -U postgres 登录数据库,执行后提示符变为 'postgres=#'
ALTER USER postgres WITH PASSWORD 'abc123' 设置postgres用户密码
\q 退出数据库
![](http://upload-images.jianshu.io/upload_images/2167535-e6447a33d4885fee.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
系统管理用的帐号和密码变更完成,现在配置一下远程连接。
7.开启远程访问
vi /var/lib/pgsql/9.5/data/postgresql.conf
修改#listen_addresses = 'localhost' 为 listen_addresses='*'
当然,此处‘*’也可以改为任何你想开放的服务器IP
![](http://upload-images.jianshu.io/upload_images/2167535-6493b2b5d28a1ed9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
8.信任远程连接
vi /var/lib/pgsql/9.5/data/pg_hba.conf
修改如下内容,信任指定服务器连接
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 10.211.55.6/32(需要连接的服务器IP) trust
![](http://upload-images.jianshu.io/upload_images/2167535-922799b3ebdb5f58.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
远程连接配置完成,由于系统原因,还需要在防火墙中打开相应的端口。
9.打开防火墙
CentOS 防火墙中内置了PostgreSQL服务,配置文件位置在/usr/lib/firewalld/services/postgresql.xml,我们只需以服务方式将PostgreSQL服务开放即可。
firewall-cmd --add-service=postgresql --permanent 开放postgresql服务
firewall-cmd --reload 重载防火墙
![](http://upload-images.jianshu.io/upload_images/2167535-051bf1d2d3fdd296.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
最后一步,不能忘记的,是重启数据库服务,使配置生效。
10. 重启PostgreSQL数据服务
systemctl restart postgresql-9.5.service
至此,PostgreSQL 9.5 在CentOS 7上完成基本安装和配置。
文/lasko(简书作者)
原文链接:http://www.jianshu.com/p/7e95fd0bc91a
远程连接设置:
修改pg_hba.conf中ipv4的设置
# IPv4 local connections:
host all all 0.0.0.0/0 trust
yum install https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm
2.安装PostgreSQL 9.5
yum install postgresql95-server postgresql95-contrib
3.初始化数据库
/usr/pgsql-9.5/bin/postgresql95-setup initdb
![](http://upload-images.jianshu.io/upload_images/2167535-e57b338fc4b2ec22.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
4.设置开机自启动
systemctl enable postgresql-9.5.service
5.启动服务
systemctl start postgresql-9.5.service
![](http://upload-images.jianshu.io/upload_images/2167535-b2fde93d27e8c9b0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
自此,PostgreSQL 9.5 安装完成,此过程中注意安装权限,我在安装过程中一直使用的是root用户进行的安装。
接下来,进行一下简单的配置。
PostgreSQL 安装完成后,会建立一下‘postgres’用户,用于执行PostgreSQL,数据库中也会建立一个'postgres'用户,默认密码为自动生成,需要在系统中改一下。
6.修改用户密码
su - postgres 切换用户,执行后提示符会变为 '-bash-4.2$'
psql -U postgres 登录数据库,执行后提示符变为 'postgres=#'
ALTER USER postgres WITH PASSWORD 'abc123' 设置postgres用户密码
\q 退出数据库
![](http://upload-images.jianshu.io/upload_images/2167535-e6447a33d4885fee.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
系统管理用的帐号和密码变更完成,现在配置一下远程连接。
7.开启远程访问
vi /var/lib/pgsql/9.5/data/postgresql.conf
修改#listen_addresses = 'localhost' 为 listen_addresses='*'
当然,此处‘*’也可以改为任何你想开放的服务器IP
![](http://upload-images.jianshu.io/upload_images/2167535-6493b2b5d28a1ed9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
8.信任远程连接
vi /var/lib/pgsql/9.5/data/pg_hba.conf
修改如下内容,信任指定服务器连接
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 10.211.55.6/32(需要连接的服务器IP) trust
![](http://upload-images.jianshu.io/upload_images/2167535-922799b3ebdb5f58.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
远程连接配置完成,由于系统原因,还需要在防火墙中打开相应的端口。
9.打开防火墙
CentOS 防火墙中内置了PostgreSQL服务,配置文件位置在/usr/lib/firewalld/services/postgresql.xml,我们只需以服务方式将PostgreSQL服务开放即可。
firewall-cmd --add-service=postgresql --permanent 开放postgresql服务
firewall-cmd --reload 重载防火墙
![](http://upload-images.jianshu.io/upload_images/2167535-051bf1d2d3fdd296.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
最后一步,不能忘记的,是重启数据库服务,使配置生效。
10. 重启PostgreSQL数据服务
systemctl restart postgresql-9.5.service
至此,PostgreSQL 9.5 在CentOS 7上完成基本安装和配置。
文/lasko(简书作者)
原文链接:http://www.jianshu.com/p/7e95fd0bc91a
远程连接设置:
修改pg_hba.conf中ipv4的设置
# IPv4 local connections:
host all all 0.0.0.0/0 trust
相关文章推荐
- centos7 安装postgresql-9.5
- postgresql9.5 安装配置和使用(on centos7)
- Centos7安装PostgreSQL9.5
- CentOS7安装PostgreSQL9.5过程
- CentOS7上安装PostgreSQL
- centos7 安装 nginx1.8+php5.6+postgresql9.4
- centos7 在线安装postgresql9.5
- CentOS7 PostgreSQL9.6安装
- opencms9.5 for postgresql 安装教程
- centos7安装python开发环境(python3_postgresql_sublime_supervisor)
- centos7 安装redmin3.3.0+postgresql数据库 推荐
- CentOS7安装、配置PostgreSQL
- CentOS6.5+PostgreSQL9.5安装参考
- CentOS 6.7 下 PostgreSQL 9.5 的安装与配置
- CentOS7 PostgreSQL安装
- centos7安装postgresql9.5.4
- centos7 通过YUM安装 PHP7 NGINX1.1.8 POSTGRESQL9.5
- 基于CentOS7开发之路 --- 第四章 :CentOS 7 安装 postgresql 9.5.0 数据库
- centos7安装postgresql和pgadmin
- Linux CentOS 7 安装PostgreSQL 9.5(源码编译)