centos7 postgresql9和postgis2.1插件编译部署
目錄
依賴(lài)安裝
下載編譯libgeos
下載編譯proj4
編譯Postgresql9
編譯PostGIS2
啟動(dòng)postgresql服務(wù)
開(kāi)通外部網(wǎng)絡(luò)訪問(wèn)
數(shù)據(jù)庫(kù)開(kāi)啟PostGIS擴(kuò)展
查看PostGIS版本
升級(jí)PostGIS版本
依賴(lài)安裝
這個(gè)命令里面安裝的包可能會(huì)多,由于是編譯GreenPlum用的,沒(méi)有嘗試最小安裝
yum install -y epel-release
yum install -y \
apr-devel \
bison \
bzip2-devel \
cmake3 \
flex \
gcc \
gcc-c++ \
krb5-devel \
libcurl-devel \
libevent-devel \
libkadm5 \
libyaml-devel \
libxml2-devel \
libzstd-devel \
openssl-devel \
perl-ExtUtils-Embed \
python-devel \
python-pip \
readline-devel \
xerces-c-devel \
zlib-devel
?
yum install -y gdal-devel
?
yum install -y gdal-devel
下載編譯libgeos
yum install -y wget
wget http://download.osgeo.org/geos/geos-3.8.0.tar.bz2
yum install -y bzip2
tar jxf geos-3.8.0.tar.bz2
#編譯
./configure -prefix=/usr/local/geos && make && make install
?
下載編譯proj4
?
wget http://download.osgeo.org/proj/proj-4.9.3.tar.gz #http://download.osgeo.org/proj/proj-6.2.1.tar.gz 注意項(xiàng)目需要的是4.x,其他版本不可用
tar zxf proj-4.9.3.tar.gz
cd proj-4.9.3
?
yum install -y libsqlite3x-devel
./configure -prefix=/usr/local/proj4 && make && make install
編譯Postgresql9
#wget http://ftp.postgresql.org/pub/source/v9.6.9/postgresql-9.6.9.tar.gz
wget http://ftp.postgresql.org/pub/source/v9.6.9/postgresql-9.6.9.tar.bz2
tar jxvf postgresql-9.6.9.tar.bz2
cd postgresql-9.6.9
./configure -prefix=/usr/local/pgsql
make && make install
編譯PostGIS2
#wget https://download.osgeo.org/postgis/source/postgis-2.2.8.tar.gz
wget https://download.osgeo.org/postgis/source/postgis-2.1.5.tar.gz
tar zxf postgis-2.1.5.tar.gz
cd postgis-2.1.5
./configure --with-pgconfig=/usr/local/pgsql/bin/pg_config --with-projdir=/usr/local/proj4
make
?
make報(bào)錯(cuò)
lwgeom_accum.c:109:46: error: ‘AggState {aka struct AggState}’ has no member named ‘a(chǎn)ggcontext’; did you mean ‘a(chǎn)ggcontexts’?
aggcontext = ((AggState *) fcinfo->context)->aggcontext;
?
搜索了好久才找到(http://osgeo-org.1560.x6.nabble.com/2-0-7-build-error-on-Fedora-22-td5214694.html)
vi postgis/lwgeom_accum.c
修改(參照https://trac.osgeo.org/postgis/browser/branches/2.1/postgis/lwgeom_accum.c)
108行附近
將
if (fcinfo->context && IsA(fcinfo->context, AggState))
? ?aggcontext = ((AggState *) fcinfo->context)->aggcontext;
else if (fcinfo->context && IsA(fcinfo->context, WindowAggState))
? ?aggcontext = ((WindowAggState *) fcinfo->context)->aggcontext;
else
改為
if ( ! AggCheckCallContext(fcinfo, &aggcontext) )
然后編譯就通過(guò)了
看來(lái)是發(fā)包之后有人修復(fù)了這個(gè)bug……
?
#安裝
make install
?
啟動(dòng)postgresql服務(wù)
adduser postgres
mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
#初始化數(shù)據(jù)庫(kù)
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
#啟動(dòng)服務(wù)
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
#創(chuàng)建test庫(kù)
/usr/local/pgsql/bin/createdb test
#psql登錄到test庫(kù)測(cè)試
/usr/local/pgsql/bin/psql test
#查看進(jìn)程
ps -ef|grep postgres
?
開(kāi)通外部網(wǎng)絡(luò)訪問(wèn)
(默認(rèn)綁定127.0.0.1僅能本機(jī)訪問(wèn))
#開(kāi)通防火墻
firewall-cmd?--zone=public?--add-port=5432/tcp?--permanent
firewall-cmd?--reload
#修改配置
cd /usr/local/pgsql/data
vi postgresql.conf
修改
listen_addresses = '0.0.0.0'
max_connections = 1000
?
#信任遠(yuǎn)程連接
vi pg_hba.conf
修改
host? ? all? ? ? ? ? ? all? ? ? 0.0.0.0/0? md5
?
?
重啟數(shù)據(jù)庫(kù)
#設(shè)置postgres用戶(hù)的密碼
/usr/local/pgsql/bin/psql -U postgres
登錄數(shù)據(jù)庫(kù),執(zhí)行后提示符變?yōu)?'postgres=#' ? ?
ALTER USER postgres with encrypted password 'postgres';? 設(shè)置postgres用戶(hù)密碼為postgres ?
? \q? 退出數(shù)據(jù)庫(kù)
?
此時(shí)可以通過(guò)外部數(shù)據(jù)庫(kù)客戶(hù)端軟件連接進(jìn)行數(shù)據(jù)庫(kù)管理
?
數(shù)據(jù)庫(kù)開(kāi)啟PostGIS擴(kuò)展
連接一個(gè)數(shù)據(jù)庫(kù),執(zhí)行sql語(yǔ)句
CREATE EXTENSION PostGIS
報(bào)錯(cuò)
ERROR: could not load library "/usr/local/pgsql/lib/postgis-2.1.so": libproj.so.12: 無(wú)法打開(kāi)共享對(duì)象文件: 沒(méi)有那個(gè)文件或目錄
?
此時(shí)修改
vi /etc/ld.so.conf
添加
/usr/local/proj4/lib
?
#使配置生效
ldconfig
?
再次執(zhí)行開(kāi)啟擴(kuò)展
CREATE EXTENSION PostGIS
成功,public模式下出現(xiàn)spatial_ref_sys表
?
創(chuàng)建GIS類(lèi)型字段成功
CREATE TABLE "public"."gis_test" (
"id" varchar(16) COLLATE "pg_catalog"."default" NOT NULL,
"name" varchar(255) COLLATE "pg_catalog"."default",
"the_geom" "public"."geometry",
CONSTRAINT "gis_test_pkey" PRIMARY KEY ("id")
)
;
查看PostGIS版本
SELECT PostGIS_version()
升級(jí)PostGIS版本
首先到源碼目錄/root/postgis-2.1.5
make uninstall
在到下載編譯源碼postgis-2.2.8
最后make install
?
重啟Postgresql后,版本依然是舊的,此時(shí)DROP掉擴(kuò)展
DROP EXTENSION PostGIS
提示有幾個(gè)表已經(jīng)使用了,需要把相應(yīng)的表刪除掉(注意做好備份)
再次
DROP EXTENSION PostGIS
此時(shí)
SELECT PostGIS_version()
看到版本是新的了
?
總結(jié)
以上是生活随笔為你收集整理的centos7 postgresql9和postgis2.1插件编译部署的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Spring Boot Scheduli
- 下一篇: 程序员的简历模板