分布式配置管理平台-Disconf

2017/01/01 分布式

摘要

          为了更好的解决分布式环境下多台服务实例的配置统一管理问题,本文提出了一套完整的分布式配置管理解决方案(简称为disconf[4],下同)。首先,实现了同构系统的配置发布统一化,提供了配置服务server,该服务可以对配置进行持久化管理并对外提供restful接口,在此基础上,基于zookeeper实现对配置更改的实时推送,并且,提供了稳定有效的容灾方案,以及用户体验良好的编程模型和WEB用户管理界面。其次,实现了异构系统的配置包管理,提出基于zookeeper的全局分布式一致性锁来实现主备统一部署、系统异常时的主备自主切换。通过在百度内部以及外部等多个产品线的实践结果表明,本解决方案是有效且稳定的。

主要目标:

  • 部署极其简单:同一个上线包,无须改动配置,即可在 多个环境中(RD/QA/PRODUCTION) 上线
  • 部署动态化:更改配置,无需重新打包或重启,即可 实时生效
  • 统一管理:提供web平台,统一管理 多个环境(RD/QA/PRODUCTION)、多个产品 的所有配置
  • 核心目标:一个jar包,到处运行

项目地址:

https://github.com/knightliao/disconf/tree/master/disconf-web

安装依赖软件

  • 安装Mysql(Ver 14.12 Distrib 5.0.45, for unknown-linux-gnu (x86_64) using EditLine wrapper)
  • 安装Tomcat(apache-tomcat-7.0.50)
  • 安装Nginx(nginx/1.5.3)
  • 安装 zookeeeper (zookeeper-3.3.0)
  • 安装 Redis (2.4.5)
  • maven

数据库安装配置:

yum install mariadb-server –y
systemctl start mariadb
create database disconfdb;
mysqladmin -u root password "wyy123456"

上线前的初始化工作

初始化数据库:

可以参考 sql/readme.md 来进行数据库的初始化。注意顺序执行 0-init_table.sql 1-init_data.sql 201512/20151225.sql 20160701/20160701.sql

安装jdk

tar xf jdk1.8.0_65.tar.gz /usr/
Vim /etc/profile
#####jdk###
JAVA_HOME=/usr/jdk1.8.0_65
JRE_HOME=/usr/jdk1.8.0_65/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH

安装tomcat

tar xf apache-tomcat-8.0.30.tar.gz -C /usr/local/

安装zookeeper集群

tar xf zookeeper-3.3.6.tar.gz –C /usr/loca/
ls /usr/local/
zookeeper0  zookeeper1  zookeeper2 伪集群(其实就是在一台机器上的集群)

zookeeper1 
vim zookeeper1/conf/zoo.cfg
tickTime=2000
initLimit=5
syncLimit=2
dataDir=/usr/local/zookeeper0/data
dataLogDir=/usr/local/zookeeper0/logs
clientPort=8581
server.0=127.0.0.1:8880:7770
server.1=127.0.0.1:8881:7771
server.2=127.0.0.1:8882:7772

zookeeper2
vim zookeeper2/conf/zoo.cfg
tickTime=2000
initLimit=5
syncLimit=2
dataDir=/usr/local/zookeeper1/data
dataLogDir=/usr/local/zookeeper1/logs
clientPort=8582
server.0=127.0.0.1:8880:7770
server.1=127.0.0.1:8881:7771
server.2=127.0.0.1:8882:7772

zookeeper3
vim zookeeper3/conf/zoo.cfg
tickTime=2000
initLimit=5
syncLimit=2
dataDir=/usr/local/zookeeper2/data
dataLogDir=/usr/local/zookeeper2/logs
clientPort=8583
server.0=127.0.0.1:8880:7770
server.1=127.0.0.1:8881:7771
server.2=127.0.0.1:8882:7772

安装redis

http://53cto.blog.51cto.com/9899631/1813429 nohup /usr/local/redis-3.2.1/src/redis-server /usr/local/redis-3.2.1/redis.conf –port 6379 & nohup /usr/local/redis-3.2.1/src/redis-server /usr/local/redis-3.2.1/redis.conf –port 6380 &

nginx

安装编译工具

yum install jemalloc jemalloc-devel -y  

建立nginx程序用户

groupadd -r www
useradd -r -g www www -c "web user" -d /dev/null -s /sbin/nologin 

安装依赖工具

zlib:

cd /usr/local/src
wget http://zlib.net/zlib-1.2.8.tar.gz
 tar xf zlib-1.2.8.tar.gz 
./configure
make test
make install
make clean
./configure --shared
make test
make install
cp zutil.h /usr/local/include
cp zutil.c /usr/local/include

Openssl(修复心脏滴血漏洞):

cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
tar-zxvf openssl-1.0.1t.tar.gz
./config shared zlib
make depend
make && make install
mv /usr/bin/openssl /usr/bin/openssl.old
mv /usr/include/openssl /usr/include/openssl.old
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl /usr/include/openssl
echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
ldconfig -v
openssl version

pcre:

cd /usr/local/src
tar zxvf pcre-8.30.tar.gz

下载luajit2.0并安装

推荐使用lujit2.0以上做lua支持 ngx_lua如果是0.9.2以上版本,建议正则过滤函数改为ngx.re.find,匹配效率会提高三倍左右。

wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz
make && make install

所以lib和include是直接放在/usr/local/lib和usr/local/include

源码安装Tengine

下载源码 wget http://tengine.taobao.org/download/tengine-2.1.2.tar.gz tar xf tengine-2.1.2.tar.gz /usr/local/src/

./configure\
  --user=www --group=www\
  --prefix=/usr/local/nginx\
  --with-http_stub_status_module\
  --with-http_ssl_module\
  --with-http_concat_module\
  --with-http_spdy_module\
  --with-http_gzip_static_module\
  --with-ipv6\
  --with-http_sub_module\
  --with-ld-opt=-ljemalloc\
  --with-openssl=/usr/local/src/openssl-1.0.1t \
  --with-pcre=/usr/local/src/pcre-8.30\
  --with-zlib=/usr/local/src/zlib-1.2.8\
  --with-http_lua_module\
  --with-luajit-inc=/usr/local/include/luajit-2.0\
  --with-luajit-lib=/usr/local/lib \

ln -s/usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
 
查看 nginx -V 


mkdir –p /disconf-rd/online-resources
mkdir –p /disconf-rd/war

vim /etc/profile
ONLINE_CONFIG_PATH=/disconf-rd/online-resources
WAR_ROOT_PATH=/disconf-rd/war
export ONLINE_CONFIG_PATH
export WAR_ROOT_PATH

cp disconf-web/profile/rd/* /disconf-rd/online-resources/
 
sh deploy/deploy.sh

部署War

修改server.xml文件,在Host结点下设定Context:

并设置端口为 8015

启动Tomcat,即可。

部署 前端

修改 nginx.conf

upstream disconf {
server 127.0.0.1:8081;
}
server {
listen   80;
server_name  123.57.152.59;

access_log /disconf-rd/logs/access.log;
error_log  /disconf-rd/logs/error.log;

location / {
root /disconf-rd/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;
}

项目配置文件:

cat application.properties
domain=IP

EMAIL_MONITOR_ON = true
EMAIL_HOST = smtp.exmail.qq.com
EMAIL_HOST_PASSWORD = w15034619520
EMAIL_HOST_USER = wangyangyang@rqbao.com
EMAIL_PORT = 25
DEFAULT_FROM_EMAIL = wangyangyang@rqbao.com

CHECK_CONSISTENCY_ON= true
 -----------------mysql------------------------
cat jdbc-mysql.properties
jdbc.driverClassName=com.mysql.jdbc.Driver

jdbc.db_0.url=jdbc:mysql://IP:3306/disconf?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&rewriteBatchedStatements=false
jdbc.db_0.username=user
jdbc.db_0.password=password

jdbc.maxPoolSize=20
jdbc.minPoolSize=10
jdbc.initialPoolSize=10
jdbc.idleConnectionTestPeriod=1200
jdbc.maxIdleTime=3600
 ----------------redis-----------------------
cat redis-config.properties
redis.group1.retry.times=2

redis.group1.client1.name=BeidouRedis1
redis.group1.client1.host=127.0.0.1
redis.group1.client1.port=6379
redis.group1.client1.timeout=5000
redis.group1.client1.password=

redis.group1.client2.name=BeidouRedis2
redis.group1.client2.host=127.0.0.1
redis.group1.client2.port=6380
redis.group1.client2.timeout=5000
redis.group1.client2.password=

redis.evictor.delayCheckSeconds=300
redis.evictor.checkPeriodSeconds=30
redis.evictor.failedTimesToBeTickOut=6
 -----------------zookeeper----------------------
cat zoo.properties
hosts=127.0.0.1:8581,127.0.0.1:8582,127.0.0.1:8583

展示图片

Search

    Table of Contents