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. logback 配置详解(下)

    logback 常用配置详解(二) <appender> <appender>: <appender>是<configuration>的子节点,是负责写 ...

  2. rbx1包里机器人仿真程序的实践

     git clone https://github.com/pirobot/rbx1.git 1.打开一个终端 cd ~/catkin_ws/ catkin_make source ./devel/s ...

  3. 51Nod 1225 余数之和 —— 分区枚举

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1225 1225 余数之和  基准时间限制:1 秒 空间限制:1 ...

  4. UEditor上传文件的默认地址修改

    using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text.Re ...

  5. html中css的三种样式

    在html中定义CSS样式的方法有三种,新建CSS文件 使用link 关联 这种是最常用的外部引用样式,第二种讲样式写在 head 头部里面 这种是页面样式 ,第三中样式直接写在行内  style里面 ...

  6. java 基础 - 反转字符串

    反转字符串 public class Main { public static void main(String[] args) { String newStr= strReverseWithArra ...

  7. Smack编程库进行代码功能调试

    http://www.tuicool.com/articles/U3Afiy 使用Smack编程库进行代码功能调试 关于Smack编程库,前面我们提到,它是面向Java端的api,主要在PC上使用,利 ...

  8. workerman介绍

    WorkerMan的特性 1.纯PHP开发 使用WorkerMan开发的应用程序不依赖php-fpm.apache.nginx这些容器就可以独立运行. 这使得PHP开发者开发.部署.调试应用程序非常方 ...

  9. checkbox怎么判断是否选中

    下面这种可以使用 if($("#checkbox1").is(':checked')) { alert("1"); } else { alert("0 ...

  10. struts2 validate手动验证

    我们前面学习struts2知道,struts2通过拦截器实现了一些验证操作. 比如,如果是不能转换的类型在action中接受的话会跳转到错误页面,错误信息中会包含对应的错误信息,例如: 首先我们了解一 ...