PostgreSQL安裝與設定
本教程適合Centos6.7或者RedHat.
PostgreSQL安裝
1、Postgresql安裝包確認
yum list postgresql* postgresql-server.x86_64 8.4.20-8.el6_9 base postgresql.x86_64 8.4.20-8.el6_9 base
2、Postgresql安裝
yum install -y postgresql-server
3、安裝結果確認
rpm -qa | grep postgresql postgresql-8.4.20-8.el6_9.x86_64 postgresql-libs-8.4.20-8.el6_9.x86_64 postgresql-server-8.4.20-8.el6_9.x86_64
PostgreSQL設定
1、資料庫初期化
/etc/rc.d/init.d/postgresql initdb
將生成/var/lib/pgsql/data目錄
2、外部連結與Port番號設定
vi /var/lib/pgsql/data/postgresql.conf #全部可連結 listen_addresses = '*' port = 5432 #log出力形式(時間,使用者,資料庫,程序,行號) log_line_prefix = '%t %u %d [%p-%l]'
3、資料庫訪問設定
vi /var/lib/pgsql/data/pg_hba.conf #所有的使用者和IP地址都可以訪問lxb資料庫 hostlxball0.0.0.0/0trust
4、系統服務設定(預設是登入狀態)
ls /etc/init.d/ | grep post postfix postgresql udev-post
5、Postgresql服務OS系統啟動時自動啟動設定
#設定狀態確認 chkconfig --list postgresql postgresql0:off1:off2:off3:off4:off5:off6:off #開啟自啟動服務 chkconfig postgresql on #設定狀態再次確認 chkconfig --list postgresql postgresql0:off1:off2:on3:on4:on5:on6:off
6、啟動PostgreSQL服務
service postgresql start postgresql サービスを開始中:[OK] service postgresql status postmaster (pid5176) を実行中..
資料庫設定
1、預設超級管理使用者密碼變更
#切換超級使用者 su - postgres #密碼變更 psql -c "alter user postgres with password 'Admin'"
2、建立使用者與資料庫
#建立使用者 createuser test #資料庫建立 createdb lxb
3、資料庫列表確認
psql -l -----------+----------+------------------+-------------+-------------------+----------------------- postgres| postgres | UTF8| ja_JP.UTF-8 | ja_JP.UTF-8| lxb| postgres | UTF8| ja_JP.UTF-8 | ja_JP.UTF-8| template0 | postgres | UTF8| ja_JP.UTF-8 | ja_JP.UTF-8| =c/postgres : postgres=CTc/postgres template1 | postgres | UTF8| ja_JP.UTF-8 | ja_JP.UTF-8| =c/postgres : postgres=CTc/postgres (4 行)
4、連結資料庫
#連結lxb資料庫 psql lxb psql (8.4.20) #test使用者密碼設定 lxb=# alter user test with password 'Test'; ALTER ROLE
資料庫操作命令參照官網:ofollow,noindex">https://www.postgresql.org/docs/9.4/static/app-psql.html
總結
由於一直習慣於Windows系的安裝包式安裝,Centos上安裝還是頭一次,所以找了很多資料才得以完成。以上只實現了基礎安裝,基本上測試夠用了,實際上線時安全與容災方面的設定還需各自探討進行設定。