Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…libaba-

# Conflicts:
#	markdown/第九章 RocketMQ.md
  • Loading branch information
tangchen.tangchen committed Feb 15, 2020
2 parents d4627f5 66ea9bf commit b51a04b
Show file tree
Hide file tree
Showing 339 changed files with 34,385 additions and 2,557 deletions.
Binary file removed markdown/image/rocketmq-store.jpg
Binary file not shown.
Binary file removed markdown/image/rocketmq_architecture_1.png
Binary file not shown.
Binary file removed markdown/image/rocketmq_architecture_10.jpg
Binary file not shown.
Binary file removed markdown/image/rocketmq_architecture_11.jpg
Binary file not shown.
Binary file removed markdown/image/rocketmq_architecture_12.jpg
Binary file not shown.
Binary file removed markdown/image/rocketmq_architecture_13.jpg
Binary file not shown.
Binary file removed markdown/image/rocketmq_architecture_14.jpg
Binary file not shown.
Binary file removed markdown/image/rocketmq_architecture_15.jpg
Binary file not shown.
Binary file removed markdown/image/rocketmq_architecture_2.png
Binary file not shown.
Binary file removed markdown/image/rocketmq_architecture_3.png
Binary file not shown.
Binary file removed markdown/image/rocketmq_architecture_4.png
Binary file not shown.
Binary file removed markdown/image/rocketmq_architecture_5.jpg
Binary file not shown.
Binary file removed markdown/image/rocketmq_architecture_6.png
Binary file not shown.
Binary file removed markdown/image/rocketmq_architecture_7.jpg
Binary file not shown.
Binary file removed markdown/image/rocketmq_architecture_8.jpg
Binary file not shown.
Binary file removed markdown/image/rocketmq_architecture_9.jpg
Binary file not shown.
Binary file removed markdown/image/sentinel-architecture_1.png
Binary file not shown.
Binary file removed markdown/image/sentinel-architecture_2.gif
Binary file not shown.
Binary file removed markdown/image/sentinel-architecture_3.png
Binary file not shown.
Binary file removed markdown/image/sentinel-architecture_4.jpg
Binary file not shown.
Binary file removed markdown/image/sentinel-architecture_5.jpg
Binary file not shown.
Binary file removed markdown/image/sentinel-architecture_6.jpg
Binary file not shown.
Binary file removed markdown/image/sentinel-dashboard.jpg
Binary file not shown.
Binary file removed markdown/image/sentinel-dashboard_0.jpg
Binary file not shown.
Binary file removed markdown/image/sentinel-dashboard_1.jpg
Binary file not shown.
Binary file removed markdown/image/sentinel-dashboard_2.jpg
Diff not rendered.
Binary file removed markdown/image/sentinel-dashboard_3.png
Diff not rendered.
Binary file removed markdown/image/sentinel-dashboard_4.jpg
Diff not rendered.
Binary file removed markdown/image/sentinel-dashboard_5.jpg
Diff not rendered.
Binary file removed markdown/image/sentinel-dashboard_6.jpg
Diff not rendered.
Binary file removed markdown/image/sentinel-dashboard_7.png
Diff not rendered.
Binary file removed markdown/image/sentinel-log_1.jpg
Diff not rendered.
Binary file removed markdown/image/spring-cloud-stream_0.png
Diff not rendered.
Binary file removed markdown/image/spring-cloud-stream_1.jpg
Diff not rendered.
Binary file removed markdown/image/spring-cloud-stream_2.png
Diff not rendered.
2,250 changes: 0 additions & 2,250 deletions markdown/第七章 Sentinel.md

This file was deleted.

61 changes: 61 additions & 0 deletions sentinel-dashboard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 1,61 @@
# Sentinel 控制台

## 0. 概述

Sentinel 控制台是流量控制、熔断降级规则统一配置和管理的入口,它为用户提供了机器自发现、簇点链路自发现、监控、规则配置等功能。在 Sentinel 控制台上,我们可以配置规则并实时查看流量控制效果。

## 1. 编译和启动

### 1.1 如何编译

使用如下命令将代码打包成一个 fat jar:

```bash
mvn clean package
```

### 1.2 如何启动

使用如下命令启动编译后的控制台:

```bash
java -Dserver.port=8080 \
-Dcsp.sentinel.dashboard.server=localhost:8080 \
-Dproject.name=sentinel-dashboard \
-jar target/sentinel-dashboard.jar
```

上述命令中我们指定几个 JVM 参数,其中 `-Dserver.port=8080` 是 Spring Boot 的参数,
用于指定 Spring Boot 服务端启动端口为 `8080`。其余几个是 Sentinel 客户端的参数。

为便于演示,我们对控制台本身加入了流量控制功能,具体做法是引入 Sentinel 提供的 `CommonFilter` 这个 Servlet Filter。
上述 JVM 参数的含义是:

| 参数 | 作用 |
|--------|--------|
|`Dcsp.sentinel.dashboard.server=localhost:8080`|向 Sentinel 接入端指定控制台的地址|
|`-Dproject.name=sentinel-dashboard`|向 Sentinel 指定应用名称,比如上面对应的应用名称就为 `sentinel-dashboard`|

全部的配置项可以参考 [启动配置项文档](https://github.com/alibaba/Sentinel/wiki/启动配置项)

经过上述配置,控制台启动后会自动向自己发送心跳。程序启动后浏览器访问 `localhost:8080` 即可访问 Sentinel 控制台。

从 Sentinel 1.6.0 开始,Sentinel 控制台支持简单的**登录**功能,默认用户名和密码都是 `sentinel`。用户可以通过如下参数进行配置:

- `-Dsentinel.dashboard.auth.username=sentinel` 用于指定控制台的登录用户名为 `sentinel`
- `-Dsentinel.dashboard.auth.password=123456` 用于指定控制台的登录密码为 `123456`;如果省略这两个参数,默认用户和密码均为 `sentinel`
- `-Dserver.servlet.session.timeout=7200` 用于指定 Spring Boot 服务端 session 的过期时间,如 `7200` 表示 7200 秒;`60m` 表示 60 分钟,默认为 30 分钟;

## 2. 客户端接入

选择合适的方式接入 Sentinel,然后在应用启动时加入 JVM 参数 `-Dcsp.sentinel.dashboard.server=consoleIp:port` 指定控制台地址和端口。
确保客户端有访问量,**Sentinel 会在客户端首次调用的时候进行初始化,开始向控制台发送心跳包**,将客户端纳入到控制台的管辖之下。

客户端接入的详细步骤请参考 [Wiki 文档](https://github.com/alibaba/Sentinel/wiki/控制台#3-客户端接入控制台)

## 3. 验证是否接入成功

客户端正确配置并启动后,会**在初次调用后**主动向控制台发送心跳包,汇报自己的存在;
控制台收到客户端心跳包之后,会在左侧导航栏中显示该客户端信息。如果控制台能够看到客户端的机器信息,则表明客户端接入成功了。

更多:[控制台功能介绍](./Sentinel_Dashboard_Feature.md)
88 changes: 88 additions & 0 deletions sentinel-dashboard/Sentinel_Dashboard_Feature.md
Original file line number Diff line number Diff line change
@@ -0,0 1,88 @@
# Sentinel 控制台功能介绍

## 0. 概述

Sentinel 控制台是流量控制、熔断降级规则统一配置和管理的入口,它为用户提供了机器自发现、簇点链路自发现、监控、规则配置等功能。在 Sentinel 控制台上,我们可以配置规则并实时查看流量控制效果。使用 Sentinel 控制台的流程如下:

```
客户端接入 -> 机器自发现 -> 查看簇点链路 -> 配置流控规则 -> 查看流控效果
```

## 1. 功能介绍

### 1.1 机器自发现

Sentinel 提供内置的机器自发现功能,无需依赖第三方服务发现组件即可实现客户端的发现。点击 Sentinel 控制台左侧导航栏的“机器列表”菜单,可查看集群机器数量和机器健康状况。

### 1.2 簇点链路自发现

Sentinel 将每一个需要流控的 URL 或者接口称为一个资源,并使用URL地址或方法签名表示资源。Sentinel 会自动发现所有潜在的资源和资源之间的调用链,并在“簇点链路”页面展示。
资源是设置流控规则的载体,通过簇点链路自发现,可以方便的对重要资源设置流控规则、熔断降级规则等。

> 注意:**客户端有访问量之后,才能在簇点链路页面看到资源监控(lazy-initializing)**
### 1.3 实时监控

Sentinel 监控功能能够实时查看集群中每个资源的实时访问以及流控情况。控制台左侧导航栏的“实时监控”菜单对应该功能。

### 1.4 流控降级规则设置

Sentinel 提供了多种规则来保护系统的不同部分。流量控制规则用于保护服务提供方,熔断降级规则用于保护服务消费方,系统保护规则用于保护整个系统。

#### 1.4.1 流量控制规则

流量控制规则用于保护服务提供方,服务提供方指任何可以对外提供服务的系统,比如向终端用户提供 Web 服务的 Web 应用,向微服务消费方提供服务的 Dubbo Service Provider 等。
系统的服务能力是有限的,如果消费方请求速度过高,则采用相应的保护策略,或是直接拒绝,或是排队等待。通过“流控规则”页面可以查看和配置流量控制规则。

#### 1.4.2 熔断降级规则

降级规则用于保护服务消费方。在微服务架构中,业务系统通常要依赖多个服务,依赖的某个服务不可用将会影响业务系统的可用性。解决这个问题的方法是及时发现服务的“不可用”状态,在调用时快速失败而不是等待调动超时或者重试。Sentinel 通过熔断降级来达到快速失败的目的。通过“降级规则”页面可以查看和配置降级规则。

#### 1.4.3 系统保护规则

系统保护规则(简称`系统规则`)用于保护整个系统指标处于安全水位。无论是服务提供方还是消费方,活跃线程数过多、系统LOAD等过高都是系统处于高水位的指标。当系统水位过高时,系统应拒绝对外提供服务以便迅速降低资源占用。通过“系统规则”页面可以查看和设置系统保护规则。

## 2. 限制

本控制台只是用于演示 Sentinel 的基本能力和工作流程,并没有依赖生产环境中所必需的组件,比如**持久化的后端数据库、可靠的配置中心**等。
目前 Sentinel 采用内存态的方式存储监控和规则数据,监控最长存储时间为 5 分钟,控制台重启后数据丢失。

## 3. 配置项

控制台的一些特性可以通过配置项来进行配置,配置项主要有两个来源:`System.getProperty()``System.getenv()`,同时存在时后者可以覆盖前者。

> 通过环境变量进行配置时,因为不支持 `.` 所以需要将其更换为 `_`
项 | 类型 | 默认值 | 最小值 | 描述
--- | --- | --- | --- | ---
sentinel.dashboard.auth.username | String | sentinel | 无 | 登录控制台的用户名,默认为 `sentinel`
sentinel.dashboard.auth.password | String | sentinel | 无 | 登录控制台的密码,默认为 `sentinel`
sentinel.dashboard.app.hideAppNoMachineMillis | Integer | 0 | 60000 | 是否隐藏无健康节点的应用,距离最近一次主机心跳时间的毫秒数,默认关闭
sentinel.dashboard.removeAppNoMachineMillis | Integer | 0 | 120000 | 是否自动删除无健康节点的应用,距离最近一次其下节点的心跳时间毫秒数,默认关闭
sentinel.dashboard.unhealthyMachineMillis | Integer | 60000 | 30000 | 主机失联判定,不可关闭
sentinel.dashboard.autoRemoveMachineMillis | Integer | 0 | 300000 | 距离最近心跳时间超过指定时间是否自动删除失联节点,默认关闭

配置示例:

- 命令行方式:

```shell
java -Dsentinel.dashboard.app.hideAppNoMachineMillis=60000
```

- Java 方式:

```java
System.setProperty("sentinel.dashboard.app.hideAppNoMachineMillis", "60000");
```

- 环境变量方式:

```shell
sentinel_dashboard_app_hideAppNoMachineMillis=60000
```

更多:

- [Sentinel 控制台启动和客户端接入](./README.md)
- [控制台 Wiki](https://github.com/alibaba/Sentinel/wiki/控制台)
194 changes: 194 additions & 0 deletions sentinel-dashboard/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 1,194 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-parent</artifactId>
<version>1.7.1</version>
</parent>

<artifactId>sentinel-dashboard</artifactId>
<packaging>jar</packaging>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring.boot.version>2.0.5.RELEASE</spring.boot.version>
<curator.version>4.0.1</curator.version>
</properties>

<dependencies>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-core</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-web-servlet</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-transport-simple-http</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-parameter-flow-control</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-api-gateway-adapter-common</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.boot.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>

<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>4.1.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore-nio</artifactId>
<version>4.4.6</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>

<!-- for Nacos rule publisher sample -->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
<!-- <scope>test</scope>-->
</dependency>
<!-- for Apollo rule publisher sample -->
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-openapi</artifactId>
<version>1.2.0</version>
<scope>test</scope>
</dependency>

<!--for Zookeeper rule publisher sample-->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>${curator.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
<version>1.16.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>sentinel-dashboard</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<configuration>
<fork>true</fork>
<mainClass>com.alibaba.csp.sentinel.dashboard.DashboardApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven.deploy.version}</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>

<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>

<resource>
<directory>src/main/webapp/</directory>
<excludes>
<exclude>resources/node_modules/**</exclude>
</excludes>
</resource>
</resources>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 1,39 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.csp.sentinel.dashboard;

import com.alibaba.csp.sentinel.init.InitExecutor;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* Sentinel dashboard application.
*
* @author Carpenter Lee
*/
@SpringBootApplication
public class DashboardApplication {

public static void main(String[] args) {
triggerSentinelInit();
SpringApplication.run(DashboardApplication.class, args);
}

private static void triggerSentinelInit() {
new Thread(() -> InitExecutor.doInit()).start();
}
}
Loading

0 comments on commit b51a04b

Please sign in to comment.