docker中安装seata,以nacos为配置中心

docker中安装seata,以nacos为配置中心

一、环境

docker23.0.3

nacos2.2.1

二、拉取seata镜像

1、查看seata有哪些镜像

使用如下命令查看seata有哪些镜像:

powershell 复制代码
docker search seata

可以看到有很多seata镜像,一般选择stars最高的那个,就是seataio/seata-server。

2、查看原来有没有seata镜像

使用如下命令查看本地镜像:

powershell 复制代码
docker images

可以看到我这里是有一份seata镜像的,使用如下命令删除:

powershell 复制代码
docker rmi -f "IMAGE ID"

这是我的

powershell 复制代码
docker rmi -f 67a654ca2e05

3、拉取最新版本

拉取最新版本的镜像直接使用如下命令:

powershell 复制代码
docker pull seataio/seata-server

拉取的过程需要点时间,耐心等待即可。

结束后可以看看拉取的结果,命令如下:

powershell 复制代码
docker images

4、拉取指定版本

假如我想要拉取 1.6.1 版本的seata,可以使用如下命令:

powershell 复制代码
docker pull seataio/seata-server:1.6.1

同样,查看一下拉取成功没有:

powershell 复制代码
docker images

拉取成功,后面就用 1.6.1 版本的镜像。

三、配置seata

1、创建seata相关的数据库

数据库脚本地址:

https://github.com/apache/incubator-seata/tree/master/script/server/db

用的是哪个数据库就选择哪个数据库的脚本,我这里用的mysql的。

创建一个数据库,执行脚本即可,我的数据库名为 cj-seata 。

2、创建seata配置文件目录

我目录为 /www/wwwroot/changjing/docker/seata ,命令如下:

powershell 复制代码
mkdir -p /www/wwwroot/changjing/docker/seata

3、启动seata容器

这里只是简单启动,为了获得seata容器最初的配置文件,后面经过修改后从宿主机挂载到容器,命令如下:

powershell 复制代码
docker run -d --name seata -p 7091:7091 seataio/seata-server:1.6.1

4、复制seata容器下的配置文件到宿主机

复制配置文件的命令如下:

powershell 复制代码
docker cp seata:/seata-server/resources /www/wwwroot/changjing/docker/seata

到宿主机的配置文件目录看一下

可以看到配置文件已经拿下来了,主要修改的就是这个配置文件。

为了防止操作失误,可以先备份一份,命令如下:

powershell 复制代码
cp application.yml application_bk.yml

5、配置yml文件

修改的是application.yml文件,修改内容如下:

这是完整的配置:

powershell 复制代码
#  Copyright 1999-2019 Seata.io Group.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

server:
  port: 7091

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:
    # support: nacos, consul, apollo, zk, etcd3
    type: nacos
    nacos:
      server-addr: 127.0.0.1:8848   # nacos的访问地址,因为是在docker中,ip地址改为宿主机地址
      namespace:
      group: SEATA_GROUP  # nacos的分组
      username: nacos     # nacos的用户名
      password: nacos     # nacos的密码
      context-path:
      ##if use MSE Nacos with auth, mutex with username/password attribute
      #access-key:
      #secret-key:
      data-id: seata.properties  # nacos中的配置文件名称
  registry:
    # support: nacos, eureka, redis, zk, consul, etcd3, sofa
    type: nacos
    nacos:
      application: seata-server       # seata启动后在nacos的服务名
      server-addr: 127.0.0.1:8848  # nacos的访问地址,因为是在docker中,ip地址改为宿主机地址
      group: SEATA_GROUP   # nacos的分组
      namespace:
      cluster: default     # 这个歌参数在每个微服务seata时会用到
      username: nacos      # nacos的用户名
      password: nacos      # nacos的密码
      context-path:
      ##if use MSE Nacos with auth, mutex with username/password attribute
      #access-key:
      #secret-key:
  store:    
    # support: file 、 db 、 redis
    mode: db
    db:
      datasource: druid
      db-type: mysql
      driver-class-name: com.mysql.jdbc.Driver
      url: jdbc:mysql://127.0.0.1:3306/cj-seata?characterEncoding=utf8&connectTimeout=10000&socketTimeout=30000&autoReconnect=true&useUnicode=true&useSSL=false
      user: root
      password: 123456
      min-conn: 10
      max-conn: 100
      global-table: global_table
      branch-table: branch_table
      lock-table: lock_table
      distributed-lock-table: distributed_lock
      query-limit: 1000
      max-wait: 5000
#  server:
#    service-port: 8091 #If not configured, the default is '${server.port} + 1000'
  security:
    secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
    tokenValidityInMilliseconds: 1800000
    ignore:
      urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login

6、在nacos中增加seata配置

完整内容如下:

powershell 复制代码
service.vgroupMapping.ruoyi-system-group=default   # 这个在微服务版的若依中使用seata的服务中会用到
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/cj-seata?useUnicode=true
store.db.user=root
store.db.password=123456
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

7、重启seata

前面为了拿到配置文件,简单启动了一下seata容器,需要把前面那个停止并删除。

停止seata命令如下:

powershell 复制代码
docker stop "容器ID或者容器名称"

这是我的:

powershell 复制代码
docker stop seata

删除命令如下:

powershell 复制代码
docker rm -f "容器ID或者容器名称"

这是我的:

powershell 复制代码
docker rm -f seata

启动命令如下:

powershell 复制代码
docker run -d --name seata \
-p 8091:8091 \
-p 7091:7091 \
-e SEATA_IP=127.0.0.1 \
-v /www/wwwroot/changjing/docker/seata/resources:/seata-server/resources \
seataio/seata-server:1.6.1

解释:

powershell 复制代码
docker run -d --name seata \                                                       -d 表示运行在后台,--name 指定名称为seata
-p 8091:8091 \                                                                     这是后面需要注册到nacos的seata服务端口号
-p 7091:7091 \                                                                     这是seata的客户端端口号
-e SEATA_IP=127.0.0.1 \                                                            这是seata注册到nacos中的 IP ,可以解决Java程序连不上seata客户端的问题,默认为运行docker容器的内网地址
-v /www/wwwroot/changjing/docker/seata/resources:/seata-server/resources \         seata 配置文件目录,":"前为服务器目录,":"后为seata容器中的目录
seataio/seata-server:1.6.1                                                         指定 docker seata 版本,这里是1.6.1版本

然后就可以在项目中使用seata了。

相关推荐
Leinwin8 小时前
OpenClaw 多 Agent 协作框架的并发限制与企业化规避方案痛点直击
java·运维·数据库
2401_865382508 小时前
信息化项目运维与运营的区别
运维·运营·信息化项目·政务信息化
漠北的哈士奇8 小时前
VMware Workstation导入ova文件时出现闪退但是没有报错信息
运维·vmware·虚拟机·闪退·ova
如意.7598 小时前
【Linux开发工具实战】Git、GDB与CGDB从入门到精通
linux·运维·git
运维小欣8 小时前
智能体选型实战指南
运维·人工智能
yy55278 小时前
Nginx 性能优化与监控
运维·nginx·性能优化
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ9 小时前
Linux 查询某进程文件所在路径 命令
linux·运维·服务器
05大叔11 小时前
网络基础知识 域名,JSON格式,AI基础
运维·服务器·网络
安当加密11 小时前
无需改 PAM!轻量级 RADIUS + ASP身份认证系统 实现 Linux 登录双因子认证
linux·运维·服务器
dashizhi201511 小时前
服务器共享禁止保存到本地磁盘、共享文件禁止另存为本地磁盘、移动硬盘等
运维·网络·stm32·安全·电脑