This article explains how to build SpringcloudAlibaba infrastructure: Mysql, Nacos, Sentinal, RocketMQ

The overall situation

This series of articles focuses on a series of environments for setting up SpringcloudAlibaba. It mainly includes two parts: basic environment preparation and project construction.

The basic environment mainly includes: Mysql, Nacos, Sentinal, RocketMQ, Docker.

The project construction includes three services: gateway, order service, commodity service and marketing service.

The first part of this article is the preparation of the basic environment.

Based on the environment

Basic environment preparation: Docker, Mysql, Nacos, Sentinal, RocketMQ

Most of the components directly use Docker installation, convenient and quick. If you don’t know about Docker, you need to prepare in advance. This article will not go into details.

Install the Docker

The installation of Docker is not described here. The author uses a Mac and can download and install it directly from the Docker official website.

Docker deplores Mysql, Nacos, and Sentinal

Considering that it is troublesome to deploy the three components separately with Docker, the author directly uses Docker-compose to deploy the three components together.

Nacos: 1.3.2

Sentinal: 1.8

Mysql: 5.7

Write a yaml file named docker-comemage. yaml ina folder, install Mysql, install Nacos, install Sentinal

version: "3"
services:
  mysql:
    container_name: mysql
    image: Mysql: 5.7
    environment:
      - MYSQL_ROOT_PASSWORD=123456
    volumes:
      - /Users/yclxiao/Program/volume/mysql/data:/var/lib/mysql
    ports:
      - "3306:3306"
    restart: always

  nacos:
    image: Nacos/nacos - server: 1.3.2
    container_name: nacos
    environment:
      - PREFER_HOST_MODE=hostname
      - MODE=standalone
      - MYSQL_DATABASE_NUM=1
      - MYSQL_SERVICE_HOST = 127.0.0.1
      - MYSQL_SERVICE_DB_NAME=nacos_config
      - MYSQL_SERVICE_PORT=3306
      - MYSQL_SERVICE_USER=root
      - MYSQL_SERVICE_PASSWORD=123456
    volumes:
      - /Users/yclxiao/logs/nacos:/home/nacos/logs
    ports:
      - "8848:8848"
    depends_on:
      - mysql
    restart: always

  sentinel:
    image: bladex/sentinel-dashboard:latest
    container_name: sentinel
    ports:
      - "8858:8858"
    restart: always
Copy the code

Docker-compose up -d: docker-compose up -d: docker-compose up -d: docker-compose up -d: docker-compose up -d

Docker ps -a query container

Verify the Mysql, Nacos, and Sentinal deployments

1, verify Mysql: directly connect to the local Mysql server using DataGrip as user root and password 123456.

2, validation Nacos: http://localhost:8848/nacos/index.html, Nacos user name, password Nacos.

3, verify Sentinal: http://localhost:8858/#/dashboard, username sentinel, password sentinel.

Install RocketMQ

Previous attempts to install RocketMQ with Docker versions have not been successful, or the page cannot be opened after success, or after container startup, Mac machine directly CPU surge, so I gave up docker deployment, directly adopt the original way of installation, download address of the installation package: Archive.apache.org/dist/rocket…

RocketMQ: 4.4.0

Install nameserver and Broker

Installation steps:

1. Create your own RocketMQ installation directory

2, enter archive.apache.org/dist/rocket…

3. Decompress the installation package

4. Create rocketMQ data folder rocketMQData

5. Edit./conf/broker

BrokerIp1 = 127.0.0.1

5.2. Add file Storage Location:

#The store path
storePathRootDir=/Users/yclxiao/Project/middleware/rocketmq/rocketmq-native/rocketmqdata/store
#CommitLog Storage path
storePathCommitLog=/Users/yclxiao/Project/middleware/rocketmq/rocketmq-native/rocketmqdata/store/commitlog
#Consumption queue storage path Storage path
storePathConsumeQueue=/Users/yclxiao/Project/middleware/rocketmq/rocketmq-native/rocketmqdata/store/consumequeue
#Message index storage path
storePathIndex=/Users/yclxiao/Project/middleware/rocketmq/rocketmq-native/rocketmqdata/store/index
#Checkpoint File storage path
storeCheckpoint=/Users/yclxiao/Project/middleware/rocketmq/rocketmq-native/rocketmqdata/store/checkpoint
#Abort File storage path
abortFile=/Users/yclxiao/Project/middleware/rocketmq/rocketmq-native/rocketmqdata/store/abort
Copy the code

In the file/Users/yclxiao/Project/middleware/rocketmq/rocketmq – native directory address into their own directory

6. Write the following startup script with the file name startrmq.sh and grant the execute permission chmod +x startrmq.sh

#! /bin/shLog 2>&1 & sleep 5 echo "namesrv started" nohup sh./rocketmq-all-4.4.0-bin-release/bin/mqnamesrv >mqnamesrv.log 2>&1 & sleep 5 echo "namesrv started" nohup sh /rocketmq-all-4.4.0-bin-release/bin/mqbroker -n localhost:9876 -c./rocketmq-all-4.4.0-bin-release/conf/broker.conf >mqbroker.log 2>&1 & echo "broker starting" nohup java -jar -Drocketmq.config.namesrvAddr=localhost:9876 -Drocketmq.config.isVIPChannel=false -Drocketmq.config.dataPath=./rocketmqdata -Dserver.port=8180 /rocketmq-dashboard-2.0.0.jar >dashboard.log 2>&1 & echo "dashboard Starting"Copy the code

7. Start:

Start namesrv: nohup sh./rocketmq-all-4.4.0-bin-release/bin/mqnamesrv >mqnamesrv.log 2> &1&

Start the broker: Nohup sh./rocketmq-all-4.4.0-bin-release/bin/mqbroker -n localhost: 9876-c . / rocketmq – all – 4.4.0 – bin – release/conf/broker. Conf > mqbroker. Log > & 1 & 2

(2) Installing dashboard

Since RocketMQ-Console has been replaced by RocketMQ-Dashboard, dashboard is installed directly

1. Copy project: github.com/apache/rock…

MVN clean package-dmaven.test.skip =true

3. Copy the JAR to the outer directory

4. Start: nohup java -jar -Drocketmq.config.namesrvAddr=localhost:9876 -Drocketmq.config.isVIPChannel=false – Drocketmq. Config. DataPath =. / rocketmqdata – Dserver. Port = 8180 / rocketmq – dashboard – 2.0.0. Jar > dashboard. The log > & 1 & 2

The reference files are listed below:

(iii) RocketMQ one-click start and stop

The startup of RocketMQ involves three components, which is quite troublesome, so a simple shell script is made to facilitate the startup.

Startup script:

#! /bin/shLog 2>&1 & sleep 5 echo "namesrv started" nohup sh./rocketmq-all-4.4.0-bin-release/bin/mqnamesrv >mqnamesrv.log 2>&1 & sleep 5 echo "namesrv started" nohup sh /rocketmq-all-4.4.0-bin-release/bin/mqbroker -n localhost:9876 -c./rocketmq-all-4.4.0-bin-release/conf/broker.conf >mqbroker.log 2>&1 & echo "broker starting" nohup java -jar -Drocketmq.config.namesrvAddr=localhost:9876 -Drocketmq.config.isVIPChannel=false -Drocketmq.config.dataPath=./rocketmqdata -Dserver.port=8180 /rocketmq-dashboard-2.0.0.jar >dashboard.log 2>&1 & echo "dashboard Starting"Copy the code

Stop script:

#! /bin/shSh./rocketmq-all-4.4.0-bin-release/bin/mqshutdown namesrv sh./rocketmq-all-4.4.0-bin-release/bin/mqshutdown broker pid=`ps ax | grep rocketmq-dashboard | grep java | grep -v grep | awk '{print $1}'` if [ -z "$pid" ] ; then echo "No rocketmq-dashboard running." exit -1; fi echo "The rocketmq-dashboard(${pid}) is running..." kill ${pid} echo "Send shutdown request to rocketmq-dashboard(${pid}) OK"Copy the code

One-click startup:./startrmq.sh

One-click stop:./ stopRMq. sh

(iv) Verify RocketMQ deployment results

conclusion

Generally speaking, the whole installation process is fairly simple and clear, follow the steps to install will be successful, if you have any questions during the installation process, please feel free to contact me, thank you for reading, we will see you next time.

Personal contact information is as follows: Mangod. Top/S/Aboutme