一、前言
PostgreSQL通常也簡稱Postgres,是一個(gè)關(guān)系型數(shù)據(jù)庫管理系統(tǒng),適用于各種Linux操作系統(tǒng)、Windows、Solaris、BSD和Mac OS X。PostgreSQL遵循PostgreSQL許可,是一個(gè)開源軟件。PostgreSQL由PostgreSQL全球開發(fā)組開發(fā),由極少數(shù)的公司志愿組成并進(jìn)行監(jiān)督管理,這些公司有紅帽、EnterPRiseDB等。
PostgreSQL的知名度越來越大,這是理所當(dāng)然的:它是如此可靠、高效。與傳統(tǒng)企業(yè)級關(guān)系型數(shù)據(jù)庫相比,PostgreSQL完全基于社區(qū)驅(qū)動(dòng),有著豐富的工具和文檔,形成了一個(gè)完善的生態(tài)系統(tǒng)。
目前搜索的大部分CentOS下安裝均是用于Centos6.X的部分命令已經(jīng)有很大變化,本文主要記錄在Linux Centos 7.1下安裝PostgreSQL的過程。
二、安裝PostgreSQL源
CentOS 6.x 32bit
rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-6-i386/pgdg-centos94-9.4-1.noarch.rpm
CentOS 6.x 64bit
rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-1.noarch.rpm
CentOS 7 64bit
rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-1.noarch.rpm
在添加源的步驟中并沒有太多的區(qū)別,主要是源的地址有一定的變化。
三、執(zhí)行安裝命令
yum updateyum install postgresql94-server postgresql94-contrib
四、驗(yàn)證是否安裝成功
rpm -aq| grep postgres
執(zhí)行結(jié)果如下:
postgresql94-libs-9.4.1-1PGDG.rhel7.x86_64postgresql94-server-9.4.1-1PGDG.rhel7.x86_64postgresql94-9.4.1-1PGDG.rhel7.x86_64postgresql94-contrib-9.4.1-1PGDG.rhel7.x86_64
五、初始化數(shù)據(jù)庫
CentOS 6.x 系統(tǒng)
service postgresql-9.4 initdb
CentOS 7系統(tǒng)
/usr/pgsql-9.4/bin/postgresql94-setup initdb
如果我在CentOS 7下執(zhí)行service postgresql-9.4 initdb 將會(huì)報(bào)如下問題
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
六、啟動(dòng)服務(wù)并設(shè)置為開機(jī)啟動(dòng)
CentOS 6.x 系統(tǒng)
service postgresql-9.4 startchkconfig postgresql-9.4 on
CentOS 7系統(tǒng)
systemctl enable postgresql-9.4systemctl start postgresql-9.4
七、開放防火墻端口
CentOS 6.x 系統(tǒng)
vi /etc/sysconfig/iptables
按下I進(jìn)入輸入模式,在文件中加入一下語句
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
輸入完成后按ESC退出編輯模式,輸入:wq退出VI編輯界面。
重啟防火墻服務(wù)
service iptables restart
CentOS 7系統(tǒng)
firewall-cmd --permanent --add-port=5432/tcpfirewall-cmd --permanent --add-port=80/tcpfirewall-cmd --reload
八、訪問PostgreSQL
su - postgres
輸出結(jié)果如下:
上一次登錄:一 5月 18 15:17:29 CST 2015pts/0 上-bash-4.2$
輸入命令psql將看到PostgrSQL的版本信息。
psql (9.4.1)輸入 "help" 來獲取幫助信息.
九、設(shè)置postgres用戶密碼
postgres=# /passWord postgres

以上操作基本完成整個(gè)PostgreSQL的安裝。
十、修改配置文件,令服務(wù)器可通過遠(yuǎn)程訪問
對于未執(zhí)行該步驟的配置將無法通過pgadmin遠(yuǎn)程管理。運(yùn)行一下腳本修改pg的配置
echo "allow remote connections"cat >> /var/lib/pgsql/9.4/data/pg_hba.conf <<EOFhost all all 0.0.0.0/0 md5EOFecho "listen all"cat >> /var/lib/pgsql/9.4/data/postgresql.conf <<EOFlisten_addresses = '*'EOFsed 's/ssl = true/#ssl = true/' -i /var/lib/pgsql/9.4/data/postgresql.conf
新聞熱點(diǎn)
疑難解答
圖片精選