美文网首页
Centos7下安装PostgreSQL10

Centos7下安装PostgreSQL10

作者: BoscoLam | 来源:发表于2017-12-15 17:23 被阅读0次

最近工作中要把服务器的postgreSQL更新到10,运维什么的都要自己来,根据pylixm大神记录,自己整理下,供以后方便使用。

准备工作

检查系统是否已安装postgreSQL,卸载并清除干净。

$ rpm -qa | grep postgres                # 检查PostgreSQL 是否已经安装

$ rpm -qal | grep postgres                # 检查PostgreSQL 安装位置

#卸载

$ rpm -e postgresql94-contrib-9.4.4-1PGDG.rhel6.x8664 postgresql94-server-9.4.4-1PGDG.rhel6.x8664

$ rpm -e postgresql94-libs-9.4.4-1PGDG.rhel6.x8664 postgresql94-9.4.4-1PGDG.rhel6.x8664

安装yum源

获取到yum源的正确链接再执行安装

yum installhttps://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-1.noarch.rpm

安装客户端和服务端

yum install postgresql10

yum install postgresql10-server

初始化数据库,启动服务

/usr/pgsql-10/bin/postgresql-10-setup initdb

systemctl enable postgresql-10

systemctl start postgresql-10

说明(可不用执行):

数据库默认路径:/var/lib/pgsql/10/data

修改默认初始化路径,使用postgreSQL自带的初始化命令initdb,如下操作:

$mkdir /opt/PostgreSQL

$mkdir /opt/PostgreSQL/data

$chmod 755 /opt/PostgreSQL/data

$chown postgres:postgres /opt/PostgreSQL/data

$su - postgres

$./initdb --encoding=UTF-8  --local=zh_CN.UTF8 --username=postgres --pwprompt --pgdata=/opt/PostgreSQL/data/

连接数据库

postgresql10 在Linux的安装,默认创建了postgres用户,无需再次创建,直接su - postgres即可

数据库登录权限设置

/var/lib/pgsql/10/data/pg_hba.conf    权限相关配置

说明: 设置 trust,本地可以使用psql -U postgres直接登录服务器;设置 peer,本地可以使用psql -h 127.0.0.1 -d postgres -U postgres直接登录服务器; password ,使用用户名密码 登录。

/var/lib/pgsql/10/data/postgresql.conf数据库相关配置

防火墙设置

此时,数据库可以在本地访问,要想在外部访问,还需要增加防火墙策略或直接关闭防火墙(不建议)。

centos 7 默认防火墙为firewalld, 我们改用熟悉的iptables操作如下:

1、关闭firewalld:

systemctl stop firewalld.service                #停止firewall

systemctl disable firewalld.service            #禁止firewall开机启动

firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)

2、iptables防火墙

yum install iptables iptables-services    # 安装

vi /etc/sysconfig/iptables         #防火墙相关配置  

systemctl restart iptables.service          #最后重启防火墙使配置生效

systemctl enable iptables.service          #设置防火墙开机启动

至此,我们已经安装并配置好数据库,可以愉快的玩耍了。

参考:http://pylixm.cc/posts/2017-11-05-postgresql-install.html

相关文章

网友评论

      本文标题:Centos7下安装PostgreSQL10

      本文链接:https://www.haomeiwen.com/subject/psmdwxtx.html