视频教程
本章将介绍ThingsBoard初始化数据Postgres+Cassandra,两种数据库结合使用,以及源码的编译安装。本机环境:Centos7、Docker、Postgres、Cassandra
环境安装
开发环境要求:
- Docker ;
- Docker;
- Postgres:
- Cassandra
Postgres数据库的安装以及使用,可查看👇文章
1、使用Docker创建Cassandra容器化创建
docker run -p 9042:9042 --name cassandra -e CASSANDRA_USERNAME=cassandra -e CASSANDRA_PASSWORD=cassandra -d cassandra:lastest
docker run :运行容器
name :容器到名称为cassandra
-e CASSANDRA_USERNAME=cassandra :数据库账号
-e CASSANDRA_PASSWORD=cassandra :数据库密码
9042:9042 :将容器的9042端口映射到主机9042上
-d :程序后台执行cassandra:lastest :cassandra最新版本号
docker logs postgres
2、使用DBeaverEE链接数据库,(你们也可以用你们自己的根据自己情况)
填入:服务器地址+端口+账号+密码
测试连接是否正常
3、将初始化数据库工程,移动到对应的目录下
4、打开application目录下的thingsboard.yml,更改datasource链接地址
localhost:修改成你们自己的地址以及数据库名称
username:Cassandra数据库用户名
password:Cassandra数据库密码
cassandra:
# Thingsboard cluster name
cluster_name: "${CASSANDRA_CLUSTER_NAME:Thingsboard Cluster}"
# Thingsboard keyspace name
keyspace_name: "${CASSANDRA_KEYSPACE_NAME:thingsboard}"
# Specify node list
url: "${CASSANDRA_URL:47.104.235.15:9042}"
# Specify the local data center name
local_datacenter: "${CASSANDRA_LOCAL_DATACENTER:datacenter1}"
ssl:
# Enable/disable secure connection
enabled: "${CASSANDRA_USE_SSL:false}"
# Enable/disable validation of Cassandra server hostname
# If enabled, the hostname of the Cassandra server must match the CN of the server certificate
hostname_validation: "${CASSANDRA_SSL_HOSTNAME_VALIDATION:true}"
# Set trust store for client authentication of the server (optional, uses trust store from default SSLContext if not set)
trust_store: "${CASSANDRA_SSL_TRUST_STORE:}"
# The password for Cassandra trust store key
trust_store_password: "${CASSANDRA_SSL_TRUST_STORE_PASSWORD:}"
# Set key store for server authentication of the client (optional, uses key store from default SSLContext if not set)
# A key store is only needed if the Cassandra server requires client authentication
key_store: "${CASSANDRA_SSL_KEY_STORE:}"
# The password for the Cassandra key store
key_store_password: "${CASSANDRA_SSL_KEY_STORE_PASSWORD:}"
# Comma-separated list of cipher suites (optional, uses Java default cipher suites if not set)
cipher_suites: "${CASSANDRA_SSL_CIPHER_SUITES:}"
# Enable/disable JMX
jmx: "${CASSANDRA_USE_JMX:false}"
# Enable/disable metrics collection.
metrics: "${CASSANDRA_USE_METRICS:false}"
# NONE SNAPPY LZ4
compression: "${CASSANDRA_COMPRESSION:none}"
# Specify cassandra cluster initialization timeout in milliseconds (if no hosts are available during startup)
init_timeout_ms: "${CASSANDRA_CLUSTER_INIT_TIMEOUT_MS:300000}"
# Specify cassandra cluster initialization retry interval (if no hosts available during startup)
init_retry_interval_ms: "${CASSANDRA_CLUSTER_INIT_RETRY_INTERVAL_MS:3000}"
# Cassandra max local requests per connection
max_requests_per_connection_local: "${CASSANDRA_MAX_REQUESTS_PER_CONNECTION_LOCAL:32768}"
# Cassandra max remote requests per connection
max_requests_per_connection_remote: "${CASSANDRA_MAX_REQUESTS_PER_CONNECTION_REMOTE:32768}"
# Credential parameters
credentials: "${CASSANDRA_USE_CREDENTIALS:false}"
# Specify your username
username: "${CASSANDRA_USERNAME:cassandra}"
# Specify your password
password: "${CASSANDRA_PASSWORD:cassandra}"
# Astra DB connect https://astra.datastax.com/
将遥测数据以及最新数据存放入cassandra中,来较少DB数据库的压力,当在生产环境的情况下,如果说遥测数据未存放到cassandra中,就会给DB造成巨大的压力
# Database telemetry parameters
database:
ts_max_intervals: "${DATABASE_TS_MAX_INTERVALS:700}" # Max number of DB queries generated by a single API call to fetch telemetry records
ts:
type: "${DATABASE_TS_TYPE:cassandra}" # cassandra, sql, or timescale (for hybrid mode, DATABASE_TS_TYPE value should be cassandra, or timescale)
ts_latest:
type: "${DATABASE_TS_LATEST_TYPE:cassandra}" # cassandra, sql, or timescale (for hybrid mode, DATABASE_TS_TYPE value should be cassandra, or timescale)
5、 初始化数据库
完成后分别查看cassandra和postgres数据库的表结构是否都创建成功