TimescaleDB部署
1、准备
操作系统: CentOS 7 64位操作系统
安装程序: postgresql-10.2.tar.gz
Timescale: timescaledb(只支持pgsql9.x和10.x)
Timescale release_tag: 1.0.0
cmake: cmake-3.10.2.tar(Timescale要求CMake 3.4或更高版本)
安装TimescaleDB时序数据库需要提前安装PostgresSQL数据库,因为TimescaleDB是实时数据库PostgresSQL的插件。并且,目前TimescaleDB只支持在PostgresSQL9.x和10.x中运行。
PostgresSQL数据库安装程序依然可以通过官网或第三方网站下载(坚定的支持从官网下载)。可以直接将程序下载到本地,然后通过FTP/SFTP方式上传到服务,也可以通过命令wget
直接下载到服务器(如果服务器能够连接到以太网,推荐此方式)。
2、部署
Timescale的安装分为两部分。一部分为安装PostgresSQL,另一部分为安装TimescaleDB插件。
2.1、部署PostgresSQL
获取安装包
现将 PostgreSQL 的安装包下载到服务器器中,我们在 /opt/
⽬目录下创建保存安装包的目录/postgresql_pkg
。
此处选择直接从服务器器下载 PostgreSQL 安装包。
执⾏命令:
> mkdir /opt/postgresql_pkg
> cd /opt/postgresql_pkg
> wget https://ftp.postgresql.org/pub/source/v10.2/postgresql-10.2.tar.gz
关闭selinux
在Linux系统中,如果selinux没有设置为permissive或者是disable的情况下,有些Linux系统上的应用程序运行时可能会被拒绝,导致无法正常运行,所以需要关闭selinux(如果有专业运维人员可以进行详细配置来规避此问题)。
执行命令:
> vim /etc/selinux/config
修改内容:
SELINUX=disable
#SELINUXTYPE=targeted
创建用户
需要注意的是PostgresSQL是禁止使用超级管理员来运行服务命令的,所以我们需要创建一个账号来进行后续的PostgresSQL的安装。
我们创建一个用户组,向创建的用户组中添加一个用户账号,并且给该用户创建密码。
执行命令:
> groupadd postgres
> useradd -g postgres postgres
> passwd postgres
创建安装目录
创建 PostgreSQL需要的⽬录,并且为⽬录 /mnt/db1
赋予读写权限。
> mkdir -p /mnt/db1/pgdata/pgsql /mnt/db1/pgdata/pgtbs /mnt/db1/archivelog /backups
> chmod -R 775 /mnt/db1
> chown -R postgres:postgres /mnt/db1
安装依赖
在编译安装程序之前先安装PostgresSQL需要的依赖。
> yum install -y gcc gcc-c++ epel-release llvm5.0 llvm5.0-devel clang libicu-
devel perl-ExtUtils-Embed zlib-devel openssl openssl-devel pam-devel libxml2-devel
libxslt-devel openldap-devel systemd-devel tcl-devel python-devel
> yum install -y llvm5.0 llvm5.0-devel
编译安装
进入保存 PostgreSQL 安装包的目录 /opt/postgresql_pkg
,解压、编译、安装等操作
执行命令:
> cd /opt/postgresql_pkg
进入保存安装包的目录之后,解压安装包并进入解压后的目录。
执行命令:
> tar -zxvf ./postgresql-11.1.tar.gz
> mkdir -p ./postgresql-11.1/build_dir
> cd ./postgresql-11.1/build_dir
开始编译
> ../configure --prefix=/usr/local/pgsql --without-readline --with-openssl
> make world
> make install
启动配置
添加启动配置文件。
执行命令:
> vim /usr/lib/systemd/system/postgresql-10.service
向新建的文件中贴入一下内容。
[Unit]
Description=PostgreSQL 10 database server
Documentation=https://www.postgresql.org/docs/10/static/
After=syslog.target
After=network.target[Service]
Type=notify
User=postgres
Group=postgres
Environment=PGDATA=/mnt/db1/pgdata/pgsql/
OOMScoreAdjust=-1000
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0
ExecStart=/usr/local/pgsql/bin/postmaster -D ${PGDATA}
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0[Install]
WantedBy=multi-user.target
环境变量
需要设置环境变量,否则 PostgreSQL 的安装命令无法正常使用。
修改 /etc/profile
文件。
执行命令:
> vim /etc/profile
向打开的配置文件最后处添加一下内容。
export PGPORT=5432
export PGHOME=/usr/local/pgsql
export PGDATA=/mnt/db1/pgdata/pgsql
export PATH=$PGHOME/bin:$PATH
export MANPATH=$PGHOME/share/man:$MANPATH
export LANG=en_US.UTF-8
export DATE='date +"%Y%m%d%H%M"'
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PGHOST=$PGDATA
export PGUSER=postgres
export PGDATABASE=postgres
保存之后,执行命令使环境变量生效。
> source /etc/profile
初始化数据库
初始化 PostgreSQL数据库,切换账号到postgres
,进行初始化操作。
> su - postgres
> initdb -D $PGDATA -U postgres --locale=en_US.UTF8 -E UTF8
需要注意的是,如果此处没有切换账号,仍然使用root账号进行初始化时,会反馈错误信息,无法初始化数据库。
可能报出错误信息如下:
initdb: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.
报出此错误时需要先执行切换用户命令。
修改数据库参数
修改监听地址权限、端口等信息。
> vim /mnt/db1/pgdata/pgsql/postgresql.conf
需要修改如下内容:
listen_addresses = '*'
unix_socket_directories = '.'
port = 5432
此处需要注意,PostgreSQL默认端口为5432,此处将端口修改为8432。
修改访问权限
> vim /mnt/db1/pgdata/pgsql/pg_hba.conf
添加如下命令
host all all 0.0.0.0/0 trust
所有配置文件修改成功后,执行 exit
命令退出 postgres
用户。
> exit
设置防火墙规则
> firewall-cmd --zone=public --add-port=5432/tcp --permanent
> firewall-cmd --reload
设置开机自启动
设置开机自动启动服务,并且启动PostgreSQL服务。
> systemctl enable postgresql-10.service
> systemctl start postgresql-10.service
至此PostgreSQL已经安装成功并且启动。
2.2、部署TimescaleDB
安装Cmake
在当前操作系统中检查是否安装了Cmake,如果已经安装,并且版本高于3.4则跳过本操作。
查看版本号命令:
> cmake --version
如果已经安装了Cmake并且版本低于3.4则需要卸载Cmake重新安装更高版本。
卸载Cmake命令:
> yum -y remove cmake
开始安装高版本的Cmake,此处选择版本号为3.10.2。通过wget
命令获取安装包,并且进行解压。
> wget https://cmake.org/files/v3.10/cmake-3.10.2.tar.gz
> tar -zxvf cmake-3.10.2.tar.gz && cd cmake-3.10.2
开始编译安装Cmake。
执行命令:
> ./bootstrap
> gmake
> gmake install
查看编译后的cmake版本
执行命令:
> /usr/local/bin/cmake --version
新建软连接
执行命令:
> ln -s /usr/local/bin/cmake /bin/
终端查看版本
执行命令:
> cmake --version
出现版本表示成功!
cmake编译完成。
获取TimescaleDB
通过git
命令获取TimescaleDB的安装包。
进入PostgresSQL的安装目录(是否存在强制要求,暂时不确定,不过可以直接放到PostgresSQL的安装目录之下),载TimescaleDB。
> git clone https://github.com/timescale/timescaledb/
> cd timescaledb
获取timescaledb的安装版本。
> wget https://github.com/timescale/timescaledb/archive/1.0.0.tar.gz
编译TimescaleDB
此操作最容易发生错误,如果发生错误,请仔细查看错误日志。错误日志上都会有详细的错误信息。
开始编译TimescaleDB
执行命令:
> ./bootstrap
> cd ./build && make
> make install
出现如下信息则编译安装成功(可能存在却别)。
[ 2%] Built target sqlupdatefile
[ 4%] Built target sqlfile
[100%] Built target timescaledb
Install the project...
-- Install configuration: "Release"
-- Installing: /home/dege.zzz/pgsql10/share/extension/timescaledb.control
-- Installing: /home/dege.zzz/pgsql10/share/extension/timescaledb--1.0.0.sql
-- Installing: /home/dege.zzz/pgsql10/share/extension/timescaledb--0.7.1--0.8.0.sql
-- Installing: /home/dege.zzz/pgsql10/share/extension/timescaledb--0.1.0--0.2.0.sql
-- Installing: /home/dege.zzz/pgsql10/share/extension/timescaledb--0.2.0--0.3.0.sql
-- Installing: /home/dege.zzz/pgsql10/share/extension/timescaledb--0.3.0--0.4.0.sql
-- Installing: /home/dege.zzz/pgsql10/share/extension/timescaledb--0.4.0--0.4.1.sql
-- Installing: /home/dege.zzz/pgsql10/share/extension/timescaledb--0.4.1--0.4.2.sql
-- Installing: /home/dege.zzz/pgsql10/share/extension/timescaledb--0.4.2--0.5.0.sql
-- Installing: /home/dege.zzz/pgsql10/share/extension/timescaledb--0.5.0--0.6.0.sql
-- Installing: /home/dege.zzz/pgsql10/share/extension/timescaledb--0.6.0--0.6.1.sql
-- Installing: /home/dege.zzz/pgsql10/share/extension/timescaledb--0.6.1--0.7.0.sql
-- Installing: /home/dege.zzz/pgsql10/share/extension/timescaledb--0.6.1--0.7.1.sql
-- Installing: /home/dege.zzz/pgsql10/share/extension/timescaledb--0.7.0--0.7.1.sql
-- Installing: /home/dege.zzz/pgsql10/lib/timescaledb.so
配置postgresql.conf,在数据库启动时自动加载timescale lib库。
vi $PGDATA/postgresql.conf
shared_preload_libraries = 'timescaledb' pg_ctl restart -m fast
对需要使用timescaledb的数据库,创建插件.
psql
psql (10.2)
Type "help" for help. postgres=# create extension timescaledb ;
执行后会展示如下信息:
waiting for server to shut down.... done
server stopped
waiting for server to start....2018-11-14 15:42:53.803 CST [8593] LOG: listening on IPv4 address "0.0.0.0", port 5432
2018-11-14 15:42:53.803 CST [8593] LOG: listening on IPv6 address "::", port 5432
2018-11-14 15:42:53.845 CST [8593] LOG: listening on Unix socket "./.s.PGSQL.5432"
2018-11-14 15:42:53.929 CST [8594] LOG: database system was shut down at 2018-11-14 15:42:53 CST
2018-11-14 15:42:53.954 CST [8593] LOG: database system is ready to accept connections
2018-11-14 15:42:53.955 CST [8600] LOG: TimescaleDB background worker launcher connected to shared catalogsdone
server started
[postgres@localhost ~]$ exit
logout
[root@localhost build]# psql
psql (10.2)
Type "help" for help.postgres=# create extension timescaledb;
2018-11-14 15:43:26.909 CST [8605] WARNING: WELCOME TO_____ _ _ ____________ |_ _(_) | | | _ \ ___ \ | | _ _ __ ___ ___ ___ ___ __ _| | ___| | | | |_/ / | | | | _ ` _ \ / _ \/ __|/ __/ _` | |/ _ \ | | | ___ \ | | | | | | | | | __/\__ \ (_| (_| | | __/ |/ /| |_/ /|_| |_|_| |_| |_|\___||___/\___\__,_|_|\___|___/ \____/Running version 1.0.0For more information on TimescaleDB, please visit the following links:1. Getting started: https://docs.timescale.com/getting-started2. API reference documentation: https://docs.timescale.com/api3. How TimescaleDB is designed: https://docs.timescale.com/introduction/architectureNote: TimescaleDB collects anonymous reports to better understand and assist our users.For more information and how to disable, please see our docs https://docs.timescaledb.com/using-timescaledb/telemetry.2018-11-14 15:43:26.909 CST [8605] CONTEXT: PL/pgSQL function inline_code_block line 3 at RAISE
WARNING:
WELCOME TO_____ _ _ ____________
|_ _(_) | | | _ \ ___ \ | | _ _ __ ___ ___ ___ ___ __ _| | ___| | | | |_/ / | | | | _ ` _ \ / _ \/ __|/ __/ _` | |/ _ \ | | | ___ \ | | | | | | | | | __/\__ \ (_| (_| | | __/ |/ /| |_/ /|_| |_|_| |_| |_|\___||___/\___\__,_|_|\___|___/ \____/Running version 1.0.0
For more information on TimescaleDB, please visit the following links:1. Getting started: https://docs.timescale.com/getting-started2. API reference documentation: https://docs.timescale.com/api3. How TimescaleDB is designed: https://docs.timescale.com/introduction/architectureNote: TimescaleDB collects anonymous reports to better understand and assist our users.
For more information and how to disable, please see our docs https://docs.timescaledb.com/using-timescaledb/telemetry.CREATE EXTENSION
3、维护
维护后期会持续更新。
TimescaleDB部署相关推荐
- title: postGreSQL 插件 timescaleDB 安装使用 date: 2019-02-14 18:02:23
基本环境 操作系统: centOS 7 postGreSQL : 10 timescaleDB : 1.0 + postGreSQL安装 Centos7 安装Postgresql10.5和PostGI ...
- CentOS 7.6安装ZABBIX 4.4.0 + TimescaleDB
介绍 2019.10 ZABBIX 4.4.0 正式发布,发布全新的基于Go语言编写全新agent2和众多新功能特性,接下来介绍最重要的新功能,TimescaleDB数据库,ZABBIX除了支持MyS ...
- TimescaleDB的结构初识
TimescaleDB 的结构 数据自动按时间和空间分片(chunk). 1.partition key(分区键) 是由一个表上的一个列或者多个列组成,用于确定某一行特定数据分布在哪个分区上,用cre ...
- 数据库案例集锦 - 开发者的《如来神掌》
标签 PostgreSQL , PG DBA cookbook , PG Oracle兼容性 , PG 架构师 cookbook , PG 开发者 cookbook , PG 应用案例 背景 「剑魔独 ...
- 安装 部署 postgresql数据库 搭建timescaledb数据库 (时序库)
安装 部署 postgresql数据库 搭建timescaledb数据库 (时序库) timescaledb 搭建 文章目录 安装 部署 postgresql数据库 搭建timescaledb数据库 ...
- 时序数据库timescaleDB安装
参考链接 :时序数据库timescaleDB安装 :http://www.lwops.cn/thread-300-1-1.html 本环境在Centos7.5采用编译安装的方式,主要介绍Postgre ...
- mysql和timescale联合查询_[技术干货] 时序数据库timescaleDB安装
本环境在Centos7.5采用编译安装的方式,主要介绍PostgreSQL 11.7,TimescaleDB 1.6.1,cmake3.8.2 PostgreSQL编译安装需要cmake3.4以上的版 ...
- 如何在Ubuntu 20.04上安装和使用TimescaleDB
The author selected the COVID-19 Relief Fund to receive a donation as part of the Write for DOnation ...
- 【IOT】Thingsboard学习笔记(1):开源IOT平台thingsboard部署-windows平台
云平台Ubuntu系统下安装Thinsboard请参考:Ubuntu下安装Thingsboard 安装Java 8(OpenJDK) ThingsBoard服务运行在Java 8上.请按照以下说明安装 ...
最新文章
- NLP入门 | 通俗讲解Subword Models
- 状态码301 302
- openjudge-NOI 2.6-1759 最长上升子序列
- P2217-[HAOI2007]分割矩阵【dfs,记忆化搜索】
- oracle dg物理和逻辑,Oracle DG介绍(物理无实例)
- template 模板是怎样通过 Compile 编译的
- 使用Sqlserver事务发布实现数据同步
- Leetcode-MySQL-180. 连续出现的数字
- Java并发——Java与多线程
- hello python jpush_Python人脸识别 + 手机推送,老板来了你就会收到短信提示
- recordset.Open strSql, Conn, 3,3
- Excel表格身份证号码如何一键提取性别、年龄、出生年月
- nginx 配置外网域名跳转到内网地址加端口的教程
- java怎么连接activemq集群_ActiveMQ之集群(主从)搭建-yellowcong
- ansiblea基本使用
- maven deploy忽略指定模块module发布到私库
- 保刚性图像变形算法-Siggraph 2004
- 统计大写字符、小写字符、数字等个数
- Observability: 如何为 APM 定制 transactions 及 spans
- 开源小程序CMS网站, JeeWx-App-CMS 1.0 首版本发布