- 1、背景
在生產部署過程當中,遇到如下問題:html
一、因爲節點較多,每次增量修改配置文件後都須要每一個節點替換配置文件。前端
二、有些動態配置修改後,須要重啓服務。java
- 2、解決方案
一、使用linux文件共享配置文件來實現,可是這個須要解決配置的權限分配問題,操做起來比較麻煩,而且沒法解決問題2。mysql
二、使用中間件來解決配置加載問題,因爲咱們服務已經使用了dubbo,因此最後採用了百度的disconf來實現動態配置加載。linux
- 3、實現
- 安裝依賴
安裝Mysqlnginx
安裝Tomcat(apache-tomcat-7)
安裝Nginx(nginx/1.10.2)(安裝nginx還須要安裝openssl-fips-2.0.十、pcre-8.40、zlib-1.2.11)
安裝 zookeeeper (zookeeper-3.5.2)
安裝 Redis (2.6.10)git
二、安裝以上文件後,下載disconfgithub
直接上去下載disconf源碼,https://github.com/knightliao/disconfweb
新建disconf目錄,並建立war、sql、src子目錄,並將壓縮包解壓到src目錄redis
三、初始化數據庫。
進入disconf/sql目錄,按照說明初始化數據腳本。
四、拷貝初始化文件
新建disconf/online-resource子目錄將配置文件拷貝進去
五、修改配置並打包
進入下面目錄修改配置文件:/home/www/soft/disconf/disconf-master/disconf-web/profile/rd
修改jdbc-mysql.properties
jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.db_0.url=jdbc:mysql://172.18.50.11:3306/wanjiaweb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&rewriteBatchedStatements=false jdbc.db_0.username=wanjiaweb jdbc.db_0.password=web@123456 jdbc.maxPoolSize=20 jdbc.minPoolSize=10 jdbc.initialPoolSize=10 jdbc.idleConnectionTestPeriod=1200 jdbc.maxIdleTime=3600
修改zoo.properties
hosts=172.18.50.4:2181,172.18.50.6:2181,172.18.50.7:2181 # zookeeper\u7684\u524D\u7F00\u8DEF\u5F84\u540D zookeeper_url_prefix=/disconf
修改redis-config.propertie
redis.group1.retry.times=2 redis.group1.client1.name=BeidouRedis1 redis.group1.client1.host=172.20.50.25 redis.group1.client1.port=6379 redis.group1.client1.timeout=5000 redis.group1.client1.password=foobared 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=foobared redis.evictor.delayCheckSeconds=300 redis.evictor.checkPeriodSeconds=30 redis.evictor.failedTimesToBeTickOut=6修改完成後執行 mvn package 命令
- 4、部署disconf
- 第一步部署war
cd /usr/local/tomcat7/conf
vi server.xml 修改該配置
在Host節點下添加如下配置
<Context path="/" docBase="/home/www/soft/disconf/war/disconf-web.war" reloadable="false" crossContext="true" />
而後進入bin目錄啓動tomcat
- 第二步配置nginx
進入nginx配置目錄/usr/local/nginx/conf
修改nginx.conf配置
http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; upstream disconf { server 127.0.0.1:8990; } #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 8992; server_name 127.0.0.1; access_log logs/disconf_access.log; error_log logs/disconf_error.log; location / { root /home/www/soft/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; } } }
upstream disconf 配置中的端口必須與tomcat啓動的端口一致
server中listen是啓動該disconf前端的端口
disconf使用先後端分離的部署方式,前端配置在nginx是那個,後端api部署在tomcat中
啓動nginx。
- 5、登錄並配置
訪問http://172.20.50.26:8992/main.html
默認用戶密碼都是admin
登錄後進行操做,能夠根據公司的環境進行配置,我將原有的rd、qa、local、online分別改爲了dev、test、stg、product