陵水网站建设哪家好seo网站查询
最新Apollo 版本发布2.1.0
https://www.apolloconfig.com/#/zh/design/apollo-design
环境说明
- ecs 主机一台
- 数据库mysql 8.0
- docker 环境
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.RELEASE
- apollo client : 2.1.0
<dependency><groupId>com.ctrip.framework.apollo</groupId><artifactId>apollo-client</artifactId><version>2.1.0</version></dependency>
配置文件
application.properties 中只需要添加
app.id=应用名
apollo.bootstrap.enabled=true
apollo.bootstrap.namespaces=application
apollo.bootstrap.eagerLoad.enabled=true
# 测试环境 cs 地址 或者 线上环境cs地址
apollo.meta=http://x.x.x.x:8060
apollo.cluster=default
注解@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);}
}