[技术干货] 时序数据库timescaleDB安装
本环境在Centos7.5采用编译安装的方式,主要介绍PostgreSQL 11.7,TimescaleDB 1.6.1,cmake3.8.2
PostgreSQL编译安装需要cmake3.4以上的版本
TimescaleDB目前只支持PostgreSQL 9.6.3 +,10.9 +或11.4+
一、postgresql11部署1、安装cmake
解压cmake-v3.8.2.zip
[root@TimescaleDB tmp]# unzip cmake-v3.8.2.zip
[root@TimescaleDB tmp]# cd cmake-v3.8.2
安装gcc++ 后,再安装cmake
[root@TimescaleDB cmake-v3.8.2]# yuminstall -y gcc*
[root@TimescaleDB cmake-v3.8.2]# ./bootstrap && make && makeinstall
[root@TimescaleDB cmake-v3.8.2]# ln -s/usr/local/bin/cmake /usr/bin/cmake
2、安装postgresq
软件包链接:https://ftp.postgresql.org/pub/source/v11.7/
解压postgresql-11.7.tar.gz
[root@TimescaleDB tmp]# tar -zxvfpostgresql-11.7.tar.gz
[root@TimescaleDB tmp]# cd postgresql-11.7
安装依赖包
[root@TimescaleDB postgresql-11.7]# yuminstall -y zlib* readline*
安装postgresql
[root@TimescaleDB postgresql-11.7]#./configure --prefix=/usr/local/postgresql --with-readline --with-zlib
[root@TimescaleDB postgresql-11.7]#make&& make install

添加环境变量
在/etc/profile最后,添加以下内容
[root@TimescaleDB postgresql-11.7]#vi/etc/profile
exportPG_CONFIG=/usr/local/postgresql/bin/pg_config:$PG_CONFIG
exportPGDATA=/usr/local/postgresql/data:$PGDATA
export PATH=/usr/local/postgresql/bin:$PATH
exportLD_LIBRARY_PATH=/usr/local/postgresql/lib:$LD_LIBRARY_PATH

[root@TimescaleDB postgresql-11.7]#source /etc/profile
创建用户和用户组,创建数据库文件目录
[root@TimescaleDB postgresql-11.7]# useraddpostgres
[root@TimescaleDB postgresql-11.7]#groupadd postgres
[root@TimescaleDB postgresql-11.7]# mkdir/usr/local/postgresql/data
[root@TimescaleDB postgresql-11.7]# chownpostgres /usr/local/postgresql/data
[root@TimescaleDB postgresql-11.7]# chgrppostgres /usr/local/postgresql/data
切换用户,初始化数据库
[root@TimescaleDB postgresql-11.7]# su -postgres
[postgres@TimescaleDB ~]$ /usr/local/postgresql/bin/initdb -D/usr/local/postgresql/data

配置访问权限
[postgres@TimescaleDB ~]$ vi/usr/local/postgresql/data/pg_hba.conf

配置监控地址,连接端口号
[postgres@TimescaleDB ~]$ vi/usr/local/postgresql/data/postgresql.conf
listen_addresses配置监听地址范围,改为*则为所有

启动数据库,修改数据库密码
[postgres@TimescaleDB ~]$/usr/local/postgresql/bin/pg_ctl -D /usr/local/postgresql/data -l/usr/local/postgresql/data/logfile start

[postgres@TimescaleDB ~]$ psql
postgres=# \password postgres

二、timescaledb安装
软件包链接https://codeload.github.com/timescale/timescaledb/zip/master
1、安装timescaledb
解压并授权
[root@TimescaleDB tmp]# unziptimescaledb-master.zip
[root@TimescaleDB tmp]# chown -Rpostgres:postgres timescaledb-master
[root@TimescaleDB tmp]# chmod -R 775 timescaledb-master
编译安装
[root@TimescaleDB tmp]# cdtimescaledb-master
[root@TimescaleDB tmp]# ./bootstrap-DUSE_OPENSSL=0 -DREGRESS_CHECKS=OFF

[root@TimescaleDB timescaledb-master]# cd./build && make

[root@TimescaleDB build]# make install

2、配置timescaledb
1、编辑postgresql.conf文件,添加timescaledb库
[root@TimescaleDB build]# su – postgres
[postgres@TimescaleDB ~]$ vi/usr/local/postgresql/data/postgresql.conf


重启postgresql数据库
[root@TimescaleDBbuild]# su – postgres
[postgres@TimescaleDB~]$ /usr/local/postgresql/bin/pg_ctl -D /usr/local/postgresql/data -l /usr/local/postgresql/data/logfilerestart

添加timescaledb扩展
[postgres@TimescaleDB ~]$ psql
postgres=# create extension timescaledb;

3、验证timescaleDB扩展安装完成
现在创建一个新的空数据库
postgres=# CREATE database tutorial;
进入tutorial库
\c tutorial
把tutorial库转换为使用TimescaleDB扩展数据库
tutorial=# CREATE EXTENSION IF NOT EXISTStimescaledb CASCADE;

验证完成,timescaleDB扩展安装成功
技术交流欢迎加入Q群:177428068