seata 1.4.1安装与配置
1、到官网下载: https://github.com/seata/seata/releases seata-server-1.4.1.tar.gz
2:解压包 tar -zxvf seata-server-1.4.1.tar.gz 。解压后包名 seata
3:修改config 目录下的文件
file.conf : 配置事物日志的存储方式(mysql , file ,redis 等) 默认是file。 为了高可用我改成 db
(1)mode = "db" // 存储模式修改成db
(2)修改db配置中的属性,数据库我使用的是mysql,连接池使用的是 druid,所以只需要修改数据的 url, user, password 属性即可。
注:mysql是我自己搭的,所以需要我们自己新建数据库seata,并且还需要建表,新建表的脚本在这里:
seata/mysql.sql at develop · seata/seata · GitHub
4:registry.conf 文件里 配置着 seata-server 需要的注册中心的服务, 和 配置中心 的服务地址。 对应着springCloud中就是 eureka 和 配置中心
我的注册中心使用nacos 所以,只需要改nacos的配置,
registry.file.name ="file.config" //file.config 就是上面的配置文件名称
config.file.name="file.config" //file.config 就是上面的配置文件名称
registry:指定注册中心的配置
file : 指定配置中心的配置
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos" # 这里使用nacos注册中心,所以只修改nacos配置即可,下面的file配置也可以删掉
nacos {
application = "seata-server"
serverAddr = "10.0.0.51:8848"
group = "SEATA_GROUP"
namespace = ""
cluster = "default"
username = ""
password = ""
}# file 配置可以删掉
file {
name = "file.conf"
}
}
config {
# file、nacos 、apollo、zk、consul、etcd3
type = "file" # 这里使用的file 配置,也就是本地file文件配置,nacos 也可以删掉
# nacos可以删掉
nacos {
serverAddr = ""
namespace = ""
group = "SEATA_GROUP"
username = ""
password = ""
}
file {
name = "file.conf"
}
}
5:启动服务
命令启动: seata-server.sh -h 127.0.0.1 -p 8091 -m db -n 1
-h: 注册到注册中心的ip
-p: Server rpc 监听端口
-m: 全局事务会话信息存储模式,file、db、redis,优先读取启动参数 (Seata-Server 1.3及以上版本支持redis)
-n: Server node,多个Server时,需区分各自节点,用于生成不同区间的transactionId,以免冲突
-e: 多环境配置参考 http://seata.io/en-us/docs/ops/multi-configuration-isolation.html ()
注:
(1)当使用-e 环境变量时,你需要修改registry.conf 文件名称,比如:registry-test.conf ,否则会抛出异常
Exception in thread "main" io.seata.common.exception.NotSupportYetException: config type can not be null at io.seata.config.ConfigurationFactory.buildConfiguration(ConfigurationFactory.java:106) at io.seata.config.ConfigurationFactory.getInstance(ConfigurationFactory.java:90) at io.seata.server.metrics.MetricsManager.init(MetricsManager.java:49) at io.seata.server.Server.main(Server.java:75) |
(2)启动异常,这个问题是因为我的mysql使用的mysql8.0 版本,在 file.config中 store.db.driverClassName 默认是 com.mysql.jdbc.Driver。 mysql8.0已经是 com.mysql.cj.jdbc.Driver。所以修改驱动即可。
20-08-10 16:51:24.052 INFO --- [reate-278240974] com.alibaba.druid.pool.DruidDataSource : put physical connection to pool failed.
2020-08-10 16:51:24.054 ERROR --- [reate-278240974] com.alibaba.druid.pool.DruidDataSource : create connection holder error
==>
java.sql.SQLException: Could not retrieve transation read-only status server
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:937)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:872)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:904)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:894)
at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3613)
at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3582)
at com.alibaba.druid.pool.DruidConnectionHolder.<init>(DruidConnectionHolder.java:135)
at com.alibaba.druid.pool.DruidConnectionHolder.<init>(DruidConnectionHolder.java:75)
at com.alibaba.druid.pool.DruidDataSource.put(DruidDataSource.java:2229)
at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2547)
Caused by: java.sql.SQLException: Unknown system variable 'tx_read_only'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3835)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3771)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2531)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2489)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1446)
at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3607)
... 5 common frames omitted
<==
(3)这个异常是因为我的registry.conf 中的 config.type="nacos" ,我起了nacos服务,但是nacos 却没有seata的配置信息。 所以改成 config.type="file" 正常了
020-08-10 19:03:18.359 INFO --- [ main] io.seata.config.FileConfiguration : The configuration file used is registry.conf
Exception in thread "main" io.seata.common.loader.EnhancedServiceNotFoundException: not found service provider for : io.seata.server.session.SessionManager caused by java.lang.IllegalStateException: Extension instance(definition: io.seata.common.loader.ExtensionDefinition@607b004b, class: interface io.seata.server.session.SessionManager) could not be instantiated: not found service provider for : io.seata.core.store.db.DataSourceProvider
at io.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader.createNewExtension(EnhancedServiceLoader.java:406)
at io.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader.getExtensionInstance(EnhancedServiceLoader.java:395)
at io.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader.loadExtension(EnhancedServiceLoader.java:360)
at io.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader.load(EnhancedServiceLoader.java:249)
at io.seata.common.loader.EnhancedServiceLoader$InnerEnhancedServiceLoader.access$200(EnhancedServiceLoader.java:190)
at io.seata.common.loader.EnhancedServiceLoader.load(EnhancedServiceLoader.java:82)
at io.seata.server.session.SessionHolder.init(SessionHolder.java:87)
at io.seata.server.Server.main(Server.java:84)
Caused by: io.seata.common.loader.EnhancedServiceNotFoundException: not found service provider for : io.seata.core.store.db.DataSourceProvider
再次启动运行正常。部分启动日志
10:00:57,677 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [WARN] to Logger[ROOT]
10:00:57,677 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [ERROR] to Logger[ROOT]
10:00:57,677 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [CONSOLE] to Logger[ROOT]
10:00:57,677 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
10:00:57,678 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@1e127982 - Registering current configuration as safe fallback point
10:00:57,678 |-INFO in c.q.l.core.rolling.helper.TimeBasedArchiveRemover - Removed 0 Bytes of files
2020-08-11 10:00:57.736 INFO --- [ main] io.seata.config.FileConfiguration : The configuration file used is registry.conf
2020-08-11 10:00:57.749 INFO --- [ main] io.seata.config.FileConfiguration : The configuration file used is file.conf
2020-08-11 10:00:58.179 INFO --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited
2020-08-11 10:00:58.279 INFO --- [ main] i.s.core.rpc.netty.NettyServerBootstrap : Server started, listen port: 8091
可以看到FileConfiguration类打印出来的日志。 使用了 registry.conf 和 file.conf
查看nacos 上seata-server服务是否注册