CentOS7にPostgresql9とPostGISをインストール
今更な内容だが、作業ログとして残す。
前提
OS: Centos 7
インストール
sudo yum install epel-release sudo yum install -y proj proj-devel proj-epsg sudo yum --enablerepo=epel install gdal sudo yum install postgis # 順番が前後するが、以下でPostgresql Serverをインストール sudo yum install postgresql-server # DB初期化 sudo postgresql-setup initdb # サーバ起動時の自動起動 systemctl enable postgresql
CentOS 7 なので、起動停止にはsystemctl を使う
sudo systemctl start postgresql sudo systemctl status postgresql sudo systemctl stop postgresql
参考にしたサイト:CentOS 7にPostgreSQL最新版をインストール - 働きたくないゆとりの備忘録
ログイン
次に、ログインできなかったので、以下を参考に対応。
peer認証の関係でpsqlログインできない時の対処法 - Qiita
まず、postgresユーザのパスワード設定
sudo su postgres -c 'psql --username=postgres' ALTER USER postgres with encrypted password 'your_password';
次に、アクセス権の設定を変更
/var/lib/pgsql/data/pg_hba.conf の
host all all ::1/128 ident
を
host all all ::1/128 md5
に変更して、Postgresql を再起動
psql -U postgres -h localhost -W でログイン
他サーバからのログイン
デフォルトでは、localhost からしかログインできない。
/var/lib/pgsql/data/postgresql.conf の
listen_addresses = '*' ←に変更 port 5432 ←コメント解除
Postgresql を再起動
psql -U postgres -h xxx.xxx.xxx.xxx -W でログイン
PostGISの動作確認
create database test; \connect test create extension postgis; select PostGIS_full_version();
これでバージョンが表示されればOK
参考:CentOSにPostGISをyumでインストール(CentOS7.2, PostgreSQL9.5, PostGIS2.2) - Qiita