linux 安装postgresql 9.6

俩大步骤 1)更新yum源 2)安装postgresql9.6 数据库 注意:安装的过程中一路选择 yes

一、跟新yum源

1.查看centos 版本

 rpm -q centos-release

2.根据版本更新yum源

CentOS 5

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo

CentOS 6

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

CentOS 7

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

我的版本是centos7 所以我用

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

3.生成yum缓存

yum makecache

4.更新系统(生成了缓存,可以不用更新)

yum -y update

二、安装数据库

下载

1.创建PostgreSQL9.6的yum源文件

yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm

2.安装PostgreSQL客户端

yum install postgresql96  

3.安装PostgreSQL服务端

yum install postgresql96-server

4.安装PostgreSQL拓展包(可选)

yum install postgresql96-devel.x86_64

5.安装PostgreSQL的附加模块(可选)

yum install postgresql96-contrib.x86_64

配置初始化

初始化数据库

/usr/pgsql-9.6/bin/postgresql96-setup initdb

启动postgresql服务,并设置为开机自动启动

systemctl enable postgresql-9.6
systemctl start postgresql-9.6

postgres用户初始配置

安装完成后,操作系统会自动创建一个postgres用户用来管理数据库,为其初始化密码(输入命令后连输2次密码):

passwd postgres

数据库初始配置

使用数据库自带的postgres用户登录数据库,并为其赋予密码

su - postgres
psql -U postgres
alter user postgres with password '我的密码123456';

配置远程连接

先修改pg_hba.conf 修改一处(一般该文件放置在 /var/lib/pgsql/9.6/data)
先找到pg_hba.conf

find / -name 'pg_hba.conf'

在最后添加允许访问IP段(全网段可访问)

host all all 0.0.0.0/0 md5

后修改 postgresql.conf 修改两处(一般该文件放置在 /var/lib/pgsql/9.6/data)
先找到 postgresql.conf

find / -name 'postgresql.conf'

一找到用户参数listen_addresses(取消掉注释),改成下面样式:

listen_addresses = '*'

二启用密码验证

#password_encryption = on 修改为 password_encryption = on  (把前面的#号去掉)

重启数据库

systemctl restart postgresql-9.6 

之后就可以使用Navicat来连接 PostgreSql 了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值