seata环境的安装

1.给每个需要进行分布式事务控制的服务的数据库增加一个undo_log表

-- 注意此处0.3.0+ 增加唯一索引 ux_undo_log
CREATE TABLE `undo_log` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `branch_id` bigint(20) NOT NULL,
  `xid` varchar(100) NOT NULL,
  `context` varchar(128) NOT NULL,
  `rollback_info` longblob NOT NULL,
  `log_status` int(11) NOT NULL,
  `log_created` datetime NOT NULL,
  `log_modified` datetime NOT NULL,
  `ext` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

2.linux虚拟机普通的部署

# seata-server部署文档

1.上传,将`seata-server-1.3.0.zip`上传到`/usr/local/software`目录下

2.解压文件到指定目录

```shell
unzip /usr/local/software/seata-server-1.3.0.zip -d /usr/local

3.修改日志配置文件,否则启动控制台乱码(如果是window的情况需要修改如下配置)

vi /usr/local/seata/conf/logback.xml

原配置如下:

<property name="CONSOLE_LOG_PATTERN" value="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx"/>

修改成如下格式:

<property name="CONSOLE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %5p --- %[%15.15t] %-40.40logger{39} : %m%n%wEx"/>

此问题是因为开发者为seata1.3.0添加字体颜色,而在window中的shell脚本内不显示发生的乱码错误

4.修改registry.config文件

vi /usr/local/seata/conf/registry.conf

修改内容如下:[注意需要把下面nacos的IP地址修改成实际地址]

registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "nacos"

  nacos {
    application = "seata-server"
    serverAddr = "nacos的IP地址:8848"
    group = "SEATA_GROUP"
    namespace = ""
    cluster = "default"
    username = ""
    password = ""
  }
}

config {
  # file、nacos 、apollo、zk、consul、etcd3
  type = "nacos"
  nacos {
    serverAddr = "nacos的IP地址:8848"
    namespace = ""
    group = "SEATA_GROUP"
    username = ""
    password = ""
  }
}

5.启动seata-server

nohup /usr/local/seata/bin/seata-server.sh -h 目前所在服务器ip地址 -p 7000 >log.out 2>1 &
1. jps看到server seata启动成功
2. 在nacos看到seata之后标识成功注册到naocs

最后就是对每个使用分布式事务的服务的配置

	com.alibaba.cloud
	spring-cloud-starter-alibaba-seata
	2.2.2.RELEASE
	
		
            io.seata
			seata-spring-boot-starter
		
	


	io.seata
	seata-spring-boot-starter
	1.3.0


yml

seata:
  tx-service-group: seckill-service-group
  registry:
    type: nacos
    nacos:
      server-addr: ${spring.cloud.nacos.config.server-addr}
      group: SEATA_GROUP
      application: seata-server
  service:
    vgroup-mapping:
      seckill-service-group: default



两个group名字要一样seckill-service-group,最好根据服务命名

最后就是在分布式事务的入口加上@GlobalTransactional就可以完成整个配置了

你可能感兴趣的:(分布式,springcloud)