disconf Use instructions _disconf use instructions

Source: Internet
Author: User
Tags mkdir tag name log4j
Brief introduction

Distributed Configuration Management Platform (Distributed configuration management platform)

Focus on a variety of distributed system Configuration management common components/common platform to provide a unified configuration management services.

Including Baidu, drop a taxi, UnionPay, NetEase, pull hook nets and other well-known internet companies are using!

Main goal: Deployment is extremely simple: the same on-line package, no need to change configuration, can be in multiple environments (rd/qa/production) on-line deployment dynamic: Change the configuration, without repackaging or restart, can be effective in real time Unified management: Provide Web platform, unified management of multiple environments (rd/qa/ PRODUCTION), all configurations for multiple products support micro-service architecture Demos Https://github.com/knightliao/disconf-demos-java

Disconf's module architecture diagram

A brief introduction to each module is as follows: Disconf-core distributed notification Module: a real-time Notification path management module supporting configuration updates: Unified management internal configuration path URL Disconf-client Configuring the Warehouse Container module: Unified management of the memory data store for local profiles and configuration items in the user Instance Reload module: Monitor changes to local profiles and automatically reload to the specified Bean Scan module: classes and domains that support scanning all disconf annotations Download modules: RESTful-style download profiles and configuration Items Watch modules: Monitoring remote configuration files and configuration items change the main standby allocation module: After the main standby competition, unified management of the main standby allocation and main standby control of the main standby competition module: Support in the distributed environment of the main standby competition Disconf-web Configuration enclosure: Manage all configured storage and read configuration management modules: Support configuration upload, download, update notification module: When the update is configured, real-time notification uses all instances of these configurations to configure the Self-Test Monitor module: Automatic timed Verification Instance local configuration is consistent with center configuration Permission control: Simple Web Permissions control Disconf-tools context Sharing module: Provides context sharing between multiple instances.
Use instructions 1. Import Jar Pack

                <artifactid>disconf-client </artifactId>
                <version> 2.6.30</version>

2. New disconf.properties files under classpath of client application

Note: parameters in all disconf.properties configuration files, all configurations can be passed through the command line-dname=value parameters. Start parameters to overwrite

This file is required for disconf startup, and the file example is:

# Whether to use remote profile
# True (default) will get configuration from remote to get config false directly to the local configuration

# #
Configure the server's HOST, separated  by commas,

# version, please use x_x_x_x format 
version=1_0_0 _0

# APP Please use product line _ Service name format 

# environment

# debug

# Ignore which distributed configurations , comma delimited

# Gets the remote configuration retry count, the default is 3 times
# Gets the hibernate time when remote configuration retries, default is 5 seconds

Configuration instructions can refer to:
Configuration item Description Whether a default value is required Disconf.conf_server_host Configure the server host, separated by commas, example:, is required Disconf.app app please use product line _ The service name format does not give precedence to the command line arguments and then reads the value disconf.version version number of the file, using the x_x_x_x format or default to Default_version. First read the command-line arguments and then read the value of the file before reading the default value. disconf.enable.remote.conf whether the remote configuration file is used, true (default) Gets the configuration from the remote, false to obtain the local configuration no false disconf.env whether the environment defaults to default_env. Read the command-line arguments first and then read the value of the file before reading the default value Disconf.ignore the ignored distributed configuration, separating the Disconf.debug debug mode with a space. In debug mode, the ZK does not reconnect after a timeout or disconnect (commonly used for client stepping debug). In non-debug mode, the ZK timeout or disconnect is automatically reconnected. No false disconf.conf_server_url_retry_times get remote configuration retry count, default is 3 times No 3 disconf.conf_server_url_retry_sleep_seconds get remote Configuration Retry hibernation time, default is 5 seconds No 5 disconf.user_define_download_dir user-defined download folder, remote files will be placed here after downloading. Note that this folder must have permissions, otherwise it cannot be downloaded to here./disconf/download Disconf.enable_local_download_dir_in_class_path The downloaded file is migrated to the Classpath root path, and it is strongly recommended that this option be set to True (the default is True) No true

For detailed design, please refer to:


3 Add disconf boot support in Applicationcontext.xml

Scanpackage is the package path where the disconf annotation class is scanned

4 Configuration item Annotations use

The configuration item, which is the form of k-v, is used as follows:

Add annotation @DisconfFileItem on the Get method of the class. Add tag name, which indicates the key name in the configuration file, which is required. The tag Associatefield is optional, representing the name of the domain to which this get method is associated, and if this tag is not filled in, the system automatically analyzes the gets method, guessing that it corresponds to the domain name. It is strongly recommended that you add the Associatefield tag so that the Get/set method that eclipse generates does not conform to the Java specification.

Example, refer to the 5 profile annotation using
5 Profile Annotation Use

The specific step is to define @DisconfFile annotations for this class, specifying the file name Code.properties. Define the domain Codeerror and use eclipse to automatically generate Get&set methods for it. Adds a annotation @DisconfFileItem to the Get method for the domain. Add tag name, which indicates the key name in the configuration file, which is required. The tag Associatefield is optional, representing the name of the domain to which this get method is associated, and if this tag is not filled in, the system automatically analyzes the gets method, guessing that it corresponds to the domain name. It is strongly recommended that you add the Associatefield tag so that the Get/set method that eclipse generates does not conform to the Java specification. Mark the class that it is hosted for spring (using @service), and "scope" must be singleton.


Eclipse automatically generates a get method that may differ from the Java specification. This can lead to a lot of problems. Therefore, it is recommended to add a Associatefield tag.

Code.properties New profile on Disconf-web (version, Environment, app and disconf.properties config file) 6 configuration update callback

Implements the Idisconfupdate interface, and the class is managed by spring

Annotation @disconfupdateservice, Conffilekeys update for monitoring profile, Itemkeys update 7 file Hosting for monitoring configuration entries

The configuration file does not have a corresponding configuration annotation class, and this profile is not injected into the configuration class. Disconf is simply "hosted" on it. Download configuration files at startup, and dynamically push when the profile changes. The program does not automatically reload the configuration, it needs to write its own callback function (implement the Idisconfupdate interface and add disconfupdateservice annotations).

<!--disconf configuration using managed mode (no code intrusion, configuration changes will not automatically reload)-->
<bean id= "configproperties_no_reloadable_disconf"
      class= "Com.baidu.disconf.client.addons.properties.ReloadablePropertiesFactoryBean" >
    <property Name= "Locations" >

<bean id= "PropertyConfigurerForProject1"
      class= " Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ">
    <property name=" Ignoreresourcenotfound "value=" true "/> <property name=" ignoreunresolvableplaceholders "value="
    true "/ >
    <property name= "Propertiesarray" >
            <ref bean= "Configproperties_no_ Reloadable_disconf "/>

8 Management End Disconf-web 8.1. Environment configuration

Configure the Java, MAVEN environment, and install Mysql,reids,zookeeeper,nginx 8.2. Download disconf

Download Https://codeload.github.com/knightliao/disconf/zip/master
Decompression: Unzip Disconf-master.zip 8.3. Compiling package

Create a table of contents

    cd disconf-master  
    mvn clean install  
    export ONLINE_CONFIG_ PATH  
    Export war_root_path  
    cd disconf-web  
    sh deploy/deploy.sh  

Complete the production of files in the/home/disconf/war directory

8.4. Modify Configuration

1 Put the configuration file under this address directory:/home/disconf/online-resources
Configuration files include:
-Jdbc-mysql.properties (Database configuration)
-Redis-config.properties (Redis configuration)
-Zoo.properties (Zookeeper configuration)
-Application.properties (Application configuration)
Note that the execution will copy application-demo.properties into application.properties:
CP Application-demo.properties Application.properties

2) Modify DISCONF configuration
Modify the address port in the file to adjust the log directory
#log4j. Properties
#logback. xml
<property name= "Log.base" value= "${catalina.home}/logs/disconf-web"/>
<property name= "Log.monitor" value= "${catalina.home}/logs/monitor"/>
8.5. Initializing the database

Follow the Disconf-master/disconf-web/sql/readme.txt instructions to import data in order

8.6. Configure Tomcat

Install Tomcat configuration Server.xml Configure the war directory
<context path= "" docbase= "/home/disconf/disconf/war" ></Context>
8.7. Configure Nginx

Install Nginx, and configure, install reference: http://blog.csdn.net/zhu_tianwei/article/details/17752581
Configuration: vi/home/disconf/nginx/conf/nginx.conf

    Upstream disconf {  
    server {  
        Listen   8000;  
        server_name localhost;  
        Access_log Logs/disconf_access.log;  
        Error_log Logs/disconf_error.log;  
            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  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.