记一次 Centos7 编译安装 PostgreSql 11.4

一、基本信息

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

下载 https://www.postgresql.org/download/

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

中文网 https://postgres.fun/

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

二、系统及工具

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

2、VMware 版本:VMware Workstation Pro15

3、工具:xshell5

4、PostgreSql: postgresql-11.4.tar.gz

三、安装部署

1、安装基本工具

[root@localhost ~]# yum install -y vim lrzsz tree wget gcc gcc-c++ readline-devel

2、创建目录,并进入指定目录

[root@localhost ~]# mkdir /opt/postgresql
[root@localhost ~]# cd /opt/postgresql

3、下载

[root@localhost postgresql]# wget https://ftp.postgresql.org/pub/source/v11.4/postgresql-11.4.tar.gz

4、解压、查看目录

[root@localhost postgresql]# tar zxvf postgresql-11.4.tar.gz

5、编译

[root@localhost postgresql-11.4]# ./configure --prefix=/usr/local/postgresql

6、安装

[root@localhost postgresql-11.4]# make && make install

7、进入安装后的目录,查看目录结构

[root@localhost ~]# cd /usr/local/postgresql/

8、创建目录 data、log

[root@localhost postgresql]# mkdir /usr/local/postgresql/data
[root@localhost postgresql]# mkdir /usr/local/postgresql/log

9、加入系统环境变量

[root@localhost ~]# vim /etc/profile

在最后写入如下内容

PGHOME=/usr/local/postgresql
export PGHOME
PGDATA=/usr/local/postgresql/data
export PGDATA
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$PGHOME/bin
export PATH

使配置文件生效

[root@localhost ~]# source /etc/profile

10、增加用户 postgres 并赋权

[root@localhost ~]# adduser postgres
[root@localhost ~]# chown -R postgres:root /usr/local/postgresql/

11、初始化数据库

切换用户 postgres

[root@localhost ~]# su postgres
[postgres@localhost root]$ /usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data/

注意:

不能在 root 用户下初始数据库,否则会报错

[root@localhost ~]# /usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data/
initdb: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.

12、编辑配置文件

[postgres@localhost ~]# vim /usr/local/postgresql/data/postgresql.conf
listen_addresses = '*'
port = 5432
[postgres@localhost ~]$ vim /usr/local/postgresql/data/pg_hba.conf

说明:

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是拒绝认证。

13、启动服务

[postgres@localhost ~]$ pg_ctl start -l /usr/local/postgresql/log/pg_server.log

14、查看版本

[postgres@localhost ~]$ psql -V
psql (PostgreSQL) 11.4

15、登录数据库

[postgres@localhost ~]$ psql -U postgres -d postgres

第三方工具测试连接

 

注意:生产环境,一定要修改密码验证方式

 

至此,Centos7 安装 PostgreSql 安装部署完毕!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值