爱星物联社区版Docker部署

[复制链接]
查看621 | 回复3 | 2024-8-26 11:05:55 | 显示全部楼层 |阅读模式

其实相关部署已经在github有详细的说明了,大家也可以直接转移到Github查看;

接下来是我在Centos7虚拟机上部署过程

Git安装

安装git,方便直接从github上下载代码

# 安装git
yum install git -y
# 验证是否安装成功
git --version

docker安装

### 安装docker依赖环境, 安装docker-ce社区版, 配置镜像加速
# step 1: 安装必要的一些系统工具
yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo
# Step 3: 更新并安装 Docker-CE
yum makecache fast
yum -y install docker-ce
# 防火墙规则允许网络桥接、允许ipv4网络转发
cat <<EOF > /etc/sysctl.d/docker.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
# 先执行这行命令启动网桥过滤功能, 否则会报错/proc/sys/net/bridge/bridge-nf-call-iptables: No such file or directory
modprobe br_netfilter   
sysctl -p /etc/sysctl.d/docker.conf
# 配置镜像加速 阿里云镜像仓库、网易镜像仓库、中科大镜像仓库
mkdir -p /etc/docker
vim /etc/docker/daemon.json
{
    "registry-mirrors":[
        "https://x9w5e7g4.mirror.aliyuncs.com",
        "https://hub-mirrors.c.163.com/",
        "https://Docker.mirrors.ustc.edu.cn/"
    ]
}
systemctl daemon-reload;systemctl enable --now docker
# 查看docker版本, Docker Engine - Community 社区版
docker version  
Client: Docker Engine - Community
 Version:           26.1.2
# 设置nginx为守护开机自启
systemctl enable docker
# 启动nginx
systemctl start docker 

安装docker-compose

# 安装docker-compose 
curl -L https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose  
# 执行加权限
chmod +x /usr/local/bin/docker-compose
# 验证是否安装完成
docker-compose --version
# 如果检测版本出现了错误
# 也可以先卸载现有版本再下别的:
pip3 uninstall  cryptography
# 如果想升级到特定版本,可以使用以下命令:
pip install  cryptography==3.4.8

安装go环境(golang1.21或以上版本)

我习惯安装gvm来管理go的版本

# 安装
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
# 安装依赖
yum install bison
# 检查版本
gvm version
查看当前机器的Go环境
gvm  list
查看所有可安装的Go版本
gvm listall
安装Go
gvm install go1.21.6
切换Go版本
gvm use go1.21.6
查看Go版本
go version

安装nodejs

https://nodejs.org/zh-cn/download/package-manager

nodejs安装v18的版本,这里也建议使用nvm管理nodejs版本

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
nvm install 18
node -v 
npm -v

下载代码

# 服务代码
git clone https://github.com/ubases/ubases_iot_community.git
# 云管平台代码
git clone https://github.com/ubases/ubases_iot_platform_web.git
# 开放平台代码 
git clone https://github.com/ubases/ubases_iot_open_web.git

编译服务&站点

cd ubases_iot_community/bin 
# 编译所有服务
./build.sh

# 编译开放平台,并将编译文件赋值到deploy/web/html/iot_platform_web
cd ubases_iot_platform_web
npm build
cp dist ../ubases_iot_community/deploy/html/iot-platform-web

# 编译开放平台,并将编译文件赋值到deploy/web/html/iot-open-web
cd ubases_iot_open_web
npm build
cp dist ../ubases_iot_community/deploy/html/iot-open-web

至此环境都已经准备好了,接下俩就是Docker部署部分

首先介绍下部署主要分为三部分:

third:第三方服务程序安装目录,包括mysql、clickhouse、nats、etcd、vernemq、ha等

services:所有平台开放的微服务

simulator:设备模拟器,模拟设备接收指令和上报数据

web:开放平台、云管平台前端编译代码、Nginx

配置docker网络

#创建docker网络:
docker network create --driver bridge --subnet 172.16.0.0/16 --gateway 172.16.0.1 docker_iot_network

配置文件依赖地址修改

修改iot_cloud_api_service.yml配置,将webmqtt节的addr改为正确的MQTT地址。可以进到bin/conf/open目录下,执行以下命令:

sed -i 's/127.0.0.1:8883/{服务器Ip}:8883/g' iot_cloud_api_service.yml

sql脚本修改:

# cd deploy/third/mysql/sql
sed -i 's/127.0.0.1/{服务器Ip}/g' iot_config_write.sql

修改MySQL、Clickhouse、redis、nats等密码,这里我就用默认密码了,大家还是修改下吧

打开docker-compose.yml,修改对应的mysql和clickhouse密码

MYSQL\_ROOT\_PASSWORD: iLmz8sCXjkTYuh

CLICKHOUSE\_PASSWORD: iLmz8sCXjkTYuh

打开third/redis/config/redis.config

requirepass iLmz8sCXjkTYuh

打开third/nats/conf/js.config

authorization {
  token: "iLmz8sCXjkTYuh"
}

image.png

修改所有微服务的配置文件中MySQL、Clickhouse、redis、nats对应的密码,如下:

image.png

第三方服务信息配置(下面附带相关账号申请地址)

oss配置修改

iot_app_api_service.yml

iot_app_oem_service.yml

iot_cloud_api_service.yml

将这个三个服务中的oss配置修改为你的,这里我选择的是qiniu

oss:
  useOss: "qiniu" # 这里切换你需要使用的oss平台,这里我选择的是qiniu, https://sso.qiniu.com/
  imgStyle:
    productImg: ""  # 这里设置产品图片增加样式返回,适用列表图片压缩返回
  qiniu:
    Endpoint: "osspublic.hogan123.com"
    AccessKeyID: "xxxxx"
    AccessKeySecret: "xxxxxxx"
    BucketName: "xxxxxx"
  ali:
    Endpoint: "xxxx.xxxx.com"
    AccessKeyID: "xxxx"
    AccessKeySecret: "xxxx"
    BucketName: "xxxxx"
  s3:
    Endpoint: "xxxx.xxxx.com"
    AccessKeyID: "xxxxx"
    AccessKeySecret: "xxxxxxx"
    BucketName: "xxxx"
    Region: "xxxxx"

阿里云IP地址服务

https://market.aliyun.com/products/57002002/cmapi00035184.html?spm=5176.2020520132.101.18.7feb7218rkCYR8#sku=yuncode2918400003

找到服务配置文件iot_app_api_service.yml、iot_app_user_service.yml、
ipService:
  queryUrl: "https://ips.market.alicloudapi.com/iplocaltion?ip="  
  appCode: "APPCODE xxxxxxxxxxxxxxxxxxx"  #修改为你购买的应用码

配置天气平台的应用码

https://openweathermap.org/

空气质量aqicn

https://aqicn.org/data-platform/token/

找到配置文件iot_weather_service.yml
weather:
  provider: openweathermap
  apikey: xxxxxxxxxxx
  aqicnToken: xxxxxxxxxx
  qps: 60
  interval: 1800  #间隔秒数

阿里云短信(首先购买短信,并申请签名和短信模板)

https://www.aliyun.com/activity/daily/cloudcommunication-daily?utm_content=se_1011878322

找到配置文件iot_message_service.yml
SMS:
  provider: Aliyun
  accessId: xxxxxxxxx
  accessKey: xxxxxxxxxx
  sign:
    zh: 测试    #中文签名
    en: "test"  #英文签名
    other: [10dlc国际短信使用]

邮箱账号配置

开放平台、APP邮箱注册使用,收取验证码

邮箱的种类请自行选择,常用腾讯、网易、outlook等,需要根据邮箱种类特殊配置授权方式;

找到配置文件iot_message_service.yml
smtp:
  host: smtp.exmail.qq.com
  port: 465
  #############用户名、密码已被删除,请本地用自己的邮箱测试###############
  userName: [email]xxxxx@xxxxxxx.com[/email]
  password: xxxxxxx
  connectTimeout: 10
  sendTimeout: 10
  helo: "xxxxxx"
  keepAlive: true
  exchange: false #exchange邮箱服务器要设置
  authType: 0 #0:AuthPlain; 1:AuthLogin; 3:AuthCRAMMD5; 4:AuthNone
  ssl: 3 #0:NONE;  3:SSLTLS;  4:STARTTLS; 注意:1和2弃用
  from: [email]xxxxx@xxxxxxx.com[/email]

安装依赖的服务

设置目录权限

chmod -R ugo+w vernemq
# 如果遇到vernemq无法启动的情况,请尝试重设置vernemq子目录和文件的权限
chmod -R ugo+w redis
chmod -R ugo+w haproxy
chmod ugo-w ./mysql/conf/my.cnf
mkdir ./mysql/data
chmod ugo+w ./mysql/data

启动安装依赖服务

cd deploy/third/
# 启动安装依赖服务
docker-compose up -d
# Nats主题注册
deploy/jetstream_tool --addrs "nats://iLmz8sCXjkTYuh@127.0.0.1:4222"

执行docker ps container ls 查看容器运行情况。

使用工具访问对应的组件,例如mysql,确认全部库表生成成功;

image.png

安装iot服务

进入service目录启动所有

cd deploy/service/
docker-compose up -d
# 检查服务运行情况
执行docker ps container ls -a |grep iot_ 查看容器运行情况。

安装web服务

之前web/html的前端代码已经编译,下面直接执行安装即可

cd deploy/web/
docker-compose up -d

安装虚拟设备服务

安装虚拟设备服务,这样开放平台的虚拟设备就可以使用了;

cd deploy/simulator/
docker-compose up -d

最后完整检查下容器的运行情况

image.png

没有失败的,说明你已经全部,接下来你可以通过下面地址访问后台和开放平台

云管平台: http://{IP}:2888

登录账号:admin

登录密码:Admin123

开放平台: http://{IP}:2887

登录账号:[email]opensource@dev.com[/email]

登录密码:Admin123

App:使用云打包构建

https://bbs.ai-thinker.com/forum.php?mod=viewthread&tid=45075&extra=

常见错误

vernemq 运行提示这个错误:

Error generating config with cuttlefish

run vernemq config generate -l debug for more information.

解决方法:

估计应该vernemq/etc和子文件的权限问题

用到Nats相关的服务没有成功运行

检查Nats的运行情况,并检查是否注册相关主题

deploy/jetstream_tool --addrs "nats://iLmz8sCXjkTYuh@127.0.0.1:4222"

确认之后,重新启动失败服务即可

docker restart \$(docker ps -a -q --filter status=exited)

运行后台提示某个服务没有注册,然后刷新一下报错一下不报错

这个是因为项目目录有两个demo_service, 里面与实际的iot_basic_service服务冲突了,直接删除demo_service容器接口,新版本好像已经去掉这个服务的自动安装;

回复

使用道具 举报

iiv | 2024-8-26 12:29:22 | 显示全部楼层
学习,点赞
回复

使用道具 举报

bzhou830 | 2024-8-26 13:39:28 | 显示全部楼层
学习,点赞
选择去发光,而不是被照亮
回复

使用道具 举报

WT_0213 | 2024-8-27 09:19:45 | 显示全部楼层
学习,点赞
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则