官方文檔
Seata高可用部署
1淆珊、注冊中心贸呢、配置中心使用nacos
2和屎、數(shù)據(jù)庫使用RDS
3、Nacos地址為192.168.199.2
4庸汗、使用阿里云SLB暴露應(yīng)用(和nacos用一個SLB實例即可)
目錄結(jié)構(gòu)
$ ll -R
total 32
-rw-r--r-- 1 localhost staff 303 2 2 12:12 config.txt
drwxr-xr-x 3 localhost staff 96 2 2 12:20 nacos
-rw-r--r-- 1 localhost staff 808 2 2 12:19 seata-client.sql
-rw-r--r-- 1 localhost staff 1899 2 2 12:19 seata-server.sql
-rw-r--r-- 1 localhost staff 1864 2 4 10:33 seata-server.yaml
./nacos:
total 8
-rwxr-xr-x 1 localhost staff 2936 2 2 12:20 nacos-config.sh
部署前準(zhǔn)備
- 創(chuàng)建seata-server需要的表
具體的 SQL 參考 script/server/db,這里使用的是 MySQL 的腳本手报,數(shù)據(jù)庫名稱為seata
同時蚯舱,也需要創(chuàng)建 undo_log 表, 可以參考 script/client/at/db/
- 修改seata-server配置
將以下配置保存為config.txt
service.vgroupMapping.my_test_tx_group=default
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://rm-2zeabcdefghijklmn.mysql.rds.aliyuncs.com/seata?useUnicode=true
store.db.user=nacos
store.db.password=password
- 創(chuàng)建nacos目錄掩蛤,將nacos-config.sh存放到nacos目錄枉昏,層級結(jié)構(gòu)如上,執(zhí)行shell腳本揍鸟,將配置導(dǎo)入Nacos配置中心兄裂,具體添加方法可以參考 script/config-center
shell:
sh ./nacos/nacos-config.sh -h 192.168.199.2 -p 8848 -g SEATA_GROUP -u username -w password
參數(shù)說明:
-h: Nacos主機(jī)地址,默認(rèn)是localhost
-p: Nacos主機(jī)端口,默認(rèn)是8848
-g: 配置分組, the default value is 'SEATA_GROUP'.
-t: 租戶信息, 與Nacos的 "命名空間ID" 字段相對應(yīng), the default value is ''.
-u: Nacos用戶名, the default value is ''.
-w: Nacos密碼, the default value is ''.
部署 seata-server 到 Kubernetes
$ kubectl apply -f seata-server.yaml
- seata-server.yaml
apiVersion: v1
kind: Service
metadata:
name: seata-ha-server
namespace: pluginprod
labels:
app.kubernetes.io/name: seata-ha-server
#annotations:
# service.beta.kubernetes.io/alibaba-cloud-loadbalancer-id: lb-2zeabcdefghijklmn
# service.beta.kubernetes.io/alicloud-loadbalancer-force-override-listeners: 'true'
spec:
#type: LoadBalancer
type: ClusterIP
ports:
- port: 8091
protocol: TCP
targetPort: 8091
name: http
selector:
app.kubernetes.io/name: seata-ha-server
---
apiVersion: v1
kind: ConfigMap
metadata:
name: seata-ha-server-config
namespace: pluginprod
data:
registry.conf: |
registry {
type = "nacos"
nacos {
application = "seata-server"
serverAddr = "192.168.199.2"
}
}
config {
type = "nacos"
nacos {
serverAddr = "192.168.199.2"
group = "SEATA_GROUP"
}
}
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: seata-ha-server
namespace: pluginprod
labels:
app.kubernetes.io/name: seata-ha-server
spec:
serviceName: seata-ha-server
replicas: 3
selector:
matchLabels:
app.kubernetes.io/name: seata-ha-server
template:
metadata:
labels:
app.kubernetes.io/name: seata-ha-server
spec:
containers:
- name: seata-ha-server
image: docker.io/seataio/seata-server:latest
imagePullPolicy: IfNotPresent
env:
- name: SEATA_CONFIG_NAME
value: file:/root/seata-config/registry
ports:
- name: http
containerPort: 8091
protocol: TCP
volumeMounts:
- name: seata-config
mountPath: /root/seata-config
volumes:
- name: seata-config
configMap:
name: seata-ha-server-config