天天看點

Centos7安裝Postgresql11及PostGIS、timescaleDB安裝一、安裝postgresql11二、安裝PostGIS三、安裝timescalDB

一、安裝postgresql11

1,檢視是否安裝postgres

rpm -qa | grep postgresql
           

2,如果有,解除安裝删除舊的,安裝新的

yum remove postgresql*
           

3,設定源

yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
           

4,安裝

yum install postgresql11 postgresql11-contrib postgresql11-libs postgresql11-server -y
           

   這一步執行完會建立一個postgres使用者。

5,自定義data存儲目錄,在資料挂在盤/data目錄下建立postgres_data目錄,并設定權限

mkdir  /data/postgres_data
chown postgres:postgres /data/postgres_data
chmod 750 /data/postgresql_data
           

6,初始化資料庫

    切換到postgres

su postgres
           

執行初始化指令,并将data初始化到上一步建立的postgres_data檔案夾裡

/usr/pgsql-11/bin/initdb -D /data/postgresql_data/
           

修改/usr/lib/systemd/system/postgresql-11.service檔案的内容,在#Location of database direcotry裡面指定正确的PGDATA:

vi /usr/lib/systemd/system/postgresql-11.service
           

 在檔案裡找到Environment=PGDATA,指定data目錄,修改成下面這樣。

#Location of database directory
Environment=PGDATA=/data/postgresql_data
           

7,配置資料庫服務開機啟動并立即啟動資料庫服務

#設定開機啟動
systemctl enable postgresql-10.service
#啟動資料庫
systemctl start postgresql-11
#檢視資料狀态
systemctl status postgresql-11
#重新開機資料庫
systemctl restart postgresql-11
           

8.修改配置

修改postgresql.conf檔案内容

vim /data/postgresql_data/postgresql.conf
           

找到listen_addresses配置項修改為*

listen_addresses = '*'
           

修改pg_hba.conf檔案内容

vim /data/postgresql_data/pg_hba.conf
           

設定能通路的ip,在最下面一行添加下面内容

host    all             all             0.0.0.0/0              md5
           

  修改完重新開機資料庫生效。

systemctl restart postgresql-11
           

9,修改密碼

su - postgres
           
psql
           
ALTER USER postgres WITH PASSWORD '密碼';
           

二、安裝PostGIS

1,先安裝幾個工具包

yum  install wget net-tools epel-release -y
           

2,安裝postgis

yum install postgis30_11 postgis30_11-client -y
           

3,安裝拓展工具

yum install ogr_fdw11 pgrouting_11 -y
           

4,建立資料庫,安裝PostGis擴充

#切換使用者
su - postgres
#登入pgsql
psl
#建立測試資料庫spatial_testdb 
CREATE DATABASE spatial_testdb OWNER postgres;
#進入建立的資料庫
\c spatial_testdb;
#安裝PostGis擴充
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
CREATE EXTENSION ogr_fdw;
#驗證是否成功
SELECT postgis_full_version();
           

三、安裝timescalDB

1,安裝yum源

在root目錄下執行,不是root使用者請加sudo

tee /etc/yum.repos.d/timescale_timescaledb.repo <<EOL
[timescale_timescaledb]
name=timescale_timescaledb
baseurl=https://packagecloud.io/timescale/timescaledb/el/$(rpm -E %{rhel})/\$basearch
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/timescale/timescaledb/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
EOL
           

2,更新源

yum update -y
           

3,安裝timescalDB

yum install -y timescaledb-2-postgresql-11
           

4,配置 postgresql.conf  使用 postgres 啟動時加載 'timescaledb'

切換到postgres賬戶下執行

vi /data/postgresql_data/postgresql.conf
           

在檔案末尾添加下面這句

shared_preload_libraries = 'timescaledb'
           

重新開機資料庫

systemctl restart postgresql-11
           

5,安裝檢驗

切換到postgres使用者下

su postgres
           

執行psql指令進入資料庫

su postgres
           

建立一個新的空資料庫

CREATE database tutorial;
           

切換庫

\c tutorial
           

建立TimescaleDB

CREATE EXTENSION IF NOT EXISTS timescaledb;
           
如果要安裝的版本不是系統上最新的版本,則可以這樣指定版本: 

CREATE EXTENSION timescaledb VERSION '2.1.0';

Centos7安裝Postgresql11及PostGIS、timescaleDB安裝一、安裝postgresql11二、安裝PostGIS三、安裝timescalDB

至此安裝成功。