Installing seata server based on docker

Posted by dclamp on Thu, 27 Jan 2022 17:41:39 +0100

1. Create the required table on the Server side

SQL official address: https://github.com/seata/seata/blob/1.2.0/script/server/db/mysql.sql , store the tables in this link in mysql (it is recommended to create a new database).

-- -------------------------------- The script used when storeMode is 'db' --------------------------------
-- the table to store GlobalSession data
CREATE DATABASE IF NOT EXISTS `seata` DEFAULT CHARSET utf8; 
DROP TABLE IF EXISTS `global_table`;
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
DROP TABLE IF EXISTS `branch_table`;
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
DROP TABLE IF EXISTS `lock_table`;
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;

2. Configuration file

The user-defined configuration file needs to be implemented by mounting the file, and the user-defined configuration file on the host computer is called registry Conf and file Conf mount to the corresponding directory in the container.

registry.conf and file Conf these two files can be found on the official website GitHub https://github.com/seata/seata/tree/1.2.0/script/client/conf

I will register Conf and file Conf is placed in the directory of virtual machine / myconfig / Seata server /.
 

The following is registry conf

There are two tags in the configuration file: registry and config.

The registry uses nacos, so all but nacos in the registry can be deleted. For the convenience of changing other types in the future, it is not deleted.

config(seata configuration information), using file type configuration, can also use nacos. The following uses file. A brief introduction to using nacos is at the end of the article.
 

# Note: added in the text#No. is configured to be modified
 
registry {
  # file ,nacos ,eureka,redis,zk,consul,etcd3,sofa
  type = "nacos"
 
  # 192.168.1.27 virtual machine IP, user name and password nacos adopt the default, so they are not configured below
  # group, namespace, etc. can be filled in according to the actual situation of individuals
  nacos {
    application = "seata-server"
    serverAddr = "192.168.1.27:8848"
    #group = "SEATA_GROUP"
    #namespace = ""
    cluster = "default"
    username = ""
    password = ""
  }
  eureka {
    serviceUrl = "http://localhost:8761/eureka"
    application = "default"
    weight = "1"
  }
  redis {
    serverAddr = "localhost:6379"
    db = 0
    password = ""
    cluster = "default"
    timeout = 0
  }
  zk {
    cluster = "default"
    serverAddr = "127.0.0.1:2181"
    sessionTimeout = 6000
    connectTimeout = 2000
    username = ""
    password = ""
  }
  consul {
    cluster = "default"
    serverAddr = "127.0.0.1:8500"
  }
  etcd3 {
    cluster = "default"
    serverAddr = "http://localhost:2379"
  }
  sofa {
    serverAddr = "127.0.0.1:9603"
    application = "default"
    region = "DEFAULT_ZONE"
    datacenter = "DefaultDataCenter"
    cluster = "default"
    group = "SEATA_GROUP"
    addressWaitTime = "3000"
  }
  file {
    name = "file.conf"
  }
}
 
config {
  # file,nacos ,apollo,zk,consul,etcd3
  type = "file" # file or nacos can be used here, but if nacos is used, the configuration information needs to be pushed to nacos (if nacos is used, there is a brief introduction at the end of the article, but it is not tested)
 
  nacos {
    serverAddr = "127.0.0.1:8848"
    namespace = ""
    group = "SEATA_GROUP"
    username = ""
    password = ""
  }
  consul {
    serverAddr = "127.0.0.1:8500"
  }
  apollo {
    appId = "seata-server"
    apolloMeta = "http://192.168.1.204:8801"
    namespace = "application"
  }
  zk {
    serverAddr = "127.0.0.1:2181"
    sessionTimeout = 6000
    connectTimeout = 2000
    username = ""
    password = ""
  }
  etcd3 {
    serverAddr = "http://localhost:2379"
  }
  file {
    name = "file.conf" # As long as the local registry Conf and file Conf does not need to be modified at the same level
  }
}

The following is file Conf (configuration is required only if the config configured in registry is file)

This file configures some basic configurations of seata, as well as transaction storage configuration.

The storage mode includes file and db. Since the official website does not mark the configuration description of MySQL in this file, there are more storage mode configurations in the following files than in the official. The following uses db mode to write the transaction log into mysql.


# Note: it exists below#The configuration places are those that need to be modified
transport {
  # tcp udt unix-domain-socket
  type = "TCP"
  #NIO NATIVE
  server = "NIO"
  #enable heartbeat
  heartbeat = true
  # the client batch send request enable
  enableClientBatchSendRequest = true
  #thread factory for netty
  threadFactory {
    bossThreadPrefix = "NettyBoss"
    workerThreadPrefix = "NettyServerNIOWorker"
    serverExecutorThread-prefix = "NettyServerBizHandler"
    shareBossWorker = false
    clientSelectorThreadPrefix = "NettyClientSelector"
    clientSelectorThreadSize = 1
    clientWorkerThreadPrefix = "NettyClientWorkerThread"
    # netty boss thread size,will not be used for UDT
    bossThreadSize = 1
    #auto default pin or 8
    workerThreadSize = "default"
  }
  shutdown {
    # when destroy server, wait seconds
    wait = 3
  }
  serialization = "seata"
  compressor = "none"
}
service {
  #transaction service group mapping
  vgroupMapping.my_test_tx_group = "default"
  #only support when registry.type=file, please don't set multiple addresses
  default.grouplist = "192.168.1.27:8091"  # 192.168.1.27 is the IP address of the virtual machine
  #degrade, current not support
  enableDegrade = false
  #disable seata
  disableGlobalTransaction = false
}
 
store {
  ## store mode: file,db,redis
  mode = "db" # The storage mode is db mode
 
  ## database store property
  db {
    ## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp)/HikariDataSource(hikari) etc.
    datasource = "druid"
    ## mysql/oracle/postgresql/h2/oceanbase etc.
    dbType = "mysql"
    driverClassName = "com.mysql.jdbc.Driver"
# Database information configuration, transaction log storage mysql address
    url = "jdbc:mysql://192.168.1.27:13306/seata"
    user = "root"
    password = "root"
    minConn = 5
    maxConn = 30
    globalTable = "global_table"
    branchTable = "branch_table"
    lockTable = "lock_table"
    queryLimit = 100
    maxWait = 5000
  }
 
}

3. Start seata server

[root@worker1 docker-yml]# cat seata.yml
version: '3'
services:
  seata:
    image: seataio/seata-server:latest
    container_name: seata-server
    environment:
      SEATA_IP: 192.168.40.199
      SEATA_PORT: 8091
    volumes:
      - /docker/seata-server/config/registry.conf:/seata-server/resources/registry.conf
      - /docker/seata-server/config/file.conf:/seata-server/resources/file.conf
    ports:
      - 8091:8091

 

4. View registration information

Then open nacos to see the registration information of Seata server

===============Below is registry config in conf adopts the method of nacos==================
The configuration information can be easily modified by using nacos. Using nacos is actually to synchronize all the configuration information in the file into nacos, and then seata reads the configuration information into seata through nacos configuration. In the future, you only need to modify the content of the nacos configuration center.

Official address: https://github.com/seata/seata/tree/develop/script/config-center

Use the command to set config Txt to nacos, and then in registry Config in conf is configured as nacos to pull.

To use this method, you need to pull the source code (nacos file [there is a nacos config. Sh method in this file] + config.txt), or manually add config.txt Txt to nacos.

Note: Registry The group and namespace of nacos configured by config in conf should be consistent with the actual situation.

 

1. First of all, let's download seata's project locally through git; seata github address

 


2. Modify config Txt configuration file

Find the two files in the figure above and modify config Txt to make it meet your current needs

Except for the following parameters that need to be modified now, other parameters can be left unchanged temporarily or modified later:

 

# Modify the storage mode to database storage
store.mode=db
# The specified database is mysql, and other database types can be modified according to their own conditions
store.db.dbType=mysql
# Specify the engine. Mysql8 is com mysql. jdbc. Driver, mysql8 is com mysql. cj. jdbc. Driver
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=jdbc:mysql://{ip}:3306/{db_name}?useUnicode=true
store.db.user={db_user}
store.db.password={db_password}

Note: most small partners only need to modify the above parameters, and other parameters can not be changed temporarily
Entire config Txt file configuration has so many parameters:

 

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.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.degradeCheck=false
client.tm.degradeCheckAllowTimes=10
client.tm.degradeCheckPeriod=2000
store.mode=file
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://127.0.0.1:3306/seata?useUnicode=true
store.db.user=username
store.db.password=password
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
client.log.exceptionRate=100
transport.serialization=seata
transport.compressor=none
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898

3. Change the modified config Txt configuration added to nacos configuration center

Execute Nacos config. Through ssh command SH file

sh nacos-config.sh -h {nacos Service host} -u {nacos user name} -w {nacos password}

 

Analyze the meaning of parameters in the above command:
[-h host] [-p port] [-g group] [-t tenant] [-u username] [-w password]

According to the nacos service, please watch the previous podcast
Screenshot of successful configuration upload:

 



 

 

 

 

 

Topics: Docker