seata 各版本实战过程踩坑记

seata 1.2 版本实战过程踩坑记:

一、

seata 各版本实战过程踩坑记_第1张图片

2、如何自己修改源码后打包seata-server

A. 删除 distribution 模块的bin、conf和lib目录。

B. ./mvnw clean install -DskipTests=true(Mac,Linux) 或 mvnw.cmd clean install -DskipTests=true(Win) -P release-seata。

C. 在 distribution 模块的 target 目录下解压相应的压缩包即可。

3、io.seata.codec.protobuf.generated不存在,导致seata server启动不了?

A: 本地执行下: ./mvnw clean install -DskipTests=true (Mac,Linux)

或   mvnw.cmd clean install -DskipTests=true (Win), 参考issues/2438,相关代码在0.8.1已经移除。

4、


Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-11-27 15:47:03.087 ERROR o.s.b.SpringApplication:822 - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'globalTransactionScanner' defined in class path resource [com/alibaba/cloud/seata/GlobalTransactionAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.seata.spring.annotation.GlobalTransactionScanner]: Factory method 'globalTransactionScanner' threw exception; nested exception is io.seata.common.exception.NotSupportYetException: not support register type: null
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)

5、seata 1.2对应 springboot 、springCloud和springCloudAlibaba 版本如下:

 

        org.springframework.boot
        spring-boot-starter-parent
        2.2.5.RELEASE
         
    


        
            com.alibaba.cloud
            spring-cloud-alibaba-seata
            
                
                    io.seata
                    seata-spring-boot-starter
                
            
        
        
            io.seata
            seata-spring-boot-starter
           1.2.0
        


  
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                Hoxton.SR3
                pom
                import
            
            
                com.alibaba.cloud
                spring-cloud-alibaba-dependencies
                2.2.0.RELEASE
                pom
                import
            
        
    

版本必须对应,否则会出现各种问题,比如springboot版本为2.1.7RELEASE(就低了一个版本),其他cloud和alibaba版本不变,会出现潜藏的问题。

如:A服务调用B服务,B服务没有产生分支事务(seata服务中没有生成相应的事务branch_table和锁lock_table数据,B客户端表undo_log没有生成反sql,即事务ID没有传到B服务),这类问题非常难以排查,必须借助官网、源码和对应版本一一核对。我们微服务项目组就出现过类似问题,我排查了一个下午,才得以解决。

类似问题:我配置的client端,单独的都能够成功回滚,并且有seata的xid,但是用feign调用模块时,只有第一个模块能回滚,这是什么问题啊??

这类列出一些最近spring生态相关版本对应:

seata 各版本实战过程踩坑记_第2张图片

目前Spring Cloud Alibaba的版本与Spring BootSpring Cloud版本的兼容关系:

seata 各版本实战过程踩坑记_第3张图片

目前Spring Cloud Alibaba的版本与SentinelNacos 、RocketMQ 、DubboSeata版本的兼容关系:

 seata 各版本实战过程踩坑记_第4张图片

此篇文章可参看,另外注意了解各版本直接的区别!

另外参考文档如下

1.Spring-Cloud-Alibaba版本说明:https://github.com/alibaba/spring-cloud-alibaba/wiki/版本说明

3.SpringCloudAlibaba中文社区地址: spring-cloud-alibaba/README-zh.md at 2.2.x · alibaba/spring-cloud-alibaba · GitHub

4.SpringCloud官方文档: Spring Cloud Gateway

5.查看boot版本方法:

查看版本号

6、最新版本对应

五、连接nacos  :seata 注册到 nacos , 在 seata 时报如下错误:

2020-11-29 01:17:01.969 INFO [main]io.seata.core.rpc.netty.RpcServerBootstrap.start:155 -Server started ... 
2020-11-29 01:17:02.074 ERROR[main]io.seata.server.Server.main:95 -rpcServer init error:ErrCode:500, ErrMsg:failed to req API:/api//nacos/v1/ns/instance after all servers([http://10.130.64.189:8848/]) tried: 

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sun Nov 29 01:17:02 EST 2020
There was an unexpected error (type=Internal Server Error, status=500).
The request was rejected because the URL was not normalized.
java.lang.RuntimeException: ErrCode:500, ErrMsg:failed to req API:/api//nacos/v1/ns/instance after all servers([http://10.130.64.189:8848/]) tried:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sun Nov 29 01:17:02 EST 2020
There was an unexpected error (type=Internal Server Error, status=500).
The request was rejected because the URL was not normalized.
at io.seata.core.rpc.netty.RpcServerBootstrap.start(RpcServerBootstrap.java:160) at io.seata.core.rpc.netty.AbstractRpcRemotingServer.init(AbstractRpcRemotingServer.java:140) at io.seata.core.rpc.netty.RpcServer.init(RpcServer.java:59) at io.seata.server.Server.main(Server.java:93) Caused by: com.alibaba.nacos.api.exception.NacosException: failed to req API:/api//nacos/v1/ns/instance after all servers([http://10.130.64.189:8848/]) tried:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sun Nov 29 01:17:02 EST 2020
There was an unexpected error (type=Internal Server Error, status=500).
The request was rejected because the URL was not normalized.
at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:490) at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:395) at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:391) at com.alibaba.nacos.client.naming.net.NamingProxy.registerService(NamingProxy.java:210) at com.alibaba.nacos.client.naming.NacosNamingService.registerInstance(NacosNamingService.java:207) at com.alibaba.nacos.client.naming.NacosNamingService.registerInstance(NacosNamingService.java:182) at com.alibaba.nacos.client.naming.NacosNamingService.registerInstance(NacosNamingService.java:170) at io.seata.discovery.registry.nacos.NacosRegistryServiceImpl.register(NacosRegistryServiceImpl.java:84) at io.seata.core.rpc.netty.RpcServerBootstrap.start(RpcServerBootstrap.java:156) ... 3 common frames omitted 2020-11-29 01:17:02.114 INFO [ShutdownHook]io.seata.core.rpc.netty.RpcServer.destroy:69 -destroyed rpcServer

原因是因为配置 nacos 地址时, 在后面多加了一个 / 

报错配置:去掉反斜杠就OK了。

seata 各版本实战过程踩坑记_第5张图片

六、 出现这个问题了,怎么解决?

seata1.3.0中 can not register RM,err:can not connect to services-server._Joseph9499的博客-CSDN博客

修改地址:sh seata-server.sh -p 8091 -h 10.130.66.188   即和Linux服务器ip地址保持一致即可!切记!!

七、.Nacos 作为 Seata 配置中心时,项目启动报错找不到服务(win和linux环境)。如何排查,如何处理?

异常:io.seata.common.exception.FrameworkException: can not register RM,err:can not connect to services-server.

排查可能的原因:

  1. 查看nacos配置列表,seata配置是否已经导入成功
  2. 查看nacos服务列表,serverAddr是否已经注册成功
  3. 检查client端的registry.conf里面的namespace,registry.nacos.namespace和config.nacos.namespace填入nacos的命名空间ID,默认"",server端和client端对应,namespace 为public是nacos的一个保留控件,如果您需要创建自己的namespace,最好不要和public重名,以一个实际业务场景有具体语义的名字来命名
  4. nacos上服务列表,serverAddr地址对应ip地址应为seata启动指定ip地址,如:sh seata-server.sh -p 8091 -h 122.51.204.197 -m file
  5. 查看seata/conf/nacos-config.txt 事务分组service.vgroupMapping.trade_group=default配置与项目分组配置名称是否一致
  6. telnet ip 端口 查看端口是都开放,以及防火墙状态

八、编译启动源码时 报错:io.seata.codec.protobuf.generated不存在,导致seata server启动不了?

io.seata.codec.protobuf.generated 源码找到这个微服务删除就OK了。

官方答案:

本地执行下: ./mvnw clean install -DskipTests=true (Mac,Linux) 或 mvnw.cmd clean install -DskipTests=true (Win), 参考issues/2438,相关代码在0.8.1已经移除。

九、启动seata过程出现闪退情况,几种原因和解决方案:

闪退问题参考

十、seata数据库连接超时:

The last packet successfully received from the server was 19,087 millisecond ago

超时解决

方案二

也可以重启seata服务端,属于临时解决方案。

十一、mysql 版本问题:比如seata1.5 版本,默认的数据库连接的jar包是5.x,如果你的数据库是更高版本,可以换一下jar


13:41:44.494 ERROR --- [                     main] i.s.s.s.db.store.LogStoreDataBaseDAO     : query transaction_name size fail, com.mysql.cj.jdbc.Driver
==>
java.sql.SQLException: com.mysql.cj.jdbc.Driver
        at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:679)
        at com.alibaba.druid.pool.DruidDataSource.resolveDriver(DruidDataSource.java:1214)
        at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:883)
        at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1393)

包的替换方式

jar包的替换方式

命令行方式

mysql-connector-java驱动包在5.x版本下,其Driver类在com.mysql.jdbc.Driver目录下;而在6.x版本下,Driver在com.mysql.cj.jdbc.Driver目录下

十二、JDK11 集成seata1.3报错,需要换成JDK1.8

Unrecognized VM option 'CMSParallelRemarkEnabled' Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.

参考方案

十三、seata1.3\1.4\1.5 容易出现关于GC的问题,比如:

seata 各版本实战过程踩坑记_第6张图片

核心是:-Xloggc is deprecated. Will use -Xlog:gc:/usr/local/seata/logs/seata_gc.log instead.

这时候修改JDK版本,如果不能修改JDK版本的话可以修改删除 seata-server.bat 或 seata-server.sh 里关于Xloggc 的 配置,比如:

seata 各版本实战过程踩坑记_第7张图片

然后重启就解决此问题了。

seata 1.4.1启动报:-Xloggc is deprecated_动哒APP的博客-CSDN博客_xloggc无法被识别

十四、服务器空间不足错误:

seata 各版本实战过程踩坑记_第8张图片

可以空间:

可以空间大概1.6G,而seata启动默认需要2G内存。  

解决方案:1、扩大服务器内存;2、适当减小seata启动所需要的内存,怎么减小呢?

seata-server.bat 或 seata-server.sh 里关于启动内存的配置修改一下:

seata 各版本实战过程踩坑记_第9张图片

这里修改成1G试试。 

 十五、本地win环境启动可以连接上数据库或者注册到nacos,但是linux环境,连接超时错误,

1、数据库连接超时:

17:22:23.191 ERROR --- [                     main] com.alibaba.druid.pool.DruidDataSource   : init datasource error, url: jdbc:mysql://38.10.1.9:3306/seata_config?useSSL=false&allowMultiQueries=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
==>
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[na:na]
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[na:na]
        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[na:na]
        at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:456) ~[na:na]
        at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) ~[na:na]
        at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197) ~[na:na]
        at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1644) ~[dru
    at io.seata.server.session.SessionHolder.init(SessionHolder.java:97) ~[seata-server-1.4.2.jar:na]
        at io.seata.server.Server.main(Server.java:80) ~[seata-server-1.4.2.jar:na]
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[na:na]
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[na:na]
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[na:na]
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[na:na]
        at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[na:na]
        at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91) ~[na:na]
        at com.mysql.cj.NativeSession.connect(NativeSession.java:144) ~[na:na]
        at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:956) ~[na:na]
        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826) ~[na:na]
        ... 24 common frames omitted
Caused by: java.net.ConnectException: Connection timed out (Connection timed out)
        at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:na]

2、nacos连接超时:

java.lang.RuntimeException: ErrCode:500, ErrMsg:failed to req API:/nacos/v1/ns/instance after all servers([172.16.176.251:8848]) tried: java.net.SocketException: Connection reset
    at io.seata.core.rpc.netty.NettyServerBootstrap.start(NettyServerBootstrap.java:157) ~[seata-core-1.4.0.jar:na]
    at io.seata.core.rpc.netty.AbstractNettyRemotingServer.init(AbstractNettyRemotingServer.java:55) ~[seata-core-1.4.0.jar:na]
    at io.seata.core.rpc.netty.NettyRemotingServer.init(NettyRemotingServer.java:52) ~[seata-core-1.4.0.jar:na]
    at io.seata.server.Server.main(Server.java:102) ~[classes/:na]
Caused by: com.alibaba.nacos.api.exception.NacosException: failed to req API:/nacos/v1/ns/instance after all servers([172.16.176.251:8848]) tried: java.net.SocketException: Connection reset
    at com.alibaba.nacos.client.naming.net.NamingProxy.reqApi(NamingProxy.java:552) ~[nacos-client-1.3.3.jar:na]
    at com.alibaba.nacos.client.naming.net.NamingProxy.reqApi(NamingProxy.java:491) ~[nacos-client-1.3.3.jar:na]
    at com.alibaba.nacos.client.naming.net.NamingProxy.reqApi(NamingProxy.java:486) ~[nacos-client-1.3.3.jar:na]
    at com.alibaba.nacos.client.naming.net.NamingProxy.registerService(NamingProxy.java:239) ~[nacos-client-1.3.3.jar:na]
    at com.alibaba.nacos.client.naming.NacosNamingService.registerInstance(NacosNamingService.java:200) ~[nacos-client-1.3.3.jar:na]
    at com.alibaba.nacos.client.naming.NacosNamingService.registerInstance(NacosNamingService.java:185) ~[nacos-client-1.3.3.jar:na]
    at io.seata.discovery.registry.nacos.NacosRegistryServiceImpl.register(NacosRegistryServiceImpl.java:85) ~[seata-discovery-nacos-1.4.0.jar:na]
    at io.seata.core.rpc.netty.NettyServerBootstrap.start(NettyServerBootstrap.java:153) ~[seata-core-1.4.0.jar:na]
    ... 3 common frames omitted
<==

原因思考了很久才豁然开朗,两个问题是一个原因,此linux环境配置数据和nacos的ip应该是内网地址!!!而我在本地启动需要外网地址,所以registry.conf 、file.conf 或nacos里配置的数据库信息 换成内网地址就可以了。

十六、linux环境seata服务端启动了,但是本地客户端服务启动时连不上seata服务端,控制台核心错误标识:

0304 register RM failed.

客户端连不上seata服务端,原因是seata服务端没有暴露配置一个外网地址,导致外网连不上内网,即两者不在一个网段。

解决方案:1、启动时指定 外网地址,此外网地址可以是你安装seata服务器的外网地址,同时注意8091端口防火墙不能拦截;

./seata-server.sh -p 8091 -h 能ping通的外网IP(根据实际业务场景选择)

2、同时注意前台启动和后台启动的问题:

#后台启动
nohup ./seata-server.sh -p 8091 -h 能ping通的外网IP(根据实际业务场景选择)>log.out 2>1 &

注意后台启动末尾必须加 &,否则报错:

nohup: ignoring input and appending output to ‘nohup.out’

 日志可以输出到指定文件:

./seata-server.sh >log.out 2>1 &

后续会持续更新,敬请期待!

你可能感兴趣的:(java事务及分布式事务,java)