Seata Server服務(wù)端搭建
一、官網(wǎng)地址
二显沈、Seata Server 下載
這里地址為
1.3.0版本
- Linux
wget https://github.com/seata/seata/releases/download/v1.3.0/seata-server-1.3.0.zip
三汇跨、修改配置文件
配置文件主要有:
registry.conf
file.conf
registry.conf
: Seata 服務(wù)注冊(cè)中心地址坝辫,配置中心地址
file.conf
: 當(dāng)配置中心使用file
時(shí),此配置文件生效狸涌。配置store
存儲(chǔ)配置這里我們使用
eureka
做為注冊(cè)中心,Apollo
做為配置中心
registry.conf
registry {
# file 、nacos 胀屿、eureka、redis包雀、zk宿崭、consul、etcd3馏艾、sofa
type = "eureka"
# 配置eureka地址
eureka {
serviceUrl = "http://10.0.17.92:9001/eureka"
application = "seata-server"
weight = "1"
}
...
file {
name = "file.conf"
}
}
config {
# file劳曹、nacos 、apollo琅摩、zk铁孵、consul、etcd3
#type = "file"
type = "apollo"
# 配置中心配置apollo地址和namespace
apollo {
appId = "seata-server"
apolloMeta = "http://10.0.17.92:9083"
namespace = "application"
}
file {
name = "file.conf"
}
}
file.conf
## transaction log store, only used in seata-server
store {
## store mode: file房资、db蜕劝、redis
mode = "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.cj.jdbc.Driver"
url = "jdbc:mysql://10.0.17.122:3306/seata"
user = "root"
password = "Pdhn^456"
minConn = 5
maxConn = 30
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
## redis store property
redis {
host = "127.0.0.1"
port = "6379"
password = ""
database = "0"
minConn = 1
maxConn = 10
queryLimit = 100
}
}
Apollo配置Server配置
主要修改:數(shù)據(jù)庫地址 用戶名 密碼等
- 注意:mysql 版本問題 1.3.0后,Seata使用mysql 8.0版本
- 使用 8.0版本后轰异,driverClassName = com.mysql.cj.jdbc.Driver 岖沛。否則會(huì)報(bào)錯(cuò):
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server
transport.type = TCP
transport.server = NIO
transport.heartbeat = true
transport.enableClientBatchSendRequest = false
transport.threadFactory.bossThreadPrefix = NettyBoss
transport.threadFactory.workerThreadPrefix = NettyServerNIOWorker
transport.threadFactory.serverExecutorThreadPrefix = NettyServerBizHandler
transport.threadFactory.shareBossWorker = false
transport.threadFactory.clientSelectorThreadPrefix = NettyClientSelector
transport.threadFactory.clientSelectorThreadSize = 1
transport.threadFactory.clientWorkerThreadPrefix = NettyClientWorkerThread
transport.threadFactory.bossThreadSize = 1
transport.threadFactory.workerThreadSize = default
transport.shutdown.wait = 3
transport.serialization = seata
transport.compressor = none
store.mode = db
store.db.datasource = druid
store.db.dbType = mysql
store.db.driverClassName = com.mysql.cj.jdbc.Driver
store.db.url = jdbc:mysql://10.0.17.122:3306/seata?useUnicode=true
store.db.user = root
store.db.password = Pdhn^456
store.db.minConn = 5
store.db.maxConn = 30
store.db.globalTable = global_table
store.db.branchTable = branch_table
store.db.queryLimit = 100
store.db.lockTable = lock_table
store.db.maxWait = 5000
server.recovery.committingRetryPeriod = 1000
server.recovery.asynCommittingRetryPeriod = 1000
server.recovery.rollbackingRetryPeriod = 1000
server.recovery.timeoutRetryPeriod = 1000
server.maxCommitRetryTimeout = -1
server.maxRollbackRetryTimeout = -1
server.rollbackRetryTimeoutUnlockEnable = false
metrics.enabled = false
metrics.registryType = compact
初始化數(shù)據(jù)庫
global_table
維護(hù)全局事務(wù)branch_table
維護(hù)分支事務(wù)lock_table
維護(hù)全局鎖
-- 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`)
);
四、Seata-Server
啟動(dòng)
- 先保證配置
eureka
apollo
配置搭独,啟動(dòng)注冊(cè)中心和配置中心
-
Apollo
配置
[圖片上傳失敗...(image-646e30-1623312838097)]
- 進(jìn)入到:
seata/bin
目錄
nohup sh seata-server.sh -h 10.0.17.92 -p 8091 &
Eureka
[圖片上傳失敗...(image-c5fe2a-1623312838097)]
五婴削、Docker
啟動(dòng) Seata server
1. 拉取 seata-server
鏡像
docker pull docker.io/seataio/seata-server:1.3.0
2. 修改配置文件registry.conf
- 配置 Apollo
registry {
# file 、nacos 牙肝、eureka唉俗、redis嗤朴、zk、consul虫溜、etcd3雹姊、sofa
type = "eureka"
loadBalance = "RandomLoadBalance"
loadBalanceVirtualNodes = 10
eureka {
serviceUrl = "http://10.0.17.92:9001/eureka"
application = "seata-server"
weight = "1"
}
file {
name = "file.conf"
}
}
config {
# file、nacos 衡楞、apollo吱雏、zk、consul瘾境、etcd3
type = "apollo"
apollo {
appId = "seata-server"
apolloMeta = "http://10.0.17.92:9083"
namespace = "application"
}
file {
name = "file.conf"
}
}
3. 啟動(dòng)腳本
start.sh
SEATA_PORT : 自定義端口
SERVER_NODE: 集群環(huán)境下歧杏,指定節(jié)點(diǎn)
seata日志目錄:/root/logs/seata ,可掛載到服務(wù)器本地目錄
#!/bin/bash
docker stop seata-server;
docker container rm seata-server;
docker run --name seata-server -it -d -p 8091:8091 \
-e SEATA_CONFIG_NAME=file:/root/seata/config/registry \
-e SEATA_IP=10.0.17.92 \
-e SEATA_PORT=8091 \
-e SERVER_NODE=1 \
-v /opt/logs/seata:/root/logs/seata \
-v /opt/seata/config:/root/seata/config \
- v /opt/seata/config/libs/mysql-connector-java-8.0.21.jar:/root/seata/config/libs/mysql-connector-java-8.0.21.jar \
--net=bridge --restart=always docker.io/seataio/seata-server:1.3.0
六寄雀、 Docker Compose
啟動(dòng) Seata server
注意數(shù)據(jù)庫版本問題得滤,1.3.0版本后 mysql驅(qū)動(dòng)為 8.0版本
- 在config目錄中,配置`mysql-connector-java-8.0.21.jar`驅(qū)動(dòng)
Apollo
數(shù)據(jù)庫驅(qū)動(dòng)cj
盒犹,連接地址加characterEncoding=utf-8&serverTimezone=UTC
store.db.driverClassName = com.mysql.cj.jdbc.Driver store.db.url = jdbc:mysql://10.0.17.122:3306/seata?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
- 啟動(dòng)容器
docker-compose up -d
1. docker-compose.yml
配置文件
version: "3"
services:
seata-server:
image: seataio/seata-server:1.3.0
container_name: seata-server
hostname: seata-server
ports:
- "8091:8091"
volumes:
- "/opt/seata/config:/root/seata/config"
- "/opt/seata/config/libs/mysql-connector-java-8.0.21.jar:/root/seata/config/libs/mysql-connector-java-8.0.21.jar"
environment:
- SEATA_CONFIG_NAME=file:/root/seata/config/registry
- SEATA_IP=10.0.17.92
- SEATA_PORT=8091
- STORE_MODE=db
restart: always
deploy:
resources:
limits:
cpus: '0.3'
memory: 300M
2. registry.conf
registry {
# file 懂更、nacos 、eureka急膀、redis沮协、zk、consul卓嫂、etcd3慷暂、sofa
type = "eureka"
loadBalance = "RandomLoadBalance"
loadBalanceVirtualNodes = 10
eureka {
serviceUrl = "http://10.0.17.92:9001/eureka"
application = "seata-server"
weight = "1"
}
file {
name = "file.conf"
}
}
config {
# file、nacos 晨雳、apollo行瑞、zk、consul餐禁、etcd3
type = "apollo"
apollo {
appId = "seata-server"
apolloMeta = "http://10.0.17.92:9083"
namespace = "application"
}
file {
name = "file:/root/seata/config/file.conf"
}
}
3. 異常 database
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server
15:09:54.010 ERROR --- [ionPool-Create-1072506992] com.alibaba.druid.pool.DruidDataSource : create connection SQLException, url: jdbc:mysql://10.0.17.122:3306/seata?useUnicode=true, errorCode 0, state 08001
==>
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:389)
at com.mysql.jdbc.Util.getInstance(Util.java:372)
4. 進(jìn)入seata server 容器
[root@lipei92 seata]# docker ps|grep seata
55af30b183b7 seataio/seata-server:1.4.1 "java -Djava.secur..." 4 minutes ago Up 8 seconds 0.0.0.0:8091->8091/tcp seata-server
[root@lipei92 seata]# docker exec -it 55af30b183b7 sh
/seata-server # pwd
/seata-server
九血久、參考文檔
-
Docker-compose
主要參考
使用docker安裝seata-server,mysql8引擎帮非,nacos作為注冊(cè)和配置中心
-
Docker
主要參考文檔
docker快速部署一個(gè)seata-server+向nacos推送配置
-
Seata Server
數(shù)據(jù)版本升級(jí) 8.0后報(bào)異常