Apollo搭建及使用


在百度网盘--安装.zip中下载并解压,得到的adminservice.jar,configservice.jar和portal.jar三部分组成的reunApollo.bat中编辑数据库连接地址,后启动,也可以用cmd一个个启动。

启动后访问http://localhost:8070  默认账号Apollo 密码 admin 。


连接appid在文件中引入依赖

<!-- 阿波罗客户端-->
<!-- https://mvnrepository.com/artifact/com.ctrip.framework.apollo/apollo-client -->
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>1.4.0</version>
</dependency>


编写测试类代码

   public class GetConfigTest {

    public static void main(String[] args) throws InterruptedException {

//VM options
//-Dapp.id=svavo_test -Denv=DEV -Ddev_meta=http://localhost:8080
while (true) {
Thread.sleep(1000);
Config appConfig = ConfigService.getAppConfig();
//获取配置信息,第一个参数:配置的key,第二个参数默认值
String value1 = appConfig.getProperty("sms_enable", null);
String someKey = "sms.enable";
String value2 = appConfig.getProperty(someKey, "svavo");
System.out.println("sms_enable:" + value1 + "sms.enable:" + value2);
}
}
}





新建部门信息  在管理员工具-->系统参数 中输入organizations,点击搜索后如图


读取namespace:Config appConfig1 =ConfigService.getConfig("spring-rocketmq");//读取指定namespace下的信息

读取集群:-Dapp.id=zuul -Denv=DEV -Dapollo.cluster=SHJQ -Ddev_meta=http://localhost:8080 创建的集群

                 -Dapp.id= zuul  -Denv=DEV -Ddev_meta=http://localhost:8080 默认群


生产环境的配置:数据库导入安装.zip中的ApolloConfigDB_PRO__initialization.sql,修改apolloportaldb库中的serverconfig表的  apollo.portal.envs  dev,pro



修改ApolloPortal的启动分Dev环境和Pro环境


echo

set url="localhost:3306"
set username="root"
set password="123456"

start "ApolloPortal" java -Xms256m -Xmx256m -Dapollo_profile=github,auth -Ddev_meta=http://localhost:8080/ -Dpro_meta=http://localhost:8081/ -Dserver.port=8070 -Dspring.datasource.url=jdbc:mysql://%url%/ApolloPortalDB?characterEncoding=utf8 -Dspring.datasource.username=%username% -Dspring.datasource.password=%password% -Dlogging.file=.\logs\apollo-portal.log -jar .\apollo-portal-1.3.0.jar

访问http://localhost:8070,在管理员工具--->系统参数中输入apollo.portal.envs查询,在输入dev,pro





后期还有灰度发布。

项目中去配置化,不适用springboot集成的Eureka而使用阿波罗自带的Eureka

工具:在线yml转换成property文件  https://toyaml.com/index.html

注意事项:一定要修改Eureka地址为服务器meta地址,如果是本地则为de或者pro环境中的地址,目前为:开发环境-->localhost:8080 或者 生产环境--> localhost:8081

                  Apollo缓存目录:C:\opt\data

        项目中的  application.yml 亦可删除