Linux与云计算——第二阶段Linux服务器架设 第一十二章:数据库搭建—PostgreSQL

Linux与云计算——第二阶段Linux服务器架设

第一十二章:数据库搭建—PostgreSQL

1.1 安装PostgreSQL

[1] 安装并启动PostgreSQL.

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

[root@server ~]# postgresql-setup initdb sql

Initializing database ... OK数据库

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

# line 59: 取消备注而且修改以便远程主机访问bash

listen_addresses = '*'服务器

# line 395: 取消备注而且修改日志格式ide

log_line_prefix = '%t %u %d 'post

[root@server ~]# systemctl start postgresql 测试

[root@server ~]# systemctl enable postgresqlui

[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

相关文章
相关标签/搜索