非VIP请到社区阅读:http://www.discuz.edgexfoundry.net/discuz/ 环境准备:
1、导入各模块项目 1.1 从github网站下载源码:https://github.com/edgexfoundry 选择java,如下图:
1.2 打开eclipse,导入下载的各项目,以maven方式导入,如下图:
导入项目后的结果类似如下: 确保上面模块不要少
2. 修改配置文件bootstrap.properties 2.1 微服务项目的bootstrap.properties配置文件,使其支持consul注册 bootstrap.properties 在src/main/resources 目录下。 比如core-command模块项目此配置文件(bootstrap.properties )改成如下内容:
- spring.application.name=core-command # 本模块注册在consul的服务名,此名称在其它两个地方也会出现(core-config-seed中的config目下子目录,ConsulDiscoveryClientTemplate.java中的APP_ID值),需要保持一致
- spring.cloud.consul.host=localhost #consul服务器IP,由于我的consul就装在本机,所以直接localhost就可以
- spring.cloud.consul.port=8500 #consul服务器端口,默认是8500
- spring.cloud.consul.config.profileSeparator=; #consul多环境下,服务名与环境名称之间的分隔符
- spring.cloud.consul.enabled=true #开启consul注册服务,此参数为true才会去找consul,若为false就不用consul了
- spring.profiles.active=consul #环境名称,此值可以自已定义,要与core-config-seed模块中一致即可
-
复制代码
现在以图形方式标注出一致要求点:
上面只是以core-command为例,其它模块bootstrap.properties文件要按上述规则改好
3、安装consul 下载consul ,社区提供了一个,地址:consul下载 将其解压,比如解压到D盘根目录下,通过dos命令,进入到consul.exe目录,执行如下命令:
- consul agent -data-dir <font color="Red">D:/consul_1.2.0_windows_amd64/data</font> -node=127.0.0.1 -bind=127.0.0.1 -datacenter=dc1 -ui -client=0.0.0.0 -server -bootstrap-expect 1
复制代码
上面红色部门要写真实存在的目录,启动后显示如下:
- D:\consul_1.2.0_windows_amd64>consul agent -data-dir D:/consul_1.2.0_windows_amd64/data -node=127.0.0.1 -bind=127.0.0.1 -datacenter=dc1 -ui -client=0.0.0.0 -server -bootstrap-expect 1
- BootstrapExpect is set to 1; this is the same as Bootstrap mode.
- bootstrap = true: do not enable unless necessary
- ==> Starting Consul agent...
- ==> Consul agent running!
- Version: 'v1.2.0'
- Node ID: '605a92fb-2a06-0180-2963-5c85fb8357ff'
- Node name: '127.0.0.1'
- Datacenter: 'dc1' (Segment: '<all>')
- Server: true (Bootstrap: true)
- Client Addr: [0.0.0.0] (HTTP: 8500, HTTPS: -1, DNS: 8600)
- Cluster Addr: 127.0.0.1 (LAN: 8301, WAN: 8302)
- Encrypt: Gossip: false, TLS-Outgoing: false, TLS-Incoming: false
-
- ==> Log data will now stream in as it occurs:
-
- 2018/10/12 10:59:52 [WARN] agent: Node name "127.0.0.1" will not be discoverable via DNS due to invalid characters. Valid characters include all alpha-numerics and dashes.
- 2018/10/12 10:59:52 [INFO] raft: Initial configuration (index=1): [{Suffrage:Voter ID:605a92fb-2a06-0180-2963-5c85fb8357ff Address:127.0.0.1:8300}]
- 2018/10/12 10:59:52 [INFO] raft: Node at 127.0.0.1:8300 [Follower] entering Follower state (Leader: "")
- 2018/10/12 10:59:52 [INFO] serf: EventMemberJoin: 127.0.0.1.dc1 127.0.0.1
- 2018/10/12 10:59:52 [INFO] serf: EventMemberJoin: 127.0.0.1 127.0.0.1
- 2018/10/12 10:59:52 [INFO] consul: Handled member-join event for server "127.0.0.1.dc1" in area "wan"
- 2018/10/12 10:59:52 [INFO] consul: Adding LAN server 127.0.0.1 (Addr: tcp/127.0.0.1:8300) (DC: dc1)
- 2018/10/12 10:59:52 [INFO] agent: Started DNS server 0.0.0.0:8600 (udp)
- 2018/10/12 10:59:52 [INFO] agent: Started DNS server 0.0.0.0:8600 (tcp)
- 2018/10/12 10:59:52 [INFO] agent: Started HTTP server on [::]:8500 (tcp)
- 2018/10/12 10:59:52 [INFO] agent: started state syncer
- 2018/10/12 10:59:59 [ERR] agent: failed to sync remote state: No cluster leader
- 2018/10/12 11:00:01 [WARN] raft: Heartbeat timeout from "" reached, starting election
- 2018/10/12 11:00:01 [INFO] raft: Node at 127.0.0.1:8300 [Candidate] entering Candidate state in term 2
- 2018/10/12 11:00:01 [INFO] raft: Election won. Tally: 1
- 2018/10/12 11:00:01 [INFO] raft: Node at 127.0.0.1:8300 [Leader] entering Leader state
- 2018/10/12 11:00:01 [INFO] consul: cluster leadership acquired
- 2018/10/12 11:00:01 [INFO] consul: New leader elected: 127.0.0.1
- 2018/10/12 11:00:01 [INFO] consul: member '127.0.0.1' joined, marking health alive
- 2018/10/12 11:00:02 [INFO] agent: Synced node info
复制代码打开浏览器,输入http://localhost:8500/ui 显示如下说明consul安装好并已成功启动了:
4、向consul中灌入配置数据
在eclipse中运行core-config-seed项目 4.1 先修改项目的application.properties文件,如下图:
config可下载我的参考,网盘地址:链接:https://pan.baidu.com/s/1LS21uFBY9GqKLFN9sA8R_g 提取码:948z
4.2 运行core-config-seed项目,如下图:
eclipse console打印如下运行信息:
- ___ _ __ __ ___ __ _ ___ _
- | __|__| |__ _ ___\ \/ / ___ / __|___ _ _ / _(_)__ _ / __| ___ ___ __| |
- | _|/ _` / _` / -_)> < |___| | (__/ _ \ ' \| _| / _` | \__ \/ -_) -_) _` |
- |___\__,_\__, \___/_/\_\ \___\___/_||_|_| |_\__, | |___/\___\___\__,_|
- |___/ |___/
- /*******************************************************************************
- * Copyright 2016-17, Dell, Inc. All Rights Reserved.
- ******************************************************************************/
-
- 2018-10-12 11:25:46.093 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : Starting EdgeXConfigSeedApplication on PC-20151211BTMT with PID 24920 (E:\baidu-host\edgex-java\core-config-seed-master\target\classes started by Administrator in E:\baidu-host\edgex-java\core-config-seed-master)
- 2018-10-12 11:25:46.200 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : No active profile set, falling back to default profiles: default
- 2018-10-12 11:25:47.530 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : Connecting to Consul at %s: %d
- 2018-10-12 11:25:47.532 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : Attempting to get consul connection.
- 2018-10-12 11:25:49.145 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : %s doesn't exist! Start importing configuration data.
- 2018-10-12 11:25:49.298 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context application;consul
- 2018-10-12 11:25:49.789 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context application;docker
- 2018-10-12 11:25:49.991 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context core-command;consul
- 2018-10-12 11:25:50.989 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context core-command;docker
- 2018-10-12 11:25:51.947 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context core-data;consul
- 2018-10-12 11:25:53.621 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context core-data;docker
- 2018-10-12 11:25:56.186 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context core-metadata;consul
- 2018-10-12 11:25:58.314 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context core-metadata;docker
- 2018-10-12 11:25:59.829 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context device-bacnet;consul
- 2018-10-12 11:26:01.430 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context device-bacnet;docker
- 2018-10-12 11:26:02.788 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context device-bluetooth;consul
- 2018-10-12 11:26:04.015 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context device-bluetooth;docker
- 2018-10-12 11:26:05.240 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context device-fischertechnik;consul
- 2018-10-12 11:26:06.585 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context device-fischertechnik;docker
- 2018-10-12 11:26:07.815 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context device-modbus;consul
- 2018-10-12 11:26:09.123 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context device-modbus;docker
- 2018-10-12 11:26:10.165 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context device-mqtt;consul
- 2018-10-12 11:26:11.898 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context device-mqtt;docker
- 2018-10-12 11:26:14.598 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context device-snmp;consul
- 2018-10-12 11:26:15.781 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context device-snmp;docker
- 2018-10-12 11:26:17.039 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context device-virtual;consul
- 2018-10-12 11:26:18.189 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context device-virtual;docker
- 2018-10-12 11:26:19.539 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context export-client;consul
- 2018-10-12 11:26:20.521 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context export-client;docker
- 2018-10-12 11:26:21.455 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context export-distro;consul
- 2018-10-12 11:26:22.205 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context export-distro;docker
- 2018-10-12 11:26:23.080 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context support-logging;consul
- 2018-10-12 11:26:23.841 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context support-logging;docker
- 2018-10-12 11:26:24.639 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context support-notifications;consul
- 2018-10-12 11:26:25.545 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context support-notifications;docker
- 2018-10-12 11:26:26.329 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context support-rulesengine;consul
- 2018-10-12 11:26:27.497 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context support-rulesengine;docker
- 2018-10-12 11:26:28.415 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context support-scheduler;consul
- 2018-10-12 11:26:29.805 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : found config file: application.properties in context support-scheduler;docker
- 2018-10-12 11:26:30.781 INFO 24920 --- [ main] o.e.EdgeXConfigSeedApplication : Started EdgeXConfigSeedApplication in 45.383 seconds (JVM running for 46.219)
-
复制代码此项目运行结束会自动退出,然后去consul界面查看结果,类似下图: 点击上面的"config"查看配置信息,结构如eclipse项目中的config目录,在此你也可手工修改每个条目信息,后面谈到的名各应用是从这里读取配置信息,而非各项目下的application.properties 到此为止,配置数据已成功灌入consul了。 注意:如果再次运行core-config-seed,需要在consul界面上删除config节点,否则已在存的话不会更新到。删除方法如下图:
5、数据库初始化
5.1 安装mongodb , 参考: mongodb安装(window版) 5.2 下载点击: developer-scripts ,此包中含有初始化脚本
5.3 以非认证方式启动mongdb, 执行developer-scripts-master目录下的 startdb-no-auth.bat 注意:确保startdb-no-auth.bat文件里定义的mongod.exe你是安装的正确路径,不对的话改成你安装的路径
5.4 执行developer-scripts-master目录下的 init_shell.bat 注意,建议以cmd 命令方式执行,可以看到执行结果,即打开dos窗口,执行结果如下表现正常:
- E:\edgex\developer-scripts-master>init_shell.bat
-
- E:\edgex\developer-scripts-master>"E:\MongoDB\Server\4.0\bin\mongo.exe" "init_mongo.js"
- MongoDB shell version v4.0.0
- connecting to: mongodb://127.0.0.1:27017
- MongoDB server version: 4.0.0
- Successfully added user: {
- "user" : "admin",
- "roles" : [
- {
- "role" : "readWrite",
- "db" : "authorization"
- }
- ]
- }
- Successfully added user: {
- "user" : "admin",
- "roles" : [
- {
- "role" : "readWrite",
- "db" : "admin"
- }
- ]
- }
- Successfully added user: {
- "user" : "meta",
- "roles" : [
- {
- "role" : "readWrite",
- "db" : "metadata"
- }
- ]
- }
- Successfully added user: {
- "user" : "core",
- "roles" : [
- {
- "role" : "readWrite",
- "db" : "coredata"
- }
- ]
- }
- Successfully added user: {
- "user" : "rules_engine_user",
- "roles" : [
- {
- "role" : "readWrite",
- "db" : "rules_engine_db"
- }
- ]
- }
- Successfully added user: {
- "user" : "notifications",
- "roles" : [
- {
- "role" : "readWrite",
- "db" : "notifications"
- }
- ]
- }
- Successfully added user: {
- "user" : "logging",
- "roles" : [
- {
- "role" : "readWrite",
- "db" : "logging"
- }
- ]
- }
复制代码5.5 关闭mongdb服务,以认证方式再次启动 ,执行startdb-no-auth.bat脚本(注意,确保脚本里是你安装mongodb路径)
5.6 查看数据库 安装mongo客户端工具,参考:mongo客户端安装与使用 数据库、用户名、密码存放在init_mongo.js文件中,如下红色字体部分:
db=db.getSiblingDB('admin') db=db.getSiblingDB('authorization') db.createUser({ user: "admin",pwd: "password",roles: [ { role: "readWrite", db: "authorization" } ]}); //Create keystore collection db.createCollection("keyStore"); db.keyStore.insert( { xDellAuthKey: "x-dell-auth-key", secretKey: "EDGEX_SECRET_KEY" } ); //Create Service Mapping db.createCollection("serviceMapping"); db.serviceMapping.insert( { serviceName: "coredata", serviceUrl: "http://localhost:48080/" }); db.serviceMapping.insert( { serviceName: "metadata", serviceUrl: "http://localhost:48081/" }); db.serviceMapping.insert( { serviceName: "command", serviceUrl: "http://localhost:48082/" }); db.serviceMapping.insert( { serviceName: "rules", serviceUrl: "http://localhost:48084/" }); db.serviceMapping.insert( { serviceName: "notifications", serviceUrl: "http://localhost:48060/" }); db.serviceMapping.insert( { serviceName: "logging", serviceUrl: "http://localhost:48061/" });
db=db.getSiblingDB('admin') db.system.users.remove({}); db.system.version.remove({}); db.system.version.insert({ "_id" : "authSchema", "currentVersion" : 3 }); db=db.getSiblingDB('admin') db.createUser({ user: "admin", pwd: "password", roles: [ { role: "readWrite", db: "admin" } ] });
db=db.getSiblingDB('metadata') db.createUser({ user: "meta", pwd: "password", roles: [ { role: "readWrite", db: "metadata" } ] }); db.createCollection("addressable"); db.addressable.createIndex({name: 1}, {unique: true}); db.createCollection("command"); db.createCollection("device"); db.device.createIndex({name: 1}, {unique: true}); db.createCollection("deviceProfile"); db.deviceProfile.createIndex({name: 1}, {unique: true}); db.createCollection("deviceReport"); db.deviceReport.createIndex({name: 1}, {unique: true}); db.createCollection("deviceService"); db.deviceService.createIndex({name: 1}, {unique: true}); db.createCollection("provisionWatcher"); db.provisionWatcher.createIndex({name: 1}, {unique: true}); db.createCollection("schedule"); db.schedule.createIndex({name: 1}, {unique: true}); db.createCollection("scheduleEvent"); db.scheduleEvent.createIndex({name: 1}, {unique: true});
db=db.getSiblingDB('coredata') db.createUser({ user: "core", pwd: "password", roles: [ { role: "readWrite", db: "coredata" } ] }); db.createCollection("event"); db.createCollection("reading"); db.createCollection("valueDescriptor"); db.valueDescriptor.createIndex({name: 1}, {unique: true});
db=db.getSiblingDB('rules_engine_db') db.createUser({ user: "rules_engine_user", pwd: "password", roles: [ { role: "readWrite", db: "rules_engine_db" } ] });
db=db.getSiblingDB('notifications') db.createUser({ user: "notifications", pwd: "password", roles: [ { role: "readWrite", db: "notifications" } ] }); db.createCollection("notification"); db.createCollection("transmission"); db.createCollection("subscription"); db.notification.createIndex({slug: 1}, {unique: true}); db.subscription.createIndex({slug: 1}, {unique: true});
db=db.getSiblingDB('logging') db.createUser({ user: "logging", pwd: "password", roles: [ { role: "readWrite", db: "logging" } ] }); db.createCollection("logEntry");
数据库连接效果如下图所示: adminmongo-2.png (55.16 KB, 下载次数: 0) 下载附件 2018-10-12 16:08 上传
至此数据初始化工作完成!
6、运行edgex各服务
现在终于到了跑服务的时间了,打开eclipse 按如下顺序跑
6.1 support-logging微服务 简述:本模用于记录日志,可以以数据库或文件格式存储,其它微服务均依赖此模块
6.2 support-notifications 微服务
6.3 core-metadata 微服务 简述:本模用于存储元数据,如 设备配信息、地址信息、事件计划调度等
6.4 core-data 微服务 简述:本模用于存储核心数据,包括设备采集返回的数据、值描述信息、导出云端客户注册信息 等
6.5 core-command 微服务 简述:本模提供向设备发送指令微服务
6.6 device-virtual 微服务 简述:本模是虚拟设备服务,在没有真实设备时,可用此模块进行模拟调测
6.7 export-client 微服务 简述:本模提供导出注册服务,需要导出的均需通过此服务注册,比导出到云端第三方系统,支持restful、mqtt
6.8 export-distro 微服务 简述:本模执行导出分发任务,接收core-data模块消息(zeromq), 扫描export-client注册客户,符合条件的进行信息导出分发
6.9 support-rulesengine 微服务 简述:本模实现了供规则引擎功能,可以接收export-distro或core-data模块发来的消息(zeromq),对满足定义好的规则条件的,会触发相应的动作(比如调用core-command发送指令)
此模块启动可能会报错,请关注applications.properties如下两个参数: #rules.default.path=/edgex/rules #下面要写绝对路径,真实存在的路径,存放生成的规则文件 rules.default.path=E:/baidu-host/edgex-java/support-rulesengine-master/src/main/drl rules.packagename=org.edgexfoundry.rules rules.fileextension=.drl #下面要写绝对路径,模块rule-template.drl 文件所在的目录路径 rules.template.path=E:/baidu-host/edgex-java/support-rulesengine-master/src/main/resources rules.template.name=rule-template.drl
6.10 全部启动完毕,将在consul看到如下效果
若看到上面界面,恭喜你!edgexfoundry主要模块都要跑起来了! |