Disconf使用说明
来源:互联网 发布:龙之谷g友戒指淘宝 编辑:程序博客网 时间:2024/05/22 15:17
简介
Distributed Configuration Management Platform(分布式配置管理平台)
专注于各种 分布式系统配置管理 的通用组件/通用平台, 提供统一的配置管理服务。
包括 百度、滴滴打车、银联、网易、拉勾网 等知名互联网公司正在使用!
主要目标:
- 部署极其简单:同一个上线包,无须改动配置,即可在 多个环境中(RD/QA/PRODUCTION) 上线
- 部署动态化:更改配置,无需重新打包或重启,即可 实时生效
- 统一管理:提供web平台,统一管理 多个环境(RD/QA/PRODUCTION)、多个产品 的所有配置
- 支持微服务架构
demos
https://github.com/knightliao/disconf-demos-javadisconf的模块架构图
每个模块的简单介绍如下:
- Disconf-core
- 分布式通知模块:支持配置更新的实时化通知
- 路径管理模块:统一管理内部配置路径URL
- Disconf-client
- 配置仓库容器模块:统一管理用户实例中本地配置文件和配置项的内存数据存储
- 配置reload模块:监控本地配置文件的变动,并自动reload到指定bean
- 扫描模块:支持扫描所有disconf注解的类和域
- 下载模块:restful风格的下载配置文件和配置项
- watch模块:监控远程配置文件和配置项的变化
- 主备分配模块:主备竞争结束后,统一管理主备分配与主备监控控制
- 主备竞争模块:支持分布式环境下的主备竞争
- Disconf-web
- 配置存储模块:管理所有配置的存储和读取
- 配置管理模块:支持配置的上传、下载、更新
- 通知模块:当配置更新后,实时通知使用这些配置的所有实例
- 配置自检监控模块:自动定时校验实例本地配置与中心配置是否一致
- 权限控制:web的简单权限控制
- Disconf-tools
- context共享模块:提供多实例间context的共享。
使用说明
1.导入jar包
<dependency> <groupId>com.baidu.disconf</groupId> <artifactId>disconf-client</artifactId> <version> 2.6.30</version> </dependency>
2.在客户端应用的classpath下新增disconf.properties文件
注:所有disconf.properties配置文件中的参数,所有配置均可以通过 命令行-Dname=value
参数传入。启动参数方式进行覆盖
Disconf启动需要此文件,文件示例是:
# 是否使用远程配置文件# true(默认)会从远程获取配置 false则直接获取本地配置enable.remote.conf=true## 配置服务器的 HOST,用逗号分隔 127.0.0.1:8000,127.0.0.1:8000#conf_server_host=127.0.0.1:8080# 版本, 请采用 X_X_X_X 格式 version=1_0_0_0# APP 请采用 产品线_服务名 格式 app=disconf_demo# 环境env=rd# debugdebug=true# 忽略哪些分布式配置,用逗号分隔ignore=# 获取远程配置 重试次数,默认是3次conf_server_url_retry_times=1# 获取远程配置 重试时休眠时间,默认是5秒conf_server_url_retry_sleep_seconds=1
配置相关说明可参考:
详细设计请参考:
http://disconf.readthedocs.io/zh_CN/latest/design/index.html
3 在applicationContext.xml
添加Disconf启动支持
scanPackage是扫描标注了disconf注解类所在包路径
4 配置项注解使用
配置项即K-V的形式,使用如下:
在类的get方法上添加注解 @DisconfFileItem 。添加标记 name, 表示配置文件中的KEY名,这是必填的。标记associateField是可选的,它表示此get方法相关连的域的名字,如果此标记未填,则系统会自动 分析get方法,猜测其相对应于域名。强烈建议添加associateField标记,这样就可以避免Eclipse生成的Get/Set方法不符合 Java规范的问题。
实例,请参考 5 配置文件注解使用
5 配置文件注解使用
具体步骤是:
- 为这个类定义 @DisconfFile 注解,指定文件名为 code.properties 。
- 定义域codeError,并使用Eclipse为其自动生成 get&set 方法。
- 为该域的get方法上添加注解 @DisconfFileItem 。添加标记 name, 表示配置文件中的KEY名,这是必填的。标记associateField是可选的,它表示此get方法相关连的域的名字,如果此标记未填,则系统会自动 分析get方法,猜测其相对应于域名。强烈建议添加associateField标记,这样就可以避免Eclipse生成的Get/Set方法不符合 Java规范的问题。
- 标记它为Spring托管的类 (使用@Service),且 "scope" 都必须是singleton的。
注意:
Eclipse自动生成的get方法,可能与Java的规范不同。这会导致很多问题。因此,建议加上 associateField 标记。
在disconf-web上code.properties新增该配置文件(版本,环境,app与disconf.properties配置文件中相同)
6 配置更新回调
实现IDisconfUpdate接口,并且该类是由spring管理
注解@DisconfUpdateService, confFileKeys为监控配置文件更新,itemKeys为监控配置项更新
7 文件托管
配置文件没有相应的配置注解类,此配置文件不会被注入到配置类中。disconf只是简单的对其进行“托管”。 启动时下载配置文件;配置文件变化时,负责动态推送。程序不会自动reload配置,需要自己写回调函数(实现IDisconfUpdate接口,并添加DisconfUpdateService注解)。
<!-- 使用托管方式的disconf配置(无代码侵入, 配置更改不会自动reload)--><bean id="configproperties_no_reloadable_disconf" class="com.baidu.disconf.client.addons.properties.ReloadablePropertiesFactoryBean"> <property name="locations"> <list> <value>myserver.properties</value> </list> </property></bean><bean id="propertyConfigurerForProject1" 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>
8 管理端disconf-web
8.1.环境配置
配置java、maven环境,并安装mysql,reids,zookeeeper,Nginx
8.2.下载disconf
下载https://codeload.github.com/knightliao/disconf/zip/master
解压:unzip disconf-master.zip
8.3.编译打包
创建目录
mkdir /home/disconf/online-resources mkdir /home/disconf/war cd disconf-master mvn clean install ONLINE_CONFIG_PATH=/home/disconf/online-resources WAR_ROOT_PATH=/home/disconf/war export ONLINE_CONFIG_PATH export WAR_ROOT_PATH cd disconf-web sh deploy/deploy.sh
-disconf-web.war -html -jpaas_control -META-INF -Release -tmp -WEB-INF
8.4.修改配置
1)将配置文件放到此地址目录下:/home/disconf/online-resources
配置文件包括:
- jdbc-MySQL.properties (数据库配置)
- redis-config.properties (Redis配置)
- zoo.properties (Zookeeper配置)
- application.properties (应用配置)
注意,记得执行将application-demo.properties复制成application.properties:
cp application-demo.properties application.properties
2)修改disconf配置
cd /home/disconf/war/WEB-INF/classes/
application.properties
jdbc-mysql.properties
redis-config.properties
zoo.properties
修改文件中的地址端口,调整日志目录
#log4j.properties
${catalina.home}/logs/disconf-log4j.log
#logback.xml
<property name="log.base" value="${catalina.home}/logs/disconf-web"/>
<property name="log.monitor" value="${catalina.home}/logs/monitor"/>
8.5.初始化数据库
按照disconf-master/disconf-web/sql/readme.txt说明按照顺序导入数据
8.6.配置tomcat
安装tomcat配置server.xml配置war目录
<Context path="" docBase="/home/disconf/disconf/war"></Context>
8.7.配置nginx
安装nginx,并配置,安装参考:http://blog.csdn.net/zhu_tianwei/article/details/17752581
配置:vi /home/disconf/nginx/conf/nginx.conf
upstream disconf { server 127.0.0.1:8080; } server { listen 8000; server_name localhost; access_log logs/disconf_access.log; error_log logs/disconf_error.log; location / { root /home/disconf/disconf/war/html; if ($query_string) { expires max; } } location ~ ^/(api|export) { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_pass http://disconf; } }
- Disconf使用说明
- Disconf使用说明
- disconf
- Disconf
- Disconf
- disconf-搭建
- Disconf介绍
- disconf回调
- Disconf(二)disconf-web
- disconf简介及disconf client使用
- 分布式配置管理平台-Disconf
- disconf基于XML实现
- Disconf入门指南(1)
- 分布式配置管理平台 Disconf
- disconf 分布式配置
- 统一配置管理-百度disconf
- 分布式配置管理平台 Disconf
- disconf使用中的问题
- linux下防火墙与SELinux状态与关闭
- Servlet学习之四连接数据库
- 预测未来 -- 大数据,机器学习与临床医学
- adb,aapt等命令使用
- Linux服务器上搭建SVN
- Disconf使用说明
- 关于oracle的环境变量
- iOS 开发-SDWebImage访问HTTPS站点获取图片资源失败解决办法
- JAVA的Random类(转)
- miniSTM32学习
- IOS动画之 转场动画 CATransition
- Spring Boot基础教程11-web应用开发-CORS支持
- struct和typedef struct
- 动态加载与插件化