Skip to content

Instantly share code, notes, and snippets.

@skitazaki
Last active September 9, 2016 02:56
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skitazaki/7746389 to your computer and use it in GitHub Desktop.
Save skitazaki/7746389 to your computer and use it in GitHub Desktop.
CentOS に PostGIS/GDAL/Proj をインストールする手順。

PostGIS on CentOS

CentOS に PostGIS/GDAL/Proj をインストールする。

環境:

  • CentOS 6.4 (64bit)
  • PostgreSQL 9.3
  • PostGIS 2.1
  • GDAL 1.9.2
  • Proj 4.8.0

手順概要:

  1. EPEL の yum レポジトリを使えるようにする
  2. PostgreSQL の yum レポジトリを使えるようにする。
  3. 紛らわしいので標準 yum レポジトリの postgresql を除外する。8.x がインストールされている場合はアンインストールする。
  4. yum でインストールする。
  5. 起動設定、データディレクトリの初期化、接続テストを実施する。
  6. テスト用データベースを作成して拡張機能を有効にする。
  7. リモートマシンからログインできるようにする。

コマンド :

# EPEL の yum レポジトリを使えるようにする
$ curl -O http://ftp.riken.jp/Linux/fedora/epel/6/i386/epel-release-6-8.noarch.rpm
$ sudo rpm -i epel-release-6-8.noarch.rpm

# PostgreSQL の yum レポジトリを使えるようにする。
$ curl -O http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm
$ sudo rpm -i pgdg-centos93-9.3-1.noarch.rpm
$ yum list gdal*
$ yum list postgresql*

#. 紛らわしいので標準 yum レポジトリの *postgresql* を除外する。
# 8.x がインストールされている場合はアンインストールする。
$ sudo vi /etc/yum.repos.d/CentOS-Base.repo
$ sudo yum remove postgresql
$ yum list postgresql*

# ``yum`` でインストールする。
$ sudo yum install -y gdal proj proj-devel proj-epsg
$ sudo yum install -y postgresql93-server postgresql93-contrib
$ sudo yum install -y postgis2_93 postgis2_93_devel postgis2_93_utils

# インストールしたコマンドの確認
$ ogr2ogr --version
$ proj
$ psql --version

# 起動設定、データディレクトリの初期化、接続テストを実施する。
$ sudo chkconfig postgresql-9.3 on
$ sudo service postgresql-9.3 initdb
$ sudo ls -l /var/lib/pgsql/9.3
$ sudo service postgresql-9.3 start
$ sudo service postgresql-9.3 status
$ sudo su - postgres -c "psql -l"

# テスト用データベースを作成して拡張機能を有効にする。
$ sudo su - postgres -c "createdb test"
$ sudo su - postgres -c "psql -l"
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 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
 test      | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
(4 rows)

$ sudo su - postgres -c "psql -d test -c \"SELECT version();\""
$ sudo su - postgres -c "psql -d test -c \"SELECT postgis_full_version();\""
$ sudo su - postgres -c "psql -d test -c \"CREATE EXTENSION postgis;\""
$ sudo su - postgres -c "psql -d test -c \"CREATE EXTENSION postgis_topology;\""
$ sudo su - postgres -c "psql -d test -c \"CREATE EXTENSION fuzzystrmatch;\""
$ sudo su - postgres -c "psql -d test -c \"CREATE EXTENSION postgis_tiger_geocoder;\""

# リモートマシンからログインできるようにする。
$ sudo vi /var/lib/pgsql/9.3/data/pg_hba.conf        # host ベース認証を追加
$ sudo vi /var/lib/pgsql/9.3/data/postgresql.conf    # listen_addresses を編集
$ sudo service postgresql-9.3 restart

# ユーザーを作成する。
$ sudo su - postgres -c "createuser -P -E -S sampleuser"
$ sudo su - postgres -c "psql -c \"GRANT ALL ON DATABASE test to sampleuser;\""
$ sudo su - postgres -c "psql -c \"SELECT * FROM pg_roles;\""

# ファイアーウォールの設定で 5432 番ポートの接続を許可する。
$ sudo iptables -A INPUT -p tcp --dport 5432 -j ACCEPT
$ sudo service iptables save
$ sudo service iptables reload
$ sudo iptables -L

メモ:

  • PostGIS をインストールするときに依存関係により EPEL の geos や hdf5, netcdf もインストールされる。
  • 拡張機能はデータベースごとに有効にする必要がある。
  • yumpostgresql93-contrib をインストールしていないと fuzzystrmatch 拡張をインストールできない。
    • postgis_tiger_geocoderfuzzystrmatch に依存している。
    • fuzzystrmatch は文字列比較の拡張で、レーベンシュタイン距離なども計算できる。
  • ユーザーを追加した場合は pg_roles テーブルを確認する。
  • postgresql.conf の listen_addresses を変更した後は reload ではなく restart を実行する。

参考:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment