The background,

The registry and configuration center are implemented using NACOS. The default file mode does not allow for distributed deployment. Nocos and mysql are assumed to be deployed on the machine by default.

Deploy the machine

The machine IP Deployment of resources The machine type
192.168.56.101 seata server The virtual machine
192.168.56.102 seata server The virtual machine
192.168.56.103 seata server The virtual machine
10.1.206.169 nacos / mysql The host machine

3. Deployment steps

Create a namespace on seata

To create seata’s namespace on NACOS, remember the id of the namespace, which will be needed later.

2. Download the corresponding version of SEATA

Download unzip:

#downloadWget HTTP: / / https://github.com/seata/seata/releases/download/v1.4.2/seata-server-1.4.2.zip#Unpack theUnzip seata - server - 1.4.2. Zip#View the SEata directory structure├─ ├─ uninhibited-press, uninhibited-press, uninhibited-press, uninhibited-press, uninhibited-press, uninhibited-press, uninhibited-press, uninhibited-press, uninhibited-press, uninhibited-pressCopy the code

3. Single startup

This is a demonstration of seata Server configured on the machine 192.168.56.101.

1. Modify the SEATA configuration file

Configuration file location: $seatA_server_HOME /conf/registry

$seatA_server_HOME This is the unzip directory of seata Server.

1. Change the registry to NACOS

Vi conf/registry.conf registry {# file, nacOS, Eureka, redis, Zk, Consul, ETCD3, SOFA type = "nacos" nacos {# Service name registered on nacOS ServerAddr = "10.1.168.152:8847" group = "SEATA_GROUP" Namespace created for previous step = "774a5264-662F-4e27-A885-8d0783e5f26a" Cluster = "default" # username = "nacos" password = "nacos"}Copy the code

2. Change the configuration center to NACOS

Conf config {# file, nacos, Apollo, zk, consul, etCD3 type = "nacos" nacos {serverAddr = "10.1.168.152:8848" Namespace = "774a5264-662F-4e27-A885-8d0783e5f26a" group = "SEATA_GROUP" username = "nacos" password DataId = "seataserver.properties"}}Copy the code

2. Import configuration to nacOS

The data storage mode can be DB or REDis. To use db, you need to create four tables global_table, BRANch_TABLE, LOCK_TABLE, and distributed_lock

1. Set the storage mode to DB and create a table

The construction sentence is 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(128),
    `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;

CREATE TABLE IF NOT EXISTS `distributed_lock`
(
    `lock_key`       CHAR(20) NOT NULL,
    `lock_value`     VARCHAR(20) NOT NULL,
    `expire`         BIGINT.primary key (`lock_key`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('AsyncCommitting'.' '.0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryCommitting'.' '.0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryRollbacking'.' '.0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck'.' '.0);
Copy the code

2. Simplified configuration

Complete configuration: github.com/seata/seata…

Note:

  • The storage mode specified here isdbTherefore, the database connection information must be configured and the specified database must existThe previous stepTable created.
  • Multiple groups are configured and multiple clusters are specified

# This is a place where grouping of things can be configured for multiple, multiple configurations for multiple lines
service.vgroupMapping.my_test_tx_group=default
service.vgroupMapping.product-service=hangzhou
service.vgroupMapping.order-service=hangzhou
Set the storage mode to DB
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=JDBC: mysql: / / 10.1.168.152:3306 / seata? useUnicode=true&rewriteBatchedStatements=true
store.db.user=root
store.db.password=root
Copy the code

3. Complete configuration

transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.enableClientBatchSendRequest=true
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.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.tableMetaCheckerInterval=60000
client.rm.sqlParserType=druid
client.rm.reportSuccessEnable=false
client.rm.sagaBranchRegisterEnable=false
client.rm.tccActionInterceptorOrder=- 2147482648.
client.tm.commitRetryCount=5
client.tm.rollbackRetryCount=5
client.tm.defaultGlobalTransactionTimeout=60000
client.tm.degradeCheck=false
client.tm.degradeCheckAllowTimes=10
client.tm.degradeCheckPeriod=2000
client.tm.interceptorOrder=- 2147482648.
store.mode=db
store.lock.mode=file
store.session.mode=file
store.publicKey=
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.jdbc.Driver
store.db.url=JDBC: mysql: / / 10.1.168.152: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.distributedLockTable=distributed_lock
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
store.redis.mode=single
store.redis.single.host=127.0.0.1
store.redis.single.port=6379
store.redis.sentinel.masterName=
store.redis.sentinel.sentinelHosts=
store.redis.maxConn=10
store.redis.minConn=1
store.redis.maxTotal=100
store.redis.database=0
store.redis.password=
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
server.distributedLockExpireTime=10000
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
client.undo.compress.enable=true
client.undo.compress.type=zip
client.undo.compress.threshold=64k
log.exceptionRate=100
transport.serialization=seata
transport.compressor=none
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898
Copy the code

4. Import to NACOS

3. Start seata Server

Sh -h 192.168.56.101 -p 8091 -n 1./seata-server.sh -h 192.168.56.101 -p 8091 -n 1Copy the code
-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 of different ranges to avoid conflicts. -e: For the multi-environment configuration, see http://seata.io/en-us/docs/ops/multi-configuration-isolation.htmlCopy the code

4. View the Seata Server list

4. Start the Seata Server cluster

1. Copy the Seata Server configuration to 3 machines

Copy the seATA configuration from 192.168.56.101 to 192.168.56.102 and 192.168.56.103 and start it.

#1. Copy the SEATA configuration for 192.168.56.101 to 102 and 103SCP - r/home/appuser/opt/seata/[email protected]: / home/appuser/opt/SCP - r/home/appuser/opt/seata / [email protected]: / home/appuser/opt /Copy the code

After the above two steps, the SEATA configuration on machines 101, 102, and 103 is identical.

Start seata Server on the three machines in sequence

#Switch to 192.168.56.101CD/home/appuser/opt/seata/seata - server - 1.4.2 / bin/seata - server. Sh 192.168.56.101 - p - 8091 - h n 1
#Switch to 192.168.56.102CD/home/appuser/opt/seata/seata - server - 1.4.2 / bin/seata - server. Sh 192.168.56.102 - p - 8091 - h n 2
#Switch to 192.168.56.103CD/home/appuser/opt/seata/seata - server - 1.4.2 / bin/seata - server. Sh 192.168.56.103 - p - 8091 - h n 3Copy the code

2. View the Seata Server list

5. Enable port 8091 on the VM

#Firewall Permits port 8091
firewall-cmd --zone=public --add-port=8091/tcp --permanent
#Reload the firewall configuration
firewall-cmd --reload
Copy the code

4. Attribute configuration

1. Core focus attributes

Server configuration end explain Client Configuration explain
registry.type Registry Type registry.type Registry Type
config.type Configuration Center Type config.type Configuration Center Type
#store.mode=dbThe following configuration is required service.vgroupMapping.my_test_tx_group Grouping of things, the corresponding value is cluster
store.db.driverClassName Drive class service.default.grouplist The TC service list is used only when the registry is file
store.db.url Database connection URL service.disableGlobalTransaction Whether to enable global transactions
store.db.user Database user name client.rm.lock.retryInterval The default retry interval for checking or occupying a global lock is 10 milliseconds
store.db.password Database password client.rm.lock.retryTimes The default value is 30
#store.mode=redisThe following configuration is required
store.redis.host Redis address
store.redis.port Redis port
store.redis.database Redis database, default is 0
store.redis.password Redis password, not left blank

2. Configure the server

1. Number of days to save undo logs

# undo Retention days. The default is 7
server.undo.logSaveDays=7
Copy the code

2. Transaction session information storage mode

# transaction session information storage, file a local file (do not support the HA), a db database | redis support (HA)
store.mode
	=file
		Attributes to be configured
			Store.file. dir(file mode file storage folder name, default sessionStore)
  =db
  	Attributes to be configured
  		Store.db. datasource(db mode datasource type	DBCP, Druid, Hikari; No default value and must be specified.
  		Store.db. dbType(DB mode Indicates the database type	Mysql, Oracle, DB2, SQLServer, Sybaee, H2, SQLite, Access, PostgresQL, OceanBase; No default value and must be specified.
  		Store.db. driverClassName(Db mode database driver, must be specified)
  		Store.db. url(DB mode Specifies the database URL. If mysql is used as the data source, it is recommended to add rewriteBatchedStatements to the connection parameter=true)
  		Store.db. user(db mode database account, must be specified)
  		Store.db. password(Db mode database account password, which must be specified)	
  		store.db.minConn	Db Mode The default number of database connections is 1
      store.db.maxConn	Db mode The maximum number of database connections is 20 by default
      store.db.maxWait	In DB mode, the maximum waiting time for obtaining a connection is 5000 milliseconds by default
      store.db.globalTable	The default global transaction table name in DB mode is global_table
      store.db.branchTable	Db mode Branch_table by default
      store.db.lockTable	Db mode Global lock table name Default lock_table
      store.db.queryLimit	The default maximum number of global transactions queried in DB mode is 100
  =redis
  	Attributes to be configured
  		store.redis.host	The default REDis IP address is 127.0.0.1
      store.redis.port	The redis mode port defaults to 6379
      store.redis.maxConn	The default maximum number of connections in Redis mode is 10
      store.redis.minConn	The default minimum number of connections in Redis mode is 1
      store.redis.database	The redis mode default library defaults to 0
      store.redis.password	Redis mode password (no blank) Default null
      store.redis.queryLimit	In Redis mode, the default value is 100
			
Copy the code

3. Metric configuration

metrics.enabled	Parameter Description Default Value False Indicates whether to enable Metrics. In the false state, all Metrics related components are not initialized to minimize performance loss
metrics.registryType	Metric registry Type Metric registry type used by Metrics. The default is the built-in Compact implementation, in which the Meter uses limited memory counts and is high enough to meet most scenarios. Currently only one metric registry implementation can be set
metrics.exporterList	Measurement Data output list The default value is Prometheus. Multiple output devices, for example, "Prometheus, JMX", are separated by commas (,). Currently, only output devices that interconnect with Prometheus are implemented
metrics.exporterPrometheusPort	Prometheus output Client port 9898 by default
Copy the code

3. Client configuration

1. Data source agent

seata.enabled	Whether to enable spring-boot automatic assembly true, false,(SSBS) Private configuration, default true
seata.enableAutoDataSourceProxy=True Indicates whether to enable the automatic proxy for the data source. True, false, seta-spring-boot-starter (SSBS) Specifies whether to enable the automatic proxy for the data source by default.
seata.useJdkProxy=False Indicates whether to use the JDK proxy as the automatic proxy for the data source. True, false,(SSBS) Specifies whether to use CGLIB as the automatic proxy for the data source
Copy the code

2. Configuration of grouping of things

service.vgroupMapping.my_test_tx_group	The transaction group my_test_tx_group is a group, and the configuration item value is the TC cluster name
service.default.grouplist	The TC service list is used only when the registry is file
Copy the code

3. Distributed transaction degrade switch

client.tm.degradeCheck	The default degrade switch is false. The service side automatically degrades a non-seATA transaction based on the number of consecutive errors
Copy the code

4. Verify or occupy the global lock and retry

client.rm.lock.retryInterval	The default retry interval for checking or occupying a global lock is 10 milliseconds
client.rm.lock.retryTimes	The default value is 30
Copy the code

5. Reporting times of global results in phase I

client.tm.commitRetryCount	Phase 1 Global submission Result The number of TC retries is 1 by default. It is recommended that the number of TC retries be greater than 1
client.tm.rollbackRetryCount	One-phase global rollback result The number of retries reported to the TC is 1 by default. It is recommended that the number be greater than 1
Copy the code

5. Reference documents

1. Seata Server download

2. Seata Novice Deployment Guide (Version 1.4.0)

3. Seata high availability deployment

4. Seata configuration properties