当前位置:   article > 正文

Cassandra集群化Docker完整部署_thingsboard + cassandra

thingsboard + cassandra

               Thingsboard下Cassandra集群化Docker部署

                                                                                 徐景周

一、环境

  • CentOS
  • 安装Nano
  1. apt-get update
  2. apt-get install nano

 

  • Oracle JDK:1.8及以上

查找Java安装路径

  1. which java
  2. ls /usr/bin/java (上一步结果路径)
  3. ls -lrt /etc/alternatives/java (上一步结果路径)
  4. ls /usr/lib/jvm/java-8-openjdk-amd64 (最终路径)

 

  • 关闭防火墙
  1. systemctl stop firewalld
  2. systemctl disable firewalld

 

二、单机部署(Docker版)

  1. 停止宿主机Cassandra(如有必要)

  1. sudo service cassandra stop
  2. sudo chkconfig cassandra off
  3. sudo service cassandra status

 

  2. 安装Docker

  • 安装

         请浏览【参考文献 1】。

  • 修改Docker默认目录
  1. sudo service docker stop
  2. mv /var/lib/docker /home/docker
  3. ln -s /home/docker /var/lib/docker
  4. sudo yum install -y nano
  5. sudo nano /usr/lib/systemd/system/docker.service
  6. 文件修改项如下:
  7. ExecStart=/usr/bin/dockerd --graph /home/docker -H fd:// --containerd=/run/containerd/containerd.soc
  8. sudo systemctl daemon-reload
  9. sudo service docker restart
  10. sudo service docker status
  11. docker info | grep Dir

 

  • Docker默认磁盘空间
  1. df -h
  2. docker info
  3. docker exec -it tb-cassandra df -h

 

  • 自启动
sudo systemctl enable docker

 

3. Docker中安装Cassandra

1. 操作指令

  • 安装

  1. docker stop tb-cassandra
  2. docker rm tb-cassandra
  3. docker run --name tb-cassandra -p 7000:7000 -p 7001:7001 -p 7199:7199 -p 9042:9042 -p 9160:9160 -d cassandra:3.0
  • 启动
docker start tb-cassandra
  • 检查
docker ps -a
  • 自启动
docker update --restart=always 容器ID

 

 2. 实现细节

    请浏览【参考文献 2】和【参考文献 3】。

 

4. 修改Cassandra配置

 1. 操作指令

  • 进入容器bash
docker exec -it  tb-cassandra bash
  • 启动cql环境
cqlsh
  • cql环境下,修改族名
update system.local set cluster_name = 'Thingsboard Cluster' where key='local';
  • cql环境下,查看族名
select cluster_name from system.local;
  • cql环境下,退出
exit
  • 刷新配置
nodetool flush system
  • 修改cassandra.yaml配置文件
  1. nano /etc/cassandra/cassandra.yaml
  2. 或者采用文件替换方式(先退出docker bash)
  3. docker exec -it tb-cassandra bash
  4. ls etc/cassandra/cassandra.yaml
  5. exit;
  6. docker ps
  7. docker cp cassandra.yaml 容器id:/etc/cassandra/cassandra.yaml
  8. docker exec -it tb-cassandra bash
  9. cat /etc/cassandra/cassandra.yaml

Cassandra.yaml配置文件修改

 创建目录及修改属性

  1. ls /var/lib/cassandra/
  2. mkdir /var/lib/cassandra/data
  3. mkdir /var/lib/cassandra/commitlog
  4. mkdir /var/lib/cassandra/saved_caches
  5. mkdir /var/lib/cassandra/hints
  6. chown 777 /var/lib/cassandra/data
  7. chown 777 /var/lib/cassandra/commitlog
  8. chown 777 /var/lib/cassandra/saved_caches
  9. chown 777 /var/lib/cassandra/hints

 修改文件下面的选项

  1. cluster_name: 'Thingsboard Cluster
  2. hints_directory: /var/lib/cassandra/hints
  3. data_file_directories:
  4. - /var/lib/cassandra/data
  5. commitlog_directory: /var/lib/cassandra/commitlog
  6. saved_caches_directory: /var/lib/cassandra/saved_caches
  7. seeds: "127.0.0.1”
  8. listen_address: localhost
  9. # broadcast_address: 1.2.3.4
  10. start_rpc: true
  11. rpc_address: 0.0.0.0
  12. broadcast_rpc_address: 1.2.3.4
  • 退出docker bash
exit;
  • 安装Thingsboard对应数据库及数据表(顺序:schema-ts.cql -> schema-entities.cql)
  1. docker ps
  2. docker cp schema-ts.cql 容器id:/root/schema-ts.cql
  3. docker cp schema-entities.cql 容器id:/root/schema-entities.cql
  4. docker exec -it tb-cassandra bash
  5. ls /root
  6. cqlsh -f /root/schema-entities.cql
  7. cqlsh -f /root/schema-ts.cql
  8. exit;
  • 重启Cassandra
docker restart tb-cassandra
  • 查看Cassandra是否启动正常
docker logs tb-cassandra

实现细节

    请浏览【参考文献4】和【参考文献 5】。

 

5. 修改Thingsboard配置

  • 修改文件thingsboard.conf(/usr/share/thingsboard/conf)
  1. # DB Configuration
  2. export DATABASE_ENTITIES_TYPE=sql
  3. export DATABASE_TS_TYPE=cassandra
  4. export SPRING_JPA_DATABASE_PLATFORM=org.hibernate.dialect.PostgreSQLDialect
  5. export SPRING_DR
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/126349
推荐阅读
相关标签
  

闽ICP备14008679号