RedHat 5.5 安裝PostgreSQL步驟

來源:互聯網
上載者:User

下面以PostgreSQL 9.1.2版本為例,也可以參考包內INSTALL檔案。步驟如下:

1、下載PostgreSQL源碼包,放在任意目錄 http://www.postgresql.org/ftp/source/v9.1.2/

2、解壓檔案

#tar zxvf postgresql-9.1.2.tar.gz

#cd postgresql-9.1.2

3、配置:

#./configure --prefix=/usr/local/pgsql

4、編譯:

#make

5、安裝:

#make install

6、建立postgresql使用者組和使用者:

#groupadd postgres

#useradd -g postgres postgres

7、建立資料庫庫檔案儲存體目錄,將儲存目錄許可權交給postgresql使用者

#mkdir /usr/local/pgsql/data

#cd /usr/local/pgsql

#chown -R postgres.postgres data

8、設定環境變數

#vi /etc/profile

export PATH=$PATH:/usr/local/pgsql/bin

export MANPATH=$MANPATH:/usr/local/pgsql/man

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/pgsql/lib

在檔案尾添加如上資訊,然後儲存退出

9、初始化資料庫,啟動資料庫

#su - postgres

#initdb -D /usr/local/pgsql/data

現在就可以啟動資料庫了

#pg_ctl -D /usr/local/pgsql/data -l /usr/local/pgsql/data/pgsql.logstart

提示“server starting”

然後我們執行進程察看命令查看服務是否已經啟動:

#ps -A|grep postgres

 10、配置監聽地址和連接埠:
#vi /usr/local/pgsql/data/postgresql.conf         

listen_addresses= '*'         #取消該行的注釋,並將單引號內的值設為*

port = 5432                 #取消該行的注釋

11、配置允許遠端連線:

#vi /usr/local/pgsql/data/pg_hba.conf

添加

hostall all 192.168.1.0/24  trust

hostall all samenet  trust

設定檔中對每一條都有詳細說明,詳細說明參考點擊開啟連結

 

#su root    擷取root使用者權限,進行如下操作

12、配置iptables讓遠程主機能訪問:

#vi /etc/sysconfig/iptables-config

添加

-ARH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT

重啟iptables服務


#service iptables restart

13、讓postgresql資料庫隨系統啟動而啟動:

從第一步解壓的安裝檔案目錄將啟動指令碼拷貝到/etc/init.d/目錄下,具體執行如下命令:

#cd /etc/rc.d/init.d

#cp /postgresql-9.1.2/contrib/start-scripts/linuxpostgresql

#chmod +x postgresql

#chkconfig --add postgresql

啟動資料庫:

#service postgresql start

配置完畢。

 

附錄:我參與的項目,postgresql使用方式如下:

1.使用securecrt,telnet登入到裝有postgresql的主機

2.鍵入命令 su root 擷取root使用者權限

3.鍵入命令 su - postgres 取的postgres使用者身份

4.鍵入命令psql  使用預設資料庫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.