Spring cloud second-generation architecture depends on the component docker full configuration broadcast (1)

Spring cloud second-generation architecture depends on the component docker full configuration broadcast (1)

Spring cloud second-generation architecture depends on the component docker full configuration broadcast (1)

A background introduction

Let's take a look at the components of the first generation of spring cloud that we are familiar with

Component name Features
Ribbon Client load balancer
Eureka Service governance (registration, discovery...)
Hystrix Fuse protection when calling remotely between services
Feign Directly call APIs of other services by defining interfaces
Zuul Service gateway
Config Distributed configuration
Sleuth Used to request link tracking

Spring cloud is now a standard, and companies can write their own components based on its programming model. For example, Netflix and Alibaba have their own set of distributed service components developed through the spring cloud programming model.

Spring Cloud second-generation components

Spring Cloud Alibaba mainly includes Sentinel, Nacos, RocketMQ, Dubbo, Seata and other components.

The second generation introduced Spring Cloud Alibaba

First-generation components Second-generation components
Eureka Nacos
Config Apollo
Zuul spring cloud gateway
Hystrix Sentinel

Plus our commonly used components

Component Features
XXL-Job Distributed Timing Task Center
Redis Distributed cache
Rocket-MQ message queue
Seata Distributed transaction
ELK Log processing
Skywalking Call chain monitoring
Prometheus metrics monitoring

In addition to spring cloud gateway, all of them need to be supported by external separate deployment services.

2. use docker-compose to simplify local deployment

apollo

version: '2'

services:
  apollo-quick-start:
    image: nobodyiam/apollo-quick-start
    container_name: apollo-quick-start
    depends_on:
      - apollo-db
    ports:
      - "8080:8080"
      - "8070:8070"
    links:
      - apollo-db

  apollo-db:
    image: mysql:5.7
    container_name: apollo-db
    environment:
      TZ: Asia/Shanghai
      MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
    depends_on:
      - apollo-dbdata
    ports:
      - "13306:3306"
    volumes:
      - ./sql:/docker-entrypoint-initdb.d
    volumes_from:
      - apollo-dbdata

  apollo-dbdata:
    image: alpine:latest
    container_name: apollo-dbdata
    volumes:
      - /var/lib/mysql

 

Note: The files under ./sql are here , they are two initialized sql files

nacos

version: "2"
services:
  nacos:
    image: nacos/nacos-server:latest
    container_name: nacos-standalone-mysql
    env_file:
      - ./env/nacos-standlone-mysql.env
    volumes:
      - ./standalone-logs/:/home/nacos/logs
      - ./init.d/custom.properties:/home/nacos/init.d/custom.properties
    ports:
      - "8848:8848"
      - "9555:9555"
    depends_on:
      - mysql
    restart: on-failure
  mysql:
    container_name: mysql
    image: nacos/nacos-mysql:5.7
    env_file:
      - ./env/mysql.env
    volumes:
      - ./mysql:/var/lib/mysql
    ports:
      - "3308:3306"
 

redis

version: '2'
services:
  #redis 
  redis:
    # 
    container_name: redis
    # 
    image: redis:6.0.8
    # 
    ports:
      - 6379:6379
    command: redis-server /etc/conf/redis.conf
    # 
    volumes:
      - ./data:/data
      - ./conf:/etc/conf
    # 
    privileged: true
    environment:
      - TZ=Asia/Shanghai
      - LANG=en_US.UTF-8
 

Note: You can find a default template file in the redis.conf configuration file under conf, and then modify it accordingly

rocket-mq

version: '2'

services:
  #Service for nameserver
  namesrv:
    image: apacherocketmq/rocketmq-nameserver:4.5.0-alpine-operator-0.3.0
    container_name: rmqnamesrv
    ports:      
      - 9876:9876
    volumes:     
      - ./data/namesrv/logs:/home/rocketmq/logs
    command: sh mqnamesrv
    environment:
      TZ: Asia/Shanghai
      JAVA_OPT_EXT: "-server -Xms512m -Xmx512m -Xmn256m"

  #Service for broker
  broker:
    image: apacherocketmq/rocketmq-broker:4.5.0-alpine-operator-0.3.0
    container_name: rmqbroker-a
    depends_on:     
      - namesrv
    ports:      
      - 10909:10909
      - 10911:10911
      - 10912:10912
    environment:      
      NAMESRV_ADDR: namesrv:9876
      JAVA_OPT_EXT: "-server -Xms512m -Xmx512m -Xmn256m"
    volumes:      
      - ./data/broker/logs:/home/rocketmq/logs     
      - ./data/broker/store:/home/rocketmq/store      
      - ./data/broker/conf/broker.conf:/opt/rocketmq-4.7.1/conf/broker.conf

    command: sh mqbroker -c /opt/rocketmq-4.7.1/conf/broker.conf

 #Service for another broker -- broker1
  broker1:
    image: apacherocketmq/rocketmq-broker:4.5.0-alpine-operator-0.3.0
    container_name: rmqbroker-b
    depends_on:     
      - namesrv
    ports:      
      - 10929:10909
      - 10931:10911
      - 10932:10912
    environment:      
      NAMESRV_ADDR: namesrv:9876
      JAVA_OPT_EXT: "-server -Xms512m -Xmx512m -Xmn256m"
    volumes:      
      - ./data1/broker/logs:/home/rocketmq/logs      
      - ./data1/broker/store:/home/rocketmq/store      
      - ./data1/broker/conf/broker.conf:/opt/rocketmq-4.7.1/conf/broker.conf
    command: sh mqbroker -c /opt/rocketmq-4.7.1/conf/broker.conf

  rmqconsole:
    image: styletang/rocketmq-console-ng
    container_name: rmqconsole
    ports:
      - 8180:8080
    environment:
        TZ: Asia/Shanghai
        JAVA_OPTS: "-Drocketmq.namesrv.addr=namesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"
    depends_on:
      - namesrv
 

There are also two configuration files

  • ./data/broker/conf/broker.conf
  • ./data1/broker/conf/broker.conf
## ./data/broker/conf/broker.conf
brokerClusterName = DefaultCluster
brokerName = broker-abroker
Id = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH

### ./data1/broker/conf/broker.conf
brokerClusterName = Default
ClusterbrokerName = broker-bbroker
Id = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
 

seata-server

version: "3.1"
services:
  seata-server:
    image: seataio/seata-server:latest
    hostname: seata-server
    ports:
      - 8091:8091
    environment:
      - SEATA_PORT=8091
    expose:
      - 8091

 

sentinel

  • There is no ready-made docker image, you need to write one yourself
FROM openjdk:8

# jar    COPY 
ADD sentinel-dashboard-1.8.0.jar sentinel-dashboard-1.8.0.jar

EXPOSE 8080

#    <ENTRYPOINT> "<CMD>"
ENTRYPOINT ["java","-jar","sentinel-dashboard-1.8.0.jar"]
 
  • Write the docker-compose configuration file using the image compiled by yourself
version: '3'
services:
  sentinel-dashboard:
    image: sentinel-dashboard:1.8.0
    container_name: sentinel-dashboard
    restart: always
    environment:
      JAVA_OPTS: "-Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject.name=sentinel-dashboard -Djava.security.egd=file:/dev/./urandom -Dcsp.sentinel.api.port=8719"
    ports: #  8080 Dockerfile EXPOSE 
      - "58080:8080"
      - "8719:8719"
    volumes:
      - ./root/logs:/root/logs

 

For more exciting content, please pay attention to the public account "Technical Sharing of Small Box"