docker安装seata
1.准备数据库表
-- the table to store GlobalSession data
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_status_gmt_modified` (`status` , `gmt_modified`),
KEY `idx_transaction_id` (`transaction_id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
-- 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 = utf8mb4;
-- the table to store lock data
CREATE TABLE IF NOT EXISTS `lock_table`
(
`row_key` VARCHAR(128) NOT NULL,
`xid` VARCHAR(128),
`transaction_id` BIGINT,
`branch_id` BIGINT NOT NULL,
`resource_id` VARCHAR(256),
`table_name` VARCHAR(32),
`pk` VARCHAR(36),
`status` TINYINT NOT NULL DEFAULT '0' COMMENT '0:locked ,1:rollbacking',
`gmt_create` DATETIME,
`gmt_modified` DATETIME,
PRIMARY KEY (`row_key`),
KEY `idx_status` (`status`),
KEY `idx_branch_id` (`branch_id`),
KEY `idx_xid` (`xid`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
CREATE TABLE IF NOT EXISTS `distributed_lock`
(
`lock_key` CHAR(20) NOT NULL,
`lock_value` VARCHAR(20) NOT NULL,
`expire` BIGINT,
primary key (`lock_key`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0);
SET FOREIGN_KEY_CHECKS = 1;
2.准备配置文件
创建挂载目录:
mkdir -p /data/seata/conf
先运行,获取配置
docker run -d -p 8091:8091 -p 7091:7091 --name seata seataio/seata-server:1.5.2
将配置文件拷贝到挂载目录:
docker cp seata:/seata-server/resources/. /data/seata/conf
我们可以看到有个application.yml文件
方便就先下载下来将这介个配置更改:
更改后:
server:
port: 7091
spring:
application:
name: seata-server
logging:
config: classpath:logback-spring.xml
file:
path: ${log.home:${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
console:
user:
username: seata
password: seata
seata:
config:
type: nacos
nacos:
server-addr: 192.168.152.130:8848
namespace:
group: DEFAULT_GROUP
username: nacos
password: nacos
registry:
type: nacos
nacos:
application: seata-server
server-addr: 192.168.152.130:8848
group: DEFAULT_GROUP
namespace:
cluster: default
username: nacos
password: nacos
store:
mode: db
db:
datasource: druid
db-type: mysql
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.152.130:3306/seata-config?characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8&rewriteBatchedStatements=true&allowPublicKeyRetrieval=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
security:
secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
tokenValidityInMilliseconds: 1800000
ignore:
urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.jpeg,/**/*.ico,/api/v1/auth/login,/metadata/v1/**
然后删除容器:
docker rm -f seata
接着再次运行:
3.启动
docker run -d --name seata \
-p 8091:8091 \
-p 7091:7091 \
--privileged=true \
-e SEATA_IP=192.168.152.130 \
-e JVM_XMS=256m -e JVM_XMX=256m \
-e MODE=standalone \
-v /data/seata/conf/:/seata-server/resources \
--restart=always \
seataio/seata-server:1.5.2
命令解析
docker run -d
:
该命令用于后台运行容器,-d
参数表示在后台启动容器。--name seata
:
设置容器的名称为seata
。你可以通过该名称来管理容器(例如停止、重启等)。-p 8091:8091 -p 7091:7091
:
将容器的 8091 端口和 7091 端口映射到主机的相同端口。这通常是为了 Seata 服务器的服务端口和管理端口能够对外开放。--privileged=true
:
该参数允许容器获得额外的权限,通常用于需要较高权限操作的容器。一般来说,除非必要,不建议使用这个选项,因为它会给容器更多的权限,可能存在安全风险。-e SEATA_IP=192.168.152.130
:
设置环境变量SEATA_IP
为192.168.152.130
,表示 Seata 服务器的 IP 地址。-e JVM_XMS=256m -e JVM_XMX=256m
:
设置 JVM 的初始内存 (XMS
) 和最大内存 (XMX
) 都为 256MB。通过这些参数调整容器中运行 Seata 服务的内存配置。-e MODE=standalone
:
设置 Seata 的运行模式为standalone
,即单机模式。Seata 也支持集群模式,通过设置其他参数可以启用。-v /data/seata/logs/:/seata-server/resources
:
通过卷挂载,将主机的/data/seata/logs/
目录挂载到容器内的/seata-server/resources
目录。这意味着容器中的日志文件会保存到主机上指定的目录,便于日志管理和持久化。--restart=always
:
设置容器的重启策略为always
,即容器如果停止或崩溃,Docker 会自动重启容器。这对于需要持续运行的服务非常有用。seataio/seata-server:1.5.2
:
指定要使用的 Seata 服务器 Docker 镜像及其版本号。这里使用的是seataio/seata-server
镜像,版本为1.5.2
。
我们可以在nacos上看到注册成功