资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

包含postgresql配置的词条

如何把postgresql 加入systemctl

您高兴能帮助您 1.安装PostgreSQL 首先根据服务器架构添加PostgreSQL库: CentOS 6.x 32bit: rpm -Uvh 1.noarch.rpm CentOS 6.x 64bit: rpm -Uvh

创新互联建站主要从事成都网站制作、网站设计、网页设计、企业做网站、公司建网站等业务。立足成都服务华龙,十多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:028-86922220

.安装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的安装文件夹\8.3\data\pg_hba.conf里面(或者在开始菜单程序下面的postgresql的配置文档)找到“# IPv4 local connections:”(不包括引号,下同) 在它上面添加“local pgsql all trust”,在它下面的“host all all 127.0.0.1/32 md5”

下面添加一行,内容为“host all all 192.168.91.1/24 md5”

注:127.0.0.1/32和192.168.91.1/24中的32与24,用32表示该IP被固定,用24表示前3位固定, 后面一位可以由自己设,这样,前3位ip地址与该设定相同的计算机就可以访问postgresql数据库。

二、 "PostgreSQL\8.3\data\postgresql.conf文件中,找到“#listen_addresses = 'localhost'”,把它改成“listen_addresses = '*'”。

" 这样,postgresql就可以监听所有ip地址的连接。

三、 重启postgresql服务。如果系统启用了防火墙,请先关闭。

CentOS 7 安装&配置PostgreSQL 12(附图片详解)

启动pg服务

设置pg服务为开机启动

-bash: netstat: 未找到命令

再次执行

使用navicat连接是无法连接的。

【遇到的问题】若没有可以跳过

【解决办法】

修改/usr/bin/firewall-cmd 下文件在首行 python改为python2(因为之前安装过python3环境)

listen_addresses='*'

或者加 ip网段

配置完成后即可使用客户端进行连接

大功告成~~

————————————————

参考 链接:

如何设置PostgreSQL允许被远程访问

通过以上设置后,远端及其无法访问此数据库,因此,需要修改postgreSQL数据库配置来实现远程访问。具体操作如下:

修改/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

虚拟机中如何安装PostgreSQL数据库?

配置PostgreSQL对应的yum源

使用命令:dnf install -y ,获取yum配置文件。

安装PostgreSQL13对应的rpm包

一般来说PostgreSQL需要安装的包包括:

依赖库包:postgresql13-libs.x86_64

模块分布式:postgresql13-contrib.x86_64

客户端:postgresql13.x86_64

服务端:postgresql13-server.x86_64

创建postgres用户及组

groupadd postgres 创建postgres组

useradd -g postgres创建postgres用户

初始化数据库

安装postgresql数据库后,默认的数据目录为: /var/lib/pgsql/10/data/。但是在实际使用中,我们必须为postgresql数据库指定专用的数据路径。

1、创建指定路径

mkdir -p /data/pgdata

2、修改pgdata的所有者

chown postgres /data/pgdata

3、切换到postgres用户

su - postgres?

4、初始化postgres数据库实例

/usr/pgsql-13/bin/initdb -D /data/pgdata

到这里就安装完成了。


网页标题:包含postgresql配置的词条
转载注明:http://cdkjz.cn/article/dsdpscc.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220