apollo
安装部署请参考官网:https://github.com/ctripcorp/apollo/wiki/分布式部署指南
多环境配置
假设配置dev,fat两套环境
1.数据库为一个apolloportaldb 两个apolloconfigdb
2.服务为一个portal 两个config 两个admin
3.每个config和admin配置对应的数据库配置
4.每个apolloconfigdb配置对应的eureka服务,注意ip端口
![](https://img.haomeiwen.com/i16701032/7c83135283fd8076.png)
5.apolloportaldb库配置多个环境
![](https://img.haomeiwen.com/i16701032/6c6429f5fc147964.png)
6.portal的apollo-env.properties 配置对应的服务
![](https://img.haomeiwen.com/i16701032/a2b0ebc0b66f5e45.png)
注意
-
1.假设有一个环境后面才配置,需要把app,appnamespace,cluster,namespace 四张表的数据手动insert全部导进去,不然会报错
image.png
-
2.查看各自的eureka服务,是否注册错乱,鼠标放上去,看左下角的ip是否错乱
image.png
之前配置生产环境的时候,一直预发环境配置不显示,原因是配置错了,在上面红的配置了,UAT, 老眼昏花了
![](https://img.haomeiwen.com/i16701032/2d6b3c6cd1b9ffae.png)
springboot整合
1.application.properties配置
app.id=statistics
apollo.bootstrap.enabled=true
apollo.bootstrap.namespaces=application,jdbc
或者applicatoin.yml配置
app:
id: statistics
apollo:
bootstrap:
enabled: true
namespaces: application,jdbc
2.opt/settings/server.properties(windows版本在c盘)
apollo.meta=http://47.99.87.200:8080
#配置自定义缓存目录
apollo.cacheDir=D:/workspace/openapi/datawarehouse-openapi-rpc-service/src/main/config
#配置本地开发
#env=Local
3.配置Local的方式
![](https://img.haomeiwen.com/i16701032/e4c45a29c69d93c7.png)
spring整合
1.spring只需要两个配置,一个是app.properties,写appid一行配置即可
![](https://img.haomeiwen.com/i16701032/bcef9566a50683d3.png)
2.在spring的配置文件中引入schema,然后配置
多个用逗号隔开
<apollo:config namespaces="openapi,application" />
![](https://img.haomeiwen.com/i16701032/ad8a8f722b841e2a.png)
3.新增opt/settings/server.properties配置文件
apollo.meta=http://47.99.87.200:8080
apollo.cacheDir=D:/workspace/openapi/datawarehouse-openapi-rpc-service/src/main/config //配置本地缓存目录
![](https://img.haomeiwen.com/i16701032/eb0a31ed910d7a10.png)
4.本地调试
![](https://img.haomeiwen.com/i16701032/2caa346777a250fb.png)
一些经验总结
1.java客户端获取当前环境代码
Foundation.server().getEnvType();
2.apollo.portal.envs配置:
直接在apolloportaldb.serverconfig表修改数据
![](https://img.haomeiwen.com/i16701032/db4c2cbc5d68d10e.png)
或
![](https://img.haomeiwen.com/i16701032/cf8e867dd1b29abb.png)
修改后要在apollo-portal中修改配置,解开注释,配置对应的服务器地址,如果就一个环境就配置一个即可,记得要重启
![](https://img.haomeiwen.com/i16701032/4878b592dc12871e.png)
3.部门配置:
直接在apolloportaldb.serverconfig表修改数据
![](https://img.haomeiwen.com/i16701032/5bcb349e1ec9ea98.png)
或者
![](https://img.haomeiwen.com/i16701032/713b642dd51cbef1.png)
4.修改apollo-configservice默认端口8080为其他端口,需要修改对应的表数据和客户端的配置也要对应修改
![](https://img.haomeiwen.com/i16701032/02615796f59cfa33.png)
5.本地启动下载跳到内网,需要配置以下,
vi apollo-configservice/config/application-github.properties和vi apollo-adminservice/config/application-github.properties
都添加一行配置,强制指定eureka服务
eureka.instance.ip-address=47.111.91.73
改之前
![](https://img.haomeiwen.com/i16701032/55c41789b3fd19c1.png)
改完后
![](https://img.haomeiwen.com/i16701032/6989ce0947d2f1f1.png)
6.删除项目,namespace
只能通过这个界面删除,管理员登录,已有实例也会直接删除,请注意通知相关人员后再删除
![](https://img.haomeiwen.com/i16701032/220d4e5fd469b810.png)
7.application 没有点发布,会一直报错,即使是空配置,也要点发布
![](https://img.haomeiwen.com/i16701032/953d3d02c4bd26b0.png)