[Reprint] SpringCloud Alibaba micro-service real nine - Seata containerized

SpringCloud Alibaba micro-service real nine - Seata containerized

By the first two articles we used  Seata as a distributed transaction components, and use  Nacos as a  Seata registration center configuration, this article we will  Seata deploy the vessel  Docker on. Of course, if everyone  Docker is not very familiar with it or use it only  Docker two articles of interest before I can look for everyone to prepare.

Seata container of

In use  Docker , when we should deploy the services of an external configuration file, so easy subsequent modification, after the modification is completed by -v command to mount the file into the container. Next we go step by step process to achieve the container.

  • Start a temporary container of Seata.
    docker run --rm --name seata-server -d -p 8091:8091 seataio/seata-server:latest
    With the  --rm parameters, such containers will be automatically deleted after stop the container, saving a lot of time.

  • Export the configuration file to the host
    vessel configuration file located  /seata-server/resources under, we export it in the specified directory on the host
    docker cp a67c272193c4:/seata-server/resources /app/cloud/seata/conf

  • Modify the configuration file  registry.conf
    according to the article, said the use of  Nacos a registered center only need to modify the configuration  registry.conf file, the result of the modification is completed as follows

registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "nacos"
  nacos {
    serverAddr = "10.0.10.48:8848"
    namespace = ""
    cluster = "default"
  }
}
config {
  # file、nacos 、apollo、zk、consul、etcd3
  type = "nacos"
  nacos {
    serverAddr = "10.0.10.48:8848"
    namespace = ""
  }
}
  • Will  Seata push the configuration to  Nacos
    Seata the container and not the  Nacos configuration files into them, we also need to download  Seata-Server the installation package, and then push it to  Nacos. For details, please refer to the article, not repeat them here.

  • Stop the container
    docker stop a67c272193c4
    due before with the  --rm parameters, so the container will be automatically deleted.

  • Restart container

 

docker run --name  seata-server  \
		-d -p 8091:8091 \
		-e SEATA_CONFIG_NAME=file:/root/seata-config/registry \  -e SEATA_IP=172.31.0.207 \  -v /app/cloud/seata/conf:/root/seata-config \  -v /app/cloud/seata/logs:/root/logs \  seataio/seata-server 

Specified container registered IP, the host will mount modified configuration file to the vessel.

  • The client transformation
    only need to  registry.conf file in the micro services  resources of buttons, the article has completed the transformation.

  • Test
    to start up service  account-service, product-service, order-service, observed Seata log
    image.png

    706 x 1581702 x 381

     

Three services have been connected to the Seata. Perform a test to see if the business filed with properly rolled back.

Seata db mode

file Mode for the stand-alone mode, the global memory write transaction session information and persistent local file  root.data, higher performance;
db mode availability mode, global transaction session information  db sharing, the respective performance badly.
Taking into account  Seata the expansion and availability, we have this section to modify the configuration so that  Seata support  db mode

  • Establish a database
    to establish a database  seata_config, and from the  https://github.com/seata/seata/blob/develop/script/server/db/mysql.sql download build table statements into the database.
    image.png

    307 x 226

     

  • Modified  store.mode adjusted db
    in nacos store.mode profile will be adjusted to the DATA ID db
    image.png

    706 x 2381736 x 586

    This environment variable can also  STORE_MODE=db specify

     

  • Modify the database connection
    in  nacos the modification  store.db of the configuration

store.db.url=jdbc:mysql://xxxxxx:3306/seata_config?useUnicode=true
store.db.user=root
store.db.password=xxxxxx
  • Restart container
docker run  --name  seata-server \
    -d -p 8091:8091 \
    -e SEATA_CONFIG_NAME=file:/root/seata-config/registry \  -e SEATA_IP=172.31.0.207 \  -v /app/cloud/seata/conf/resources:/root/seata-config \  -v /app/cloud/seata/logs:/root/logs/seata \  seataio/seata-server 

 

After starting the container service to restart the micro to see if properly registered, and perform tests to see if the business filed with the rollback normal.
image.png

738 x 1181704 x 272

 

Docker-Compose deployment

Watch this series of articles the students should know that our first article with the  docker-compose deployment of MySQL, nacos, sentinel three components, before we complete this section  nacos-base.yml, seata will also be integrated into it. With base in the previous section 2 of this operation it should be very simple, done after their completion yml file as follows:

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: always   seata:  image: seataio/seata-server:latest  container_name: seata  ports:  - "8091:8091"  environment:  - SEATA_CONFIG_NAME=file:/root/seata-config/registry  - SEATA_IP=10.0.10.48  volumes:  - /app/cloud/seata/conf:/root/seata-config  - /app/cloud/seata/logs:/root/logs  restart: always

 

We see this yml file uploaded to the server, start-Compose Docker  docker-compose -f nacos-base.yml up, start the client service and execution of business test observations.

Seata environment variables

seata-server environment supports the following variables:

  • SEATA_IP

Optionally, the specified seata-server-initiated IP, IP is used when the registration to the registration centers, and other such eureka

  • SEATA_PORT

Optionally, specify the start seata-server port, default to 8091

  • STORE_MODE

Optionally, specify a transaction log storage seata-server, support for db and file, default file

  • SERVER_NODE

Alternatively, seata-server specifies the node ID, for example, 2, 3 ..., the default is 1

  • SEATA_ENV

Optionally, specify seata-server operating environment, such as dev, test, etc., would use such a configuration registry-dev.conf when the service starts

  • SEATA_CONFIG_NAME

Optionally, specify the configuration file location, such as file: / root / registry, as a configuration file will be loaded /root/registry.conf

Well, ladies and friends, the contents of this issue on all over it, if this article help you, then please scan the following QR code to add a concern. "Forward" plus "look", to form good habits!

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/12497780.html