部署 seata 連接 nacos


 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 : 指定配置中心的配置


配置文件太長,精簡之后的配置

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服務是否注冊

 

 config.type="nacos" 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM