开源配置中心 – Apollo
Apollo(阿波罗)是携程框架部门研发的配置管理平台,能够集中化管理应用不同环境、不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限、流程治理等特性。服务端基于Spring Boot和Spring Cloud开发,打包后可以直接运行,不需要额外安装Tomcat等应用容器。
检出代码
apollo github
可以fork下然后本地使用idea打开
数据库脚本
执行以下脚本创建ApolloConifgDB、ApolloPortalDB
- apollo.scripts.sql.apolloconfigdb.sql
- apollo.scripts.sql.apolloportaldb.sql
启动configservice adminservice
Main class配置
|
1
|
com.ctrip.framework.apollo.assembly.ApolloApplication
|
VM opions
|
1
2
3
4
5
6
|
-Dapollo_profile=github
-Dspring.datasource.url=jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8
-Dspring.datasource.username=root
-Dspring.datasource.password=
Program arguments
--configservice --adminservice
|
启动完后,打开 http://localhost:8080可以看到apollo-configservice和apollo-adminservice都已经启动完成并注册到Eureka
启动Apollo-Portal
Main class配置
|
1
2
3
4
5
6
7
|
com.ctrip.framework.apollo.portal.PortalApplication
-Dapollo_profile=github,auth
-Ddev_meta=http://localhost:8080/
-Dserver.port=8070
-Dspring.datasource.url=jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8
-Dspring.datasource.username=root
-Dspring.datasource.password=
|
如果启用了auth profile的话,默认的用户名是apollo,密码是admin
应用在SIT、UAT、生产环境机器上
1.新增目录/opt/data/目录,且有可读写权限;
2.新增文件:/opt/settings/server.properties 且加入配置:
|
1
2
3
4
|
env=DEV
sit: env=FAT
uat: env=UAT
生产:env=PRO
|
客户端例子
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
@Component 设置组件名称
@RefreshScope 指定配置改变可以刷新
@ConfigurationProperties(prefix = "redis.cache")
@Component("sampleRedisConfig")
@RefreshScope
public class SampleRedisConfig {
private static final Logger logger = LoggerFactory.getLogger(SampleRedisConfig.class);
private int expireSeconds;
private String clusterNodes;
private int commandTimeout;
private Map<String, String> someMap = Maps.newLinkedHashMap();
private List<String> someList = Lists.newLinkedList();
@PostConstruct
private void initialize() {
logger.info(
"SampleRedisConfig initialized - expireSeconds: {}, clusterNodes: {}, commandTimeout: {}, someMap: {}, someList: {}",
expireSeconds, clusterNodes, commandTimeout, someMap, someList);
}
public void setExpireSeconds(int expireSeconds) {
this.expireSeconds = expireSeconds;
}
public void setClusterNodes(String clusterNodes) {
this.clusterNodes = clusterNodes;
}
public void setCommandTimeout(int commandTimeout) {
this.commandTimeout = commandTimeout;
}
public Map<String, String> getSomeMap() {
return someMap;
}
public List<String> getSomeList() {
return someList;
}
@Override
public String toString() {
return String.format(
"[SampleRedisConfig] expireSeconds: %d, clusterNodes: %s, commandTimeout: %d, someMap: %s, someList: %s",
expireSeconds, clusterNodes, commandTimeout, someMap, someList);
}
}
|
设置监听
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
@Component
public class SpringBootApolloRefreshConfig {
private static final Logger logger = LoggerFactory.getLogger(SpringBootApolloRefreshConfig.class);
@Autowired
private ApolloRefreshConfig apolloRefreshConfig;
@Autowired
private SampleRedisConfig sampleRedisConfig;
@Autowired
private RefreshScope refreshScope;
@ApolloConfigChangeListener
public void onChange(ConfigChangeEvent changeEvent) {
logger.info("before refresh {}", sampleRedisConfig.toString());
refreshScope.refresh("sampleRedisConfig");
logger.info("after refresh {}", sampleRedisConfig.toString());
}
}
|
总结
以上所述是小编给大家介绍的spring cloud 阿波罗 apollo 本地开发环境搭建过程,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对快网idc网站的支持!
原文链接:http://blog.csdn.net/qq_27384769/article/details/79123193
相关文章
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
- 个人服务器网站搭建:如何选择合适的服务器提供商? 2025-06-10
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
-
2025-05-27 104
-
2025-05-27 35
-
2025-05-27 15
-
2025-05-29 21
-
2025-05-27 27

