`

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下。
  • 大小: 38.8 KB
分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

    disconf-web-2.6.33简化版

    1.按照disconf-web.war/sql/readme.md执行SQL脚本创建库表和基础数据。 2.修改war包下的配置文件,具体目录是disconf-web.war\WEB-INF\classes\ jdbc-mysql.properties (数据库配置) redis-config.properties ...

    docker快速构建disconf镜像

    dd676e1ecbee zookeeper:3.3.6 "/docker-entrypoin..." About an hour ago Up About an hour 0.0.0.0:2181-&gt;2181/tcp, 0.0.0.0:2888-&gt;2888/tcp, 0.0.0.0:3888-&gt;3888/tcp dockerdisconfmaster_disconf_zookeeper_1 ...

    分布式配置中心 Disconf 安装包

    分布式配置中心 Disconf 编译好的安装包, 分布式配置中心 Disconf 编译好的安装包,。

    disconf-web简化可部署版

    官网下载的disconf-web得依赖nginx实现动静分离比较麻烦,简化后可以直接部署到tomcat不用依赖nginx

    Disconf配置war包

    linux环境、windows环境Disconf的disconf-web.war,可以直接部署。另外还包含环境搭建操作部署、配置说明、部署操作步骤以及war包,可以直接部署

    Disconf 分布式配置使用教程

    Disconf 分布式配置使用教程

    apollo和disconf对比

    这个文档描述的是,apollo和disconf对比,有需要的朋友可以看看

    disconf-master.zip

    官方disconf-master.zip (2.6.36),包含disconf-core, disconf-client,disconf-web

    disconf-demo

    disconf demo程序, 使用spring boot相关技术开发,代码无侵入性。

    disconf-client-2.6.36.jar

    适用升级disconf + springcloud 高版本

    disconf-web部署指南_V1.3

    disconf, web部署指南,V1.3 disconf, web部署指南,V1.3

    disconf 例子

    disconf 例子,包括使用 disconf.properties 文件和不使用的2种方式

    disconf小文档

    disconf自做文档,主要用途是自己看,以便于学习,毕竟不是一天都在公司

    python3通过disconf的api自动进行appname的配置文件下载和配置添加

    百度的disconf确实好用,但是手工添加配置项和配置文件很烦躁,自己利用闲余时间写了该脚本,主要支持对disconf的app自动下载和添加配置,运行之前,请先在桌面上新建一个applist的文本,里面填上待操作的appname...

    disconf打包后的war

    如果不想导入eclipse用maven安装,可直接下载就可以用.

    disconf-web-2.6.36 maven项目

    disconf-web项目,可直接部署到tomcat上,不依赖nginx。 修改其中 jdbc-mysql.properties (数据库配置), redis-config.properties (Redis配置),zoo.properties (Zookeeper配置), application.properties (应用...

    disconf使用

    NULL 博文链接:https://gjp014.iteye.com/blog/2360663

    重写的disconf jar包 支持高版本spring 框架

    替代之前的jar包,为了解决过时的方法,这里只修改了两行代码。disconf版本是2.6.36

    knightliao#disconf#Zookeeper异常考虑1

    下面按情况进行分析:服务启动前,zk连接不上:开始连接不上:因此,web上所有操作均会失败,抛大异常,请求失败,只会重试一次,不会重试多次后面突然连接上了:ap

    Disconf分布式配置管理平台 v2.6.36

    为您提供Disconf分布式配置管理平台下载,Disconf(Distributed Configuration Management Platform)分布式配置管理平台,...Disconf主要目标:部署极其简单:同一个上线包,无须改动配置,即可在多个环境中(RD/QA/

Global site tag (gtag.js) - Google Analytics