helm部署Seata服务
拉取Seata服务代码
git clone https://github.com/seata/seata.git
cd seata/
// 切到自己需要的版本
git checkout v1.4.2
打chart包并推送到自己chart仓库
cd script/server/helm/
helm package ./seata-server --version 1.4.2
helm cm-push seata-server-1.4.2.tgz --password=密码 --username=用户名 chart仓库地址
部署Seata服务
// 添加seata所在chart仓库
helm repo add 仓库名称 --username 用户名 --password 密码 chart库地址
// 在需要部署seata服务的集群节点上拉取chart包
helm pull 仓库名称/seata-server --version 1.4.2
// 安装seata服务
helm install -f values.yaml seata-server ./seata-server
values.yaml文件内容
replicaCount: 1
namespace: default
image:
repository: seataio/seata-server
tag: 1.4.2
pullPolicy: IfNotPresent
service:
type: NodePort
port: 30091
env:
seataPort: "8091"
storeMode: "file"
seataIp: "127.0.0.1"
seataConfigName: "file:/root/seata-config/registry"
volume:
- name: seata-config
mountPath: /root/seata-config
hostPath: /root/work/seata/seata-config/file
-
将部署节点上/root/work/seata/seata-config/file目录挂载到/root/seata-config
-
env.seataConfigName指定seata服务启动时加载配置文件位置,registry即registry.conf文件
-
官方提供的chart包不能直接通过环境参数指定注册中心、连接数据库等信息,只能通过挂载文件的方式配置。如果想要直接通过values文件中指定这些
信息只能自己基于官方源码自己制作镜像、chart包 -
通过挂载主机文件的方式有个问题就是必须在每个节点上都需要有这个配置文件,因为如果seata服务的pod调度到没有配置文件的节点将会拿不到文件无法启动
/root/work/seata/seata-config/file下需要的配置文件
registry.conf
配置注册中心及配置中心的信息
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "eureka"
nacos {
application = "seata-server"
serverAddr = "127.0.0.1:8848"
group = "SEATA_GROUP"
namespace = ""
cluster = "default"
username = ""
password = ""
}
eureka {
# 配置eureka注册中心信息
serviceUrl = "http://localhost:8000/eureka"
application = "seata-server"
weight = "1"
}
redis {
serverAddr = "localhost:6379"
db = 0
password = ""
cluster = "default"
timeout = 0
}
zk {
cluster = "default"
serverAddr = "127.0.0.1:2181"
sessionTimeout = 6000
connectTimeout = 2000
username = ""
password = ""
}
consul {
cluster = "default"
serverAddr = "127.0.0.1:8500"
aclToken = ""
}
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 {
# file、nacos 、apollo、zk、consul、etcd3
type = "file"
nacos {
serverAddr = "127.0.0.1:8848"
namespace = ""
group = "SEATA_GROUP"
username = ""
password = ""
dataId = "seataServer.properties"
}
consul {
serverAddr = "127.0.0.1:8500"
aclToken = ""
}
apollo {
appId = "seata-server"
## apolloConfigService will cover apolloMeta
apolloMeta = "http://192.168.1.204:8801"
apolloConfigService = "http://192.168.1.204:8080"
namespace = "application"
apolloAccesskeySecret = ""
cluster = "seata"
}
zk {
serverAddr = "127.0.0.1:2181"
sessionTimeout = 6000
connectTimeout = 2000
username = ""
password = ""
nodePath = "/seata/seata.properties"
}
etcd3 {
serverAddr = "http://localhost:2379"
}
file {
name = "file.conf"
}
}
- 如果使用Spring Cloud微服务架构,需要将Seata服务注册到注册中心,以便客户端能通过注册中心访问Seata服务
file.conf
配置数据库等信息,如下为配置mysql数据库样例
## transaction log store, only used in seata-server
store {
## store mode: file、db、redis
mode = "db"
## rsa decryption public key
publicKey = ""
## 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.jdbc.Driver"
## if using mysql to store the data, recommend add rewriteBatchedStatements=true in jdbc connection param
url = "jdbc:mysql://localhost:3306/seata?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=utf-8&useSSL=false"
user = "root"
password = "root"
minConn = 5
maxConn = 100
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
## redis store property
redis {
## redis mode: single、sentinel
mode = "single"
## single mode property
single {
host = "127.0.0.1"
port = "6379"
}
## sentinel mode property
sentinel {
masterName = ""
## such as "10.28.235.65:26379,10.28.235.65:26380,10.28.235.65:26381"
sentinelHosts = ""
}
password = ""
database = "0"
minConn = 1
maxConn = 10
maxTotal = 100
queryLimit = 100
}
}
如下为配置oracle数据库样例
## transaction log store, only used in seata-server
store {
## store mode: file、db、redis
mode = "redis"
## rsa decryption public key
publicKey = ""
## 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 = "oracle"
driverClassName = "oracle.jdbc.driver.OracleDriver"
## if using mysql to store the data, recommend add rewriteBatchedStatements=true in jdbc connection param
url = "jdbc:oracle:thin:@localhost:1521:FEIDA"
user = "root"
password = "root"
minConn = 5
maxConn = 100
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
## redis store property
redis {
## redis mode: single、sentinel
mode = "single"
## single mode property
single {
host = "localhost"
port = "6379"
}
## sentinel mode property
sentinel {
masterName = ""
## such as "10.28.235.65:26379,10.28.235.65:26380,10.28.235.65:26381"
sentinelHosts = ""
}
password = ""
database = "0"
minConn = 1
maxConn = 10
maxTotal = 100
queryLimit = 100
}
}
配置数据库的原因是Seata服务需要一些表来记录分布式事务的信息,以便进行分布式事务控制。即可以单独创建数据库指定,也可以使用已有数据库,建议
单独创建数据库