记一次 Centos7.4 使用 yum 安装 PostgreSql v11

一、基础信息说明

官网:https://www.postgresql.org/

下载说明地址:https://www.postgresql.org/download/linux/redhat/

中文社区 http://www.postgres.cn/index.php/v2/home

中文网 https://postgres.fun/

易百教程 https://www.yiibai.com/postgresql

二、系统、工具说明

1、系统版本 Centos7.4    CentOS-7-x86_64-Minimal-1804

下载地址:  http://archive.kernel.org/centos-vault/7.4.1708/isos/x86_64/   

2、VMware 版本:VMware Workstation Pro15

虚拟机安装过程可参考:https://blog.csdn.net/llwy1428/article/details/89328381

3、工具:xshell5

三、安装、部署

1、配置虚拟机网络,每台虚拟机均接入互联网

参考:

https://blog.csdn.net/llwy1428/article/details/85058028

2、设置静态IP

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33

[root@localhost ~]# service network restart

3、安装基本工具

[root@localhost ~]# yum install -y vim lrzsz tree wget rpm net-tools
[root@localhost ~]# yum update -y

4、浏览器打开 https://www.postgresql.org/download/linux/redhat/ 

如下图:

5、安装资源 rpm 、客户端、服务端

[root@localhost ~]# yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
[root@localhost ~]# yum install -y postgresql11

[root@localhost ~]# yum install -y postgresql11-server

6、数据库初始化

[root@localhost ~]# /usr/pgsql-11/bin/postgresql-11-setup initdb
效果:
Initializing database ... OK

7、设置允许外部连接

查看目录

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

[root@localhost ~]# vim /var/lib/pgsql/11/data/pg_hba.conf
host    all             all             0.0.0.0/0               md5

说明:

TYPE:pg的连接方式,local:本地unix套接字,host:tcp/ip连接

DATABASE:指定数据库

USER:指定数据库用户

ADDRESS:ip地址,可以定义某台主机或某个网段,32代表检查整个ip地址,相当于固定的ip,24代表只检查前三位,最后一                         位是0~255之间的任何一个

METHOD:认证方式,常用的有ident,md5,password,trust,reject。

                      md5是常用的密码认证方式。

                      password是以明文密码传送给数据库,建议不要在生产环境中使用。

                      trust是只要知道数据库用户名就能登录,建议不要在生产环境中使用。

                      reject是拒绝认证。

8、防火墙开放 5432 端口(条件允许可关闭防火墙)

例如:
[root@localhost ~]# firewall-cmd --zone=public(作用域) --add-port=80/tcp(端口和访问类型) --permanent(永久生效)
操作:
[root@localhost ~]# firewall-cmd --zone=public --add-port=5432/tcp --permanent
success
[root@localhost ~]#  firewall-cmd --reload
success

其它防火墙操作可参考:

https://blog.csdn.net/llwy1428/article/details/99676257

9、 postgresql 安装目录授权

[root@localhost ~]# chown postgres:root -R /usr/pgsql-11/

10、启动服务

[root@localhost ~]# systemctl start postgresql-11
[root@localhost ~]# netstat -lntp

11、切换用户,设置数据库密码

[root@localhost ~]# su - postgres
-bash-4.2$ psql -U postgres
postgres=# ALTER USER postgres with encrypted password '123456';
postgres=# \l

注意:遇到启动错误及解决方式:

[root@localhost ~]# systemctl start postgresql-11
Job for postgresql-11.service failed because the control process exited with error code. See "systemctl status postgresql-11.service" and "journalctl -xe" for details.

查看错误详情:

[root@localhost ~]# journalctl -xe

说明:data 目录下信息可能丢失

重新初始化,提示 data 目录已经存在

[root@localhost ~]# /usr/pgsql-11/bin/postgresql-11-setup initdb
Data directory is not empty!

删除现有 data 目录下的所有信息

[root@localhost ~]# rm -rf /var/lib/pgsql/11/data/*

重新执行数据库初始化:

[root@localhost ~]# /usr/pgsql-11/bin/postgresql-11-setup initdb
Initializing database ... OK

再次启动 postgresql 服务

[root@localhost ~]# systemctl start postgresql-11
[root@localhost ~]# netstat -lntp

12、第三方客户端工具测试连接:

 

 

至此  Centos7.4  使用  yum  安装 PostgreSql   v11  操作完毕!

安装、配置 Pgadmin 可参考:

https://hunter.blog.csdn.net/article/details/102486511

扩展:Centos7 编译安装 PostgreSql 11.4

https://blog.csdn.net/llwy1428/article/details/95444151

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值