background

Home page address

Sentinel can only store traffic limiting rules in memory by default

Use Sentinel in a production environment

The official documentation describes data persistence as follows

We provide dynamic data source implementation of ZooKeeper, Apollo, Nacos, etc. Take ZooKeeper as an example. If you want to use a third-party configuration center for configuration management, you need to do the following:

  1. Implement a public ZooKeeper Client for pushing rules. The ZooKeeper address needs to be specified in the Sentinel console configuration item, and the ZooKeeper Client will be created upon startup.
  2. We need to set a different path for each rule for each application (appName) (which can be changed at any time); Or the convention is greater than the configuration. For example, the path mode is/sentinel_rules/{appName}/{ruleType}, um participant.sentinel_rules/appA/flowRule).
  3. The rule configuration page needs to be modified accordingly, directly forApplication of dimensionConfigure rules. When you modify the rules of multiple application resources, you can push them in batches or separately. The Sentinel console caches the rules in memory (e.gInMemFlowRuleStore), it can be modified to support the rule cache of application dimension (key is appName). Every time rules are added/modified/deleted, the rule cache in memory is updated first, and then the full rule is obtained from the rule cache when push is needed. Then push the rules to ZooKeeper through the Client implemented above.
  4. Application clients need to register the corresponding read data source to listen for changes, refer to the related documentation.

Since Alibaba /Sentinel has not officially realized the support of writing to specific data sources, it only provides the realized interface, so it cannot be used out of the box

The solution

A contributor has provided implementation PR for three dynamic data sources, but it has not been incorporated into the main release

Added persistence support with optional persistence options

Further refinement

The project FJiayang/Sentinel, based on Jiajiangnan /Sentinelfork, realized docker image packing, and built and uploaded products automatically based on GitHub Actions.

Jiajiangnan Sentinel warehouse source code

Sentinel warehouse source code of FJiayang

Add Dockerfile

Based on minimal JDK image production

FROM openjdk:8-jdk-alpine3.7

MAINTAINER [email protected]

ENV VERSION 1.8.0

RUN mkdir -p /sentinel

WORKDIR /sentinel

ADD ./sentinel-dashboard/target/sentinel-dashboard.jar ./app-${VERSION}.jar

Set time zone. Default is UTC
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo 'Asia/Shanghai' > /etc/timezone

CMD java ${PARAM} -jar app-${VERSION}.jar
Copy the code

Add the GitHub pipeline configuration file

name: Publish Docker image

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Set up Maven Central Repository
        uses: actions/setup-java@v1
        with:
          java-version: 1.8

      - name: Publish package
        run: mvn --batch-mode clean package -Dmaven.test.skip=true

      - name: Push to Docker Hub
        uses: docker/build-push-action@v1
        with:
          username: The ${{ secrets.DOCKER_USERNAME }}
          password: The ${{ secrets.DOCKER_PASSWORD }}
          repository: fjy8018/sentinel
          tag_with_ref: true
Copy the code

Specific assembly line preparation can refer to the article

Juejin. Cn/post / 684490…

Method of use

Specific parameter document

item type The default value The minimum value describe
sentinel.dashboard.auth.username String sentinel There is no User name for logging in to the console. The default value issentinel
sentinel.dashboard.auth.password String sentinel There is no Password for logging in to the console. The default value issentinel
sentinel.dashboard.app.hideAppNoMachineMillis Integer 0 60000 Indicates the number of milliseconds since the last heartbeat communication between the host. This parameter is disabled by default
sentinel.dashboard.removeAppNoMachineMillis Integer 0 120000 Indicates whether to automatically delete an application that has no healthy node. The value is milliseconds since the last heartbeat time of the node under the application. The application is disabled by default
sentinel.dashboard.unhealthyMachineMillis Integer 60000 30000 The host is disconnected and cannot be shut down
sentinel.dashboard.autoRemoveMachineMillis Integer 0 300000 Whether to automatically delete the lost node when the time between the latest heartbeat communication exceeds the specified time. The function is disabled by default
datasource.provider String memory There is no The default ismemory, optional persistent configurationnacos,apollo,zookeeper
datasource.provider.nacos.server-addr String localhost:8848 There is no Nacos registry address
datasource.provider.nacos.username String There is no Nacos User name, which is empty by default
datasource.provider.nacos.password String There is no Nacos password, empty by default
datasource.provider.nacos.namespace String There is no Nacos Celebrity space, empty by default
datasource.provider.nacos.group-id String SENTINEL_GROUP There is no Nacos group. The default value isSENTINEL_GROUP
datasource.provider.apollo.server-addr String http://localhost:10034 There is no Apollo registry address, must be prefixedhttp://https://
datasource.provider.apollo.token String token There is no Apollo login token, default istoken
datasource.provider.zookeeper.server-addr String localhost:2181 There is no Address of the ZooKeeper registry
datasource.provider.zookeeper.session-timeout Integer 60000 0 Timeout period of the ZooKeeper session. Default value60000
datasource.provider.zookeeper.connection-timeout Integer 15000 0 Timeout period of the ZooKeeper connection. Default value15000
datasource.provider.zookeeper.retry.max-retries Integer 3 0 Maximum number of ZooKeeper retries. Default value3
datasource.provider.zookeeper.retry.base-sleep-time Integer 1000 1000 Minimum retry interval of ZooKeeper. Default value1000
datasource.provider.zookeeper.retry.max-sleep-time Integer 2147483647 0 Maximum retry interval of ZooKeeper. Default value2147483647

For a single Docker command launch

$ docker run --rm -e PARAM="-Dserver.port=8858 -Dcsp.sentinel.dashboard.server=localhost:8858 -Dproject.name=sentinel-dashboard - Ddatasource. The provider = nacos - Ddatasource. Provider. Nacos. Server - addr = 192.168.133.128:8848 -Ddatasource.provider.nacos.username=nacos -Ddatasource.provider.nacos.password=nacos -Ddatasource.provider.nacos.group-id=SENTINEL_GROUP"Fjy8018 / sentinel: 1.8.0 comes withCopy the code

For docker-compose startup, examples are given here in combination with nacOS and mysql infrastructure. Mysql needs to write nacOS related initialization table structures in advance

version: '3.7'
services:

  mysql57:
    image: Mysql: 5.7.29
    restart: always
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    ports:
      - 3306: 3306
    networks:
      - dev
    volumes:
      - ./mysql57/data:/var/lib/mysql
      - ./mysql57/custom-master.cnf:/etc/mysql/conf.d/custom.cnf
      - ./mysql57/log:/var/log/mysql
    environment:
      MYSQL_ROOT_PASSWORD: root

  nacos-standalone:
    image: Nacos/nacos - server: 1.1.4
    networks:
      - dev
    environment:
      - PREFER_HOST_MODE=hostname
      - MODE=standalone
      - SPRING_DATASOURCE_PLATFORM=mysql
      - MYSQL_MASTER_SERVICE_HOST=mysql57
      - MYSQL_MASTER_SERVICE_DB_NAME=nacos
      - MYSQL_MASTER_SERVICE_PORT=3306
      - MYSQL_SLAVE_SERVICE_HOST=mysql57
      - MYSQL_SLAVE_SERVICE_PORT=3306
      - MYSQL_MASTER_SERVICE_USER=root
      - MYSQL_MASTER_SERVICE_PASSWORD=root
    ports:
      - 8848: 8848
    depends_on:
      - mysql57
    volumes:
      - ./standalone-logs/:/home/nacos/logs

  sentinel:
    image: Fjy8018 / sentinel: 1.8.0 comes with
    environment:
      - PARAM=-Dserver.port=8858 -Dcsp.sentinel.dashboard.server=localhost:8858 -Dproject.name=sentinel-dashboard -Ddatasource.provider=nacos -Ddatasource.provider.nacos.server-addr=nacos-standalone:8848 -Ddatasource.provider.nacos.username=nacos -Ddatasource.provider.nacos.password=nacos -Ddatasource.provider.nacos.group-id=SENTINEL_GROUP
    networks:
      - dev
    ports:
      - 8858: 8858
    restart: on-failure

networks:
  dev:
Copy the code

After successful startup, you can see that sentinel-Dashboard has been successfully registered on NACOS