The SEata-server cluster is set up
introduce
Seata has three roles: TC, TM, and RM. TC (Server) is deployed as an independent Server, and TM and RM (Client) are integrated by service systems. High availability of SEATA-Server depends on the registry, configuration center, and database.
There are three storage modes on the Server side (Store. mode) : File, DB, and Redis (Raft and mongodb will be introduced later). The file mode does not need to be changed and can be directly started.
Note: The file mode is the single-machine mode, and the global transaction session information is read and written in the memory and the local file root.data is persisted, which provides high performance.
Db mode is high availability mode, global transaction session information is shared through DB, corresponding performance is poor;
Redis mode SeATA-Server 1.3 or later supports high performance and risks of transaction information loss. Therefore, you need to configure redis persistence in advance.
The following mainly introduces the construction and implementation of cluster high availability based on NACOS registry and mysql database.
Principle and architecture diagrams
The implementation of high availability of SEATa-Server, mainly based on DB and registry, obtains global transactions through DB and realizes multi-instance transaction sharing. Seata-server multi-instance dynamic management is implemented through a registry. The schematic diagram is as follows:
Installation steps
Installation environment: centos7 and JDK8
-
Downloading the Installation package
Click to download the latest seata- Server installation package, currently seata 1.4.2
-
Unpack the installation
Decompress the installation package:
Create seata-server database, name: seata, database script: mysql
Then go to the conf directory of seata-server and modify the configuration files file.conf and registry.
Conf file: Change the storage mode of seata-server to DB mode, and modify the database connection information of DB.
Modify the registry. Conf file: Modify both the registry and configuration center of seata-Server using nacOS as shown below
The registry
Configuration center
To initialize the configuration to nacos, create a new config.txt file with the following contents:
service.vgroupMapping.sharding_jdbc_group=default
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=JDBC: mysql: / / 127.0.0.1:3306 / seata? useUnicode=true&rewriteBatchedStatements=true
store.db.user=root
store.db.password=root
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
Copy the code
Download the execution script: nacos-config.sh, then run the following command: nacos-config.sh
sh nacos-config.sh -h localhost -p 8848 -g SEATA_GROUP -t 5a3c7d6c-f497-4d68-a71a-2e5e3340b3ca -u username -w password
Copy the code
After successful execution, the configuration in config. TXT will be pushed to nacOS for management. The effect is as follows:
For other machines, you only need to repeat the above steps to install SEata-Server.
- Start the seata – server
Sh -h IP -p 8091 -m db -n 1 To start the master node
Run the sh seata-server.sh -h IP -p 8091 -m db -n 2 command to start the slave node
-h: IP registered with the registry -p: Server RPC listening port -m: global transaction session information storage mode, file, DB, redis, preferentially read startup parameters (Redis is supported by Seata-Server 1.3 and later versions) -n: Server node: If there are multiple Servers, separate the nodes to generate Transactionids in different ranges to avoid conflictsCopy the code
Start-up success
Check out the registration on NACOS
The seata-server cluster has been set up successfully.
SpringCloud integrates with the Seata cluster
This is similar to the configuration of a single SeATA integrated SpringCloud, but I won’t go into details. The main point is how SpringCloud connects to the seATA cluster configuration:
seata:
enabled: true # Seata switch
application-id: ${spring.application.name}
tx-service-group: sharding_jdbc_group
enable-auto-data-source-proxy: false
service:
vgroup-mapping:
sharding_jdbc_group: 'seata-cluster' Seata - Cluster name set when server is registered with NACOS.
registry:
type: nacos
nacos:
application: seata-server # seta-server instance name
server-addr: ${spring.cloud.nacos.discovery.server-addr}
namespace: 777a9882-1ec7-45bb-9a68-a54b9dee89ac
group: SEATA_GROUP
transport:
compressor: gzip
Copy the code