本文涉及CentOS7下PostgreSQL9.6的yum安装,访问配置及简单使用。
一.验证环境
1. 操作系统
CentOS-7-x86_64-Everything-1511
2. PostgresSQL版本
PostgreSQL 9.6.3:https://www.postgresql.org/download/linux/RedHat/
二.安装
1. 安装rpm
[root@psql_master ~]# yum install -y https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
2. 安装客户端
[root@psql_master ~]# yum install -y postgresql96
3. 安装服务器端
#yum安装postgresql,默认会建一个名为”postgres”的系统账号,用于执行PostgreSQL; #同时数据库中也会生成一个名为”postgres”的数据库用户,且密码已自动生成,需要进入数据库后修改; #PostgreSQL在数据库用户同名的系统账号下登录免密。 [root@psql_master ~]# yum install -y postgresql96-server
4. 初始化
[root@psql_master bin]# /usr/pgsql-9.6/bin/postgresql96-setup initdb
5. 设置开机启动
[root@psql_master ~]# systemctl enable postgresql-9.6
6. 启动
[root@psql_master ~]# systemctl start postgresql-9.6
三.配置使用
1. 修改用户密码
#yum安装postgresql,默认会建一个名为”postgres”的系统账号,用于执行PostgreSQL; [root@psql_master ~]# su - postgres #切换用户后,提示符变更为“-bash-4.2$”; #同时数据库中也会生成一个名为”postgres”的数据库用户,且密码已自动生成; #PostgreSQL在数据库用户同名的系统账号下登录免密; -bash-4.2$ psql -U postgres #进入数据库后修改密码; postgres=# alter user postgres with password 'postgres@123'
2. 允许远程访问
#配置文件中,默认只能本机访问postgresql; #修改listen_addresses = 'localhost'为listen_addresses = '*',允许所有远程访问; #修改配置文件需要重启服务。 [root@psql_master ~]# sed -i "s|#listen_addresses = 'localhost'|listen_addresses = '*'|g" /var/lib/pgsql/9.6/data/postgresql.conf
3. 主机认证
#在第82行之后,”IPv4 local connections”下新增允许的客户端;
#“host” 代表主机类型,第一个“all”代表db ,第二个“all”代表user ,“172.29.3.67/32” 代表client ip,“trust”代表认证方式;
#认证方式除“trust”外,还有“peer”, “ident”, “md5”, “password”等,具体可参考pg-hba文件: https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html
#修改pg.hba文件需要重启服务。
[root@psql_master ~]# vim /var/lib/pgsql/9.6/data/pg_hba.conf
文章评论