1:下载 seata 编译后的代码包, 下载地址:https://github.com/seata/seata/tags。我下载的是zip的包
2:解压包 gunzip seata-server-1.3.0.zip 。(没有解压命令gunzip的请自行安装),解压后包名 seata
3:修改config 目录下的文件
file.conf : 配置事物日志的存储方式(mysql , file ,redis 等) 默认是file。 为了高可用我改成 db
(1)mode = "db" // 存储模式修改成db
(2)修改db配置中的属性,数据库我使用的是mysql,连接池使用的是 druid,所以只需要修改数据的 url, user, password 属性即可。
注:mysql是我自己搭的,所以需要我们自己新建数据库seata,并且还需要建表,新建表的脚本在这里:https://github.com/seata/seata/blob/develop/script/server/db/mysql.sql
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 、nacos 、eureka、redis、zk、consul、etcd3、sofa type = "nacos" nacos { application = "seata-server" serverAddr = "10.0.0.51:8848" group = "SEATA_GROUP" namespace = "" cluster = "default" username = "" password = "" } file { name = "file.conf" } } config { # file、nacos 、apollo、zk、consul、etcd3 type = "file" nacos { serverAddr = "10.0.0.51:8848" 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 <==
再次启动运行正常。
查看nacos 上seata-server服务是否注册
原文:https://www.cnblogs.com/zhangXingSheng/p/13470848.html