LoginSignup
3
4

More than 5 years have passed since last update.

CentOS 7 に PostGIS をインストールする

Last updated at Posted at 2016-06-03

CentOS 7 環境に PostgreSQL 9.5 + PostGIS 2.2.2 をインストールしてみた。

PostGIS — Spatial and Geographic Objects for PostgreSQL
http://postgis.net/

CentOS のバージョンは以下。

# cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
# uname -a
Linux postgis 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

インストール

yum のデフォルトのリポジトリから入る PostgreSQL は 9.2.15。
ちょっと古いので PostgreSQL 公式の yum リポジトリから入れる。

PostgreSQL RPM Repository (with Yum)
http://yum.postgresql.org/repopackages.php#pg95

上記から PostgreSQL 9.5 の CentOS 7 用の RPM を取得してインストール。

# yum install -y https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm
# yum install -y postgresql95 postgresql95-server postgresql95-libs postgresql95-contrib postgresql95-devel

PostGIS は EPEL から入れるので EPEL リポジトリを追加してからインストール。

# rpm --import http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7
# yum install -y http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-6.noarch.rpm
# yum install -y postgis2_95

バージョン確認。

# psql --version
psql (PostgreSQL) 9.5.3

データベースの初期化。

# /usr/pgsql-9.5/bin/postgresql95-setup initdb
Initializing database ... OK

認証モードを変更するために pg-hba.conf を編集。

# vi /var/lib/pgsql/9.5/data/pg_hba.conf

自宅の開発環境なので取り敢えず以下のように変更。

/var/lib/pgsql/9.5/data/pg_hba.conf
# IPv4 local connections:
host    all             all             0.0.0.0/0            trust

postgresql.conf を編集。

# vi /var/lib/pgsql/9.5/data/postgresql.conf

listen_addresses のコメントアウトを解除し、localhost を「*」に変更。

/var/lib/pgsql/9.5/data/postgresql.conf
listen_addresses = '*'

サーバ起動。

# systemctl start postgresql-9.5

ログ確認。

/var/log/messages
# tail -F /var/log/messages
Jun  3 14:53:48 localhost systemd: Starting PostgreSQL 9.5 database server...
Jun  3 14:53:48 localhost pg_ctl: < 2016-06-03 14:53:48.306 JST >LOG:  ログ出力をログ収集プロセスにリダイレクトしています
Jun  3 14:53:48 localhost pg_ctl: < 2016-06-03 14:53:48.306 JST >ヒント:  ここからのログ出力はディレクトリ"pg_log"に現れます。
Jun  3 14:53:49 localhost systemd: Started PostgreSQL 9.5 database server.
/var/lib/pgsql/9.5/data/pg_log/postgresql-Fri.log
# tail -F /var/lib/pgsql/9.5/data/pg_log/postgresql-Fri.log
< 2016-06-03 14:53:48.307 JST >LOG:  データベースシステムは 2016-06-03 14:43:27 JST にシャットダウンしました
< 2016-06-03 14:53:48.309 JST >LOG:  MultiXact member wraparound protections are now enabled
< 2016-06-03 14:53:48.311 JST >LOG:  データベースシステムの接続受付準備が整いました。
< 2016-06-03 14:53:48.311 JST >LOG:  自動バキュームランチャプロセス

エラー等出ていないようであれば自動起動設定を有効にする。

# systemctl enable postgresql-9.5
# systemctl is-enabled postgresql-9.5
enabled

他のマシンから接続してみる。

% psql -h 192.168.33.99 -U postgres
psql (9.3.13, server 9.5.3)
WARNING: psql major version 9.3, server major version 9.5.
         Some psql features might not work.
Type "help" for help.

postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | 
 template0 | postgres | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 rows)

postgres=# \q

接続できた。

DB を作成

PostgreSQL をインストールしたマシンで postgres ユーザになり DB を作成。

# sudo su - postgres
$ createdb example

DB に接続。

$ psql -d example

create extension postgis; を実行して PostGIS を有効化。

example=# create extension postgis;
CREATE EXTENSION

PostGIS のバージョンを確認。

example=# SELECT postgis_full_version() ;
                                                                       postgis_full_version

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
 POSTGIS="2.2.2 r14797" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.11.4, released 2016/01/25" LIBXML="2.9.1" LIBJSON="0.11" RASTER
(1 行)

取り敢えず出来てるっぽい。

動作確認にちょうどいい数行で試せるようなサンプルデータが見当たらなかったので取り敢えずここまで

参考サイト

CentOSにPostgreSQL/PostGISの環境構築 | JURI★GIS
http://www.jurigis.me/2015/01/09/postgis-install-2/

CentOSにPostgreSQL9.5をインストールおよびテスト - Qiita
http://qiita.com/SOJO/items/a1d97887d24c3e44596f

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4