美文网首页PostGIS
centos7源码安装postgresql11.6+postgi

centos7源码安装postgresql11.6+postgi

作者: 享吉斯的彬彬 | 来源:发表于2020-01-13 10:56 被阅读0次

安装Postgresql-11

前期都比较顺利,直接上命令

yum install zlib-devel gcc make
yum install -y readline-devel.x86_64 uuid uuid-devel
groupadd postgres
useradd -g postgres postgres
passwd postgres
mkdir -p /usr/local/postgresql
chown -R postgres:postgres /usr/local/postgresql
cd /usr/local/src/
wget https://ftp.postgresql.org/pub/source/v11.6/postgresql-11.6.tar.gz
tar -xzvf postgresql-11.6.tar.gz
cd postgresql-11.6
./configure --prefix=/usr/local/postgresql --without-readline --with-ossp-uuid
make && make install
安装contrib目录下的一些工具,是第三方组织的一些工具代码,建议安装
cd contrib
make && make install
把程序目录全部赋权给postgres用户
chown -R postgres.postgres /usr/local/postgresql
创建数据目录 /data/postgresql/data
[root@localhost /]# mkdir data
[root@localhost /]# cd data
[root@localhost data]# mkdir postgresql
[root@localhost data]# cd postgresql
[root@localhost postgresql]# mkdir data
把数据目录全部赋权给postgres用户
chown -R postgres.postgres /data/postgresql/data
配置环境变量

编辑用户目录下.bashrc文件,主要是设置PGDATA变量

切换到postgres账户

su - postgres

编辑用户下配置文件

vim .bashrc

编辑内容如下:

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

编辑完成,按esc,输入 wq!保存退出,重新启用下配置文件
source .bashrc
初始化数据库

initdb -D /data/postgresql/data

启动服务

pg_ctl start -D $PGDATA

设置用户密码

使用postgres账户进入控制台(现在密码应该是空)

[postgres@pg1 ]# psql -U postgres
postgres=# \password
Enter new password: <123456>
Enter it again: <123456>

把密码设置成123456可以使用\q命令退出控制台

设置监听 修改postgresql/data目录下的pg_hba.conf
[postgres@pg1 ~]$  vim $PGDATA/pg_hba.conf
修改IPv4 一行内容如下:
# IPv4 local connections:
host    all             all             0.0.0.0/0            trust
修改postgresql.conf:
[postgres@pg1 ~]$ vim $PGDATA/postgresql.conf

修改监听一节如下:

# - Connection Settings -
listen_addresses = '*' 
port = 5432 

wq!保存退出。 重启pg服务生效

[postgres@pg1 ~]$ pg_ctl restart -D $PGDATA
配置防火墙
su - root
vi /etc/sysconfig/iptables
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5432 -j ACCEPT

执行命令:

service iptables restart

或者直接关闭:

/etc/init.d/iptables status
chkconfig iptables off   #永久关闭,重启生效
/etc/init.d/iptables stop #当前关闭

安装 PostGIS

安装LibXML2 json-c 等等
yum install -y libtool libxml2 libxml2-devel libxslt libxslt-devel json-c json-c-devel cmake gmp gmp-devel mpfr mpfr-devel boost-devel pcre-devel
安装Proj4
cd /usr/local/src/
wget http://download.osgeo.org/proj/proj-4.9.3.tar.gz
tar -xf proj-4.9.3.tar.gz
cd proj-4.9.3
./configure --prefix=/usr/local/postgresql/plugin/proj
make
make install
echo "/usr/local/postgresql/plugin/proj/lib" > /etc/ld.so.conf.d/proj-4.9.3.conf
ldconfig
安装GEOS
wget http://download.osgeo.org/geos/geos-3.7.3.tar.bz2
tar -jxf geos-3.7.3.tar.bz2
cd geos-3.7.3
./configure --prefix=/usr/local/postgresql/plugin/geos
make
make install
echo "/usr/local/postgresql/plugin/geos/lib" > /etc/ld.so.conf.d/geos-3.7.3.conf
ldconfig
安装GDAL
wget http://download.osgeo.org/gdal/2.1.2/gdal-2.1.2.tar.gz
tar -xf gdal-2.1.2.tar.gz
cd gdal-2.1.2
./configure --prefix=/usr/local/postgresql/plugin/gdal
make
make install
echo "/usr/local/postgresql/plugin/gdal/lib" > /etc/ld.so.conf.d/gdal-2.1.2.conf
ldconfig
安装PostGIS
wget https://download.osgeo.org/postgis/source/postgis-2.5.2.tar.gz
tar -xvzf postgis-2.5.2.tar.gz
cd postgis-2.5.2
./configure --prefix=/usr/local/postgresql/plugin/postgis --with-pgconfig=/usr/local/postgresql/bin/pg_config --with-geosconfig=/usr/local/postgresql/plugin/geos/bin/geos-config --with-gdalconfig=/usr/local/postgresql/plugin/gdal/bin/gdal-config --with-projdir=/usr/local/postgresql/plugin/proj
make
make install
安装fuzzystrmatch
cd /usr/local/src/postgresql-11.6/contrib/fuzzystrmatch
make && make install
检查PostGIS是否安装成功
#切换postgres用户
su - postgres
#登录PG数据库
psql
# 创建一个数据库
create database postgis;
#切换到postgis库中
\c postgis
#显示一下扩展模块
\dx

CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
CREATE EXTENSION fuzzystrmatch;
CREATE EXTENSION postgis_tiger_geocoder;

环境配置

设置系统服务(用root权限):

复制postgresql安装目录下的linux文件到/etc/init.d/,进入postgresql 的安装目录(即刚刚使用tar命令解压的目录):

cd postgresql-11.6
cp contrib/start-scripts/linux /etc/init.d/postgresql
vim /etc/init.d/postgresql

修改如下:

# 修改prefix
prefix = /home/hadoop/pgsql

# 修改PGDATA
PGDATA="/home/hadoop/pgsql/data"

# 修改PGUSER
PGUSER=hadoop

# 修改PGLOG
PGLOG="$PGDATA/log-history"

添加执行权限:

chmod +x /etc/init.d/postgresql

这样,还可以通过系统命令开启和关闭postgresql服务(需要root权限):

/etc/init.d/postgresql start
/etc/init.d/postgresql stop
让数据库开机启动
chkconfig --add postgresql
chkconfig postgresql on

源码安装相关问题及解决方案

uuid扩展报错
postgres=# CREATE EXTENSION "uuid-ossp"; 
ERROR:  could not access file "$libdir/uuid-ossp": No such file or directory

回源码目录,安装uuid就可以

# cd postgresql-11.6/contrib/uuid-ossp
# make && make install

相关文章

  • centos7源码安装postgresql11.6+postgi

    安装Postgresql-11 前期都比较顺利,直接上命令 安装contrib目录下的一些工具,是第三方组织的一些...

  • Centos7 多种方法 安装git

    源码安装 安装对应的依赖 下载源码编译安装 确保系统git 已经被卸载 rpm 安装(基于CentOS7)

  • Python基础知识

    Python下载地址:官方源码 centos7下安装方法 :Centos7安装Python3.5 Python B...

  • VPP基本安装

    以下安装方式在centos7上安装测试(可用)有三种安装方式:源码安装、yum安装、vpp-config安装 源码...

  • CentOS7上安装Nodejs

    CentOS7上安装Nodejs 下载源码 解压源码,并重命名源码 编译安装 配置NODE_HOME,进入prof...

  • CentOS7安装Tomcat8

    1 、安装说明 安装环境:CentOS7安装方式:源码安装软件:apache-tomcat-8.0.39-src....

  • centos7源码安装redis-5.0.0vv

    centos7源码安装redis-5.0.0 1.下载redis源码包 [root@localhostlocal]...

  • centos7源码安装lnmp

    centos7源码安装lnmp 相关链接 源码安装 使用systemd 编译选项 my.cnf配置文件说明 下载源...

  • centos7安装测试criu

    centos7安装criu 下载安装包 下载依赖包 安装源码 简单测试安装是否成功

  • Kaldi(一)安装编译

    我使用的centos7安装的。需要克隆下来kaldi源码,编译安装 从github克隆下来源码:git clone...

网友评论

    本文标题:centos7源码安装postgresql11.6+postgi

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