一、安裝環(huán)境
- postgresql-12.0
- CentOS-7.6
- 注意:確認linux系統(tǒng)可以正常連接網(wǎng)絡(luò),因為在后面需要添加依賴包。
-
二、pg數(shù)據(jù)庫安裝包下載
下載地址:PostgreSQL: File Browser
選擇要安裝的版本進行下載:
-
-
三、安裝依賴包
在要安裝postgresql數(shù)據(jù)庫的Linux服務(wù)器上執(zhí)行以下命令安裝所需要的依賴包:
-
yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake
四、安裝postgres
1、在根目錄下新建/opt/pgsql文件夾,并將pgsql的壓縮包移入。
-
-
2、解壓壓縮包
-
tar -zxvf postgresql-12.0.tar.gz
3、進入解壓后的文件夾?
-
cd postgresql-12.0
4、編譯postgresql源碼
-
?./configure --prefix=/opt/pgsql/postgresql
make
make install
至此,已完成postgreql的安裝。進入/opt/pgsql/postgresql目錄可以看到安裝后的postgresql的文件。
-
五、創(chuàng)建用戶組postgres并創(chuàng)建用戶postgres?
-
groupadd postgres
useradd -g postgres postgres
id postgres
-
六、創(chuàng)建postgresql數(shù)據(jù)庫的數(shù)據(jù)主目錄并修改文件所有者
- 這個數(shù)據(jù)庫主目錄是隨實際情況而不同,這里我們的主目錄是在/opt/pgsql/postgresql/data目錄下
-
mkdir data
chown postgres:postgres data
-
七、配置環(huán)境變量
進入home/postgres目錄可以看到.bash_profile文件。
-
cd /home/postgres
ls -al
編輯修改.bash_profile文件。
-
vim .bash_profile
添加以下內(nèi)容。
-
export PGHOME=/opt/pgsql/postgresql export PGDATA=/opt/pgsql/postgresql/data PATH=$PATH:$HOME/bin:$PGHOME/bin
保存,退出vim。執(zhí)行以下命令,使環(huán)境變量生效
-
source .bash_profile
八、切換用戶到postgres并使用initdb初使用化數(shù)據(jù)庫
-
su - postgres
initdb
可以看到/opt/pgsql/postgresql/data已經(jīng)有文件了。
cd /opt/pgsql/postgresql/data
九、配置服務(wù)
修改/opt/pgsql/postgresql/data目錄下的兩個文件。
postgresql.conf? ?配置PostgreSQL數(shù)據(jù)庫服務(wù)器的相應(yīng)的參數(shù)。 ?
pg_hba.conf? ? ? ??配置對數(shù)據(jù)庫的訪問權(quán)限。
vim postgresql.conf
其中,參數(shù)“l(fā)isten_addresses”表示監(jiān)聽的IP地址,默認是在localhost處監(jiān)聽,也就是127.0.0.1的ip地址上監(jiān)聽,只接受來自本機localhost的連接請求,這會讓遠程的主機無法登陸這臺數(shù)據(jù)庫,如果想從其他的機器上登陸這臺數(shù)據(jù)庫,需要把監(jiān)聽地址改為實際網(wǎng)絡(luò)的地址,一種簡單的方法是,將行開頭的#去掉,把這個地址改為*,表示在本地的所有地址上監(jiān)聽。
vim pg_hba.conf
host all all 0.0.0.0/0 trust #新增這一行
找到最下面這一行?,這樣局域網(wǎng)的人才能訪問
十、設(shè)置PostgreSQL開機自啟動
PostgreSQL的開機自啟動腳本位于PostgreSQL源碼目錄的contrib/start-scripts路徑下。
linux文件即為linux系統(tǒng)上的啟動腳本
cd /opt/pgsql/postgresql-12.0/contrib/start-scripts
切換為root用戶,修改linux文件屬性,添加X屬性
su root
chmod a+x linux
復制linux文件到/etc/init.d目錄下,更名為postgresql
cp linux /etc/init.d/postgresql
修改/etc/init.d/postgresql文件的兩個變量
prefix設(shè)置為postgresql的安裝路徑:/pgsql/postgresql
PGDATA設(shè)置為postgresql的數(shù)據(jù)目錄路徑:/pgsql/postgresql/data
vim /etc/init.d/postgresql
設(shè)置postgresql服務(wù)開機自啟動
chkconfig --add postgresql
執(zhí)行service postgresql start,啟動PostgreSQL服務(wù)文章來源:http://www.zghlxwxcb.cn/news/detail-850376.html
service postgresql start
文章來源地址http://www.zghlxwxcb.cn/news/detail-850376.html
到了這里,關(guān)于Linux下PostgreSQL-12.0安裝部署詳細步驟的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!