2024-08-15 麒麟V10.X86_64安裝postgresql

前言

使用yum安裝postgresql,裝了一天,剛啟動起來,記錄一下

本章用到的一些命令

1、yum list installed 查看系統(tǒng)安裝了哪些yum軟件
2、yum search "postgresql" 查看yum源有哪些postgresql開頭的包
3、yum list "postgis
" 好像和上面類似
4、find / -name "bin" 查找電腦中關(guān)鍵字 bin 的目錄和文件

安裝步驟

1、安裝客戶端
yum -y install postgresql
2、安裝服務(wù)端
yum -y install postgresql-server
3、創(chuàng)建用戶:
useradd postgres
4、修改postgres用戶密碼方法一:
echo "密碼" | passwd --stdin postgres

Postgresql默認的數(shù)據(jù)目錄是/var/lib/pgsql/版本號/data目錄,這要求你在/var下有足夠的存儲空間,我們這里將其換掉,假設(shè)/home的空間很大。首先在/home下創(chuàng)建一個Postgresql的數(shù)據(jù)目錄,指定所有者postgres同時分配權(quán)限
1、創(chuàng)建目錄:
mkdir /home/postgresql_data
2、分配給postgres權(quán)限:chown postgres:postgres /home/postgresql_data
chmod 750 /home/postgresql_data

3、設(shè)置環(huán)境變量目前這步?jīng)]做,
vim /etc/profile
在末尾打開后增加如下信息:i-->插入功能
export PATH=/usr/pgsql-10/bin:$PATH
export LD_LIBRARY_PATH=/usr/pgsql-10/lib
export PGDATA=/home/postgresql_data
esc-->:wq退出
4、添加后刷新一下
source /etc/profile

5、 切換到posgtres用戶下使用initdb初始化數(shù)據(jù)庫
su postgres
cd /home/postgresql_data/
initdb -D /home/postgresql_data
這樣在/home/postgresql_data下會增加很多東西

6、修改/usr/lib/systemd/system/postgresql.service文件的內(nèi)容
Environment=PGDATA=/home/postgresql_data

7、修改配置 /home/postgresql_data/pg_hba.conf文件,文件末尾按鍵盤“i”鍵,輸入host all all 0.0.0.0/0 md5之后按鍵盤“esc”輸入:wq保存退出。


1204515-20230316173638325-2761232.png

8、編輯vim postgresql.conf:修改在文件中找到#listen_addresses = 'localhost' 按鍵盤“i”切換為輸入模式,改為listen_addresses = '*'


1204515-20230316174004831-1319458484.png

找到#password_encryption = md5修改為password_encryption = on


1204515-20230316174004831-1319458484.png

取消端口注釋port=5432;
1204515-20230316174004831-1319458484.png

三、配置數(shù)據(jù)庫服務(wù)開機啟動并立即啟動數(shù)據(jù)庫服務(wù)
1、設(shè)置開機自動啟動服務(wù):systemctl enable postgresql.service
2、開啟postgres服務(wù):service postgresql start (systemctl start postgresql.service)
3、查看postgres服務(wù)狀態(tài)service postgresql status # active (running)表示該服務(wù)正在運行
4、關(guān)閉postgres服務(wù):service postgresql stop(systemctl stop postgresql.service) # inactive (dead)表示該服務(wù)已經(jīng)停止運行
5、排錯:如果啟動失敗如下圖:


1204515-20230316174004831-1319458484.png

處理辦法:進入目錄/home/postgresql_data下的postmaster.pid刪除再重啟服務(wù)就好了
6、 關(guān)閉防火墻輸入systemctl stop firewalld
7、 開機關(guān)閉防火墻輸入systemctl disable firewalld
8、 啟動防火墻輸入systemctl status firewalld.service

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容