本章将介绍ThingsBoard初始化数据Postgres+Cassandra,两种数据库结合使用,以及源码的编译安装。本机环境:Centos7、Docker、Postgres、Cassandra

环境安装

开发环境要求:

  1. Docker ;
  2. Docker;
  3. Postgres:
  4. Cassandra

Thingsboard本地源码部署并初始化数据库-CSDN博客文章浏览阅读155次,点赞2次,收藏2次。本章将介绍ThingsBoard的本地环境搭建,以及源码的编译安装。Jdk 11 版本 ;Postgresql 9 以上;Maven 3.6 以上;Git 工具;Idea 开发工具;并初始化数据库https://blog.csdn.net/2401_85648342/article/details/139641461?spm=1001.2014.3001.5501

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

填入:服务器地址+端口+账号+密码

ThingsBoard初始化数据库Postgres+Cassandra_SSL

测试连接是否正常

ThingsBoard初始化数据库Postgres+Cassandra_Cassandra_02

3、将初始化数据库工程,移动到对应的目录下

ThingsBoard初始化数据库Postgres+Cassandra_SSL_03

4、打开application目录下的thingsboard.yml,更改datasource链接地址 

localhost:修改成你们自己的地址以及数据库名称

username:Cassandra数据库用户名

password:Cassandra数据库密码

ThingsBoard初始化数据库Postgres+Cassandra_SSL_04

ThingsBoard初始化数据库Postgres+Cassandra_Cassandra_05

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造成巨大的压力

ThingsBoard初始化数据库Postgres+Cassandra_Cassandra_06

# 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、 初始化数据库

ThingsBoard初始化数据库Postgres+Cassandra_数据库_07

完成后分别查看cassandra和postgres数据库的表结构是否都创建成功

ThingsBoard初始化数据库Postgres+Cassandra_Cassandra_08

ThingsBoard初始化数据库Postgres+Cassandra_数据库_09

初始化数据库完成后,启动ThingsBoard后,你可以http://{your-host-ip}:8080在浏览器中打开(例如http://localhost:8080)。 使用以下默认凭据:

  • 系统层账号: sysadmin@thingsboard.org / sysadmin
  • 租户层账号: tenant@thingsboard.org / tenant
  • 客户层账号: customer@thingsboard.org / customer

可以在帐户详情页面中更改每个帐户的密码。

ThingsBoard初始化数据库Postgres+Cassandra_SSL_10