这段时间接手的项目用到apollo配置中心,感觉和cloud的config、阿里的nacos一样,结果。。。还是要了解、学习内部的一些原理,因为遇到一个问题,简单描述一下:应用程序代码修改配置后需要立即调用查询配置,由于adminservice修改配置后会通知configservice,configservice会每隔一秒钟拉取db中的配置,所以不会立即查询到修改后的配置,其实可以用本地缓存+事务代码可以解决,但是看是否可以用apollo本身技术解决该问题,之前也没用过apollo,需要研究学习一下,从头开始。
一、下载地址:apollo源码地址http://xn--apollo-u20k9d284uuzt/
这里我是 git bash环境下载的,zip包没试过,也不知道出现的异常会不会和git一样;
然后用idea打开,并构建编译,保证不编译出错,如果有maven引用编译出错,在idea或者dos命令执行 mvn -U clean install ,然后再编译打包就可以
二、执行sql,生成数据库
找到目录下的两个sql文件,并数据库执行这两个sql文件,之后会生成两个数据库:
apolloconfigdb、apolloportaldb
三、修改文件:
先修改build.bat文件里的 下图中画出的配置变量值,然后双击运行。注意,这里url配置如果你的mysql是8.0+的版本,就要加:serverTimezone=Asia/Shanghai 时间区域,不然连接数据库异常。然后是自己的数据库用户名,密码
四、启动项目:
首先启动:apollo-configservice 注册中心项目,启动参数vmoptions:
-Denv=dev
-Dspring.profiles.active=github
-Deureka.service.url=http://localhost:8080/eureka/
-Dspring.datasource.url=jdbc:mysql://localhost:3306/apolloconfigdb?characterEncoding=utf8&serverTimezone=Asia/Shanghai
-Dspring.datasource.username=root
-Dspring.datasource.password=root
-Dlogging.file=D:/logs/apollo-assembly.log
附图下:
然后启动:apollo-assembly ,配置系统启动参数vmoptions:
-Denv=dev
-Dspring.profiles.active=github
-Deureka.service.url=http://localhost:8080/eureka/
-Dspring.datasource.url=jdbc:mysql://localhost:3306/apolloconfigdb?characterEncoding=utf8&serverTimezone=Asia/Shanghai
-Dspring.datasource.username=root
-Dspring.datasource.password=root
-Dlogging.file=D:/logs/apollo-assembly.log
prigram arguments:
–configservice --adminservice
附下图:
最后启动:apollo-portal ,配置系统启动参数vmoptions:
-Denv=dev
-Ddev_meta=http://localhost:8080
-Dspring.profiles.active=github,auth
-Deureka.client.enabled=false
-Dhibernate.query.plan_cache_max_size=192
-Dserver.port=8170
-Dspring.datasource.url=jdbc:mysql://localhost:3306/apolloportaldb?characterEncoding=utf8&serverTimezone=Asia/Shanghai
-Dspring.datasource.username=root
-Dspring.datasource.password=root
-Dlogging.file=D:/logsh/apollo-portal.log
prigram arguments:
–portal
附下图:
启动无异常后:http://localhost:8080 ,查看注册中心
然后打开portal,这里端口为:8170 ,http://localhost:8170
到这里就是整个源码本地启动步骤,之前由于看了好多个博客,踩了好多坑,相信这是该问题最后一坑。
有建议留言,谢谢!