edgexfoundry eclipse开发环境搭建 跑起来!

非VIP请到社区阅读:http://www.discuz.edgexfoundry.net/discuz/ 

 

 

环境准备:

  • eclipse
  • JDK 8

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 )改成如下内容:
  
  1. spring.application.name=core-command  # 本模块注册在consul的服务名,此名称在其它两个地方也会出现(core-config-seed中的config目下子目录,ConsulDiscoveryClientTemplate.java中的APP_ID值),需要保持一致
  2. spring.cloud.consul.host=localhost           #consul服务器IP,由于我的consul就装在本机,所以直接localhost就可以
  3. spring.cloud.consul.port=8500                 #consul服务器端口,默认是8500
  4. spring.cloud.consul.config.profileSeparator=;   #consul多环境下,服务名与环境名称之间的分隔符
  5. spring.cloud.consul.enabled=true   #开启consul注册服务,此参数为true才会去找consul,若为false就不用consul了
  6. spring.profiles.active=consul   #环境名称,此值可以自已定义,要与core-config-seed模块中一致即可
  7.  
复制代码

现在以图形方式标注出一致要求点:



上面只是以core-command为例,其它模块bootstrap.properties文件要按上述规则改好

3、安装consul
下载consul ,社区提供了一个,地址:consul下载
将其解压,比如解压到D盘根目录下,通过dos命令,进入到consul.exe目录,执行如下命令:
 
  1. 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
复制代码

上面红色部门要写真实存在的目录,启动后显示如下:
  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
  2. BootstrapExpect is set to 1; this is the same as Bootstrap mode.
  3. bootstrap = true: do not enable unless necessary
  4. ==> Starting Consul agent...
  5. ==> Consul agent running!
  6.            Version: 'v1.2.0'
  7.            Node ID: '605a92fb-2a06-0180-2963-5c85fb8357ff'
  8.          Node name: '127.0.0.1'
  9.         Datacenter: 'dc1' (Segment: '<all>')
  10.             Server: true (Bootstrap: true)
  11.        Client Addr: [0.0.0.0] (HTTP: 8500, HTTPS: -1, DNS: 8600)
  12.       Cluster Addr: 127.0.0.1 (LAN: 8301, WAN: 8302)
  13.            Encrypt: Gossip: false, TLS-Outgoing: false, TLS-Incoming: false
  14.  
  15. ==> Log data will now stream in as it occurs:
  16.  
  17.     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.
  18.     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}]
  19.     2018/10/12 10:59:52 [INFO] raft: Node at 127.0.0.1:8300 [Follower] entering Follower state (Leader: "")
  20.     2018/10/12 10:59:52 [INFO] serf: EventMemberJoin: 127.0.0.1.dc1 127.0.0.1
  21.     2018/10/12 10:59:52 [INFO] serf: EventMemberJoin: 127.0.0.1 127.0.0.1
  22.     2018/10/12 10:59:52 [INFO] consul: Handled member-join event for server "127.0.0.1.dc1" in area "wan"
  23.     2018/10/12 10:59:52 [INFO] consul: Adding LAN server 127.0.0.1 (Addr: tcp/127.0.0.1:8300) (DC: dc1)
  24.     2018/10/12 10:59:52 [INFO] agent: Started DNS server 0.0.0.0:8600 (udp)
  25.     2018/10/12 10:59:52 [INFO] agent: Started DNS server 0.0.0.0:8600 (tcp)
  26.     2018/10/12 10:59:52 [INFO] agent: Started HTTP server on [::]:8500 (tcp)
  27.     2018/10/12 10:59:52 [INFO] agent: started state syncer
  28.     2018/10/12 10:59:59 [ERR] agent: failed to sync remote state: No cluster leader
  29.     2018/10/12 11:00:01 [WARN] raft: Heartbeat timeout from "" reached, starting election
  30.     2018/10/12 11:00:01 [INFO] raft: Node at 127.0.0.1:8300 [Candidate] entering Candidate state in term 2
  31.     2018/10/12 11:00:01 [INFO] raft: Election won. Tally: 1
  32.     2018/10/12 11:00:01 [INFO] raft: Node at 127.0.0.1:8300 [Leader] entering Leader state
  33.     2018/10/12 11:00:01 [INFO] consul: cluster leadership acquired
  34.     2018/10/12 11:00:01 [INFO] consul: New leader elected: 127.0.0.1
  35.     2018/10/12 11:00:01 [INFO] consul: member '127.0.0.1' joined, marking health alive
  36.     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打印如下运行信息:
  1.   ___    _         __  __         ___           __ _        ___             _
  2. | __|__| |__ _ ___\ \/ /  ___   / __|___ _ _  / _(_)__ _  / __| ___ ___ __| |
  3. | _|/ _` / _` / -_)>  <  |___| | (__/ _ \ ' \|  _| / _` | \__ \/ -_) -_) _` |
  4. |___\__,_\__, \___/_/\_\        \___\___/_||_|_| |_\__, | |___/\___\___\__,_|
  5.           |___/                                     |___/                     
  6. /*******************************************************************************
  7. * Copyright 2016-17, Dell, Inc.  All Rights Reserved.
  8. ******************************************************************************/
  9.  
  10. 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)
  11. 2018-10-12 11:25:46.200  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : No active profile set, falling back to default profiles: default
  12. 2018-10-12 11:25:47.530  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : Connecting to Consul at %s: %d
  13. 2018-10-12 11:25:47.532  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : Attempting to get consul connection.
  14. 2018-10-12 11:25:49.145  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : %s doesn't exist! Start importing configuration data.
  15. 2018-10-12 11:25:49.298  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context application;consul
  16. 2018-10-12 11:25:49.789  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context application;docker
  17. 2018-10-12 11:25:49.991  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context core-command;consul
  18. 2018-10-12 11:25:50.989  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context core-command;docker
  19. 2018-10-12 11:25:51.947  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context core-data;consul
  20. 2018-10-12 11:25:53.621  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context core-data;docker
  21. 2018-10-12 11:25:56.186  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context core-metadata;consul
  22. 2018-10-12 11:25:58.314  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context core-metadata;docker
  23. 2018-10-12 11:25:59.829  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context device-bacnet;consul
  24. 2018-10-12 11:26:01.430  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context device-bacnet;docker
  25. 2018-10-12 11:26:02.788  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context device-bluetooth;consul
  26. 2018-10-12 11:26:04.015  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context device-bluetooth;docker
  27. 2018-10-12 11:26:05.240  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context device-fischertechnik;consul
  28. 2018-10-12 11:26:06.585  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context device-fischertechnik;docker
  29. 2018-10-12 11:26:07.815  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context device-modbus;consul
  30. 2018-10-12 11:26:09.123  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context device-modbus;docker
  31. 2018-10-12 11:26:10.165  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context device-mqtt;consul
  32. 2018-10-12 11:26:11.898  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context device-mqtt;docker
  33. 2018-10-12 11:26:14.598  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context device-snmp;consul
  34. 2018-10-12 11:26:15.781  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context device-snmp;docker
  35. 2018-10-12 11:26:17.039  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context device-virtual;consul
  36. 2018-10-12 11:26:18.189  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context device-virtual;docker
  37. 2018-10-12 11:26:19.539  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context export-client;consul
  38. 2018-10-12 11:26:20.521  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context export-client;docker
  39. 2018-10-12 11:26:21.455  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context export-distro;consul
  40. 2018-10-12 11:26:22.205  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context export-distro;docker
  41. 2018-10-12 11:26:23.080  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context support-logging;consul
  42. 2018-10-12 11:26:23.841  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context support-logging;docker
  43. 2018-10-12 11:26:24.639  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context support-notifications;consul
  44. 2018-10-12 11:26:25.545  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context support-notifications;docker
  45. 2018-10-12 11:26:26.329  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context support-rulesengine;consul
  46. 2018-10-12 11:26:27.497  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context support-rulesengine;docker
  47. 2018-10-12 11:26:28.415  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context support-scheduler;consul
  48. 2018-10-12 11:26:29.805  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : found config file: application.properties in context support-scheduler;docker
  49. 2018-10-12 11:26:30.781  INFO 24920 --- [           main] o.e.EdgeXConfigSeedApplication           : Started EdgeXConfigSeedApplication in 45.383 seconds (JVM running for 46.219)
  50.  
复制代码此项目运行结束会自动退出,然后去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窗口,执行结果如下表现正常:
  1. E:\edgex\developer-scripts-master>init_shell.bat
  2.  
  3. E:\edgex\developer-scripts-master>"E:\MongoDB\Server\4.0\bin\mongo.exe" "init_mongo.js"
  4. MongoDB shell version v4.0.0
  5. connecting to: mongodb://127.0.0.1:27017
  6. MongoDB server version: 4.0.0
  7. Successfully added user: {
  8.         "user" : "admin",
  9.         "roles" : [
  10.                 {
  11.                         "role" : "readWrite",
  12.                         "db" : "authorization"
  13.                 }
  14.         ]
  15. }
  16. Successfully added user: {
  17.         "user" : "admin",
  18.         "roles" : [
  19.                 {
  20.                         "role" : "readWrite",
  21.                         "db" : "admin"
  22.                 }
  23.         ]
  24. }
  25. Successfully added user: {
  26.         "user" : "meta",
  27.         "roles" : [
  28.                 {
  29.                         "role" : "readWrite",
  30.                         "db" : "metadata"
  31.                 }
  32.         ]
  33. }
  34. Successfully added user: {
  35.         "user" : "core",
  36.         "roles" : [
  37.                 {
  38.                         "role" : "readWrite",
  39.                         "db" : "coredata"
  40.                 }
  41.         ]
  42. }
  43. Successfully added user: {
  44.         "user" : "rules_engine_user",
  45.         "roles" : [
  46.                 {
  47.                         "role" : "readWrite",
  48.                         "db" : "rules_engine_db"
  49.                 }
  50.         ]
  51. }
  52. Successfully added user: {
  53.         "user" : "notifications",
  54.         "roles" : [
  55.                 {
  56.                         "role" : "readWrite",
  57.                         "db" : "notifications"
  58.                 }
  59.         ]
  60. }
  61. Successfully added user: {
  62.         "user" : "logging",
  63.         "roles" : [
  64.                 {
  65.                         "role" : "readWrite",
  66.                         "db" : "logging"
  67.                 }
  68.         ]
  69. }
复制代码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主要模块都要跑起来了!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

灰哥哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值