apollo添加自定義環境

基礎的準備工作,數據庫 java mav什麼的之前的文章是有的 這裡就不囉嗦了

這裡以添加GRAY環境為案例

1、源碼修改的部分

都加入gray環境

<code>#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;
}/<code>
<code>#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;
}/<code>
<code>#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"));

}/<code>

2、數據庫的部分

2.1 導入apolloconfigdb.sql 裡邊的庫修改成gray的庫

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

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

<code># 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是否開啟緩存,開啟後能提高性能,但是會增大內存消耗!');/<code>

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

apollo-configservice部分

<code>路徑:/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/<code>
<code>路徑:/soft/apollo/apollo-configservice/src/main/resources
文件:application.yml,bootstrap.yml,configservice.properties

端口全部換成8580/<code>
<code>文件:/soft/apollo/apollo-configservice/src/main/scripts/startup.sh
端口換成:8580/<code>

apollo-adminservice部分

<code>路徑:/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/<code>
<code>路徑:/soft/apollo/apollo-adminservice/src/main/resources
文件:adminservice.properties application.yml bootstrap.yml
adminservice.properties端口換成8590
application.yml端口換成8590
bootstrap.yml端口換成8580/<code>
<code>文件:/soft/apollo/apollo-adminservice/src/main/scripts/startup.sh
端口換成8590/<code>

apollo-portal的部分(以下是編譯完成之後的文件)

<code>文件:/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/<code>

最後編譯,拷貝文件即可

<code>路徑;/soft/apollo/scripts   執行./build.sh即可 /<code>

最後開啟服務

<code>#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//<code>
<code># cd /soft/apollo-service/apollo-configservice_gray/
# unzip apollo-configservice-1.7.0-SNAPSHOT-github.zip
# cd>
<code># cd /soft/apollo-service/apollo-adminservice_gray/
# unzip apollo-adminservice-1.7.0-SNAPSHOT-github.zip
# cd>
apollo添加自定義環境

<code>


分享到:


相關文章: