seata相关介绍
创建配置文件方式搭建seata
1、拉取seata镜像
docker pull seataio/seata-server
2、准备工作目录
mkdir /usr/local/docker/seata/
cd /usr/local/docker/seata/
3、复制容器数据卷
docker run -d --name seata-server -p 8091:8091 seataio/seata-server
docker cp seata-server:/seata-server /usr/local/docker/seata/
4、清除停止旧容器
docker stop seata-server
docker rm -f seata-server
5、修改数据库配置和nacos的配置
1、备份复制配置文件
cd /usr/local/docker/seata/seata-server/resources
\cp -r application.yml application.back_yml
rm -rf application.yml
\cp -r application.example.yml application.yml
2、修改配置文件
server:
port: 7091
spring:
application:
name: seata-server
logging:
config: classpath:logback-spring.xml
file:
path: ${user.home}/logs/seata
extend:
logstash-appender:
destination: 127.0.0.1:4560
kafka-appender:
bootstrap-servers: 127.0.0.1:9092
topic: logback_to_logstash
seata:
config:
type: nacos
nacos:
server-addr: 192.168.11.136:8848
namespace:
group: SEATA_GROUP
username: "nacos"
password: "nacos"
context-path:
data-id: seataServer.properties
consul:
server-addr: 127.0.0.1:8500
acl-token:
key: seata.properties
apollo:
appId: seata-server
apollo-meta: http://192.168.1.204:8801
apollo-config-service: http://192.168.1.204:8080
namespace: application
apollo-access-key-secret:
cluster: seata
zk:
server-addr: 127.0.0.1:2181
session-timeout: 6000
connect-timeout: 2000
username:
password:
node-path: /seata/seata.properties
etcd3:
server-addr: http://localhost:2379
key: seata.properties
registry:
type: nacos
preferred-networks: 30.240.*
nacos:
application: seata-server
server-addr: 192.168.11.136:8848
group: SEATA_GROUP
namespace:
cluster: default
username: "nacos"
password: "nacos"
context-path:
eureka:
service-url: http://localhost:8761/eureka
application: default
weight: 1
redis:
server-addr: localhost:6379
db: 0
password:
cluster: default
timeout: 0
zk:
cluster: default
server-addr: 127.0.0.1:2181
session-timeout: 6000
connect-timeout: 2000
username:
password:
consul:
cluster: default
server-addr: 127.0.0.1:8500
acl-token:
etcd3:
cluster: default
server-addr: http://localhost:2379
sofa:
server-addr: 127.0.0.1:9603
application: default
region: DEFAULT_ZONE
datacenter: DefaultDataCenter
cluster: default
group: SEATA_GROUP
address-wait-time: 3000
server:
service-port: 8091
max-commit-retry-timeout: -1
max-rollback-retry-timeout: -1
rollback-retry-timeout-unlock-enable: false
enable-check-auth: true
enable-parallel-request-handle: true
retry-dead-threshold: 130000
xaer-nota-retry-timeout: 60000
enableParallelRequestHandle: true
recovery:
committing-retry-period: 1000
async-committing-retry-period: 1000
rollbacking-retry-period: 1000
timeout-retry-period: 1000
undo:
log-save-days: 7
log-delete-period: 86400000
session:
branch-async-queue-size: 5000
enable-branch-async-remove: false
store:
mode: db
session:
mode: file
lock:
mode: file
file:
dir: sessionStore
max-branch-session-size: 16384
max-global-session-size: 512
file-write-buffer-cache-size: 16384
session-reload-read-size: 100
flush-disk-mode: async
db:
datasource: druid
db-type: mysql
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.11.136:3306/seata?rewriteBatchedStatements=true
user: root
password: 123456
min-conn: 10
max-conn: 100
global-table: global_table
branch-table: branch_table
lock-table: lock_table
distributed-lock-table: distributed_lock
query-limit: 1000
max-wait: 5000
redis:
mode: single
type: lua
database: 0
min-conn: 10
max-conn: 100
password:
max-total: 100
query-limit: 1000
single:
host: 127.0.0.1
port: 6379
sentinel:
master-name:
sentinel-hosts:
metrics:
enabled: false
registry-type: compact
exporter-list: prometheus
exporter-prometheus-port: 9898
transport:
rpc-tc-request-timeout: 15000
enable-tc-server-batch-send-response: false
shutdown:
wait: 3
thread-factory:
boss-thread-prefix: NettyBoss
worker-thread-prefix: NettyServerNIOWorker
boss-thread-size: 1
3准备seata的数据库表(用于上面配置db事务数据库做准备)
create database seata;
use seata;
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
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;
4、修改核心配置文件说明
- 1、配置中心seata.config.type
作者此处使用的type: nacos作为配置中心,然后修改nacos的相关配置信息
seata:
config:
type: nacos
nacos:
server-addr: 192.168.11.136:8848
namespace:
group: SEATA_GROUP
username: "nacos"
password: "nacos"
context-path:
data-id: seataServer.properties
- 2、注册中心seata.config.registry.type
作者此处使用的type: nacos作为注册中心,然后修改nacos的相关配置信息
seata:
registry:
type: nacos
preferred-networks: 30.240.*
nacos:
application: seata-server
server-addr: 192.168.11.136:8848
group: SEATA_GROUP
namespace:
cluster: default
username: "nacos"
password: "nacos"
context-path:
- 3、存储模式(seata事务的存储模式seata.config.store.mode)
作者此处使用的 mode: db作为存储模式,然后修改db的相关数据库配置信息
seata:
store:
mode: db
session:
mode: file
lock:
mode: file
db:
datasource: druid
db-type: mysql
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.11.136:3306/seata?rewriteBatchedStatements=true
user: root
password: 123456
min-conn: 10
max-conn: 100
global-table: global_table
branch-table: branch_table
lock-table: lock_table
distributed-lock-table: distributed_lock
query-limit: 1000
max-wait: 5000
6、启动容器
1、启动方式一
docker run -d --restart always --name seata \
-p 8091:8091 \
-v /usr/local/docker/seata/seata-server \
-e SEATA_PORT=8091 \
seataio/seata-server
2、启动方式二
docker run -d \
--name seata-server \
-v /usr/local/docker/seata/registry.conf:/seata-server/resources/registry.conf \
-v /usr/local/docker/seata/file.conf:/seata-server/resources/file.conf \
-p 8091:8091 \
-e SEATA_IP=192.168.11.136 \
seataio/seata-server