1.简介

本篇文章将记录开发环境Seata-Server的搭建步骤,在后期部署环境变更可以快速回忆起搭建方法,同事通过阅读搭建步骤后,有优化的建议可以要求我改正。

2.搭建步骤

  1. - seata数据库及表的创建
  2. - nacos配置文件的同步
  3. - seata-server的配置和启动

2.1seata数据库及表的创建

  1. 创建seata数据库 (10.11.0.215数据库)

    1. CREATE DATABASE seata;
  2. 创建相关表 ``sql -- the table to store GlobalSession data CREATE TABLE IF NOT EXISTSglobal_table(xidVARCHAR(128) NOT NULL,transaction_idBIGINT,statusTINYINT NOT NULL,application_idVARCHAR(32),transaction_service_groupVARCHAR(32),transaction_nameVARCHAR(128),timeoutINT,begin_timeBIGINT,application_dataVARCHAR(2000),gmt_createDATETIME,gmt_modifiedDATETIME, PRIMARY KEY (xid), KEYidx_gmt_modified_status(gmt_modified,status), KEYidx_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;

  1. <a name="CSiMK"></a>
  2. ## 2.2nacos配置文件的同步
  3. 1. config.txt修改部分位置

… service.vgroupMapping.yurun_dev_tx_group=default … store.mode=db … store.db.url=jdbc:mysql://10.11.0.215:3306/seata?useUnicode=true&rewriteBatchedStatements=true store.db.user=root store.db.password=123456 …

  1. 2. 运行脚本-同步到Nacos
  2. ```shell
  3. sh nacos-config.sh -h 10.11.0.220 -p 8855 -g SEATA_GROUP -t b8e5a017-9dab-4fea-a323-c1a7b41774fc -u dev -w dev

注:这里会出现2个同步失败的参数,不影响我们的使用,不用关心

2.3seata-server的配置和启动

  1. 下载,解压
  2. 配置seata-server的注册和配置中心(conf/registry.conf) ``` registry {

    file 、nacos 、eureka、redis、zk、consul、etcd3、sofa

    type = “nacos” loadBalance = “RandomLoadBalance” loadBalanceVirtualNodes = 10

    nacos { application = “seata-server” serverAddr = “10.11.0.220:8855” group = “SEATA_GROUP” namespace = “1533a078-f017-4f3a-b834-63e475ea7a40” cluster = “default” username = “dev” password = “dev” } ………. }

config {

file、nacos 、apollo、zk、consul、etcd3

type = “nacos”

nacos { serverAddr = “10.11.0.220:8855” namespace = “b8e5a017-9dab-4fea-a323-c1a7b41774fc” group = “SEATA_GROUP” username = “appconnect” password = “appconnect” } ……… }

  1. 3.seata的解压目录下创建一个logs目录(可选,放置gc日志用)<br />![image.png](https://cdn.nlark.com/yuque/0/2021/png/1609516/1614824568814-79749bb4-2054-4fca-bac1-a2896f6d0b76.png#align=left&display=inline&height=45&margin=%5Bobject%20Object%5D&name=image.png&originHeight=45&originWidth=421&size=15688&status=done&style=none&width=421)<br />4.编写一个使用nohup启动的脚本并启动
  2. ```shell
  3. #!/bin/bash
  4. nohup /home/software/seata-server-1.4.1/bin/seata-server.sh >log.out 2>&1 &