一,下載
1.官網(wǎng)下載安裝包
PostgreSQL: File Browser
?
?2.?下載成功后上傳到Linux服務器
?3.解壓文件
tar -zxvf postgresql-14.5.tar.gz
二,配置
1、初始化配置
1、創(chuàng)建一個安裝目錄
mkdir /home/postgresql/install
2.創(chuàng)建一個存儲目錄
mkdir /home/postgresql/data
3.進入解壓包目錄
cd /home/postgresql/postgresql-12.2
?4.執(zhí)行初始化配置命令
./configure --prefix=/home/postgresql/install --without-readline
?
2、創(chuàng)建用戶組 和 用戶
groupadd postgres
useradd -g postgres postgres
?3、賦予用戶權限
chown postgres /home/postgresql-12.2/data/
chown postgres /home/postgresql-12.2/install/*
chown postgres /home/postgresql-12.2/*
?
4、修改環(huán)境變量
vim /etc/profile
尾部增加
#postgresql
export PGHOME=/home/postgresql/postgresql-12.2
export PGDATA=/home/postgresql/data
PATH=$PATH:$HOME/bin:$PGHOME/bin
更新環(huán)境變量
source /etc/profile
?三,安裝
1、安裝
進入解壓包目錄
編譯安裝
make & make install
2、初始化數(shù)據(jù)庫
進入安裝目錄下的bin
cd /home/postgresql/install/bin
切換用戶
?
su postgres
初始化數(shù)據(jù)庫
./initdb -D /home/postgresql/data/
?
3、網(wǎng)絡配置
(1)設置監(jiān)聽整個網(wǎng)絡,查找“l(fā)isten_addresses ”字符串
進入 存儲目錄
cd /home/postgresql/data
打開配置文件
vim postgresql.conf
修改配置如下:
listen_addresses = '*'
?
?
(2) 修改客戶端認證配置文件pg_hba.conf
將需要遠程訪問數(shù)據(jù)庫的IP地址或地址段加入該文件
編輯文件
vim pg_hba.conf
在文件的最下方加上
host all all 0.0.0.0/0 trust
?
4、啟動數(shù)據(jù)庫
還是初始化時的目錄和用戶postgresql
執(zhí)行
?./pg_ctl start -l ?/usr/local/postgresql/log/pg_server.log
?
5,?創(chuàng)建數(shù)據(jù)庫
進入安裝目錄下的bin
cd /home/postgresql/install/bin
?
postgres用戶 默認是沒有密碼的
./psql -U postgres
?
設置密碼
ALTER USER postgres with encrypted password '123456';
?四,常見異常
?出現(xiàn)異常:configure: error: readline library not found
?解決:
yum install -y readline-devel
?五,開機自啟
如果使用官方y(tǒng)um源安裝,會自動配置服務腳本;如果通過源碼編譯安裝,則需要手動配置。
進入源碼安裝包目錄
?
進入contrib目錄下的start-scripts,找到linux文件
復制linux文件到/etc/init.d文件夾下
cp {源碼路徑}/contrib/start-scripts/linux /etc/init.d
修改文件名為postgresql
mv /etc/init.d/linux /etc/init.d/postgresql
修改postgresql文件,設置啟動配置
具體配置根據(jù)數(shù)據(jù)庫安裝情況來設置
給postgresql分配執(zhí)行權限
chmod a+x /etc/init.d/postgresql
添加開機啟動
chkconfig --add postgresql
查看PostgreSQL是否開機啟動
chkconfig --list |grep postgresql
重啟服務器驗證設置是否成功
reboot
查詢服務啟動是否正常
systemctl status postgresql
文章來源:http://www.zghlxwxcb.cn/news/detail-727388.html
或者通過端口查看數(shù)據(jù)庫是否啟動文章來源地址http://www.zghlxwxcb.cn/news/detail-727388.html
lsof -i:5432
到了這里,關于linux下postgresql的安裝和部署的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!