CentOS實驗十四:安裝PostgreSQLpg_hba.conf 檔案簡析

來源:互聯網
上載者:User

CentOS 6.4當前軟體源中的postgresql-server版本為8.4.13。

 

1. 安裝PostgreSQL Server:

$ yum groupinstall "PostgreSQL Database server"

預設的安裝目錄是/var/lib/pgsql。安裝過程中會建立postgres使用者和群組。安裝完成後可以將服務postgresql設定成自啟動:

$ chkconfig postgresql on

 

2. 啟動postgresql服務,在此之前需要先初始化:

$ service postgresql initdbInitializing database:                                     [  OK  ]$ ls /var/lib/pgsql/data/total 76drwx------. 5 postgres postgres  4096 May 25 09:53 basedrwx------. 2 postgres postgres  4096 May 25 10:07 globaldrwx------. 2 postgres postgres  4096 May 25 09:53 pg_clog-rw-------. 1 postgres postgres  3411 May 25 09:53 pg_hba.conf-rw-------. 1 postgres postgres  1631 May 25 09:53 pg_ident.confdrwx------. 2 postgres postgres  4096 May 25 10:06 pg_logdrwx------. 4 postgres postgres  4096 May 25 09:53 pg_multixactdrwx------. 2 postgres postgres  4096 May 25 10:07 pg_stat_tmpdrwx------. 2 postgres postgres  4096 May 25 09:53 pg_subtransdrwx------. 2 postgres postgres  4096 May 25 09:53 pg_tblspcdrwx------. 2 postgres postgres  4096 May 25 09:53 pg_twophase-rw-------. 1 postgres postgres     4 May 25 09:53 PG_VERSIONdrwx------. 3 postgres postgres  4096 May 25 09:53 pg_xlog-rw-------. 1 postgres postgres 16886 May 25 09:53 postgresql.conf-rw-------. 1 postgres postgres    57 May 25 10:06 postmaster.opts$ service postgresql startStarting postgresql service:                               [  OK  ]

 

3. 修改postgresql.conf監聽地址和連接埠:

$ cat /var/lib/pgsql/data/postgresql.conf... ...# - Connection Settings -listen_addresses = '*'                # what IP address(es) to listen on;                    # comma-separated list of addresses;                    # defaults to 'localhost', '*' = all                    # (change requires restart)port = 5432                # (change requires restart)... ...

 

4. 修改pg_hba.conf,配置用戶端串連許可權。詳細的pg_hba.conf配置方法參考《pg_hba.conf 檔案簡析》。

$ cat /var/lib/pgsql/data/pg_hba.conf# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD# "local" is for Unix domain socket connections onlylocal   all         all                               ident# IPv4 local connections:host    all         all         127.0.0.1/32          ident# IPv6 local connections:host    all         all         ::1/128               identhost    all         all         192.168.12.0/24       md5

 

5. 切換到postgres使用者,修改資料庫預設角色postgres的密碼(預設密碼為空白):

$ su - postgres$ psqlpostgres=# \password postgresEnter new password: Enter it again: 

 

6. 設定完所有posgresql服務參數後,重新載入配置參數:

$ pg_ctl reload

 

7. 修改iptables規則,允許遠端連線5432連接埠:

$ cat /etc/sysconfig/iptables# Firewall configuration written by system-config-firewall# Manual customization of this file is not recommended.*filter:INPUT ACCEPT [0:0]:FORWARD ACCEPT [0:0]:OUTPUT ACCEPT [0:0]-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT-A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT-A INPUT -j REJECT --reject-with icmp-host-prohibited-A FORWARD -j REJECT --reject-with icmp-host-prohibitedCOMMIT$ service iptables restart

 

8. 最後,就可以在其它Windows用戶端安裝pgAdmin,使用postgres角色遠端管理伺服器了:

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.