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 安装包。
执⾏命令:
1
2
3
4> 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(如果有专业运维人员可以进行详细配置来规避此问题)。
执行命令:
1
2> vim /etc/selinux/config
修改内容:
1
2
3SELINUX=disable #SELINUXTYPE=targeted
创建用户
需要注意的是PostgresSQL是禁止使用超级管理员来运行服务命令的,所以我们需要创建一个账号来进行后续的PostgresSQL的安装。
我们创建一个用户组,向创建的用户组中添加一个用户账号,并且给该用户创建密码。
执行命令:
1
2
3
4> groupadd postgres > useradd -g postgres postgres > passwd postgres
创建安装目录
创建 PostgreSQL需要的⽬录,并且为⽬录 /mnt/db1
赋予读写权限。
1
2
3
4> 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需要的依赖。
1
2
3
4
5
6> 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
,解压、编译、安装等操作
执行命令:
1
2> cd /opt/postgresql_pkg
进入保存安装包的目录之后,解压安装包并进入解压后的目录。
执行命令:
1
2
3
4> tar -zxvf ./postgresql-11.1.tar.gz > mkdir -p ./postgresql-11.1/build_dir > cd ./postgresql-11.1/build_dir
开始编译
1
2
3
4> ../configure --prefix=/usr/local/pgsql --without-readline --with-openssl > make world > make install
启动配置
添加启动配置文件。
执行命令:
1
2> vim /usr/lib/systemd/system/postgresql-10.service
向新建的文件中贴入一下内容。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21[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
文件。
执行命令:
1
2> vim /etc/profile
向打开的配置文件最后处添加一下内容。
1
2
3
4
5
6
7
8
9
10
11
12export 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
保存之后,执行命令使环境变量生效。
1
2> source /etc/profile
初始化数据库
初始化 PostgreSQL数据库,切换账号到postgres
,进行初始化操作。
1
2
3> su - postgres > initdb -D $PGDATA -U postgres --locale=en_US.UTF8 -E UTF8
需要注意的是,如果此处没有切换账号,仍然使用root账号进行初始化时,会反馈错误信息,无法初始化数据库。
可能报出错误信息如下:
1
2
3
4initdb: cannot be run as root Please log in (using, e.g., "su") as the (unprivileged) user that will own the server process.
报出此错误时需要先执行切换用户命令。
修改数据库参数
修改监听地址权限、端口等信息。
1
2> vim /mnt/db1/pgdata/pgsql/postgresql.conf
需要修改如下内容:
1
2
3
4listen_addresses = '*' unix_socket_directories = '.' port = 5432
此处需要注意,PostgreSQL默认端口为5432,此处将端口修改为8432。
修改访问权限
1
2> vim /mnt/db1/pgdata/pgsql/pg_hba.conf
添加如下命令
1
2
3
4
5
6host all all 0.0.0.0/0 trust
所有配置文件修改成功后,执行 exit
命令退出 postgres
用户。
1
2> exit
设置防火墙规则
1
2
3> firewall-cmd --zone=public --add-port=5432/tcp --permanent > firewall-cmd --reload
设置开机自启动
设置开机自动启动服务,并且启动PostgreSQL服务。
1
2
3> systemctl enable postgresql-10.service > systemctl start postgresql-10.service
至此PostgreSQL已经安装成功并且启动。
2.2、部署TimescaleDB
安装Cmake
在当前操作系统中检查是否安装了Cmake,如果已经安装,并且版本高于3.4则跳过本操作。
查看版本号命令:
1
2> cmake --version
如果已经安装了Cmake并且版本低于3.4则需要卸载Cmake重新安装更高版本。
卸载Cmake命令:
1
2> yum -y remove cmake
开始安装高版本的Cmake,此处选择版本号为3.10.2。通过wget
命令获取安装包,并且进行解压。
1
2
3> 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。
执行命令:
1
2
3
4> ./bootstrap > gmake > gmake install
查看编译后的cmake版本
执行命令:
1
2> /usr/local/bin/cmake --version
新建软连接
执行命令:
1
2> ln -s /usr/local/bin/cmake /bin/
终端查看版本
执行命令:
1
2> cmake --version
出现版本表示成功!
cmake编译完成。
获取TimescaleDB
通过git
命令获取TimescaleDB的安装包。
进入PostgresSQL的安装目录(是否存在强制要求,暂时不确定,不过可以直接放到PostgresSQL的安装目录之下),载TimescaleDB。
1
2
3> git clone https://github.com/timescale/timescaledb/ > cd timescaledb
获取timescaledb的安装版本。
1
2> wget https://github.com/timescale/timescaledb/archive/1.0.0.tar.gz
编译TimescaleDB
此操作最容易发生错误,如果发生错误,请仔细查看错误日志。错误日志上都会有详细的错误信息。
开始编译TimescaleDB
执行命令:
1
2
3
4> ./bootstrap > cd ./build && make > make install
出现如下信息则编译安装成功(可能存在却别)。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23[ 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库。
1
2
3
4vi $PGDATA/postgresql.conf shared_preload_libraries = 'timescaledb' pg_ctl restart -m fast
对需要使用timescaledb的数据库,创建插件.
1
2
3
4
5psql psql (10.2) Type "help" for help. postgres=# create extension timescaledb ;
执行后会展示如下信息:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84waiting 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 catalogs done 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.0 For more information on TimescaleDB, please visit the following links: 1. Getting started: https://docs.timescale.com/getting-started 2. API reference documentation: https://docs.timescale.com/api 3. How TimescaleDB is designed: https://docs.timescale.com/introduction/architecture Note: 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-started 2. API reference documentation: https://docs.timescale.com/api 3. How TimescaleDB is designed: https://docs.timescale.com/introduction/architecture Note: 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部署的全部内容,更多相关TimescaleDB部署内容请搜索靠谱客的其他文章。
发表评论 取消回复