Springcloud Aibaba is so popular now that I have always wanted to write a series of blog posts on Springcloud Alibaba step by step to build microservices architecture, and finally decided to start the first article of this series today – Basic environment preparation.

This series of articles is based on three microservices: user service AccountService, OrderService OrderService, and ProductService ProductService

The components used are:

  • Registry, configuration center Nacos
  • Current limiting Sentinel
  • Distributed transaction Seata
  • The Gateway SpringCloud Gateway
  • Authenticate and authorize Spring Cloud Oauth2
  • Docker, docker – compose

Due to the relatively large number of components used, the deployment will be tedious. The most important thing is that there is no resource server, so I will gradually deploy some components using Docker-compose in the development process.

This article uses DokCer-compose to deploy Nacos, Sentinel, and Mysql as the basis for the next series of articles.

If you’re not familiar with Docker or Docker-compose, check out my previous two articles and you’ll be able to get started quickly.

  • Docker basics and combat, read this article is enough
  • Docker-compose: Docker-compose: Docker-compose: Docker-compose: Docker-Compose

The container is changed

mysql

Since nacOS needs to rely on Mysql as the resource store, I will start the temporary Mysql container with Docker before writing the complete Docker-compose, and then prepare the database required by NACOS.

  • Start temporary container

    Docker run - p3306:3306 - rm - name mysql - e MYSQL_ROOT_PASSWORD = 123456 - v/app/cloud/mysql/data: / var/lib/mysql mysql: 5.7

    The host directory needs to be mounted here, and data need not be initialized again after docker-Compse is started.
  • Connect to your container with a mysql client and import the nacOS data table

    `https://github.com/alibaba/nacos/tree/develop/distribution/conf/

    nacos-mysql.sql`

  • Stop the container due to the addition--rmParameter, so the container is automatically deleted

    docker stop 3475ef078d3a

nacos

Let’s look at the environment variables of NACOS, as shown in the following table:

Configuration items describe Optional parameters The default value
MODE Model cluster/standalone cluster/standalone cluster
PREFERHOSTMODE Whether hostname is supported hostname/ip ip
NACOSSERVERPORT Service port number
8848
SPRINGDATASOURCEPLATFORM Single-machine mode supports mysql mysql / empty empty
MYSQLMASTERSERVICE_HOST Host of the primary mysql node

MYSQLMASTERSERVICE_PORT Port of the primary mysql node
3306
MYSQLMASTERSERVICEDBNAME Name of the primary mysql database

MYSQLMASTERSERVICE_USER Username of the primary mysql node

MYSQLMASTERSERVICE_PASSWORD Password of the primary mysql node

MYSQLSLAVESERVICE_HOST Host of the mysql secondary node

MYSQLSLAVESERVICE_PORT Mysql secondary node port
3306

Nacos supports master-slave configuration. Considering resources, we only configure a single mysql server. Students with resources can set up a master-slave environment.

sentinel

Sentinel is simple. You can directly configure a Sentinel-Dashboard image. (I didn’t need to introduce sentinel at the beginning of the series, so I will add it to my Docker-compose this time as well, so as not to cover it separately.)

seata

Seata, for some reason, has not released an official image yet and is temporarily suspended.

docker-compose

Here is the docker-compse file I wrote, you can modify

Version: "3" services: mysql: container_name: mysql image: mysql:5.7 environment: -mysql_root_password =123456 Volumes: - /app/cloud/mysql/data:/var/lib/mysql ports: - "3306:3306" restart: always nacos: image: Nacos/nacos - server: 1.1.4 container_name: nacos environment: - PREFER_HOST_MODE=hostname - MODE=standalone - MYSQL_DATABASE_NUM=1 - SPRING_DATASOURCE_PLATFORM=mysql - MYSQL_MASTER_SERVICE_HOST=mysql - MYSQL_MASTER_SERVICE_DB_NAME=nacos_config - MYSQL_MASTER_SERVICE_PORT=3306 - MYSQL_MASTER_SERVICE_USER=root - MYSQL_MASTER_SERVICE_PASSWORD=123456 volumes: - /app/cloud/nacos/logs:/home/nacos/logs ports: - "8848:8848" depends_on: - mysql restart: always sentinel: image: bladex/sentinel-dashboard:latest container_name: sentinel ports: - "8858:8858" restart: alwaysCopy the code

Upload it to your server and run the docker-compose up -d command to start it

Environmental authentication

nacos

Visit nacoshttp://192.168.136.129:8848/nacos, log in with the account password nacos/nacos, and add oneName = JAVA day recordThe configuration.Nacos installed successfully!

mysql

Connect to the mysql server using the client toolhis_config_infoTable to verify that the configuration just described existsMysql installed successfully!

sentinel

accesshttp://192.168.136.129:8858Log in using the account sentinel/sentinelSentinel installed successfully!

At this point, the required components are successfully installed, so this period of “SpringCloud Alibaba micro-service actual combat – basic environment preparation” is the end of the chapter, let’s see you next time!

Personal official account: JAVA Daily Information record, javadaily.cn