instructions

  • The environment used is run using docker container, with docker-compose orchestration.
  • In the early stage, we will focus on the integration demonstration. All containers are run on a single machine. Later, we will explain how to build an HA cluster environment.

Local Environment Configuration

The operating system Run a memory Number of CPU core Docker version
Mac OS 11 32 GB Six nuclear 20.10.5

Environment set up

The containers created here are: Nacos 2.0.0, MySql 8.0.16, Sentinel Dashboard 1.8.0, Seata 1.4.1.

Redis, Mongo, RocketMQ, ES, and so on, we’ll get to that later.

Note: Here our Seata configuration is directly integrated into Nacos

The configuration file

docker-compose

Docker-comemage. yml is configured as follows

version: "3"
services:
  ali-nacos:
    image: Nacos/nacos - server: 2.0.0
    container_name: ali-nacos
    hostname: ali-nacos
    env_file:
      - ./nacos/nacos-standlone-mysql.env
    environment:
      - TZ=Asia/Shanghai
    volumes:
      - ./nacos/logs/:/home/nacos/logs
      - ./nacos/init.d/custom.properties:/home/nacos/init.d/custom.properties
    ports:
      - 8848: 8848
      - 9555: 9555
    depends_on:
      - ali-mysql
    restart: always
    networks:
      - cloud_alibaba
  ali-mysql:
    image: Nacos/nacos - mysql: 8.0.16
    container_name: ali-mysql
    hostname: ali-mysql
    env_file:
      - ./mysql/mysql.env
    environment:
      - TZ=Asia/Shanghai
    volumes:
      - ./mysql/data:/var/lib/mysql
    ports:
      - 3306: 3306
    restart: always
    networks:
      - cloud_alibaba
      
  ali-sentinel:
    image: Bladex/sentinel - dashboard: 1.8.0 comes with
    container_name: ali-sentinel
    hostname: ali-sentinel
    ports:
      - 8858: 8858
    environment:
      - TZ=Asia/Shanghai
    restart: always
    networks:
      - cloud_alibaba
    
  ali-seata:
    image: Seataio/seata - server: 1.4.1
    container_name: ali-seata
    hostname: ali-server
    ports:
      - 8091: 8091
    environment:
      - SEATA_CONFIG_NAME=file:/root/seata-config/registry
      - SEATA_IP = 127.0.0.1
      - SEATA_PORT=8091
      - TZ=Asia/Shanghai
    volumes:
      - ./seata/config:/root/seata-config
    depends_on:
      - ali-mysql
      - ali-nacos
    restart: always
    networks:
      - cloud_alibaba
    
networks:
  cloud_alibaba:
    external:
      name: cloud_alibaba
Copy the code

nacos

Official configuration: github.com/nacos-group…

Create the nacOS directory under the same directory as the YML files, and then create the following two files under the directory

Create nacos-standlone-mysql.env

PREFER_HOST_MODE=hostname
MODE=standalone
SPRING_DATASOURCE_PLATFORM=mysql
MYSQL_SERVICE_HOST=ali-mysql
MYSQL_SERVICE_DB_NAME=nacos_config
MYSQL_SERVICE_PORT=3306
MYSQL_SERVICE_USER=nacos
MYSQL_SERVICE_PASSWORD=nacos
Copy the code

Description of environment variable configuration:

The name of the describe options
MODE Cluster/Standalone mode cluster/standalone default cluster
NACOS_SERVERS Nacos cluster address eg. ip1,ip2,ip3
PREFER_HOST_MODE Whether hostname is supported hostname/ip default ip
NACOS_SERVER_PORT Nacos server port default 8848
NACOS_SERVER_IP A customized NACOS server IP address for multiple nics
SPRING_DATASOURCE_PLATFORM Standalone support mysql mysql / empty default empty
MYSQL_MASTER_SERVICE_HOST Host of the primary mysql node
MYSQL_MASTER_SERVICE_PORT Port of the primary mysql node default : 3306
MYSQL_MASTER_SERVICE_DB_NAME Mysql Database of the primary node
MYSQL_MASTER_SERVICE_USER Database user name
MYSQL_MASTER_SERVICE_PASSWORD Database password
MYSQL_SLAVE_SERVICE_HOST Host of the mysql secondary node
MYSQL_SLAVE_SERVICE_PORT Mysql secondary node port default :3306
MYSQL_DATABASE_NUM Number of databases default :2
JVM_XMS -Xms default :2g
JVM_XMX -Xmx default :2g
JVM_XMN -Xmn default :1g
JVM_MS -XX:MetaspaceSize default :128m
JVM_MMS -XX:MaxMetaspaceSize default :320m
NACOS_DEBUG Enabling remote Debugging y/n default :n
TOMCAT_ACCESSLOG_ENABLED server.tomcat.accesslog.enabled default :false

Create the init.d/custom.properties file

#spring.security.enabled=false
#management.security=false
#security.basic.enabled=false
#nacos.security.ignore.urls=/**
#management.metrics.export.elastic.host=http://localhost:9200
# metrics for prometheus
management.endpoints.web.exposure.include=*

# metrics for elastic search
#management.metrics.export.elastic.enabled=false
#management.metrics.export.elastic.host=http://localhost:9200

# metrics for influx
#management.metrics.export.influx.enabled=false
#management.metrics.export.influx.db=springboot
#management.metrics.export.influx.uri=http://localhost:8086
#management.metrics.export.influx.auto-create-db=true
#management.metrics.export.influx.consistency=one
#management.metrics.export.influx.compressed=true
Copy the code

mysql

Official configuration: github.com/nacos-group…

Create the mysql directory in the same directory as the yML file, and then create the mysql.env file

MYSQL_ROOT_PASSWORD=codelong
MYSQL_DATABASE=nacos_config
MYSQL_USER=nacos
MYSQL_PASSWORD=nacos
Copy the code

Configuration description:

The name of the describe
MYSQL_ROOT_PASSWORD Password of user root
MYSQL_DATABASE Nacos Specifies the database name
MYSQL_USER Nacos user name
MYSQL_PASSWORD Nacos password

seata

Official configuration: github.com/seata/seata…

Create the seata directory under the same directory as the YML file, and then create the /config/registry

registry:
  # file,nacos,eureka,redis,zk,consul,etcd3,sofa
  type: nacos

  nacos:
    application: seata-server
    serverAddr: ali-nacos:8848
    group: SEATA_GROUP
    namespace: 
    cluster: default
    username: nacos
    password: nacos
  
config:
  # file, NACOS, Apollo, ZK, Consul, ETCD3
  type: nacos

  nacos:
    serverAddr: ali-nacos:8848
    namespace: 
    group: SEATA_GROUP
    username: nacos
    password: nacos
Copy the code

Create a config-center directory in the same directory as the YML file to store the scripts and configurations that push seATA configurations to NacOS

Create the config.txt configuration file

transport.type=TCP transport.server=NIO transport.heartbeat=true transport.enableClientBatchSendRequest=false transport.threadFactory.bossThreadPrefix=NettyBoss transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler transport.threadFactory.shareBossWorker=false transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector transport.threadFactory.clientSelectorThreadSize=1 transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread transport.threadFactory.bossThreadSize=1 transport.threadFactory.workerThreadSize=default transport.shutdown.wait=3 service.vgroupMapping.my_test_tx_group=default service.vgroupMapping.product-service_group=default service.vgroupMapping.order-service_group=default service.vgroupMapping.account-service_group=default Service. The default. Grouplist = 127.0.0.1:8091 service. EnableDegrade = false service. DisableGlobalTransaction = false client.rm.asyncCommitBufferLimit=10000 client.rm.lock.retryInterval=10 client.rm.lock.retryTimes=30 client.rm.lock.retryPolicyBranchRollbackOnConflict=true client.rm.reportRetryCount=5 client.rm.tableMetaCheckEnable=false client.rm.sqlParserType=druid client.rm.reportSuccessEnable=false client.rm.sagaBranchRegisterEnable=false client.tm.commitRetryCount=5 client.tm.rollbackRetryCount=5 client.tm.defaultGlobalTransactionTimeout=60000 client.tm.degradeCheck=false client.tm.degradeCheckAllowTimes=10 client.tm.degradeCheckPeriod=2000 store.mode=db store.file.dir=file_store/data store.file.maxBranchSessionSize=16384 store.file.maxGlobalSessionSize=512 store.file.fileWriteBufferCacheSize=16384 store.file.flushDiskMode=async store.file.sessionReloadReadSize=100 store.db.datasource=druid store.db.dbType=mysql store.db.driverClassName=com.mysql.cj.jdbc.Driver store.db.url=jdbc:mysql://ali-mysql:3306/seata_config?useUnicode=true&serverTimezone=GMT%2b8 store.db.user=root store.db.password=codelong store.db.minConn=5 store.db.maxConn=30 store.db.globalTable=global_table store.db.branchTable=branch_table store.db.queryLimit=100 store.db.lockTable=lock_table store.db.maxWait=5000 Store.redis. host=127.0.0.1 store.redis.port=6379 store.redis.maxConn=10 store.redis.minConn=1 store.redis.database=0 store.redis.password=null store.redis.queryLimit=100 server.recovery.committingRetryPeriod=1000 server.recovery.asynCommittingRetryPeriod=1000 server.recovery.rollbackingRetryPeriod=1000 server.recovery.timeoutRetryPeriod=1000 server.maxCommitRetryTimeout=-1 server.maxRollbackRetryTimeout=-1 server.rollbackRetryTimeoutUnlockEnable=false client.undo.dataValidation=true client.undo.logSerialization=jackson client.undo.onlyCareUpdateColumns=true server.undo.logSaveDays=7 server.undo.logDeletePeriod=86400000 client.undo.logTable=undo_log log.exceptionRate=100 transport.serialization=seata transport.compressor=none metrics.enabled=false metrics.registryType=compact metrics.exporterList=prometheus metrics.exporterPrometheusPort=9898Copy the code

Here we upload using sh script (or optionally python script) and create the config-center/nacos/nacos-config.sh file

#! /usr/bin/env bash
# Copyright 1999-2019 Seata.io Group.
#
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
#
# 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.

while getopts ":h:p:g:t:u:w:" opt
do
  case $opt in
  h)
    host=$OPTARG
    ;;
  p)
    port=$OPTARG
    ;;
  g)
    group=$OPTARG
    ;;
  t)
    tenant=$OPTARG
    ;;
  u)
    username=$OPTARG
    ;;
  w)
    password=$OPTARG;; ?).echo " USAGE OPTION: $0 [-h host] [-p port] [-g group] [-t tenant] [-u username] [-w password] "
    exit1;;esac
done

if [[ -z ${host}]].then
    host=localhost
fi
if [[ -z ${port}]].then
    port=8848
fi
if [[ -z ${group}]].then
    group="SEATA_GROUP"
fi
if [[ -z ${tenant}]].then
    tenant=""
fi
if [[ -z ${username}]].then
    username=""
fi
if [[ -z ${password}]].then
    password=""
fi

nacosAddr=$host:$port
contentType="content-type:application/json; charset=UTF-8"

echo "set nacosAddr=$nacosAddr"
echo "set group=$group"

failCount=0
tempLog=$(mktemp -u)
function addConfig() {
  curl -X POST -H "${contentType}" "http://$nacosAddr/nacos/v1/cs/configs? dataId=The $1&group=$group&content=$2&tenant=$tenant&username=$username&password=$password" >"${tempLog}" 2>/dev/null
  if [[ -z $(cat "${tempLog}")]];then
    echo " Please check the cluster status. "
    exit 1
  fi
  if [[ $(cat "${tempLog}") = ~"true"]].then
    echo "Set The $1=$2 successfully "
  else
    echo "Set The $1=$2 failure "
    (( failCount++ ))
  fi
}

count=0
for line in $(cat $(dirname "$PWD")/config.txt | sed s/[[:space:]]//g); do
  (( count++ ))
	key=${line%%=*}
    value=${line#*=}
	addConfig "${key}" "${value}"
done

echo "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ="
echo " Complete initialization parameters,  total-count:$count ,  failure-count:$failCount "
echo "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ="

if [[ ${failCount} -eq 0 ]]; then
	echo " Init nacos config finished, please start seata-server. "
else
	echo " init nacos config fail. "
fi
Copy the code

The directory structure

Start the container

Enter the directory created by the YML file and run the startup command

Create a netgroup
docker network create cloud_alibaba

# run
docker-compose -f docker-compose-cloud-ali.yaml up -d
Copy the code

After the startup is complete, connect to mysql

Go to the config-center/nacos directory and run sh to upload the seATA configuration to nacOS

cdConfig-center /nacos sh./nacos-config.sh -h 127.0.0.1 -p 8848 -g SEATA_GROUP -u nacos -w nacosSh -h nacos address -p nacos port -g Group -u nacos user name -w nacos password
Copy the code

If Init nacOS config finished is displayed, please start seta-server. That’s it.

Then create a database seatA_config and execute the following statement to create three tables of the seATA global transaction

Official SQL: github.com/seata/seata…

-- -------------------------------- The script used when storeMode is 'db' --------------------------------
-- the table to store GlobalSession data
CREATE TABLE IF NOT EXISTS `global_table`
(
    `xid`                       VARCHAR(128) NOT NULL,
    `transaction_id`            BIGINT,
    `status`                    TINYINT      NOT NULL,
    `application_id`            VARCHAR(32),
    `transaction_service_group` VARCHAR(32),
    `transaction_name`          VARCHAR(128),
    `timeout`                   INT,
    `begin_time`                BIGINT,
    `application_data`          VARCHAR(2000),
    `gmt_create`                DATETIME,
    `gmt_modified`              DATETIME,
    PRIMARY KEY (`xid`),
    KEY `idx_gmt_modified_status` (`gmt_modified`, `status`),
    KEY `idx_transaction_id` (`transaction_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8;

-- the table to store BranchSession data
CREATE TABLE IF NOT EXISTS `branch_table`
(
    `branch_id`         BIGINT       NOT NULL,
    `xid`               VARCHAR(128) NOT NULL,
    `transaction_id`    BIGINT,
    `resource_group_id` VARCHAR(32),
    `resource_id`       VARCHAR(256),
    `branch_type`       VARCHAR(8),
    `status`            TINYINT,
    `client_id`         VARCHAR(64),
    `application_data`  VARCHAR(2000),
    `gmt_create`        DATETIME(6),
    `gmt_modified`      DATETIME(6),
    PRIMARY KEY (`branch_id`),
    KEY `idx_xid` (`xid`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8;

-- the table to store lock data
CREATE TABLE IF NOT EXISTS `lock_table`
(
    `row_key`        VARCHAR(128) NOT NULL,
    `xid`            VARCHAR(96),
    `transaction_id` BIGINT,
    `branch_id`      BIGINT       NOT NULL,
    `resource_id`    VARCHAR(256),
    `table_name`     VARCHAR(32),
    `pk`             VARCHAR(36),
    `gmt_create`     DATETIME,
    `gmt_modified`   DATETIME,
    PRIMARY KEY (`row_key`),
    KEY `idx_branch_id` (`branch_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8;
Copy the code

Sometimes the Seata container will not refresh, you can manually restart the Seata container

docker restart ali-seata
Copy the code

Service validation

The name of the address The user name password
nacos http://127.0.0.1:8848/nacos nacos nacos
sentinel http://127.0.0.1:8858/ sentinel sentinel
seata 127.0.0.1:8091
mysql 127.0.0.1:3306 nacos nacos

The password of user root of mysql is codelong

nacos

The browser input: http://127.0.0.1:8848/nacos

The username and password are both nacos

Nacos is successfully started.

sentinel

Enter http://127.0.0.1:8858/ in the browser

The username and password are both sentinel

Sentinel is successfully started.

seata

Enter the NACOS console to view the service list. If seATa-Server is displayed, seATA is successfully registered.

mysql

The username and password are both nacos

You can also log in as user root

To this basic environment has been built, the specific configuration we will explain one by one in the integration.

The attachment

I have uploaded all the files used in this article to GitHub, so you can download them directly.

GitHub link: github.com/lovemianhua…