1. 程式人生 > >CentOS下非root 原始碼安裝PostgreSQL

CentOS下非root 原始碼安裝PostgreSQL

1. 建立postgres使用者,設定其HOME目錄為/usr/local/pgsql
groupadd -g 88 postgres
useradd -u 88 -g 88 -d /usr/local/pgsql postgres
chmod 755 /usr/local/pgsql
passwd postgres

##########################################################
2. 使用postgres使用者登陸,上傳原始碼至其HOME目錄,然後開始編譯安裝:

tar -xvf postgresql-9.3.4.tar.bz2
cd postgresql-9.3.4
./configure --without-readline

make && make install

##########################################################
3. 初始化資料庫

cd ~
mkdir data
chown -R postgres data
su postgres #使用postgres使用者來初始化資料庫
cd bin
./initdb -D ../data -E UTF8

##########################################################
5. 修改配置檔案

cd ~
vi .bash_profile
#在檔案最後追加下面6行(先按i鍵,然後貼上以下內容,再按insert鍵,輸入:wq)

export PATH="$PATH":/usr/local/pgsql/bin
export POSTGRES_HOME=/usr/local/pgsql
export PGLIB=$POSTGRES_HOME/lib
export PGDATA=$POSTGRES_HOME/data
export MANPATH="$MANPATH":$POSTGRES_HOME/man
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":"$PGLIB"
#重新讀入
source ~/.bash_profile
驗證一下
echo $POSTGRES_HOME

##########################################################

6. 開啟遠端客戶端連線

cd ~

cd data

vi postgresql.conf
修改 #listen_addresses = "localhost"
改為 listen_addresses = "*"
將 port = 5432 前的註釋(#)去掉

vi pg_hba.conf
在 IPv4 local connections 裡增加:
host    all             all             192.168.1.88/24         md5

##########################################################
7. 啟動資料庫並設定超級使用者postgres和密碼

cd ~
cd bin
./pg_ctl -D ../data -l logfile start
./psql -d postgres
alter user postgres with password '123456';
\q #退出PostgreSQL控制檯

##########################################################
備註:
##########################################################

啟動資料庫
cd ~
cd bin
./pg_ctl -D ../data -l logfile start

停止資料庫
cd ~
cd bin
./pg_ctl stop -D ../data -w

如不能遠端連線資料庫,以root許可權關閉防火牆再試(/etc/init.d/iptables stop)

轉自:http://www.centoscn.com/image-text/install/2014/0605/3086.html