歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> 學習Linux >> CentOS6使用YUM安裝Postgresql9.4

CentOS6使用YUM安裝Postgresql9.4

日期:2017/3/3 17:24:34   编辑:學習Linux

CentOS6使用YUM安裝Postgresql9.4


熱度1 評論 216 www.BkJia.Com 網友分享於: 2017-02-28 06:02:17 浏覽數24110次

CentOS6使用YUM安裝Postgresql9.4


最近需要使用postgresqsl,所以安裝了postgresql9.4。下面說說在centOS6環境下,在網絡聯通的情況下,使用YUM安裝postgresql。(僅供大家參考)

(1) 查看系統環境

(2) 首先屏蔽centos系統上yum源的postgresql自動升級[plain]view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. vim/etc/yum.repos.d/CentOS-Base.repo
在[base]和[updates]下添加exclude=postgresql*。如圖: (3) 也可以獲取postgresql rpm包,使用rpm安裝。下載地址:https://yum.postgresql.org/repopackages.php (4) YUM安裝postgresql9.4:[sql]view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. #yuminstallpostgresql94postgresql94-serverpostgresql94-contrib
使用該方式安裝postgresql。它的默認路徑如下: data路徑: /var/lib/pgsql/9.4/data 主目錄: /usr/pgsql-9.4 (5) 進入data目錄初始化postgresql安裝 [sql]view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. #sudo–upostgres/user/pgsql-9.4/bin/initdb
(6) 配置postgresql服務器監聽地址和端口號 [sql]view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. #vim/var/lib/pgsql/9.4/data/postgresql.conf
  2. listen_address=‘*’
  3. port=5432
(7) 可以設置postgresql訪問權限,在文件最後加上:[plain]view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. #vim/var/lib/pgsql/9.4/data/pg_hba.conf
[plain]view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. hostallall0.0.0.00.0.0.0md5
(8) 啟動postgresql服務
[plain]view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. #servicepostgresql-9.4start

(9) 修改postgresql默認postgres數據庫密碼
[plain]view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. #sudo–upostgrespsql
  2. postgres=#ALTERUSERpostgresWITHPASSWORD‘postgres’;
[plain]view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. 或者直接:
  2. postgres=#\passwordpostgres
(10) 創建數據庫與用戶,並且授權
[plain]view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. postgres=#createuser“tuser”withpassword‘123456’nocreatedb;
  2. postgres=#createdatabase“testdb”withowner=”tuser”;
  3. postgres=#grantallprivilegesondatabasetestdbtotuser;
(11) 使用制定用戶登陸指定數據庫[plain]view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. #sudo–upostgrespsql–Utuser–dtestdb–h127.0.0.1–p5432或者在postgres用戶下:psql-Utuser-dtestdb-h127.0.0.1-p5432

(12) 修改postgresql數據庫配置,實現遠程登錄
[plain]view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. #vim/var/lib/pgsql/9.4/data/postgresql.conf
[plain]view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. a)監聽地址
  2. #listen_addresses=‘localhost’改為listen_addresses=‘*’
  3. b)啟用密碼驗證
  4. #password_encryption=on改為password_encryption=on
  5. c)可訪問的用戶ip端
  6. #vim/var/lib/pgsql/9.4/data/pg_hba.conf在最後添加
  7. hostallall0.0.0.00.0.0.0md5
  8. d)重啟postgresql數據庫
  9. #servicepostgresql-9.4restart

(13) 修改postgresql防火牆配置:
[plain]view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. #vim/etc/sysconfig/iptables添加以下內容
[plain]view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. -AINPUT-mstate--stateNEW-mtcp-ptcp--dport5432-jACCEPT
  2. -AINPUT-mstate--stateNEW-mtcp-ptcp--dport80-jACCEPT
  3. #重啟防火牆
  4. #sudoserviceiptablesrestart

(14)修改postgres用戶密碼
[plain]view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. #sudo–passwd–upostgres
  2. #sudo–upostgrespasswd

done。配置了postgresql9.4版本,並且修改了一些數據庫默認的選項。參考文章:http://blog.sina.com.cn/s/blog_6af33caa0100ypck.htmlhttp://www.cnblogs.com/mchina/archive/2012/06/06/2539003.htmlhttp://www.wvser.com/archives/install-postgresql-on-fedora-centos-red-hat-rhel.htmlhttp://www.ruanyifeng.com/blog/2013/12/getting_started_with_postgresql.html

http://www.bkjia.com/Linuxjc/1196009.htmlwww.bkjia.comtrue

Copyright © Linux教程網 All Rights Reserved