apollo添加自定义环境

  • Post author:
  • Post category:其他


基础的准备工作,数据库 java mav什么的之前的文章是有的 这里就不啰嗦了

这里以添加GRAY环境为案例

1、源码修改的部分

都加入gray环境

#vim  /apollo/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/Env.java 
public enum Env{
  LOCAL, DEV, FWS, FAT, UAT, LPT, GRAY, PRO, TOOLS, UNKNOWN;
  public static Env fromString(String env) {
    Env environment = EnvUtils.transformEnv(env);
    Preconditions.checkArgument(environment != UNKNOWN, String.format("Env %s is invalid", env));
    return environment;
  }
#vim /apollo/apollo-core/src/main/java/com/ctrip/framework/apollo/core/enums/EnvUtils.java
switch (envName.trim().toUpperCase()) {
      case "LPT":
        return Env.LPT;
      case "FAT":
      case "FWS":
        return Env.FAT;
      case "UAT":
        return Env.UAT;
      case "PRO":
      case "PROD": //just in case
        return Env.PRO;
      case "DEV":
        return Env.DEV;
      case "LOCAL":
        return Env.LOCAL;
      case "GRAY":
        return Env.GRAY;
      case "TOOLS":
        return Env.TOOLS;
      default:
        return Env.UNKNOWN;
    }
#vim /apollo/apollo-core/src/main/java/com/ctrip/framework/apollo/core/internals/LegacyMetaServerProvider.java
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.GRAY, getMetaServerAddress(prop, "gray_meta", "gray.meta"));
  domains.put(Env.PRO, getMetaServerAddress(prop, "pro_meta", "pro.meta"));

  }

2、数据库的部分

2.1 导入apolloconfigdb.sql 里边的库修改成gray的库

2.2、apolloportaldb.sql加入gray环境的支持

2.3、修改eureka信息端口换成8580

# Config
# ------------------------------------------------------------
INSERT INTO `ServerConfig` (`Key`, `Cluster`, `Value`, `Comment`)
VALUES
    ('eureka.service.url', 'default', 'http://localhost:8580/eureka/', 'Eureka服务Url,多个service以英文逗号分隔'),
    ('namespace.lock.switch', 'default', 'false', '一次发布只能有一个人修改开关'),
    ('item.key.length.limit', 'default', '128', 'item key 最大长度限制'),
    ('item.value.length.limit', 'default', '20000', 'item value最大长度限制'),
    ('config-service.cache.enabled', 'default', 'false', 'ConfigService是否开启缓存,开启后能提高性能,但是会增大内存消耗!');

3、配置的部分,这里apolloconfig端口用8580,apollo-adminservice端口用8590

apollo-configservice部分

路径:/soft/apollo/apollo-configservice/src/main/config
文件:application-github.properties
# DataSource
spring.datasource.url = jdbc:mysql://localhost:3306/ApolloConfigDB_gray?useSSL=false&characterEncoding=utf8
spring.datasource.username = root
spring.datasource.password = 123456
路径:/soft/apollo/apollo-configservice/src/main/resources
文件:application.yml,bootstrap.yml,configservice.properties
端口全部换成8580
文件:/soft/apollo/apollo-configservice/src/main/scripts/startup.sh
端口换成:8580

apollo-adminservice部分

路径:/soft/apollo/apollo-adminservice/src/main/config
文件:application-github.properties
# DataSource
spring.datasource.url = jdbc:mysql://localhost:3306/ApolloConfigDB_gray?useSSL=false&characterEncoding=utf8
spring.datasource.username = root
spring.datasource.password = 123456
路径:/soft/apollo/apollo-adminservice/src/main/resources
文件:adminservice.properties  application.yml  bootstrap.yml
adminservice.properties端口换成8590
application.yml端口换成8590
bootstrap.yml端口换成8580
文件:/soft/apollo/apollo-adminservice/src/main/scripts/startup.sh
端口换成8590

apollo-portal的部分(以下是编译完成之后的文件)

文件:/soft/apollo-service/apollo-portal/config/apollo-env.properties
local.meta=http://localhost:8080
dev.meta=http://localhost:8080
fat.meta=http://localhost:8180
uat.meta=http://localhost:8280
lpt.meta=http://localhost:8380
gray.meta=http://localhost:8580
pro.meta=http://localhost:8480

最后编译,拷贝文件即可

路径;/soft/apollo/scripts   执行./build.sh即可 

最后开启服务

#mkdir  /soft/apollo-service/{apollo-configservice_gray,apollo-adminservice_gray,apollo-portal}
cp apollo-adminservice/target/apollo-adminservice-1.7.0-SNAPSHOT-github.zip /soft/apollo-service/apollo-adminservice_gray/
cp apollo-configservice/target/apollo-configservice-1.7.0-SNAPSHOT-github.zip   /soft/apollo-service/apollo-configservice_gray/
# cd /soft/apollo-service/apollo-configservice_gray/
# unzip  apollo-configservice-1.7.0-SNAPSHOT-github.zip
# cd scripts/;./startup.sh
# cd /soft/apollo-service/apollo-adminservice_gray/
# unzip  apollo-adminservice-1.7.0-SNAPSHOT-github.zip
# cd scripts/;./startup.sh

bc8d29981dddf2ad2fef75a326f42db7.png

 



版权声明:本文为ethnicitybeta原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。