1. 下载release版本

本次构建的是1.4.0的版本

2. 初始化数据库信息

数据库表信息

2.1 修改注册中心配置

初始化数据库表后,需要修改 ApolloConfigDB.ServerConfig表中的注册中心信息,apollo在启动的时候回读取该表的信息然后将服务注册上去。

2.2 初始化配置环境信息

修改ApolloPortalDB.serverConfig表的apollo.portal.envs

3. 修改对应数据库配置

3.1 修改打包脚本

  1. 位置:scripts/build.sh
  2. 修改配置

# apollo config db info
apollo_config_db_url=jdbc:mysql://yun2:3306/ApolloConfigDB?characterEncoding=utf8
apollo_config_db_username=root
apollo_config_db_password=root # apollo portal db info
apollo_portal_db_url=jdbc:mysql://yun2:3306/ApolloPortalDB?characterEncoding=utf8
apollo_portal_db_username=root
apollo_portal_db_password=root # meta server url, different environments should have different meta server addresses
# 这里是对应的是各个环境中的configService地址
dev_meta=http://localhost:8080
#fat_meta=http://fill-in-fat-meta-server:8080
uat_meta=http://localhost:8082
pro_meta=http://localhost:8083

从以上脚本可以看出,需要有3个configService和3个adminService。所以需要初始化3个不同的ApolloConfigDB库。

3. 执行脚本

./build.sh

注意:修改dev_meta的信息要与实际启动的机器相同

3.2 上传压缩包

对用户来说,实际有用的包就是三个:configService,adminService,portalService。执行完脚本后可以看到





  1. 解压相应的带github标签的包
  2. 修改相关配置
    1. portal
    2. admin,config包修改,两者数据库配置信息要一致

      admin 包配置
.
├── apollo-adminservice-1.4.0.jar
├── apollo-adminservice-1.4.0-sources.jar
├── apollo-adminservice.conf
├── apollo-adminservice_dataserveradmin.pid
├── apollo-adminservice.jar
├── config
│   ├── application-github.properties -->数据库配置信息,与config一致
│   └── app.properties
└── scripts
├── shutdown.sh
└── startup.sh

config 包配置

├── apollo-configservice-1.4.0.jar
├── apollo-configservice-1.4.0-sources.jar
├── apollo-configservice.conf
├── apollo-configservice_dataserverapollo-configservice.pid
├── apollo-configservice.jar
├── config
│   ├── application-github.properties -->config模块的数据库连接信息
│   └── app.properties
└── scripts
├── shutdown.sh
└── startup.sh --->启动端口信息

所以config模块主要修改压缩包解压后两个部分: config下的数据库配置信息和启动脚本,启动端口要与3.2步骤设置的启动脚本一致

3.3 启动

修改完后数据库配置信息,和启动脚本的端口后,直接运行启动脚本。

    ./admin/scripts/shutdown.sh
./config/scripts/shutdown.sh
./admin/scripts/startup.sh
./config/scripts/startup.sh

4.效果图



左侧就能看到对应的不同环境的配置信息了。

5. 项目依赖

在运行build.sh脚本的时候,会将apollo运行和依赖相关的jar包打包。apollo服务端运行的话就只需要adminservice,configservice,portal三个模块。如果其它项目需要使用这个配置中心就需要将打包好的client包依赖进去。

当其它项目想使用这个配置中心,传统的做法是需要在application.yml中添加apollo.meata=xxxx.xxx的配置信息来告诉项目此时该连接哪个配置中心下载哪些配置中心的配置。但是可以优化这个操作,具体步骤如下

5.1 在core模块添加配置中心配置信息



具体配置信息要跟build.sh脚本指定的一致

dev.meta=http://node3:8080
#fat_meta=http://fill-in-fat-meta-server:8080
uat.meta=http://node3:8082
pro.meta=http://node1:8083

5.2 修改core的pom文件打包方式,将配置文件打包进jar中

5.3 将打包好的client,core上传到私服

6 具体使用和改造

如果就这样引入客户端还是无法读到相关配置的,需要修改core模块的相关代码。

经调试,如果客户端中没有配置apollo.meta=xxx的配置,他会默认返回http://apollo.meta,具体的实现在LegacyMetaServerProvider中,需要做一下改造,来根据实际环境连接读取相应的configservice

public LegacyMetaServerProvider() {
initialize();
} private void initialize() {
Properties prop = new Properties();
prop = ResourceUtils.readConfigFile("apollo-env.properties", prop); domains.put(Env.LOCAL, getMetaServerAddress(prop, "local_meta", "local.meta"));
domains.put(Env.DEV, getMetaServerAddress(prop, "dev_meta", "dev.meta"));
domains.put(Env.FAT, getMetaServerAddress(prop, "fat_meta", "fat.meta"));
domains.put(Env.UAT, getMetaServerAddress(prop, "uat_meta", "uat.meta"));
domains.put(Env.LPT, getMetaServerAddress(prop, "lpt_meta", "lpt.meta"));
domains.put(Env.PRO, getMetaServerAddress(prop, "pro_meta", "pro.meta"));
}

配置文件与环境相匹配

 @Override
public String getMetaServerAddress(Env targetEnv) {
String metaServerAddress = domains.get(targetEnv);
return metaServerAddress == null ? null : metaServerAddress.trim();
}

7 新特性

7.1 自动更新配置

具体实现在AutoUpdateConfigChangeListener

@Override
public void onChange(ConfigChangeEvent changeEvent) {
Set<String> keys = changeEvent.changedKeys();
if (CollectionUtils.isEmpty(keys)) {
return;
}
for (String key : keys) {
// 1. check whether the changed key is relevant
Collection<SpringValue> targetValues = springValueRegistry.get(beanFactory, key);
if (targetValues == null || targetValues.isEmpty()) {
continue;
} // 2. update the value
for (SpringValue val : targetValues) {
updateSpringValue(val);
}
}
} private void updateSpringValue(SpringValue springValue) {
try {
Object value = resolvePropertyValue(springValue);
springValue.update(value); logger.info("Auto update apollo changed value successfully, new value: {}, {}", value,
springValue);
} catch (Throwable ex) {
logger.error("Auto update apollo changed value failed, {}", springValue.toString(), ex);
}
}

源码构建Apollo以及改造的更多相关文章

  1. java开源即时通讯软件服务端openfire源码构建

    java开源即时通讯软件服务端openfire源码构建 本文使用最新的openfire主干代码为例,讲解了如何搭建一个openfire开源开发环境,正在实现自己写java聊天软件: 编译环境搭建 调试 ...

  2. Flink源码分析 - 源码构建

    原文地址:https://mp.weixin.qq.com/s?__biz=MzU2Njg5Nzk0NQ==&mid=2247483692&idx=1&sn=18cddc1ee ...

  3. vue源码分析—Vue.js 源码构建

    Vue.js 源码是基于 Rollup 构建的,它的构建相关配置都在 scripts 目录下.(Rollup 中文网和英文网) 构建脚本 通常一个基于 NPM 托管的项目都会有一个 package.j ...

  4. Elasticsearch源码分析 - 源码构建

    原文地址:https://mp.weixin.qq.com/s?__biz=MzU2Njg5Nzk0NQ==&mid=2247483694&idx=1&sn=bd03afe5a ...

  5. centos7 源码构建、安装dubbo-monitor

    按照官方文档 ,发现dubbo-monitor-simple-x.x.x-assembly.tar.gz  下载不下来(地址访问不了),那么就自己下载源码构建吧. 我的zookeeper,hadoop ...

  6. Vue.js 源码构建(三)

    Vue.js 源码是基于 Rollup 构建的,它的构建相关配置都在 scripts 目录下. 构建脚本 通常一个基于 NPM 托管的项目都会有一个 package.json 文件,它是对项目的描述文 ...

  7. 从源码构建Vim

    从源码构建Vim 引言 事情是介样滴,因为我是个Vim 重度使用者了差不多.. 但在大部分系统上能安装到的或者自带的都是比较老的版本,可能是7.x 之类的.也或者是你需要使用到Vim 的某些特性或者功 ...

  8. Dubbo源码构建

    代码签出 通过以下的这个命令签出最新的项目源码: git clone https://github.com/apache/incubator-dubbo.git dubbo 分支 我们使用 maste ...

  9. vue源码构建代码分析

    这是xue源码学习记录,如有错误请指出,谢谢!相互学习相互进步. vue源码目录为 vue ├── src #vue源码 ├── flow #flow定义的数据类型库(vue通过flow来检测数据类型 ...

随机推荐

  1. Unity基本API总览

  2. Windows编程MessageBox函数

    API: int MessageBox(HWND hWnd, LPCTSTRlpText, LPCTSTRlpCaption, UINTuType); MSDN描述: This function cr ...

  3. 算法(Algorithms)第4版 练习 1.3.20

    方法实现: //1.3.20 /** * delete the kth element in a linked list, if it exists. * * @param k the kth ele ...

  4. Jmeter-线程日志查看

    jstack可以定位到线程堆栈,根据堆栈信息我们可以定位到具体代码,所以它在JVM性能调优中使用得非常多. 1.  压测时,使用top命令查看哪个java进行占用了较多的CPU资源: 上图中可以看出p ...

  5. leetcode 111 Minimum Depth of Binary Tree(DFS)

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  6. create-react-app使用的问题

    // 设置 npm config set registry https://registry.npm.taobao.org // 验证是否成功 npm config get registry或npm ...

  7. Codeforces Gym 101190 NEERC 16 .L List of Primes(递归)

    ls特别喜欢素数,他总是喜欢把素数集合的所有子集写下来,并按照一定的顺序和格式.对于每一个子集,集合内 的元素在写下来时是按照升序排序的,对于若干个集合,则以集合元素之和作为第一关键字,集合的字典序作 ...

  8. 1139 First Contact(30 分)

    Unlike in nowadays, the way that boys and girls expressing their feelings of love was quite subtle i ...

  9. iOS UINavgationController、 UINavigationBar、 UINavigationItem关系分析

    一般导航控制器含有4个对象,UINavigationController.UINavigationBar.UIViewController.UINavigationItem. 1:UINavigati ...

  10. Codeforces 762C Two strings 字符串

    Cpdeforces 762C 题目大意: 给定两个字符串a,b\((len \leq 10^5)\),让你去b中的一个连续的字段,使剩余的b串中的拼接起来的两个串是a穿的子序列.最大化这个字串的长度 ...