Linux下源码编译安装PostgreSQL

操作系统:Centos

下载源码包

https://www.postgresql.org/ftp/source/v10.3/

解压

# tar -zxvf postgresql-10.3.tar.gz

编译安装

# cd postgresql-10.3

指定安装路径

# ./configure --prefix=/usr/local/postgresql

 可能出现错误configure: error: readline library not found

 执行

 # yum install readline-devel

编译安装

# make && make install

用户权限

添加用户和用户组

# useradd postgres
# groupadd postgres

生成数据库文件目录

# mkdir /usr/local/postgresql/data

用户文件访问权限变更

# chown postgres /usr/local/postgresql/data
# chgrp postgres /usr/local/postgresql/data

用户切换

# su - postgres

数据库初始化

$ /usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data

配置修改

配置数据库允许访问的IP

vi /usr/local/postgresql/data/pg_hba.conf

配置IP都可以连接数据库(如需要所有IP都可以访问则对应为0.0.0.0/0),此处认证类型选择的是MD5,可参考官方文档认证类型,选择适合的认证方式

 host    all             postgres       10.0.0.0/8               md5

     80 
     81 # TYPE  DATABASE        USER            ADDRESS                 METHOD
     82 
     83 # "local" is for Unix domain socket connections only
     84 local   all             all                                     trust
     85 # IPv4 local connections:
     86 host    all             all             127.0.0.1/32            trust
     87 # IPv6 local connections:
     88 host    all             all             ::1/128                 trust
     89 # Allow replication connections from localhost, by a user with the
     90 # replication privilege.
     91 local   replication     all                                     trust
     92 host    replication     all             127.0.0.1/32            trust
     93 host    replication     all             ::1/128                 trust
     94 host    all             postgres        0.0.0.0/0               md5

配置监听地址、连接端口号等

$ vi /usr/local/postgresql/data/postgresql.conf 

listen_addresses配置监听地址范围,改为*则为所有

port 默认为5432

     57 # - Connection Settings -
     58 
     59 listen_addresses = '*'          # what IP address(es) to listen on;
     60                                         # comma-separated list of addresses;
     61                                         # defaults to 'localhost'; use '*' for all
     62                                         # (change requires restart)
     63 port = 5432                             # (change requires restart)

启动数据库服务

$ /usr/local/postgresql/bin/pg_ctl -D /usr/local/postgresql/data -l /usr/local/postgresql/data/logfile start

修改密码

$ /usr/local/postgresql/bin/psql 

# \password postgres
Enter new password

 

posted @ 2018-04-17 18:00  还是搬砖踏实  阅读(3800)  评论(1编辑  收藏  举报