seata集群部署-单机版和集群版

一、 单机版

a) 安装jdk8

tar -zxvf jdk-8u261-linux-x64.tar.gz && \
echo "export JAVA_HOME=/home/csii/jdk1.8.0_261
export PATH=\$JAVA_HOME/bin:\$PATH
export CLASSPATH=.\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar" >> ~/.bash_profile && \
source ~/.bash_profile && \
java -version

b) 安装nacos:

从seata官网 https://github.com/seata/seata/releases 下载安装包,最新正式版:seata-server-1.4.0.tar.gz,直接解压

tar -zxf seata-server-1.4.0.tar.gz

c) 修改registry.conf文件:

cd seata/conf

vi registry.conf

registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "nacos"  # 这里修改为nacos
 
  nacos {
    serverAddr = "192.168.0.201:8848"   # 这里填你的nacos地址
    namespace = ""
cluster = "default"
username = "nacos"
password = "nacos"
  }
}
 
config {
  # file、nacos 、apollo、zk、consul、etcd3
  type = "file"
 
  file {
    name = "file.conf"
  }
}

d) 启动

cd ../bin
nohup sh seata-server.sh -p 8091 -h 192.168.100.206 -m file &> seata.log &

-p 指定启动seata server的端口号。
-h 指定seata server所绑定的主机。
-m 事务日志、事务执行信息存储的方式,目前支持file(文件方式)、db(数据库方式,建表语句请查看config/db_store.sql、config/db_undo_log.sql)

tail -1000f seata.log

二、 集群版(三个节点同时操作)

a) 安装jdk8

tar -zxvf jdk-8u261-linux-x64.tar.gz && \
echo "export JAVA_HOME=/home/csii/jdk1.8.0_261
export PATH=\$JAVA_HOME/bin:\$PATH
export CLASSPATH=.\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar" >> ~/.bash_profile && \
source ~/.bash_profile && \
java -version

b) 安装seata

从seata官网 https://github.com/seata/seata/releases 下载安装包,最新正式版:seata-server-1.4.0.tar.gz,直接解压

tar -zxf nacos-server-2.0.0-ALPHA.1.tar.gz

c) 配置file文件

进入conf目录

cd seata/conf

vim file.conf

## transaction log store, only used in seata-server
store {
  ## store mode: file、db、redis
  mode = "db" #选择db模式

  ## file store property
  file {
    ## store location dir
    dir = "sessionStore"
    # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
    maxBranchSessionSize = 16384
    # globe session size , if exceeded throws exceptions
    maxGlobalSessionSize = 512
    # file buffer size , if exceeded allocate new buffer
    fileWriteBufferCacheSize = 16384
    # when recover batch read size
    sessionReloadReadSize = 100
    # async, sync
    flushDiskMode = async
  }

  ## 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"
#填写mysql的jdbc
    url = "jdbc:mysql://192.168.100.205:3306/seata"
    user = "seata"
    password = "seata"
    minConn = 5
    maxConn = 100
    globalTable = "global_table"
    branchTable = "branch_table"
    lockTable = "lock_table"
    queryLimit = 100
    maxWait = 5000
  }
	service {
	  vgroupMapping.storage-service-group= "default"
	  vgroupMapping.order-service-group= "default"
	  vgroupMapping.business-service-group= "default"
	}
}

d) 配置MySQL数据库

创建seata数据库

create database seata;

创建mysql用户seata/seatapass

create user 'seata'@'%' identified by 'seatapass';
grant all privileges on seata.* to 'seata'@'%' identified by 'seatapass';

执行建表语句

/*
 Navicat Premium Data Transfer
 Source Server         : OBD服务器
 Source Server Type    : MySQL
 Source Server Version : 50730
 Source Host           : 192.168.100.205:3306
 Source Schema         : seata
 Target Server Type    : MySQL
 Target Server Version : 50730
 File Encoding         : 65001
 Date: 09/09/2020 11:54:01
*/
 
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
 
-- ----------------------------
-- Table structure for branch_table
-- ----------------------------
DROP TABLE IF EXISTS `branch_table`;
CREATE TABLE `branch_table` (
  `branch_id` bigint(20) NOT NULL,
  `xid` varchar(128) NOT NULL,
  `transaction_id` bigint(20) DEFAULT NULL,
  `resource_group_id` varchar(32) DEFAULT NULL,
  `resource_id` varchar(256) DEFAULT NULL,
  `branch_type` varchar(8) DEFAULT NULL,
  `status` tinyint(4) DEFAULT NULL,
  `client_id` varchar(64) DEFAULT NULL,
  `application_data` varchar(2000) DEFAULT NULL,
  `gmt_create` datetime(6) DEFAULT NULL,
  `gmt_modified` datetime(6) DEFAULT NULL,
  PRIMARY KEY (`branch_id`),
  KEY `idx_xid` (`xid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-- ----------------------------
-- Table structure for global_table
-- ----------------------------
DROP TABLE IF EXISTS `global_table`;
CREATE TABLE `global_table` (
  `xid` varchar(128) NOT NULL,
  `transaction_id` bigint(20) DEFAULT NULL,
  `status` tinyint(4) NOT NULL,
  `application_id` varchar(32) DEFAULT NULL,
  `transaction_service_group` varchar(32) DEFAULT NULL,
  `transaction_name` varchar(128) DEFAULT NULL,
  `timeout` int(11) DEFAULT NULL,
  `begin_time` bigint(20) DEFAULT NULL,
  `application_data` varchar(2000) DEFAULT NULL,
  `gmt_create` datetime DEFAULT NULL,
  `gmt_modified` datetime DEFAULT NULL,
  PRIMARY KEY (`xid`),
  KEY `idx_gmt_modified_status` (`gmt_modified`,`status`),
  KEY `idx_transaction_id` (`transaction_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-- ----------------------------
-- Table structure for lock_table
-- ----------------------------
DROP TABLE IF EXISTS `lock_table`;
CREATE TABLE `lock_table` (
  `row_key` varchar(128) NOT NULL,
  `xid` varchar(96) DEFAULT NULL,
  `transaction_id` bigint(20) DEFAULT NULL,
  `branch_id` bigint(20) NOT NULL,
  `resource_id` varchar(256) DEFAULT NULL,
  `table_name` varchar(32) DEFAULT NULL,
  `pk` varchar(36) DEFAULT NULL,
  `gmt_create` datetime DEFAULT NULL,
  `gmt_modified` datetime DEFAULT NULL,
  PRIMARY KEY (`row_key`),
  KEY `idx_branch_id` (`branch_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
SET FOREIGN_KEY_CHECKS = 1;

每个需要全局事务的数据库中,放一个undo_log的表

/*
 Navicat Premium Data Transfer
 Source Server         : OBD服务器
 Source Server Type    : MySQL
 Source Server Version : 50730
 Source Host           : 192.168.100.205:3306
 Source Schema         : seata-demo
 Target Server Type    : MySQL
 Target Server Version : 50730
 File Encoding         : 65001
 Date: 07/08/2020 10:15:13
*/
 
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
 
-- ----------------------------
-- Table structure for undo_log
-- ----------------------------
DROP TABLE IF EXISTS `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=432 DEFAULT CHARSET=utf8;
 
SET FOREIGN_KEY_CHECKS = 1;

e) 配置registry文件

vim application.properties

registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "nacos"
  loadBalance = "RandomLoadBalance"
  loadBalanceVirtualNodes = 10

  nacos {
    application = "seata-server1" #每个节点命名不同1,2,3
    serverAddr = "192.168.100.201:8848,192.168.100.202:8848,192.168.100.203:8848" #nacos地址
    group = "SEATA_GROUP"
    namespace = ""
    cluster = "default"
    username = "nacos"
    password = "nacos" #nacos登陆账密
  }
}

config {
  # file、nacos 、apollo、zk、consul、etcd3
  type = "file"

 file {
    name = "file.conf"
  }

}

f) 启动seata

cd bin/
sh seata-server.sh -p 8091 -h 192.168.100.206 -m db -n 1 &> seata.log &

-h 为注册到注册中心的地址,通常为seata自身IP
#另外两节点启动

sh seata-server.sh -p 8091 -h 192.168.100.207 -m db -n 2 &> seata.log &
sh seata-server.sh -p 8091 -h 192.168.100.208 -m db -n 3 &> seata.log &

g) 启动成功 登陆nacos控制台查看

http://192.168.100.203:8848/nacos

h) 开机自启

1节点
vi startseata.sh

sh /home/ywzt/seata-server.sh -p 8091 -h 192.168.100.206 -m file &> seata.log &

2节点
vi startseata.sh

sh /home/ywzt/seata-server.sh -p 8091 -h 192.168.100.206 -m file &> seata.log &

3节点
vi startseata.sh

sh /home/ywzt/seata-server.sh -p 8091 -h 192.168.100.206 -m file &> seata.log &

三个节点操作
(使用root用户操作)
vi /etc/rc.d/rc.local
在最后一行加上

su - ywzt -c "/home/ywzt/seata/startseata.sh"
chmod +x /etc/rc.d/rc.local
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

范一刀

你的鼓励是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值