前提:https://github.com/alibaba/spring-cloud-alibaba/wiki/版本说明
Spring Cloud Alibaba | Spring Cloud | Spring Boot | Nacos | Seata |
2.2.7.RELEASE | Spring Cloud Hoxton.SR12 | 2.3.12.RELEASE | 2.0.3 | 1.3.0 |
背景:seata配合nacos使用,并开启nacos,nacos使用默认的namespace,mysql5.7
seata1.3.0下载地址: https://github.com/seata/seata/releases/tag/v1.3.0
windows、linux下载各自的包,如果在浏览器下载很慢,也可以丢到服务器上下载
wget https://github.com/seata/seata/releases/download/v1.3.0/seata-server-1.3.0.zip
wget https://github.com/seata/seata/archive/refs/tags/v1.3.0.zip
wget https://github.com/seata/seata/releases/download/v1.3.0/seata-server-1.3.0.tar.gz
wget https://github.com/seata/seata/archive/refs/tags/v1.3.0.tar.gz
一、pom.xml文件
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
<exclusions>
<exclusion>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-all</artifactId>
<version>1.3.0</version>
</dependency>
二、nacos中seata配置
seata:
tx-service-group: lanren312_tx_group
service:
vgroup-mapping:
lanren312_tx_group: default
config:
type: nacos
nacos:
server-addr: 192.168.0.103:8848
group: SEATA_GROUP
username: "nacos"
password: "nacos"
registry:
type: nacos
nacos:
server-addr: 192.168.0.103:8848
group: SEATA_GROUP
username: "nacos"
password: "nacos"
三、windows环境配置seata
找到下载的 seata-1.3.0.zip、seata-server-1.3.0.zip,解压 seata-1.3.0、seata-server-1.3.0
1、建库建表
找到 seata-1.3.0\script\server\db\mysql.sql,在首个建表语句前加上
create database IF NOT EXISTS `seata` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
USE `seata`;
将sql跑到数据库中。
2、将配置跑到nacos中
2.1、修改 seata-1.3.0\script\config-center\config.txt
修改后的
service.vgroupMapping.lanren312_tx_group=default
# lanren312_tx_group要和服务nacos配置中的
# seata:
# service:
# vgroupMapping:
# lanren312_tx_group: default 的对应上
store.mode=db
store.db.url=jdbc:mysql://192.168.0.103:3306/seata?useUnicode=true
store.db.user=root
store.db.password=123456
2.2、运行 seata-1.3.0\script\config-center\nacos\nacos-config.sh
seata-1.3.0\script\config-center\nacos 打开cmd窗口,输入命令行
nacos-config.sh -h 192.168.0.103 -p 8848 -u nacos -w nacos
nacos-config.sh脚本里面写了[-h host] [-p port] [-g group] [-t tenant] [-u username] [-w password]
默认会打开git(本机安装过git)窗口,运行 行后面会提示 fail或success,运行完成会关闭。成功就会将配置跑到nacos中,在nacos控制台的配置列表可以看到,group为SEATA_GROUP有97条。
用到的
service.vgroupMapping.*=default
store.mode=db
store.db.* (13个)
插个题外话,截图中的/nacos后面再讲,因为之前我将nacos默认的contextPath=/nacos改成了/admin,后面又改成了/nacos
3、启动seata-server
3.1、修改 seata-server-1.3.0\seata\conf\registry.conf
修改后的
registry {
type = "nacos"
nacos {
application = "seata-server"
serverAddr = "192.168.0.103:8848"
group = "SEATA_GROUP"
# namespace = "" # nacos使用默认的namespace,这里就先注释
cluster = "default"
username = "nacos"
password = "nacos"
}
}
config{
type = "nacos"
nacos {
serverAddr = "192.168.0.103:8848"
# namespace = "" # nacos使用默认的namespace,这里就先注释
group = "SEATA_GROUP"
username = "nacos"
password = "nacos"
}
}
3.2、修改 seata-server-1.3.0\seata\conf\file.conf
修改后的
mode = "db"
url = "jdbc:mysql://192.168.0.103:3306/seata"
user = "root"
password = "123456"
3.3、运行 seata-server-1.3.0\seata\bin\seata-server.bat
需要手动在seata-server-1.3.0文件夹下创建logs\seata_gc.log
seata-server-1.3.0\seata\bin 打开cmd窗口,输入命令行
seata-server.bat -h 192.168.0.103 -p 8091 -m db
-m: 全局事务会话信息存储模式,file、db、redis
seata-server.bat会自动关闭,如果有报错不好排查,在倒数第二行加上cmd,就不会自动关闭了。
启动成功,在nacos的服务列表注册上了seata-server
四、Linux环境配置seata
tar -zxvf seata-1.3.0.tar.gz
tar -zxvf seata-server-1.3.0.tar.gz
1、建库建表
cd /lanren312/seata-1.3.0/script/server/db # 在mysql.sql首个建表语句前加上
create database IF NOT EXISTS `seata` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
USE `seata`;
source /lanren312/seata-1.3.0/script/server/db/mysql.sql;
2、将配置跑到nacos中
2.1、修改 seata-1.3.0/script/config-center/config.txt
cd /lanren312/seata-1.3.0/script/config-center
参照window方法修改config.txt
2.2、运行 seata-1.3.0/script/config-center/nacos/nacos-config.sh
cd /lanren312/seata-1.3.0/script/config-center/nacos
chmod +x nacos-config.sh
./nacos-config.sh -h 192.168.0.103 -p 8848 -u nacos -w nacos
运行成功就会将配置跑到nacos中,在nacos控制台的配置列表可以看到,group为SEATA_GROUP有97条。
3、启动seata-server
参照windows修改 /lanren312/seata-server-1.3.0/conf/registry.conf、file.conf
后台运行方式启动
nohup sh /lanren312/seata-server-1.3.0/bin/seata-server.sh -h 192.168.0.103 -p 8091 -m db >/lanren312/log/seata.log 2>&1 &
参照redis开机自启动的脚本写了一个脚本,启动一直失败,所以改用后台运行的方式启动。
启动正常,通过 ps -ef|grep seata,就可以看到seate已经启动,在nacos的服务列表注册上了seata-server。
如果虚拟机内存不够大,可以调整seata-server.sh中的参数
-Xmx1024m -Xms1024m -Xmn512m -Xss512k
五、碰到的问题
将nacos默认的contextPath=/nacos改成了/admin
1、seata-1.3.0\script\config-center\nacos\nacos-config.sh中的 /nacos要改成 /admin,否则git窗口每行都会提示fail失败
2、seata-server-1.3.0\seata\bin\seata-server.bat 运行失败报错
not found service prodvider for io.seata.core.store.db.datasourceProvider
又没找到在哪里设置,应该是有个位置要将 /nacos 改成 /admin,如有人知道还望指教。文章来源:https://www.toymoban.com/news/detail-522369.html
后将nacos的contextPath设置 /nacos,seata启动正常。文章来源地址https://www.toymoban.com/news/detail-522369.html
到了这里,关于windows、linux部署seata1.3.0的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!