PostgreSQL11.2+PostGIS2.5部署
軟體版本:
PostgreSQL-11.2 gdal-2.2.3 proj-4.8.0 geos-3.5.0 json-c-0.13.1 protobuf-2.6.1 protobuf-c-1.2.1 postgis-2.5.0
一、原始碼安裝pg11.2
使用者配置
建立安裝使用者 groupadd dba -g 1000 useradd postgres -g 1000 -u 1000
安裝依賴
yum install -y openssl openssl-devel readline readline-devel zlib-devel gcc gcc-c++ libxml2 libxml2-devel flex
切換到postgres使用者
su - postgres
獲取並解壓包
wget tar -xf postgresql-11.2.tar.gz
進入目錄
cd postgresql-11.2
編譯環境檢查
./configure --prefix=/home/postgres/soft --with-openssl --with-pgport=6000 (最後出現makefile)
編譯安裝
make world -j24 make install-world -j24
初始化資料庫資料目錄到/home/postgres/data
/home/postgres/soft/bin/initdb -D /home/postgres/data -E UTF8
啟動資料庫
/home/postgres/soft/bin/pg_ctl start -D /home/postgres/data -l /tmp/logfile
配置環境變數.bashrc
vi .bashrc export PGPORT=6000 export PGUSER=postgres export PGHOME=/home/postgres/soft export PGDATA=/home/postgres/data export PATH=${PGHOME}/bin:${PATH} LD_LIBRARY_PATH=$PGHOME/lib:/usr/local/lib:/usr/local/lib64:/usr/lib64:$LD_LIBRARY_PATH
–讀取環境變數
source .bashrc
資料庫配置
su - postgres
mkdir -p /home/postgres/archive/wal
cluster_name='enmo_6001' listen_addresses='0.0.0.0' port=6000 wal_log_hints=on logging_collector=on logging_collector=on log_filename='pg_log_%u.log' log_file_mode=0600 log_truncate_on_rotation=on log_rotation_age=1d wal_keep_segments=100 archive_mode = on archive_command = 'cp %p /home/postgres/archive/wal/%f' wal_level = 'logical' max_wal_senders = 10 max_replication_slots = 10 hot_standby = on client_encoding='UTF8' lc_messages = 'en_US.UTF-8' lc_monetary = 'en_US.UTF-8' lc_numeric = 'en_US.UTF-8' lc_time = 'en_US.UTF-8
修改引數,其餘引數根據環境進行調整。
重啟資料庫生效
pg_ctl restart -D $PGDATA -l /tmp/logfile
二、postgis安裝
mkdir /home/postgres/postgis cd /home/postgres/postgis
1.安裝gdal
wget tar xf gdal-2.2.3.tar.gz cd gdal-2.2.3 ./configure make -j 24 make install -j 24
2.安裝proj
wget tar xf proj-4.8.0.tar.gz cd proj-4.8.0 ./configure export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig export LD_LIBRARY_PATH=/usr/local/lib make -j 24 make install -j 24
3.安裝geos
wget tar jxvf geos-3.5.0.tar.bz2 cd geos-3.5.0 ./autogen.sh ./configure make -j 24 make install -j 24
4.安裝json-c
wget tar -xf json-c-0.13.1.tar.gz ./autogen.sh ./configure make -j 24 make install -j 24
5.安裝protobuf-c
wget tar xvf protobuf-2.6.1.tar.gz cd protobuf-2.6.1 ./configure make -j 24 make check make install -j 24 wget tar xvf protobuf-c-1.2.1.tar.gz cd protobuf-c-1.2.1 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig // 指定protobuf.pc檔案所在 ./configure make -j 24 make install -j 24
6.配置ldconfig
將資料庫軟體、gdal、proj、geos的lib目錄新增到ldconfig。
cat /etc/ld.so.conf include ld.so.conf.d/*.conf /usr/local/gdal/lib/ /usr/local/proj/lib/ /usr/local/geos/lib/ /home/postgres/soft/lib/ /usr/local/lib #儲存退出 ldconfig
7.安裝postgis(./configure對應目錄需校對)
wget tar -xf postgis-2.5.0.tar.gz cd postgis-2.5.0/ ./configure -prefix=/usr/local/postgis --with-geosconfig=/usr/local/bin/geos-config --with-projdir=/usr/local/proj --with-gdalconfig=/usr/local/bin/gdal-config --with-pgconfig=/home/postgres/soft/bin/pg_config make -j 24 make install -j 24
8.檢查postgis元件是否安裝
ls /home/postgres/soft/share/extension/postgis*
9.使用超級使用者建立擴充套件
[postgres@ysl ~]$psql -Upostgres postgres create extension postgis; create extension postgis_topology; create extension fuzzystrmatch; create extension postgis_tiger_geocoder;
三、測試
postgres=# select postgis_full_version();
postgres=# SELECT ST_SetSRID(ST_Point(-87.71,43.741),4326),ST_GeomFromText('POINT(-87.71 43.741)',4326);
四、建立空間資料庫模板
1.模板及相關的函式,型別,操作符建立
# 建立無空間特性資料庫 [postgres@ysl ~]$ createdb template_postgis # 建立相關空間資料庫相關的函式,型別,操作符等 [postgres@ysl ~]$ psql -f /home/postgres/soft/share/contrib/postgis-2.5/postgis.sql -d template_postgis [postgres@ysl ~]$ psql -f /home/postgres/soft/share/contrib/postgis-2.5/rtpostgis.sql -d template_postgis # 驗證空間資料庫版本 [postgres@ysl ~]$ psql template_postgis psql (11.2) Type "help" for help. template_postgis=# select postgis_full_version(); postgis_full_v ersion --------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------- POSTGIS="2.5.0 r16836" PGSQL="110" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel. 4.8.0, 6 March 2 012" GDAL="GDAL 2.2.3, released 2017/11/20 GDAL_DATA not found" LIBXML="2.9.1" RASTER (1 row) template_postgis=# \d List of relations Schema | Name | Type | Owner --------+-------------------+-------+---------- public | geography_columns | view | postgres public | geometry_columns | view | postgres public | raster_columns | view | postgres public | raster_overviews | view | postgres public | spatial_ref_sys | table | postgres (5 rows)
2.根據空間資料庫模板建立新的空間資料庫
[postgres@ysl ~]$ createdb -T template_postgis new_database template_postgis=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges ------------------+----------+----------+-------------+-------------+----------------------- new_database | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template_postgis | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (5 rows)
3.測試
測試點(0, 0)是否在指定的多邊形內。
new_database=# select ST_Within(ST_GeomFromText('POINT(0 0)', 4326), ST_GeomFromText('POLYGON((1 1, 1 -1, -1 -1, -1 1, 1 1))', 4326)) ; st_within ----------- t (1 row)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69990629/viewspace-2846601/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 灰度部署、滾動部署與藍綠部署
- Kubuesphere部署Ruoyi(二):部署kubesphere
- 部署:無伺服器部署模式伺服器模式
- [部署02] Docker 部署vue專案DockerVue
- MySQL MHA部署 Part 5 MHA部署指南MySql
- Linux部署之Docker方式部署專案LinuxDocker
- Sentry部署
- 部署方案
- Harbor部署
- PalServer部署Server
- es 部署
- 部署SkyWalking
- istio部署
- vue 部署Vue
- polardb 部署
- 部署openrestyREST
- Jenkins部署Jenkins
- nginx部署Nginx
- ELK部署
- NFS 部署NFS
- svn部署
- 部署dashboard
- Java一鍵部署包,Linux部署不用愁!!!JavaLinux
- SSIS 部署篇-如何部署SSIS包到SqlServerSQLServer
- 輕鬆部署 Laravel 應用 | 《08. 手動部署 - 部署應用程式碼》Laravel
- 分散式爬蟲的部署之Scrapyd批量部署分散式爬蟲
- KingbaseRAC部署案例之---基於SAN儲存部署
- 【持續部署】批量部署工具,總結、對比
- ansible部署配置
- redmine docker部署Docker
- Taiga容器部署AI
- python web 部署PythonWeb
- hadoop 部署配置Hadoop
- Django部署HTTPSDjangoHTTP
- CentOS 部署 NodeBBCentOS
- CentOS部署pyspiderCentOSIDE
- 微服務部署微服務
- 社群版部署