建设银行英文网站,建设教育信息网站工作总结,营销方案案例范文通用,什么软件能搜索关键词能快速找到最新Apollo 版本发布2.1.0 https://www.apolloconfig.com/#/zh/design/apollo-design 环境说明
ecs 主机一台数据库mysql 8.0docker 环境 apollo 是内网可信应用#xff0c;最好是部署在内网里面#xff0c;外网不可使用#xff0c;避免配置信息泄漏#xff0c;这里为了方…最新Apollo 版本发布2.1.0 https://www.apolloconfig.com/#/zh/design/apollo-design 环境说明
ecs 主机一台数据库mysql 8.0docker 环境 apollo 是内网可信应用最好是部署在内网里面外网不可使用避免配置信息泄漏这里为了方便演示直接把端口暴露到了外网 导入sql 官方的sql地址https://github.com/apolloconfig/apollo/tree/master/scripts/sql 注意对应分支与版本部署的时候是最新版本所以我直接拿master的 三个组件admi-service、config-service 、 portal 环境与db的关系可以参考这张图
admin-service、config-service 连config 每个环境都需要独立部署一个config 的db这样做到隔离portal 连portal 可以简单理解为 admin 负责的是管理端的接口 config 负责客户端java 连的就是config portal 负责的是界面和权限管理端的那边逻辑
docker 部署 安装docker 比较多教程这边就不赘述了 脚本https://raw.githubusercontent.com/freshgeek/linux_software/master/apollo-docker-start.sh
其中需要修改的是对应的数据库连接信息和cs 对应的访问路径docker 部署最大的问题是IP和端口在外网情况下不识别。所以这里也直接吧端口映射出去了 修改完成后直接 sh apollo-docker-start.sh
注意主机的防火墙问题可能导致内部连不上、外部访问不了等情况。务必检查一下
登陆之后的配置
登陆apollo portal 的地址和端口 默认是apollo/admin注意修改系统管理工具 - 系统参数 将环境 修改为前面docker 脚本中对应的两个环境和对应的地址
在config service 中的eureka 改为自己可以访问的config service 地址 准备springboot 项目连接apollo
我这边是springboot 2.2.6.RELEASEapollo client 2.1.0
dependencygroupIdcom.ctrip.framework.apollo/groupIdartifactIdapollo-client/artifactIdversion2.1.0/version/dependency
配置文件
application.properties 中只需要添加 app.id应用名
apollo.bootstrap.enabledtrue
apollo.bootstrap.namespacesapplication
apollo.bootstrap.eagerLoad.enabledtrue
# 测试环境 cs 地址 或者 线上环境cs地址
apollo.metahttp://x.x.x.x:8060
apollo.clusterdefault
注解EnableApolloConfig
添加到启动类上 即可
其他的都可以放apollo动态配置了注意配置需要发布之后才能拿到
更多好玩的官方还推荐的https://github.com/apolloconfig/apollo-use-cases
官方的那个动态调整日志的写得有点啰嗦这里贴下我的
import cn.hutool.core.util.StrUtil;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfig;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.logging.LogLevel;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.context.annotation.Configuration;import javax.annotation.PostConstruct;
import javax.annotation.Resource;/*** author chenchao*/
Slf4j
Configuration
public class DynamicLogLevelConfig {private static final String LOGGER_TAG logging.level.;Resourceprivate LoggingSystem loggingSystem;ApolloConfigprivate Config config;ApolloConfigChangeListenerprivate void onChange(ConfigChangeEvent changeEvent) {changeEvent.changedKeys().forEach(this::changeLevel);}PostConstructprivate void refreshLoggingLevels() {config.getPropertyNames().forEach(this::changeLevel);}private void changeLevel(String key) {if (!StrUtil.startWith(key, LOGGER_TAG)) {return;}String strLevel config.getProperty(key, info);LogLevel level LogLevel.valueOf(strLevel.toUpperCase());loggingSystem.setLogLevel(key.replaceFirst(LOGGER_TAG, StrUtil.EMPTY), level);log.info({}{}, key, strLevel);}
}