一、環(huán)境
docker23.0.3
nacos2.2.1
二、拉取seata鏡像
1、查看seata有哪些鏡像
使用如下命令查看seata有哪些鏡像:
docker search seata
可以看到有很多seata鏡像,一般選擇stars最高的那個,就是seataio/seata-server。
2、查看原來有沒有seata鏡像
使用如下命令查看本地鏡像:
docker images
可以看到我這里是有一份seata鏡像的,使用如下命令刪除:
docker rmi -f "IMAGE ID"
這是我的
docker rmi -f 67a654ca2e05
3、拉取最新版本
拉取最新版本的鏡像直接使用如下命令:
docker pull seataio/seata-server
拉取的過程需要點時間,耐心等待即可。
結(jié)束后可以看看拉取的結(jié)果,命令如下:
docker images
4、拉取指定版本
假如我想要拉取 1.6.1 版本的seata,可以使用如下命令:
docker pull seataio/seata-server:1.6.1
同樣,查看一下拉取成功沒有:
docker images
拉取成功,后面就用 1.6.1 版本的鏡像。
三、配置seata
1、創(chuàng)建seata相關(guān)的數(shù)據(jù)庫
數(shù)據(jù)庫腳本地址:
https://github.com/apache/incubator-seata/tree/master/script/server/db
用的是哪個數(shù)據(jù)庫就選擇哪個數(shù)據(jù)庫的腳本,我這里用的mysql的。
創(chuàng)建一個數(shù)據(jù)庫,執(zhí)行腳本即可,我的數(shù)據(jù)庫名為 cj-seata 。
2、創(chuàng)建seata配置文件目錄
我目錄為 /www/wwwroot/changjing/docker/seata ,命令如下:
mkdir -p /www/wwwroot/changjing/docker/seata
3、啟動seata容器
這里只是簡單啟動,為了獲得seata容器最初的配置文件,后面經(jīng)過修改后從宿主機(jī)掛載到容器,命令如下:
docker run -d --name seata -p 7091:7091 seataio/seata-server:1.6.1
4、復(fù)制seata容器下的配置文件到宿主機(jī)
復(fù)制配置文件的命令如下:
docker cp seata:/seata-server/resources /www/wwwroot/changjing/docker/seata
到宿主機(jī)的配置文件目錄看一下
可以看到配置文件已經(jīng)拿下來了,主要修改的就是這個配置文件。
為了防止操作失誤,可以先備份一份,命令如下:
cp application.yml application_bk.yml
5、配置yml文件
修改的是application.yml文件,修改內(nèi)容如下:
這是完整的配置:
# 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地址改為宿主機(jī)地址
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的服務(wù)名
server-addr: 127.0.0.1:8848 # nacos的訪問地址,因為是在docker中,ip地址改為宿主機(jī)地址
group: SEATA_GROUP # nacos的分組
namespace:
cluster: default # 這個歌參數(shù)在每個微服務(wù)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配置
完整內(nèi)容如下:
service.vgroupMapping.ruoyi-system-group=default # 這個在微服務(wù)版的若依中使用seata的服務(wù)中會用到
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命令如下:
docker stop "容器ID或者容器名稱"
這是我的:
docker stop seata
刪除命令如下:
docker rm -f "容器ID或者容器名稱"
這是我的:
docker rm -f seata
啟動命令如下:
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
解釋:
docker run -d --name seata \ -d 表示運(yùn)行在后臺,--name 指定名稱為seata
-p 8091:8091 \ 這是后面需要注冊到nacos的seata服務(wù)端口號
-p 7091:7091 \ 這是seata的客戶端端口號
-e SEATA_IP=127.0.0.1 \ 這是seata注冊到nacos中的 IP ,可以解決Java程序連不上seata客戶端的問題,默認(rèn)為運(yùn)行docker容器的內(nèi)網(wǎng)地址
-v /www/wwwroot/changjing/docker/seata/resources:/seata-server/resources \ seata 配置文件目錄,“:”前為服務(wù)器目錄,“:”后為seata容器中的目錄
seataio/seata-server:1.6.1 指定 docker seata 版本,這里是1.6.1版本
文章來源:http://www.zghlxwxcb.cn/news/detail-856877.html
然后就可以在項目中使用seata了。文章來源地址http://www.zghlxwxcb.cn/news/detail-856877.html
到了這里,關(guān)于docker中安裝seata,以nacos為配置中心的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!