1. 程式人生 > >Centos7安裝postgresql9.5

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 [[email protected] ~]# yum install http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-redhat95-9.5-2.noarch.rpm

安裝postgresql95-server [[email protected] ~]# yum install postgresql95-server postgresql95-contrib postgresql95-devel 安裝postgresql95的odbc [[email protected] ~]# yum install postgresql95-odbc

[[email protected] ~]# 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
[roo
[email protected]
~]#

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

4、資料初始化

資料庫初始化

[[email protected] opt]# /usr/pgsql-9.5/bin/postgresql95-setup initdb
Initializing database ... OK
[[email protected] opt]# 

修改配置檔案,供外部地址訪問 修改配置檔案/var/lib/pgsql/9.5/data/pg_hba.conf

[[email protected] 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

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

修改開機啟動、 啟動服務 開機自啟動

[[email protected] opt]# systemctl enable postgresql-9.5.service

啟動服務

[[email protected] opt]# systemctl start postgresql-9.5.service

執行psql的指令碼 修改postgres密碼為postgres

[[email protected] ~]# su - postgres -c "psql -c \" ALTER  USER postgres WITH PASSWORD 'postgres';\"" 

建立使用者:freeswitch,密碼:freeswitch

[[email protected] ~]# su - postgres -c "psql -c \" CREATE USER freeswitch WITH PASSWORD 'freeswitch';\"" 

建立資料庫:freeswitch

[[email protected] ~]# su - postgres -c "psql -c \" CREATE DATABASE freeswitch;\"" 

賦予資料庫freeswitch,擁有者為freeswitch

[[email protected] ~]# su - postgres -c "psql -c \" ALTER DATABASE freeswitch OWNER TO freeswitch;\""

賦予freeswitch使用者,資料庫freeswitch所有許可權

[[email protected] ~]# su - postgres -c "psql -c \" GRANT ALL PRIVILEGES ON DATABASE freeswitch to freeswitch;\""