Centos7安装postgresql9.5

1、环境

操作系统:CentOS Linux release 7.2.1511 (Core) 
pgdg版本:9.5.5

2、数据库在线安装

如需配置yum缓存,修改/etc/yum.conf,keepcache=0为keepcache=1,如在rhel-server-7.2上安装另还需修改plugins=1为plugins=0

安装PostgreSQL95 Yum Repository
[root@localhost ~]# yum install http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-redhat95-9.5-2.noarch.rpm
安装postgresql95-server
[root@localhost ~]# yum install postgresql95-server postgresql95-contrib postgresql95-devel
安装postgresql95的odbc
[root@localhost ~]# yum install postgresql95-odbc

[root@localhost ~]# find /var -name *.rpm
/var/cache/yum/x86_64/7/base/packages/libxslt-1.1.28-5.el7.x86_64.rpm
/var/cache/yum/x86_64/7/base/packages/unixODBC-2.3.1-11.el7.x86_64.rpm
/var/cache/yum/x86_64/7/updates/packages/libtool-ltdl-2.4.2-21.el7_2.x86_64.rpm
/var/cache/yum/x86_64/7/pgdg95/packages/postgresql95-9.5.5-1PGDG.rhel7.x86_64.rpm
/var/cache/yum/x86_64/7/pgdg95/packages/postgresql95-libs-9.5.5-1PGDG.rhel7.x86_64.rpm
/var/cache/yum/x86_64/7/pgdg95/packages/postgresql95-server-9.5.5-1PGDG.rhel7.x86_64.rpm
/var/cache/yum/x86_64/7/pgdg95/packages/postgresql95-contrib-9.5.5-1PGDG.rhel7.x86_64.rpm
/var/cache/yum/x86_64/7/pgdg95/packages/postgresql95-odbc-09.05.0400-1PGDG.rhel7.x86_64.rpm
/var/cache/yum/x86_64/7/pgdg95/packages/postgresql95-devel-9.5.5-1PGDG.rhel7.x86_64.rpm
/var/tmp/yum-root-mBRLdw/pgdg-redhat95-9.5-2.noarch.rpm
[root@localhost ~]#

3、数据库离线安装

安装文件准备

  1. libtool-ltdl-2.4.2-21.el7_2.x86_64.rpm
  2. libxslt-1.1.28-5.el7.x86_64.rpm
  3. pgdg-redhat95-9.5-2.noarch.rpm
  4. postgresql95-9.5.5-1PGDG.rhel7.x86_64.rpm
  5. postgresql95-contrib-9.5.5-1PGDG.rhel7.x86_64.rpm
  6. postgresql95-devel-9.5.5-1PGDG.rhel7.x86_64.rpm
  7. postgresql95-libs-9.5.5-1PGDG.rhel7.x86_64.rpm
  8. postgresql95-odbc-09.05.0400-1PGDG.rhel7.x86_64.rpm
  9. postgresql95-server-9.5.5-1PGDG.rhel7.x86_64.rpm
  10. unixODBC-2.3.1-11.el7.x86_64.rpm

下载地址:https://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/
使用rpm -Uvh *.rpm 或rpm -Uvh --nodeps *.rpm

4、数据初始化

数据库初始化

[root@localhost opt]# /usr/pgsql-9.5/bin/postgresql95-setup initdb
Initializing database ... OK
[root@localhost opt]# 

修改配置文件,供外部地址访问
修改配置文件/var/lib/pgsql/9.5/data/pg_hba.conf

[root@localhost opt]# sed -i 's/127.0.0.1\/32            ident/0.0.0.0\/0            md5/g' /var/lib/pgsql/9.5/data/pg_hba.conf

修改配置文件/var/lib/pgsql/9.5/data/postgresql.conf

[root@localhost opt]# sed -i 's/localhost/*/g' /var/lib/pgsql/9.5/data/postgresql.conf
[root@localhost opt]# sed -i 's/#listen_addresses/listen_addresses/g' /var/lib/pgsql/9.5/data/postgresql.conf

修改开机启动、 启动服务
开机自启动

[root@localhost opt]# systemctl enable postgresql-9.5.service

启动服务

[root@localhost opt]# systemctl start postgresql-9.5.service

执行psql的脚本
修改postgres密码为postgres

[root@localhost ~]# su - postgres -c "psql -c \" ALTER  USER postgres WITH PASSWORD 'postgres';\"" 

创建用户:freeswitch,密码:freeswitch

[root@localhost ~]# su - postgres -c "psql -c \" CREATE USER freeswitch WITH PASSWORD 'freeswitch';\"" 

创建数据库:freeswitch

[root@localhost ~]# su - postgres -c "psql -c \" CREATE DATABASE freeswitch;\"" 

赋予数据库freeswitch,拥有者为freeswitch

[root@localhost ~]# su - postgres -c "psql -c \" ALTER DATABASE freeswitch OWNER TO freeswitch;\""

赋予freeswitch用户,数据库freeswitch所有权限

[root@localhost ~]# su - postgres -c "psql -c \" GRANT ALL PRIVILEGES ON DATABASE freeswitch to freeswitch;\""

你可能感兴趣的:(数据库,postgresql9.5安装)