Linux與雲計算——第二階段Linux服務器架設 第一十二章:數據庫搭建—PostgreSQL

Linux與雲計算——第二階段Linux服務器架設

第一十二章:數據庫搭建—PostgreSQL

1.1 安裝PostgreSQL

[1] 安裝並啓動PostgreSQL.

[root@server ~]# yum -y install postgresql-server

[root@server ~]# postgresql-setup initdb

Initializing database ... OK

[root@server ~]# vim /var/lib/pgsql/data/postgresql.conf

# line 59: 取消備註並且修改以便遠程主機訪問

listen_addresses = '*'

# line 395: 取消備註並且修改日誌格式

log_line_prefix = '%t %u %d '

[root@server ~]# systemctl start postgresql

[root@server ~]# systemctl enable postgresql

[2] 設置PostgreSQL管理員用戶的密碼並且添加一個用戶和測試數據庫。

# 設置密碼

[root@server ~]# su - postgres

-bash-4.2$ psql -c "alter user postgres with password 'redhat'"

ALTER ROLE

# 添加DB用戶 "jeffrey"

-bash-4.2$ createuser jeffrey

# 添加測試數據庫

-bash-4.2$ createdb testdb -O jeffrey

[3] 登陸用戶並且操作數據庫.

# 查看數據庫

[jeffrey@server ~]$ psql -l

                                  List of databases

   Name    |  Owner   | Encoding |   Collate          |    Ctype          |   Access privileges   

-----------+----------+----------+-------------+-------------+-----------------------

 postgres  | postgres  | UTF8        | en_US.UTF-8 | en_US.UTF-8 |

 template0 | postgres | UTF8      | en_US.UTF-8  | en_US.UTF-8  | =c/postgres          +

            |                 |                |                          |                          | postgres=CTc/postgres

 template1 | postgres  | UTF8     | en_US.UTF-8 | en_US.UTF-8   | =c/postgres          +

      |                  |               |                           |                         | postgres=CTc/postgres

 testdb        |  jeffrey     |   UTF8     |   en_US.UTF-8   |   en_US.UTF-8   |

(4 rows)

# 連接到測試DB

[jeffrey@server ~]$ psql testdb

psql (9.2.13)

Type "help" for help.

# 配置密碼

testdb=> alter user jeffrey with password 'redhat';

ALTER ROLE

# 創建測試

testdb=>create table test ( no int,name text );

CREATE TABLE

# 插入測試數據

testdb=>insert into test (no,name) values (1,'jeffrey');

INSERT 0 1

# 查看錶

testdb=> select * from test;

 no | name

----+-------

  1 | jeffrey

(1 row)

# 刪除測試數據庫

testdb=>drop table test;

DROP TABLE

# 退出

testdb=>\q

# 刪除測試DB

[jeffrey@server ~]$ dropdb testdb 

1.2 安裝phpPgAdmin

[1] 安裝和配置HTTPD。

[2] 安裝PHP

[root@server ~]# yum -y install php php-mbstring php-pear

[3] 安裝phpPgAdmin.

[root@server ~]# yum -y install phpPgAdmin php-pgsql

[root@server ~]# vi /etc/phpPgAdmin/config.inc.php

# line 18: 增加

$conf['servers'][0]['host'] = 'localhost';

# line 93: 如果你允許類似於root或postgres這些特權用戶登陸的話,修改爲false

$conf['extra_login_security'] = false;

# line 99: 修改

$conf['owned_only'] = true;

[root@server ~]# vi /var/lib/pgsql/data/pg_hba.conf

# line 82: 參考下面內容修改並且添加訪問許可

 host    all         all         127.0.0.1/32          md5

host    all         all         192.168.96.0/24           md5

host    all         all         ::1/128               md5

[root@server ~]# vim /etc/httpd/conf.d/phpPgAdmin.conf

# line 11:添加訪問許可

Require local

Require ip 192.168.96.0/24

[root@server ~]# systemctl restart postgresql httpd


[4]
訪問"http://(主機名或者IP地址/phpPgAdmin/" 在左邊菜單中點擊"PostgreSQL" 

 wKiom1eufu7QCnYfAACM8ej321A293.png-wh_50

 

[5] 輸入認證的用戶名和密碼PostgreSQL.

 

wKioL1eufwfzHCN3AABis0o1-Y0074.png-wh_50


[6]
成功登陸系統,並可以在此配置數據庫.

wKiom1eufxbx08h4AAB3aWmTk9Q271.png-wh_50

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章