disconf实践(一)
公司目前的应用基本采用分布式部署,通过F5进行集群管理。分布式应用带来的好处是,随着流量的增加,可以快速扩展应用节点,分摊压力。分布式也会带来一定的挑战,譬如配置文件管理。如果某个配置要修改,那么所有的节点都要进行修改,当面临大规模集群时,很容易改错或改漏。因此,需要一个统一的配置管理中心对配置进行管理,集中修改一个配置文件,所有机器能够自动同步。disconf就是百度开源的配置管理中心。
以下是参照开源文档与公司的项目进行集成实践。
1. 下载管理端,并安装。
https://github.com/knightliao/disconf/tree/master/disconf-web
2. 登录管理端,并新建APP,然后上传相关配置文件
3. 新建disconf.properties,根据管理端新建的APP修改相关属性,放在classpath下。
- enable.remote.conf=true
- conf_server_host=http://192.168.3.141:8080/
- version=V1.0
- app=GTW
- env=local
- debug=true
- ignore=
- conf_server_url_retry_times=1
- conf_server_url_retry_sleep_seconds=1
4. 增加spring配置(spring-disconf.xml)
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:cache="http://www.springframework.org/schema/cache" xmlns:p="http://www.springframework.org/schema/p"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-4.0.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
- http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd">
- <!-- 使用disconf必须添加以下配置 -->
- <bean id="disconfMgrBean" class="com.baidu.disconf.client.DisconfMgrBean"
- destroy-method="destroy">
- <property name="scanPackage" value="com.baidu"/>
- </bean>
- <bean id="disconfMgrBean2" class="com.baidu.disconf.client.DisconfMgrBeanSecond"
- init-method="init" destroy-method="destroy">
- </bean>
- <!-- 使用托管方式的disconf配置(无代码侵入, 配置更改不会自动reload)-->
- <bean id="configproperties_no_reloadable_disconf"
- class="com.baidu.disconf.client.addons.properties.ReloadablePropertiesFactoryBean">
- <property name="locations">
- <list>
- <value>redis.properties</value>
- <value>jdbc.properties</value>
- <value>config.properties</value>
- </list>
- </property>
- </bean>
- <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="ignoreResourceNotFound" value="true"/>
- <property name="ignoreUnresolvablePlaceholders" value="true"/>
- <property name="propertiesArray">
- <list>
- <ref bean="configproperties_no_reloadable_disconf"/>
- </list>
- </property>
- </bean>
- </beans>
其中 redis.properties, jdbc.properties,config.properties 为管理端上传的三个配置文件。
5.添加依赖包
- <dependency>
- <groupId>com.baidu.disconf</groupId>
- <artifactId>disconf-client</artifactId>
- <version>2.6.36</version>
- </dependency>
至此,已经可以使用properties中的属性。如果要修改属性,只要在管理端修改相应的配置文件即可,相关属性会自动同步到各个应用部署的机器中。
注意:这种做法是最简单的应用,只会同步属性文件到本地,但不会reload到系统中,需要系统重启一下。disconf也可以做到热加载,同时也可以通过annotation的方式进行集成,后续再介绍相关内容。对于大部分应用,这样的集成已经可以,毕竟配置文件不会经常改动。
只要正确运行过一遍配置文件,文件就会被缓存在本地,即使与管理端断开,也不影响系统的正常运行。从集成情况看,应该是下载到disconf/download目录下,然后在运行的时候发布到classpath下。
disconf实践(一)的更多相关文章
- disconf实践(四)基于注解的分布式配置文件管理,自动reload
上一篇讲解了基于xml的自动reload的分布式配置文件管理,这一篇讲解基于注解的自动reload的方式(基于disconf实践二). 1. 修改spring配置文件 <?xml version ...
- disconf实践(三)基于XML的分布式配置文件管理,自动reload
上一篇介绍了基于xml的非自动reload的分布式配置文件管理,这一篇介绍自动reload的方式(基于disconf实践二). 1. 修改RedisConfig.java package org.sp ...
- Disconf实践指南:改造篇
上一篇文章Disconf实践指南:使用篇介绍了如何在项目中应用disconf,虽然实现了分布式配置的实时刷新,但是我们希望能够去除所有的配置文件,把配置都交给disconf管理,本地只需要实现配置监听 ...
- Disconf实践指南:使用篇
在上一篇文章Disconf实践指南:安装篇介绍了如何在本地搭建Disconf环境,下面我们介绍如何在项目中使用Disconf.由于某些功能特性对源码做了修改,所以在官方文档并没有提及. 环境基于mac ...
- Disconf实践指南:安装篇
Disconf是百度开源出来的一款基于Zookeeper的分布式配置管理软件.目前很多公司都在使用,包括滴滴.百度.网易.顺丰等公司.通过简单的界面操作就可以动态修改配置属性,还是很方便的.使用Dis ...
- disconf实践(二)
因为有些系统的配置文件会随着业务更改,如某些控制开关,当大批量集群时,按照上一篇文章的配置就不够啦,需要做到热加载. 研究了一下,还好,比较简单,只要替换上一篇文章第4步的配置文件(spring-di ...
- disconf实践(二)基于XML的分布式配置文件管理,不会自动reload
上一篇博文介绍了disconf web的搭建流程,这一篇就介绍disconf client通过配置xml文件来获取disconf管理端的配置信息. 1. 登录管理端,并新建APP,然后上传配置文件 2 ...
- disconf实践(一)Ubuntu16.04部署disconf
在企业中,随着公司业务的扩张,用户量的增大,单一节点应用无法支撑正常的业务逻辑,比较常见的现象是访问速度变慢,甚至超时,严重时可能会造成系统宕机.为了尽量减少宕机的风险,单一节点系统需要进行水平扩展, ...
- Github开源Java项目(Disconf)上传到Maven Central Repository方法详细介绍
最近我做了一个开源项目 Disconf:Distributed Configuration Management Platform(分布式配置管理平台) ,简单来说,就是为所有业务平台系统管理配置文件 ...
随机推荐
- AngularJS 路由:ui-router
UI-Router是Angular-UI提供的客户端路由框架,它解决了原生的ng-route的很多不足:视图不能嵌套.这意味着$scope会发生不必要的重新载入.这也是我们在Onboard中引入ui- ...
- 通过css实现文本超出部分以省略号(......)代替
一.单行溢出 1,固定宽度(非常容易) text-overflow: ellipsis; 2,不固定宽度 思路:想让这个区域成为块元素,然后不换行,溢出隐藏. display: block; whit ...
- 8种CSS清除浮动的方法优缺点分析
为什么清除CSS浮动这么难? 因为浮动会使当前标签产生向上浮的效果,同时会影响到前后标签.父级标签的位置及 width height 属性.而且同样的代码,在各种浏览器中显示效果也有可能不相同,这样让 ...
- Swift 中的getting和setter的使用
以下简单的介绍Swift中的getting和setting的使用方法: Xcode version: 6.1 先附代码: class Test { var num1: Double = 0.0 ini ...
- U盘安装ubuntu时出现的gfxboot.c32:not a COM32R image问题
方法特别简单:只需在提示后面输入 live 然后回车 就OK了
- 最近采用Instruments
最近采用Instruments 来分析整个应用程序的性能.发现很多有意思的点,以及性能优化和一些分析性能消耗的技巧,小结如下. Instruments使用技巧 关于Instruments官方有一个很有 ...
- linux系统下,递归删除.svn文件
linux系统下,递归删除.svn文件 SVNLinux 进入要删除的目录,执行下面的命令就可以啦. find . -name "*.svn" | xargs rm -rf
- sql update from 修改一个表的值来自另一个表
假设有桌子表名 icate_table_set(table_id,table_name,table_state_id,store_id), 桌子状态表名icate_table_state(state_ ...
- vim设置
折腾一下vim http://www.cnblogs.com/zhangsf/archive/2013/06/13/3134409.html
- Windows常见蓝屏故障分析
转自Windows常见蓝屏故障分析 症状描述: 当您在运行Microsoft Windows 2000/XP/Server 2003.Microsoft Windows Vista/Server 20 ...