【Seata微服务分布式事务】1.Seata服务端环境搭建

编程

https://github.com/seata/seata/releases

wget https://github.com/seata/seata/releases/download/v0.9.0/seata-server-0.9.0.tar.gz

链接:https://pan.baidu.com/s/1jlBwCEYM3hn7zQiSpwRijg  密码:56vm

官网0.9.0版本以后conf文件已经没有SQL文件

执行SQL脚本

数据库名称:seata

-- the table to store GlobalSession data

drop table if exists `global_table`;

create table `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`)

);

-- the table to store BranchSession data

drop table if exists `branch_table`;

create table `branch_table` (

`branch_id` bigint not null,

`xid` varchar(128) not null,

`transaction_id` bigint ,

`resource_group_id` varchar(32),

`resource_id` varchar(256) ,

`lock_key` varchar(128) ,

`branch_type` varchar(8) ,

`status` tinyint,

`client_id` varchar(64),

`application_data` varchar(2000),

`gmt_create` datetime,

`gmt_modified` datetime,

primary key (`branch_id`),

key `idx_xid` (`xid`)

);

-- the table to store lock data

drop table if exists `lock_table`;

create table `lock_table` (

`row_key` varchar(128) not null,

`xid` varchar(96),

`transaction_id` long ,

`branch_id` long,

`resource_id` varchar(256) ,

`table_name` varchar(32) ,

`pk` varchar(36) ,

`gmt_create` datetime ,

`gmt_modified` datetime,

primary key(`row_key`)

);

开始安装

解压安装包:

tar -zxvf seata-server-0.9.0.tar.gz

进入到conf目录:

cd seata/conf/

修改vim file.conf文件

service节点:

service {

#service修改点2个 其他不要动

#vgroup->rgroup

#修改全局事务分组 修改点1

vgroup_mapping.prex_tx_group = "default"

#only support single node

#seata‐server的连接地址 这个是我服务器的地址 修改单2

default.grouplist = "47.112.217.177:8091"

#degrade current not support

enableDegrade = false

#disable

disable = false

#unit ms,s,m,h,d represents milliseconds, seconds, minutes, hours, days, default permanent

max.commit.retry.timeout = "-1"

max.rollback.retry.timeout = "-1"

}

store节点:

store {

#store修改点5个 其他不要动

## store mode: file、db

#db储存 修改单1

mode = "db"

## file store

file {

dir = "sessionStore"

# branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions

max-branch-session-size = 16384

# globe session size , if exceeded throws exceptions

max-global-session-size = 512

# file buffer size , if exceeded allocate new buffer

file-write-buffer-cache-size = 16384

# when recover batch read size

session.reload.read_size = 100

# async, sync

flush-disk-mode = async

}

## database store

db {

## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp) etc.

#修改点2

datasource = "druid"

## mysql/oracle/h2/oceanbase etc.

db-type = "mysql"

driver-class-name = "com.mysql.jdbc.Driver"

#修改点3 上面创建数据库的路径地址

url = "jdbc:mysql://127.0.0.1:3306/seata"

#修改单4

user = "root"

#修改点5

password = "123456"

min-conn = 1

max-conn = 3

global.table = "global_table"

branch.table = "branch_table"

lock-table = "lock_table"

query-limit = 100

}

}

修改vim register.conf文件

registry节点:

registry {

#registry修改点4个 其他不要动

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

#修改点1

type = "nacos"

nacos {

#修改点2 nacos地址

serverAddr = "47.112.217.177:8847"

#修改点3

namespace = "public"

#修改点4

cluster = "default"

}

eureka {

serviceUrl = "http://localhost:8761/eureka"

application = "default"

weight = "1"

}

redis {

serverAddr = "localhost:6379"

db = "0"

}

zk {

cluster = "default"

serverAddr = "127.0.0.1:2181"

session.timeout = 6000

connect.timeout = 2000

}

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节点:

config {

#config修改点3个 其他不要动

# file、nacos 、apollo、zk、consul、etcd3

#修改点1

type = "nacos"

nacos {

#修改点2

serverAddr = "47.112.217.177:8847"

#修改点3

namespace = "public"

}

consul {

serverAddr = "127.0.0.1:8500"

}

apollo {

app.id = "seata-server"

apollo.meta = "http://192.168.1.204:8801"

}

zk {

serverAddr = "127.0.0.1:2181"

session.timeout = 6000

connect.timeout = 2000

}

etcd3 {

serverAddr = "http://localhost:2379"

}

file {

name = "file.conf"

}

}

修改vim nacos-config.txt文件

transport.type=TCP

transport.server=NIO

transport.heartbeat=true

transport.thread-factory.boss-thread-prefix=NettyBoss

transport.thread-factory.worker-thread-prefix=NettyServerNIOWorker

transport.thread-factory.server-executor-thread-prefix=NettyServerBizHandler

transport.thread-factory.share-boss-worker=false

transport.thread-factory.client-selector-thread-prefix=NettyClientSelector

transport.thread-factory.client-selector-thread-size=1

transport.thread-factory.client-worker-thread-prefix=NettyClientWorkerThread

transport.thread-factory.boss-thread-size=1

transport.thread-factory.worker-thread-size=8

transport.shutdown.wait=3

#修改点1

service.vgroup_mapping.prex_tx_group=default

service.enableDegrade=false

service.disable=false

service.max.commit.retry.timeout=-1

service.max.rollback.retry.timeout=-1

client.async.commit.buffer.limit=10000

client.lock.retry.internal=10

client.lock.retry.times=30

client.lock.retry.policy.branch-rollback-on-conflict=true

client.table.meta.check.enable=true

client.report.retry.count=5

client.tm.commit.retry.count=1

client.tm.rollback.retry.count=1

#修改点2

store.mode=db

store.file.dir=file_store/data

store.file.max-branch-session-size=16384

store.file.max-global-session-size=512

store.file.file-write-buffer-cache-size=16384

store.file.flush-disk-mode=async

store.file.session.reload.read_size=100

#修改点3

store.db.datasource=druid

store.db.db-type=mysql

store.db.driver-class-name=com.mysql.jdbc.Driver

#修改点4

store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true

#修改点5

store.db.user=root

#修改点6

store.db.password=123456

store.db.min-conn=1

store.db.max-conn=3

store.db.global.table=global_table

store.db.branch.table=branch_table

store.db.query-limit=100

store.db.lock-table=lock_table

recovery.committing-retry-period=1000

recovery.asyn-committing-retry-period=1000

recovery.rollbacking-retry-period=1000

recovery.timeout-retry-period=1000

transaction.undo.data.validation=true

transaction.undo.log.serialization=jackson

transaction.undo.log.save.days=7

transaction.undo.log.delete.period=86400000

transaction.undo.log.table=undo_log

transport.serialization=seata

transport.compressor=none

metrics.enabled=false

metrics.registry-type=compact

metrics.exporter-list=prometheus

metrics.exporter-prometheus-port=9898

support.spring.datasource.autoproxy=false

初始化seata的nacos配置

conf目录执行:

sh nacos-config.sh 47.112.217.177

注意:如果你的nacos的端口不是默认的8848需要改一下nacos-config.sh

我的nacos是集群所以改了默认端口。nacos集群搭建:https://my.oschina.net/u/1046143/blog/3217779

result=`curl -X POST "http://$nacosIp:8847/nacos/v1/cs/configs?dataId=$key&group=SEATA_GROUP&content=$value"`

执行完登录nacos后台:

启动 seata-server服务

[root@iZwz9e2l6djknfngtgxfbnZ conf]# cd ../bin/

[root@iZwz9e2l6djknfngtgxfbnZ bin]# ls

seata-server.bat seata-server.sh

执行:./seata-server.sh

如果部署在服务器使用:./seata-server.sh -h 47.112.217.177  启动,指定外网IP

如果服务详情里面的IP是内网IP,但是客服端项目在我们本地启动那边就会访问不到

以上是 【Seata微服务分布式事务】1.Seata服务端环境搭建 的全部内容, 来源链接: utcz.com/z/515045.html

回到顶部