# 分布式架构

## 1 服务部署

```
                            +-----------------------+
                            |     client/brower     |
                            +-----------+-----------+
........................................|(域名)............................................
+1--------------------------------------V(vip)--------------------------------------------+
|+Nginx-----------------------------------------------------------------+ +Nginx---------+|
||+config--------------------------------------------------------------+| |              ||
|||configfile:/etc/nginx/conf.d/default.conf                           || |              ||
|||+location------------+ +location-+ +location-----------------------+|| |              ||
||||= /auth/verification| |/        | |~* /static/                    ||| |              ||
||||= /butterfly_401    | |         | |= /index.html                  ||| |      ...     ||
||||= /auth/ssologin    | |         | |= /                            ||| |              ||
|||+--------*-----------+ +----*----+ +--------------*----------------+|| |              ||
||+---------|------------------|---------------------|-----------------+| |              || 
||          |                  |      +dir-----------V----------------+ | |              ||
||          |                  |      |/usr/share/nginx/html/static   | | |              ||
||          |                  |      |/usr/share/nginx/html/templates| | |              ||
||          |                  |      +-------------------------------+ | |              ||
|+----------|------------------|----------------------------------------+ +--------------+|
+-----------|------------------|----------------------------------------------------------+
            | vip              |
+2----------V----------+       | 
|   Auth(port:8011)    |       |
| +Auth---+ +Auth---+  |       |
| |huoyan1| |huoyan2|  |       |
| +-------+ +-------+  |       |
+----------------------+       |
...............................V....................................................... APP
 +APP-------------------------------------------------------------------------------------+
 | +3common---------------------------------+  +4chunfeng---+ +5yiqiu------+ +6zoneheng-+ |
 | | +wuxing----+ +ruqi------+ +xingqiao--+ |  |  bianque   | | program    | | pool     | |
 | | |          | |          | |          | |  |  xunzong   | | unit       | | machine  | |
 | | +----------+ +----------+ +----------+ |  |  qingnang  | | service    | |          | |
 | | +baichuan--+ +fuxi------+ +...-------+ |  |  paoding   | |            | | service  | |
 | | |          | |          | |          | |  |  yiye      | |            | | instance | |
 | | +----------+ +----------+ +----------+ |  |  ...       | |            | |          | |
 | +----------------------------------------+  +------------+ +------------+ +----------+ |
 |                 通用服务                       <DevOps>      <Service>     <Machine>   |
 +---------------+--------------------------+------------------------------|--------------+
                 |                          |                              |
 +---------------|--------------------------|------------------------------|--------------+
 | +7Cache-------V-----------+  +8DB--------V-------------+  +9MQ----------V-----------+  |
 | |+---------+              |  |+-------+                |  |+-----------------------+|  |
 | ||Twemproxy| \            |  ||DBproxy| \              |  ||        (redis)        ||  |
 | |+--+---+--+  +----------+|  |+-+---+-+   +---------+  |  |+-----^----------^------+|  |
 | |   |   |     |Metaserver||  |  |   |     | Control |  |  |      |          |       |  |
 | |+--V---V--+  +----------+|  |+-V---V-+   +---------+  |  |   +--+---+   +--+---+   |  |
 | ||  Redis  | /            |  || MySQL | /              |  |   |worker|   |worker|   |  |
 | |+---------+              |  |+-------+                |  |   +------+   +------+   |  |
 | +-------------------------+  +-------------------------+  +-------------------------+  |
 |      Redis Cluster           MySQL Cluster/Redis Cluster                               |
 +----------------------------------------------------------------------------------------+
```

## 2 服务异步处理

```
      APP
 +------------+
 | +--------+ |
 | |  API   | | 
 | +---+-+--+ | 
 |     | |    |     +--------------+
 |     | +----|---->|   XingQiao   |  星桥
 |     |      |     +------+-------+
 |     |      |            |                    +--------------+ 
 |     |      |            |       push         |              |   pop
 |     |      |            +------------------->| Redis broker |<------+
 |     +------|-------------------------------->|              |       |
 |            |                                 +--------------+       |
 |            |                                                        |
 |            |                                                        |
 | +--------+ |                                                        |
 | |  TASK  +-|--------------------------------------------------------+
 | +--------+ |
 +------------+
```
