Disconf简介
参考:
https://github.com/knightliao/disconf/wiki/TutorialSummary
在一个分布式环境中,同类型的服务往往会部署很多实例。这些实例使用了一些配置,为了更好地维护这些配置就产生了配置管理服务。通过这个服务可以轻松地管理成千上百个服务实例的配置问题。
王阿晶提出了基于zooKeeper的配置信息存储方案的设计与实现[1], 它将所有配置存储在zookeeper上,这会导致配置的管理不那么方便,而且他们没有相关的源码实现。淘宝的diamond[2]是淘宝内部使用的一个管理持久配置的系统,它具有完整的开源源码实现,它的特点是简单、可靠、易用,淘宝内部绝大多数系统的配置都采用diamond来进行统一管理。他将所有配置文件里的配置打散化进行存储,只支持KV结构,并且配置更新的推送是非实时的。百度内部的BJF配置中心服务[3]采用了类似淘宝diamond的实现,也是配置打散化、只支持KV和非实时推送。
同构系统是市场的主流,特别地,在业界大量使用部署虚拟化(如JPAAS系统,SAE,BAE)的情况下,同一个系统使用同一个部署包的情景会越来越多。但是,异构系统也有一定的存在意义,譬如,对于“拉模式”的多个下游实例,同一时间点只能只有一个下游实例在运行。在这种情景下,就存在多台实例机器有“主备机”模式的问题。目前国内并没有很明显的解决方案来统一解决此问题。
Disconf安装
参考
- Git:https://github.com/knightliao/disconf/tree/master/disconf-web
- OS China: http://www.oschina.net/p/disconf/similar_projects?fromerr=vfYXkqGn
- 个人网站 http://www.liaoqiqi.com/post/105
安装依赖软件
- 安装 Mysql
- 安装 Tomcat(apache-tomcat-7.0.50)
- 安装 Nginx(nginx/1.5.3)
- 安装 zookeeeper (zookeeper-3.3.0)
- 安装 Redis (2.4.5)
准备配置文件
- 1
- 2
- 3
- 4
- 5
下载好对应的代码,准备对应的配置文件:将disconf-web/profile/rd目录下的文件copy到build/online-resources目录下
- 1
- 2
- 3
- 4
注意,记得执行将application-demo.properties复制成application.properties:
- 1
构建
- 1
- 2
- 3
- 4
- 5
- 6
编译完成后,会在 /home/dev1/Downloads/disconf/build/war 生成以下结果:
- 1
- 2
- 3
- 4
部署
Disconf代码设计采用了静动分离设计,整个的代码的前后端完全分离。
初始化数据库:
对应的数据库脚本都在disconf-web/sql目录下,依次执行对应的sql语句就可以了
- 1
- 2
- 3
用户数据:可以参考 sql/readme.md 来进行数据库的初始化。里面默认有6个用户
如果想自己设置初始化的用户名信息,可以参考代码来自己生成用户:
src/main/java/com/baidu/disconf/web/tools/UserCreateTools.java
动静部署
Disconf代码采用了动静分离设计,
部署War(tomcat)
vim /etc/tomcat7/server.xml
修改server.xml文件,在Host结点下添加Context:
- 1
并在对应的war目录下创建tmp目录,启动tomcat服务器。
部署前端(nginx)
修改 nginx.conf,在HTTP标签中添加以下内容:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
注意:访问的html路径应该具有访问权限,可以在在nginx.conf文件第一行中更改用户,或者更改对应的HTML文件的权限。静态配置成功后,可以通过查看tomcat的日志和nginx日志文件来查看访问的记录,静态文件由nginx直接处理,而动态文件则是tomcat来处理的。
业务功能说明
支持用户登录/登出
浏览配置
按 APP/版本/环境 选择
修改配置
修改配置
修改配置项
修改配置文件
新建配置
新建配置项
新建配置文件
新建APP
Client使用
在spring boot中使用
1. 创建maven工程,添加对应的Maven库
- 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
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
2.添加对应的属性文件/resources
disconf.properties
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
disconf.xml
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
Disconf启动需要加载的类,以及需要扫描的包文件目录
3.添加对应的代码 redis示例
RedisConfig.java
- 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
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
示例代码上传至csdn:
http://pan.baidu.com/s/1nuoFNvj
http://download.csdn.net/detail/fiboliu/9464185