sit环境(sit环境和uat环境的区别)

1. apollo部署

本次部署环境为DEV(开发环境)、SIT(集成测试环境)、UAT(用户验收测试环境)、PRO(生产环境),采用apollo版本为1.4.0,相关的部署文档可参考官网。

2. apollo项目介绍

Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中化管理应用不同环境、不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限、流程治理等特性,适用于微服务配置管理场景。

apollo主要项目如下:

apollo-configservice:提供配置获取接口,提供配置更新推送接口,接口服务对象为Apollo客户端。

apollo-adminservice:提供配置管理接口,提供配置修改、发布等接口,接口服务对象为Portal,以及Eureka。

apollo-portal:提供Web界面供用户管理配置。

apollo-client:Apollo提供的客户端程序,为应用提供配置获取、实时更新等功能。

3.自定义apollo环境

自定义一个apollo部署环境也很简单,比如我们加入一个SIT环境,我们需要进行如下操作:

1. 修改apollo-core项目,com.ctrip.framework.apollo.core.enums.Env,在其中加入SIT枚举:

public enum Env{ LOCAL, DEV, FWS, FAT, UAT, LPT, PRO, TOOLS, UNKNOWN,SIT; ……..}

2.修改apollo-core项目,com.ctrip.framework.apollo.core.enums.EnvUtils,在其中加入SIT枚举的转换逻辑:

public final class EnvUtils { //新增SIT环境规则public static Env transformEnv(String envName) {if (StringUtils.isBlank(envName)) {return Env.UNKNOWN;}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 casereturn Env.PRO;case "DEV":return Env.DEV;case "LOCAL":return Env.LOCAL;case "TOOLS":return Env.TOOLS;case "SIT":return Env.SIT;default:return Env.UNKNOWN;}}}

3.修改apollo-core项目,com.ctrip.framework.apollo.core.internals.LegacyMetaServerProvider类,增加读取SIT环境的meta server地址逻辑:

public class LegacyMetaServerProvider implements MetaServerProvider { // make it as lowest as possible, yet not the lowest public static final int ORDER = MetaServerProvider.LOWEST_PRECEDENCE – 1; private static final Map<Env, String> domains = new HashMap<>(); 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")); domains.put(Env.SIT, getMetaServerAddress(prop, "sit_meta", "sit.meta")); } …………….}

4. 修改log日志文件生成路径:

修改apollo-adminservice项目下/script/startup.sh,日志路径替换为:LOG_DIR=/usr/local/nlp/logs/apollo-adminservice/100003172。修改apollo-configservice项目下/script/startup.sh,日志路径替换为:LOG_DIR=/usr/local/nlp/logs/apollo-configservice/100003171。修改apollo-portal项目下/script/startup.sh,日志路径替换为:LOG_DIR=/usr/local/nlp/logs/apollo-portal/100003173。

经过如上四步我们完成了SIT环境的添加。

4.apollo打包

由于我们存在DEV,UAT,SIT,PRO四套环境,apollo-configservice,apollo-adminservice项目需要切换四次环境打包。apollo-portal项目只需打包一次。

#dev 环境mvn clean package -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=github -Dspring_datasource_url=jdbc:mysql://10.xxx.xx25:3519/apollo_configdb_dev?characterEncoding=utf8 -Dspring_datasource_username=wxt_apollo -Dspring_datasource_password=xxxx#uat环境mvn clean package -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=github -Dspring_datasource_url=jdbc:mysql://10.xxx.xx.25:3519/apollo_configdb_uat?characterEncoding=utf8 -Dspring_datasource_username=wxt_apollo -Dspring_datasource_password=xxxx#sit环境mvn clean package -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=github -Dspring_datasource_url=jdbc:mysql://10.xxx.xx.25:3519/apollo_configdb_sit?characterEncoding=utf8 -Dspring_datasource_username=wxt_apollo -Dspring_datasource_password=xxxx#pro环境mvn clean package -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=github -Dspring_datasource_url=jdbc:mysql://10.xxx.xx.25:3519/apollo_configdb_pro?characterEncoding=utf8 -Dspring_datasource_username=wxt_apollo -Dspring_datasource_password=xxx#portalmvn clean package -DskipTests -pl apollo-portal -am -Dapollo_profile=github,auth -Dspring_datasource_url=jdbc:mysql://10.180.14.25:3519/apollo_portaldb?characterEncoding=utf8 -Dspring_datasource_username=yrz_apollo -Dspring_datasource_password=xxxx -Ddev_meta=http://10.xxx.xx.127:8080 -Dsit_meta=http://10.xxx.xx.129:8080 -Duat_meta=http://10.xxx.xx.128:8080 -Dpro_meta=http://10.xxx.xx.130:8080

5.apollo部署

在自己的服务器上新建一个目录 /usr/local/wxt/apollo_xxx/ 将官方提供的安装包直接下载到这个目录下,然后解压:

unzip apollo-adminservice-1.4.0-github.zip -d apollo-adminservice-1.4.0-githubunzip apollo-configservice-1.4.0-github.zip -d apollo-configservice-1.4.0-githubunzip apollo-portal-1.4.0-github.zip -d apollo-portal-1.4.0-github

6. 启动项目

在每一个工程的解压包中,都有一个 scripts 文件夹,这里面是 Apollo 工程的启动脚本。三个工程分别先后启动:apollo-configservice、apollo-adminservice、apollo-portal,就是分别执行这三个工程下面的 /scripts/startup.sh 脚本即可,关闭执行的是

7. apollo 客户端调用规则

apollo meta由核心服务统一进行了封装,各服务只需在pom文件引入microservice-apollo服务即可。

1.导包

<!–apollo配置中心–><dependency> <groupId>com.wxt</groupId> <artifactId>microservice-apollo</artifactId></dependency>

2.新增配置文件

新增bootstrap.yml,引入apollo相关配置

app: id: microservice-gateway #从服务端获取配置的唯一标识apollo: cacheDir: /usr/local/wxt/config-data #本地缓存路径 bootstrap: enabled: true namespaces: application,eureka-gateway #配置项集合

app.id 是应用的唯一身份标识,Apollo客户端使用这个标识来获取应用自己的私有Namespace配置。

apollo.cacheDir 为本地环境配置路径。

apollo.bootstrap.namespaces 获取远端配置,多个时逗号分隔。

3.修改启动项

修改启动项新增如下注解:

@EnableApolloConfigpublic class MicroserviceGatewayApplication {………..}

本文由美行思远留学整理发布,如若转载,请注明出处:https://www.mxsyedu.com/24207.html