
修改/opt/postgres/9.1/data/postgresql.conf文件的内容:
监听任何地址的访问,修改连接权限:
#listen_address = ‘localhost’ 修改为listen_address = ‘*’
启用密码验证
#password_encryption = on 修改为 password_encryption = on
修改/opt/postgres/9.1/data/pg_hba.conf文件的内容:
可访问的用户ip段
在文件末尾加入:host all all 0.0.0.0/0 md5
重启postgreSQL数据库:sudo /etc/init.d/postgresql-9.1-openscg restart
您高兴能帮助您 1.安装PostgreSQL 首先根据服务器架构添加PostgreSQL库: CentOS 6.x 32bit: rpm -Uvh 1.noarch.rpm CentOS 6.x 64bit: rpm -Uvh.安装PostgreSQL
首先根据服务器架构添加PostgreSQL库:
于其发行版查看链接并建立库:
使用命令更新库:
yum update
使用命令安装PostgreSQL:
yum install postgresql93-server postgresql93-contrib
使用命令初始化PostgreSQL数据库:
CentOS 6.x 系统:
service postgresql-9.3 initdb
CentOS 7系统:
/usr/pgsql-9.3/bin/postgresql93-setup initdb
启PostgreSQL服务并使机自启:
CentOS 6.x 系统:
service postgresql-9.3 start
chkconfig postgresql-9.3 on
CentOS 7系统:
systemctl enable postgresql-9.3
systemctl start postgresql-9.3
2.调整Iptables/Firewall
接调整防火墙站规则:
CentOS 6.x系统:
vi /etc/sysconfig/iptables
并添加行
-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
退并保存文件重启iptables服务:
service iptables restart
CentOS系统:
firewall-cmd --permanent –add-port=5432/tcp
firewall-cmd --permanent –add-port=80/tcp
firewall-cmd --reload
3.访问PostgreSQL用命令提示符
默认情况数据库名用户名都postgres切换至用户执行相关 *** 作:
su – postgres
输入命令登陆:
psql
例输:
psql (9.3.5)
Type "help" for help.
Postgres=#
通输入\q退postgresql返命令终端:
4.设置用户密码
登陆至postgres命令提示符界面
su – postgres
psql
使用命令设置密码
postgres=# \password postgres
Enter new password:
Enter it again:
postgres=# \q
输入命令建立PostgreSQL系统管理工具
postgres=# CREATE EXTENSION adminpack
CREATE EXTENSION
5.创建用户数据库
例:用户名:senthil 密码:centos 数据库名:mydb
转postgres用户
su – postgres
创建用户senthil
$ createuser senthil
创建数据库
$ createdb mydb
现登陆至psql提示符界面用户senthil设置密码及授权数据库mydb访问:
$ psql
psql (9.3.5)
Type "help" for help.
postgres=# alter user senthil with encrypted password 'centos'
ALTER ROLE
postgres=# grant all privileges on database mydb to senthil
GRANT
postgres=#
6.删除用户数据库
首先转postgres界面
su – postgres
输入命令
$ dropdb <database-name>
删除用户名输入
$ dropuser <user-name>
7.配置PostgreSQL-MD5认证
MD5认证需要客户端提供MD5-encrypted 密码便身份验证需要编辑 /var/lib/pgsql/9.3/data/pg_hba.conf文件:
vi /var/lib/pgsql/9.3/data/pg_hba.conf
添加或修改行:
[...]
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 192.168.1.0/24 md5
# IPv6 local connections:
host all all ::1/128 md5
[...]
重启postgresql服务应用更改
CentOS 6.x系统
service postgresql-9.3 restart
CentOS 7系统
systemctl restart postgresql-9.3
8.配置PostgreSQL-Configure TCP/IP
默认情况TCP/IP连接行所其计算机用户能连接postgresql编辑文件 /var/lib/pgsql/9.3/data/postgresql.conf允许连接:
vi /var/lib/pgsql/9.3/data/postgresql.conf
找面行:
[...]
#listen_addresses = 'localhost’
[...]
#port = 5432
[...]
两行都取消并设置postgresql服务器IP址或设置*监听所客户端所示:
listen_addresses = '*'
port = 5432
重启应用更改
CentOS6.x系统:
/etc/init.d/postgresql-9.3 restart
CentOS7系统:
systemctl restart postgresql-9.3
9.使用phpPgAdmin管理PostgreSQL
phpPgAdmin使用PHP编写基于web管理工具用于管理PostgreSQL适用与PostgreSQL RPM库
没添加PostgreSQL库添加EPEL库
使用命令更新库
yum update
现输入命令安装phpPgAdmin:
yum install phpPgAdmin httpd
注意phpPgAdmin区写要准确使用面所示写
编辑文件/etc/httpd/conf.d/phpPgAdmin.conf
vi /etc/httpd/conf.d/phpPgAdmin.conf
修改加粗部:
[...]
Alias /phpPgAdmin /usr/share/phpPgAdmin
<Location /phpPgAdmin>
<IfModule mod_authz_core.c>
# Apache 2.4
Require all granted
#Require host example.com
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order deny,allow
Allow from all
# Allow from .example.com
</IfModule>
</Location>
启或重启Apache服务
CentOS 6.x系统
service httpd start
chkconfig httpd on
CentOS 7系统
systemctl enable httpd
systemctl start httpd
现打浏览器并转终于看面界面
使用前创建用户登录我用户senthil密码CentOS
能遇:Login failed
SELLinux能限制用户连接PostgreSQL需输入命令更改即:
setsebool -P httpd_can_network_connect_db 1
现应该能登录
我phpPgAdimn:
OK现使用图形化界面phpPgAdmin创建、删除管理数据库
postgresql是功能强大的开源数据库。
postgresql数据库是功能强大的开源数据库,它支持丰富的数据类型(如JSON和JSONB类型、数组类型)和自定义类型。
PostgreSQL数据库提供了丰富的接口,可以很方便地扩展它的功能,如可以在GiST框架下实现自己的索引类型,支持使用C语言写自定义函数、触发器,也支持使用流行的编程语言写自定义函数。
PostgreSQL数据库优点
1、对超许可数量软件使用的天然免疫力
对一些商业性质的数据库销售商来说,超许可数量的软件使用是第一位的问题。而使用PostgreSQL,因为没有任何授权的费用是,也就没有任何人可以起诉您违反授权协议违规使用软件。
2、比商业服务商更好的支持
除了有一般商业公司的支持外,我们还有由PostgreSQL专业人员和热心的爱好者组成的各种社区,用户可以向他们寻求支持和帮助。
3、员工成本的显著降低
相对于市场上大型的商业私有数据库软件,我们的系统在设计和开发时已考虑仅需少量的维护和优化,同时仍保持所有功能正常、稳定和性能正常。不仅如此,我们的培训过程相对于那些商业私有数据库供应商来说,总体来说有更好的性价比、更容易管理和更接近真实的使用场景。
4、享有盛名的可靠性和稳定性
与很多商业私有数据库不一样的是,对很多公司特别常见的是,PostgreSQL在几年的运行过程中几乎未出现哪怕是一次的宕机情况,即使是一次,它就是这样稳定地工作着。
5、扩展性
所有PostgreSQL的源代码对所有人都是可以免费获得的。如果您的公司员工需要定制或是给PostgreSQL增加一些功能,他们只需做很少的改动工作,也没有额外的成本。全球PostgreSQL社区的专业人员和热心的爱好者也在积极地扩展PostgreSQL的功能。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)