大纲
下载seata 选择1.6.0。下载后得到 seata-server-1.6.0.zip 已经上传到百度云盘
下载地址:http://seata.io/zh-cn/blog/download.html
使用unzip 解压 seata-server-1.6.0.zip
unzip seata-server-1.6.0.zip
解压后得到如下文件夹
seata文件夹内部包含
可以直接Dockerfile来创建镜像
docker build -t my-seata-server .
docker tag my-seata-server registry.cn-hangzhou.aliyuncs.com/jimliu/my-seata-server:1.6.0
docker push registry.cn-hangzhou.aliyuncs.com/jimliu/my-seata-server:1.6.0
创建好镜像后推送到私库备用
注意:
关于nacos 与 mysql配置可参考
可参考 《seata1.6.0 单机,集群搭建 基于nacos注册中心 mysql数据库》
如果要实现配置文件修改后自动重启,可以使用linux-inotify监听文件变化后重启
可参考 《linux-inotify工具监控文件状态变化总结》
《k8s 部署nginx 实现集群统一配置,自动更新nginx.conf配置文件 总结》
准备两个configmap
主要是把 application.yml logback-spring.xml 和 logback文件夹中的配置文件交由configmap管理
configmap-for-server.yaml 内容如下 保存server相关配置文件
# 将配置放置在configmap中统一管理
apiVersion: v1
kind: ConfigMap
metadata:
name: seata-server-config
data:
application.yml: |
server:
port: 17091 #修改控制台端口
spring:
application:
name: seata-server
logging:
config: classpath:logback-spring.xml
file:
path: ${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.0.206:8248
namespace: 8422b4bf-8b04-406e-8295-39d4968b2ec4
group: DEFAULT_GROUP
data-id: seata.properties
#username:
#password:
registry:
type: nacos
nacos:
application: seata-server
server-addr: 192.168.0.206:8248
namespace: 8422b4bf-8b04-406e-8295-39d4968b2ec4
group: DEFAULT_GROUP
cluster: default
#username:
#password:
security:
secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
tokenValidityInMilliseconds: 1800000
ignore:
urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login
logback-spring.xml: |
configmap-for-logger.yaml 内容如下 保存logback相关配置文件 (注意 kafka-appender.xml logstash-appender.xml 并没有使用 这里为了演示统一也加入了管理)
# 将配置放置在configmap中统一管理
apiVersion: v1
kind: ConfigMap
metadata:
name: seata-server-log-config
data:
console-appender.xml: |
${CONSOLE_LOG_PATTERN}
UTF-8
file-appender.xml: |
${LOG_FILE_PATH}/${APPLICATION_NAME:-seata-server}.${RPC_PORT}.all.log
true
${LOG_FILE_PATH}/history/${APPLICATION_NAME:-seata-server}.${RPC_PORT}.all.%d{yyyy-MM-dd}.%i.log.gz
2GB
7
7GB
true
${FILE_LOG_PATTERN}
UTF-8
WARN
ACCEPT
DENY
${LOG_FILE_PATH}/${APPLICATION_NAME:-seata-server}.${RPC_PORT}.warn.log
true
${LOG_FILE_PATH}/history/${APPLICATION_NAME:-seata-server}.${RPC_PORT}.warn.%d{yyyy-MM-dd}.%i.log.gz
2GB
7
7GB
true
${FILE_LOG_PATTERN}
UTF-8
ERROR
ACCEPT
DENY
${LOG_FILE_PATH}/${APPLICATION_NAME:-seata-server}.${RPC_PORT}.error.log
true
${LOG_FILE_PATH}/history/${APPLICATION_NAME:-seata-server}.${RPC_PORT}.error.%d{yyyy-MM-dd}.%i.log.gz
2GB
7
7GB
true
${FILE_LOG_PATTERN}
UTF-8
kafka-appender.xml: |
{
"@timestamp": "%d{yyyy-MM-dd HH:mm:ss.SSS}",
"level":"%p",
"app_name":"${APPLICATION_NAME:-seata-server}",
"PORT": ${RPC_PORT:-0},
"thread_name": "%t",
"logger_name": "%logger",
"X-TX-XID": "%X{X-TX-XID:-}",
"X-TX-BRANCH-ID": "%X{X-TX-BRANCH-ID:-}",
"message": "%m",
"stack_trace": "%wex"
}
${KAFKA_TOPIC}
bootstrap.servers=${KAFKA_BOOTSTRAP_SERVERS}
acks=0
linger.ms=1000
max.block.ms=0
logstash-appender.xml: |
${LOGSTASH_DESTINATION}
{
"app_name": "${APPLICATION_NAME:-seata-server}"
}
net.logstash.logback.composite.LogstashVersionJsonProvider
net.logstash.logback.composite.loggingevent.JsonMessageJsonProvider
net.logstash.logback.composite.loggingevent.TagsJsonProvider
net.logstash.logback.composite.loggingevent.LogstashMarkersJsonProvider
net.logstash.logback.composite.loggingevent.ArgumentsJsonProvider
准备部署两个seata服务来实现集群
由于业务服务部署在k8s集群外部无法访问k8s集群内部ip,seata注册到nacos需要使用独立的主机ip, 所以需要两个Deployment来部署seata 无法直接使用 --replicas=2
如果业务服务,nacos ,seata 都在k8s集群内部 ,则直接使用一个Deployment 指定–replicas=2
deploy.yaml 内容如下
# deploy1
apiVersion: apps/v1
kind: Deployment
metadata:
name: seata-server-deploy-1
labels:
k8s-app: seata-server-1
spec:
replicas: 1
selector:
matchLabels:
k8s-seata-node1: node1
template:
metadata:
labels:
k8s-seata-node1: node1
k8s-app: seata-server
spec:
imagePullSecrets:
- name: myaliyunsecret
containers:
- name: seata-server-run
image: registry.cn-hangzhou.aliyuncs.com/jimliu/my-seata-server:1.6.0 #使用开始创建的镜像
env:
- name: SEATA_IP #环境变量中配置一个IP 用于注册中心
value: "192.168.0.54"
- name: SERVER_NODE #指定seata-server节点ID, 默认为 根据ip生成 (可以不配置)
value: "1"
- name: SEATA_PORT
value: "5959" #注意环境变量中是数字也需要使用“”
volumeMounts:
- name: seata-config
mountPath: /seata-server/conf #使用configMap挂载配置文件
- name: seata-log-config
mountPath: /seata-server/conf/logback #使用configMap挂载配置文件
volumes:
- name: seata-config
configMap:
name: seata-server-config
- name: seata-log-config
configMap:
name: seata-server-log-config
---
# deploy2
apiVersion: apps/v1
kind: Deployment
metadata:
name: seata-server-deploy-2
labels:
k8s-app: seata-server-2
spec:
replicas: 1
selector:
matchLabels:
k8s-seata-node2: node2
template:
metadata:
labels:
k8s-seata-node2: node2
k8s-app: seata-server
spec:
imagePullSecrets:
- name: myaliyunsecret
containers:
- name: seata-server-run
image: registry.cn-hangzhou.aliyuncs.com/jimliu/my-seata-server:1.6.0 #使用开始创建的镜像
env:
- name: SEATA_IP #环境变量中配置一个IP 用于注册中心
value: "192.168.0.124"
- name: SERVER_NODE #指定seata-server节点ID, 默认为 根据ip生成 (可以不配置)
value: "2"
- name: SEATA_PORT
value: "5959" #注意环境变量中是数字也需要使用“”
volumeMounts:
- name: seata-config
mountPath: /seata-server/conf #使用configMap挂载配置文件
- name: seata-log-config
mountPath: /seata-server/conf/logback #使用configMap挂载配置文件
volumes:
- name: seata-config
configMap:
name: seata-server-config
- name: seata-log-config
configMap:
name: seata-server-log-config
---
# service
apiVersion: v1
kind: Service
metadata:
name: seata-server
labels:
k8s-app: seata-server
spec:
type: NodePort
ports:
- port: 5959
nodePort: 5959
targetPort: 5959
protocol: TCP
name: http1
- port: 17091
nodePort: 17091 #for seata 控制台
targetPort: 17091
protocol: TCP
name: http2
selector:
k8s-app: seata-server
kubectl apply -f configmap-for-logger.yaml
kubectl apply -f configmap-for-server.yaml
kubectl apply -f deploy.yaml
在nacos上可以看到 seata已经成功注册
控制台可以正常访问
启动seata 容器时注意关注k8s内是否有LimitRange限制,seata默认启动使用1G内存