PostgreSQL starts with the system
創(chuàng)新互聯(lián)建站專注于索縣企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,商城開發(fā)。索縣網(wǎng)站建設(shè)公司,為索縣等地區(qū)提供建站服務(wù)。全流程按需定制設(shè)計(jì),專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)建站專業(yè)和態(tài)度為您提供的服務(wù)The document describe how to configure automatic start PostgreSQL when the system starts.
The ways suitable for systemd on CentOS 7.0 or latest release.
1. Create and configure postgresql.service
# vim /usr/lib/systemd/system/postgresql.service
[Unit]
Description=PostgreSQL database server
After=remote-fs.target nss-lookup.target
After=network.target sshd.service
After=proc-fs-nfsd.mount
After=network.target local-fs.target
After=nfs-config.service
After=nfs-mountd.service
After=nfs-blkmap.service
After=nfs-client.target
After=nfs-config.service
After=nfs-idmapd.service
After=nfs-idmap.service
After=nfs-lock.service
After=nfslock.service
After=nfs-mountd.service
After=nfs-secure-server.service
After=nfs-secure.service
After=nfs.service
After=nfs-utils.service
[Service]
Type=forking
User=postgres
Group=appuser
Environment=PGPORT=5432
Environment=PGDATA=/data/01/local/pgsql/data
ExecStart=/data/01/local/pgsql/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300
ExecStop=/data/01/local/pqsql/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/data/01/local/pgsql/bin/pg_ctl reload -D ${PGDATA} -s
TimeoutSec=300
[Install]
WantedBy=remote-fs.target
#chmod 644 /usr/lib/systemd/system/postgresql.service
2. Reload systemd and enable postgresql.service
#systemctl daemon-reload
#systemctl enable postgresql.service
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql.service to /usr/lib/systemd/system/postgresql.service.
#systemctl is-enabled postgresql.service
Enabled
#systemctl start postgresql.service
#systemctl status postgresql.service
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2018-02-23 22:48:49 KST; 28min ago
Main PID: 2506 (postgres)
CGroup: /system.slice/postgresql.service
├─2506 /data/01/local/pgsql/bin/postgres -D /data/01/local/pgsql/data -p 5432
├─2508 postgres: logger process
├─2510 postgres: checkpointer process
├─2511 postgres: writer process
├─2512 postgres: wal writer process
├─2513 postgres: autovacuum launcher process
└─2514 postgres: stats collector process
Feb 23 22:48:47 ec5d-pbfcompilation-02 systemd[1]: Starting PostgreSQL database server...
Feb 23 22:48:48 ec5d-pbfcompilation-02 pg_ctl[1414]: < 2018-02-23 22:48:48.671 KST >LOG: redirecting log output to logging collector process
Feb 23 22:48:48 ec5d-pbfcompilation-02 pg_ctl[1414]: < 2018-02-23 22:48:48.671 KST >HINT: Future log output will appear in directory "pg_log".
Feb 23 22:48:49 ec5d-pbfcompilation-02 systemd[1]: Started PostgreSQL database server.
Note: CentOS7.x not support /etc/rc.local script file, Detailed description as following:
#cat /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#這是明智的在系統(tǒng)重啟的時(shí)候,去創(chuàng)建一個(gè)systemd 服務(wù)或者udev規(guī)則去運(yùn)行腳本,而不是用/etc/rc.local
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#與先前的系統(tǒng)版本相比較,在系統(tǒng)啟動(dòng)的時(shí)候,由于服務(wù)是并行運(yùn)行的,所以在其他服務(wù)啟動(dòng)之后,/etc/rc.local不會(huì)運(yùn)行
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
雖然這里說(shuō)可以使用chmod +x /etc/rc.local 去執(zhí)行這個(gè)腳本,但是筆者在這個(gè)文件中添加一行:su - postgres -c ‘pg_ctl start -D /usr/local/pgsql/data’
然后reboot測(cè)試了多次,postgres最后都沒有隨系統(tǒng)啟動(dòng)成功,所以不再推薦(官方也不推薦了)使用/etc/rc.local文件的方式啟動(dòng)postgres,啟動(dòng)其他服務(wù)也一樣,最好配置一個(gè)systemd服務(wù)。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
本文標(biāo)題:Centos7.x配置PostgreSQL自啟動(dòng)-創(chuàng)新互聯(lián)
網(wǎng)站地址:http://aaarwkj.com/article22/jchcc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、App開發(fā)、響應(yīng)式網(wǎng)站、用戶體驗(yàn)、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容