1. 程式人生 > >Disconf實踐指南:安裝篇

Disconf實踐指南:安裝篇

需要 logs start class pre 安裝nginx 百度 穩定 屬性

Disconf是百度開源出來的一款基於Zookeeper的分布式配置管理軟件。目前很多公司都在使用,包括滴滴、百度、網易、順豐等公司。通過簡單的界面操作就可以動態修改配置屬性,還是很方便的。使用Disconf後發現的一大好處是省卻應用很多配置,而且配置可以自動load,實時生效。

Disconf優點總結如下:

部署簡單:同一個上線包,無須改動配置,即可在多個環境中上線
部署動態化:更改配置,無需重新打包或重啟,即可實時生效
統一管理:提供web平臺,統一管理多個環境多個產品的所有配置

如果想直接了解如何使用Disconf,可直接閱讀Disconf實踐指南:使用篇,不過了解如何安裝可以更深入了解Disconf的工作原理,同時方便以後代碼的調試。

需要安裝Nginx、Tomcat、Zookeeper、Redis和MySQL。
Nginx:處理靜態資源請求、動態請求轉發到Tomcat
Tomcat:處理Nginx的請求
Zookeeper:管理Disconf配置信息,配置變更通過zk通知
Redis:用戶session管理
MySQL:應用管理、用戶管理、角色管理、環境管理、配置持久化

一、安裝Nginx
1、Nginx官網下載源碼包
下載穩定版本:nginx-1.12.0.tar.gz

2、安裝到/usr/local/nginx

tar -zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0
./configure –prefix=/usr/local/nginx –with-zlib=../zlib-1.2.11 –with-pcre=../pcre-8.39
make
sudo make install

3、修改監聽端口

server {
        listen       8091;
        server_name  localhost;

        index index.html;
        #charset koi8-r;

        #access_log  logs/disconf_access.log;

    location / {
            #root /Users/chubin/Applications/disconf-stable/disconf-web/html;
            root /usr/local/disconf/war/html;
        index index.html;
        }
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

4、啟動Nginx

cd /usr/local/nginx
啟動
sudo sbin/nginx #ps aux | grep nginx或者訪問localhost:8091
重啟
sudo sbin/nginx -s reload
停止
sudo sbin/nginx -s stop

5、將disconf-stable/disconf-web/html復制到/usr/local/disconf/war/

6、修改Nginx代理配置和靜態資源目錄

upstream disconf {
        server 127.0.0.1:8080; #tomcat服務器的地址
    }

    server {
        listen       8091; #監聽端口
        server_name  localhost;

        index index.html;
    location / {
            root /usr/local/disconf/war/html; #靜態資源目錄
        index index.html;
        }

        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;
        }
     }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

二、安裝Tomcat
1、Tomcat官網下載安裝包
下載Tomcat 7.x以上的版本:apache-tomcat-8.5.15.tar.gz
2、安裝到任意目錄
/xxx/apache-tomcat-8.5.15
3、啟動Tomcat

./catalina.sh start #訪問瀏覽器localhost:8080

三、安裝Zookeeper
1、Zookeeper官網下載安裝包
zookeeper-3.4.10.tar.gz
2、啟動Zookeeper

cd zookeeper-3.4.10/bin
./zkServer start #ps aux | grep zoo驗證進程是否起來
./zkCli.sh #zk客戶端

四、安裝Redis
1、下載Redis源碼包,Redis官網
2、解壓安裝

tar zxvf ../Downloads/redis-3.2.9.tar.gz
cd redis-3.2.9
make
make install #安裝後在/usr/local/bin會有redis的腳本
cp redis.conf /etc
vi /etc/redis.conf ##將daemonize no改為daemonize yes
/usr/local/bin/redis-server /etc/redis.conf
ps aux | grep redis #如果啟動成功會有redis的進程

3、配置主從
由於Disconf至少需要配置兩臺redis-client,所以我們可以在一臺機器(本機)上安裝master/slave模式的redis集群

cp /etc/redis.conf /etc/redis2.conf #redis2啟動在6380端口
vi redis2.conf #配置slaveof 127.0.0.1 6379
sudo ./redis-server /etc/redis2.conf
ps aux | grep redis

4、設置主從的shardname

./redis-cli #redis.conf
auth foobared
set name ‘BeidouRedis1’
./redis.cli #redis2.conf
auth foobared
set name ‘BeidouRedis2’

五、安裝MySQL
1、下載MySQL源碼包,MySQL官網
2、安裝MySQL

tar zxvf ../Downloads/mysql-5.7.18-macos10.12-x86_64.tar.gz
sudo mv mysql-5.7.18 /usr/local/mysql #移動MySQL到安裝目錄
sudo support-files/mysql.server start #啟動MySQL
./mysqladmin -u root -p password 1234 #修改root用戶初始密碼
./mysql -u root -p 1234 #自帶客戶端連接MySQL

3、如果覺得麻煩,可以直接下載dmg安裝文件,簡單省事
4、導入disconf的sql腳本

  • 0-init_table.sql #建庫建表
  • 1-init_data.sql #插入數據
  • 201512/20151225.sql #歷史配置表

5、最終數據庫如下:
技術分享

六、安裝Disconf
1、下載Disconf源碼包,Disconf-stable
disconf-stable
2、導入IDEA,運行Disconf
到disconf-web目錄,將online-resources下的配置文件拷貝一份到src/main/resources下,包含的文件有:

application.properties #應用自身的配置文件
jdbc-mysql.properties #數據庫配置
redis-config.properties #redis配置
zoo.properties #Zookeeper配置

如果以上配置都OK的話,在IDEA啟動本地Tomcat,訪問http://localhost:8091,默認賬戶admin/admin。

技術分享

技術分享

至此,全部安裝結束,本地搭建Disconf成功,下一步就是讓應用接入Disconf了。安裝配置有任何問題歡迎評論O(∩_∩)O哈!

Disconf實踐指南:安裝篇