安裝PostgreSQL 15
1 安裝必要的依賴(lài)
#yum install -y readline-devel zlib-devel gcc
2、下載源碼
# wget https://ftp.postgresql.org/pub/source/v15.6/postgresql-15.6.tar.gz
# tar -xzvf postgresql-15.6.tar.gz
3 配置
# cd postgresql-15.6/
# ./configure
4 編譯安裝
# ./configure
# make
# make install
5 創(chuàng)建用戶(hù)和用戶(hù)組
# groupadd postgres
# useradd -g postgres postgres
# passwd postgres
更改用戶(hù) postgres 的密碼 。
新的密碼:
重新輸入新的密碼:
passwd:所有的身份驗(yàn)證令牌已經(jīng)成功更新。
6 初始化數(shù)據(jù)庫(kù)
6.1 創(chuàng)建數(shù)據(jù)目錄
# mkdir /usr/local/pgsql/data
# chown postgres /usr/local/pgsql/data
6.2 切換到 postgres 操作系統(tǒng)用戶(hù)
# su - postgres
6.3 初始化數(shù)據(jù)庫(kù)
[postgres@localhost ~]$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "zh_CN.UTF-8".
The default database encoding has accordingly been set to "UTF8".
initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
The default text search configuration will be set to "simple".
Data page checksums are disabled.
fixing permissions on existing directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Shanghai
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
6.4 啟動(dòng)數(shù)據(jù)庫(kù)
[postgres@localhost ~]$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
waiting for server to start.... done
server started
[postgres@localhost ~]$
把 start 改為 stop 就是停止。
7 安裝后的操作系統(tǒng)配置
7.1 以管理員的身份配置/etc/profile
在/etc/profile.d 目錄下新增 postgresql.sh 文件,內(nèi)容如下
[root@localhost profile.d]# cat postgresql.sh
export PATH=$PATH:/usr/local/pgsql/bin
7.2 設(shè)置開(kāi)機(jī)自動(dòng)啟動(dòng)
(1)創(chuàng)建啟動(dòng)文件
在/usr/lib/systemd/system 下創(chuàng)建文件 postgresql.service,內(nèi)容如下:
# vim postgresql.service
[Unit]
Description=PostgreSQL database server
After=network.target
[Service]
Type=forking
User=postgres
Group=postgres
OOMScoreAdjust=-1000
Environment=PGDATA=/usr/local/pgsql/data
Environment=PGPORT=5432
ExecStart=/usr/local/pgsql/bin/pg_ctl start -D ${PGDATA} -l ${PGDATA}/logfile -s -o "-p ${PGPORT}" -w -t 300
ExecStop=/usr/local/pgsql/bin/pg_ctl stop -D ${PGDATA} -l ${PGDATA}/logfile -s -m fast
ExecReload=/usr/local/pgsql/bin/pg_ctl reload -D ${PGDATA} -l ${PGDATA}/logfile -s
TimeoutSec=300
[Install]
WantedBy=multi-user.target
(2)設(shè)置自動(dòng)啟動(dòng)
# chmod a+x postgresql.service
# systemctl enable postgresql.service
# systemctl start postgresql.service
7.3 設(shè)置遠(yuǎn)程訪問(wèn)
PostgreSQL安裝后,默認(rèn)是只接受本地機(jī)器連接訪問(wèn)。如果想在其他主機(jī)上訪問(wèn)PostgreSQL數(shù)據(jù)庫(kù)服務(wù)器,就需要進(jìn)行相應(yīng)的配置。以下是我配置遠(yuǎn)程連接PostgreSQL數(shù)據(jù)庫(kù)方式:
(1)pg_hba.conf 配置PostgreSQL數(shù)據(jù)庫(kù)的訪問(wèn)權(quán)限
修改配置文件:(PostgreSQL安裝路徑下的data,也是安裝時(shí)data的默認(rèn)路徑)data目錄下的 pg_hba.conf 和 postgresql.conf。
# cd /usr/local/pgsql/data
# vim pg_hba.conf
找到“# IPv4 local connections:“后,回車(chē)另起一行,添加參數(shù)行如下,保存。
?host all all 0.0.0.0/0 trust
?
其中0.0.0.0/0表示運(yùn)行任意ip地址訪問(wèn)
??
(2)postgresql.conf 配置PostgreSQL數(shù)據(jù)庫(kù)服務(wù)器的相應(yīng)的參數(shù)
找到“l(fā)isten_addresses“參數(shù)后,設(shè)置listen_addresses = ‘*’,保存。
# vim postgresql.conf
??
設(shè)置好后重啟服務(wù)即可被遠(yuǎn)程連接。
8 問(wèn)題
8.1 遠(yuǎn)程連接失敗解決方案
一般服務(wù)器端防火窗入站規(guī)則打開(kāi)后,如果外部物理機(jī)遠(yuǎn)程連接失敗。 建議在服務(wù)器端安裝Navicat檢查是否能夠連接成功。如果可以連接成功,請(qǐng)?jiān)诜?wù)器進(jìn)行安全組端口開(kāi)放。
開(kāi)放端口
# systemctl start firewalld.service(開(kāi)啟防火墻)
# systemctl stop firewalld.service(關(guān)閉防火墻)
# systemctl status firewalld(查看防火墻是否開(kāi)啟)
如需要開(kāi)放80和443端口,如下:
# firewall-cmd --zone=public --permanent --add-port=80/tcp
# firewall-cmd --zone=public --permanent --add-port=443/tcp
# firewall-cmd --reload
查看所有開(kāi)啟的端口:
# firewall-cmd --list-ports
常用命令介紹:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-829761.html
firewall-cmd --state ##查看防火墻狀態(tài),是否是running
firewall-cmd --reload ##重新載入配置,比如添加規(guī)則之后,需要執(zhí)行此命令
firewall-cmd --get-zones ##列出支持的zone
firewall-cmd --get-services ##列出支持的服務(wù),在列表中的服務(wù)是放行的
firewall-cmd --query-service ftp ##查看ftp服務(wù)是否支持,返回yes或者no
firewall-cmd --add-service=ftp ##臨時(shí)開(kāi)放ftp服務(wù)
firewall-cmd --add-service=ftp --permanent ##永久開(kāi)放ftp服務(wù)
firewall-cmd --remove-service=ftp --permanent ##永久移除ftp服務(wù)
firewall-cmd --add-port=80/tcp --permanent ##永久添加80端口
iptables -L -n ##查看規(guī)則,這個(gè)命令是和iptables的相同的
?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-829761.html
到了這里,關(guān)于openEuler 22.03 LTS 上源碼安裝 PostgreSQL 15的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!