docker部署seata-1.2.0
默認要安裝activemq的主機上已經安裝了docker。
1、查詢seata:
docker search seata
2、按照name接取鏡像
docker pull seataio/seata-server
3、創建seata-config目錄,並在該目錄下邊新建registry.conf、file.conf文件。
這裏我們使用zookeeper爲註冊中心,並指定指定 file.conf
配置文件。因此registry.conf內容如下:
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "zk"
zk {
cluster = "default"
serverAddr = "xxx.xxx.xxx.xxx:2181"
sessionTimeout = 6000
connectTimeout = 2000
username = ""
password = ""
}
}
config {
# file、nacos 、apollo、zk、consul、etcd3
type = "file"
file {
name = "file:/root/seata-config/file.conf"
}
}
注:serverAddr爲zookeeper地址;
config.file.name = "file:docker容器內的file.conf配置文件";
file.conf文件內容如下:
## transaction log store, only used in seata-server
store {
## store mode: file、db
mode = "db"
## database store property
db {
## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp) etc.
datasource = "druid"
## mysql/oracle/postgresql/h2/oceanbase etc.
dbType = "mysql"
driverClassName = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://xxx.xxx.xxx.xxx:3306/seata"
user = "xxxxx"
password = "xxxxx"
minConn = 5
maxConn = 30
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
}
4、創建數據庫和表,全局事務會話信息由3塊內容構成,全局事務-->分支事務-->全局鎖,對應表global_table、branch_table、lock_table
-- -------------------------------- The script used when storeMode is 'db' --------------------------------
-- 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_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;
5、啓動docker容器
docker run -d --name seata-server \
-p 8091:8091 \
-e SEATA_IP=xxx.xxx.xxx.xxx \
-e STORE_MODE=db \
-e SEATA_CONFIG_NAME=file:/root/seata-config/registry \
-v /opt/seata-config:/root/seata-config \
seataio/seata-server
注:其中 -e
用於配置環境變量, -v
用於掛載宿主機的目錄
-v 本地目錄:docker容器目錄
6、查看
docker ps
7、查看運行日誌
docker logs -f b41aba2eff17
8、查看seata容器內目錄結構
docker exec -it seata-server sh