spring cloud alibaba之seata1.4 安装记录(上)

  1. 第一步下载seata-1.4服务端 截止2021-1-12 seata最新版本为1.4
    1. 下载地址https://github.com/seata/seata/releases/tag/v1.4.0   (win下载zip linux下载tar.gz)
    2. https://github.com/seata/seata/releases/download/v1.4.0/seata-server-1.4.0.tar.gz 我linux的实际下载地址
  2. 安装服务端
    1. 解压缩 tar -zxvf seata-server-1.4.0.tar.gz
    2. 修改注册中心配置文件(我这里使用spring cloud alibaba的naocs注册中心)
      1. vim ./seata/conf/registry.conf 
      2. 主要修改注册中心地址以及账号密码 主要修改两个地址
  3.   1 registry {
      2   # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
      3   type = "nacos" #修改为nacos
      4   loadBalance = "RandomLoadBalance"
      5   loadBalanceVirtualNodes = 10
      6 
      7   nacos {
      8     application = "seata-server"
      9     serverAddr = "nacos.baidu.cn:80"#修改nacos地址(这里写你自己的)
     10     group = "SEATA_GROUP"
     11     namespace = ""
     12     cluster = "default"
     13     username = "nacos" #nacos账号
     14     password = "nacos" #nacos密码
     15   }
     58  config {
     59   # file、nacos 、apollo、zk、consul、etcd3
     60   type = "nacos" #修改为nacos
     61 
     62   nacos {
     63     serverAddr = "nacos.baidu.cn:80" #修改nacos地址(这里写你自己的)
     64     namespace = ""
     65     group = "SEATA_GROUP"
     66     username = "nacos" #nacos账号
     67     password = "nacos" #nacos密码
     68   }
     69 }

     

  4.  接下来修改mysql配置(我这里使用数据库的形式保存seata的数据)

    1. vim seata/conf/file.conf  需要修改的地方我用#号在后面注明了 (这里需要先创建一个数据库 保存seata的数据脚本我放后面)

      1. 1 ## transaction log store, only used in seata-server
          2 store {
          3   ## store mode: file、db、redis
          4   mode = "db" #这里改成DB
          5 
          6   ## file store property
          7   file {
          8     ## store location dir
          9     dir = "sessionStore"
         10     # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
         11     maxBranchSessionSize = 16384
         12     # globe session size , if exceeded throws exceptions
         13     maxGlobalSessionSize = 512
         14     # file buffer size , if exceeded allocate new buffer
         15     fileWriteBufferCacheSize = 16384
         16     # when recover batch read size
         17     sessionReloadReadSize = 100
         18     # async, sync
         19     flushDiskMode = async
         20   }
         21 
         22   ## database store property
         23   db {
         24     ## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp)/HikariDataSource(hikari) etc.
         25     datasource = "druid"
         26     ## mysql/oracle/postgresql/h2/oceanbase etc.
         27     dbType = "mysql"
         28     driverClassName = "com.mysql.jdbc.Driver" #注意mysql5和8的驱动不一样我使用的是5
         29     url = "jdbc:mysql://127.0.0.1:3307/seata?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=tru" #写你的自己的mysql地址 这里需要先新建一个seata数据库
         30     user = "mysql" #你的mysql用户名
         31     password = "mysql" #你的mysql密码
         32     minConn = 5
         33     maxConn = 100
         34     globalTable = "global_table"
         35     branchTable = "branch_table"
         36     lockTable = "lock_table"
         37     queryLimit = 100
         38     maxWait = 5000
         39   }

         

先建立seata数据库我把脚本放下面 实际地址 https://github.com/seata/seata/blob/1.4.0/script/server/db/mysql.sql

并建立下面三张表(branch_table, global_table, lock_table),创建undo_log表放到业务库中

-- -------------------------------- The script used when storeMode is 'db' --------------------------------
-- the table to store GlobalSession data
CREATE TABLE IF NOT EXISTS `global_table`
(
    `xid`                       VARCHAR(128) NOT NULL,
    `transaction_id`            BIGINT,
    `status`                    TINYINT      NOT NULL,
    `application_id`            VARCHAR(32),
    `transaction_service_group` VARCHAR(32),
    `transaction_name`          VARCHAR(128),
    `timeout`                   INT,
    `begin_time`                BIGINT,
    `application_data`          VARCHAR(2000),
    `gmt_create`                DATETIME,
    `gmt_modified`              DATETIME,
    PRIMARY KEY (`xid`),
    KEY `idx_gmt_modified_status` (`gmt_modified`, `status`),
    KEY `idx_transaction_id` (`transaction_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8;

-- the table to store BranchSession data
CREATE TABLE IF NOT EXISTS `branch_table`
(
    `branch_id`         BIGINT       NOT NULL,
    `xid`               VARCHAR(128) NOT NULL,
    `transaction_id`    BIGINT,
    `resource_group_id` VARCHAR(32),
    `resource_id`       VARCHAR(256),
    `branch_type`       VARCHAR(8),
    `status`            TINYINT,
    `client_id`         VARCHAR(64),
    `application_data`  VARCHAR(2000),
    `gmt_create`        DATETIME(6),
    `gmt_modified`      DATETIME(6),
    PRIMARY KEY (`branch_id`),
    KEY `idx_xid` (`xid`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8;

-- the table to store lock data
CREATE TABLE IF NOT EXISTS `lock_table`
(
    `row_key`        VARCHAR(128) NOT NULL,
    `xid`            VARCHAR(96),
    `transaction_id` BIGINT,
    `branch_id`      BIGINT       NOT NULL,
    `resource_id`    VARCHAR(256),
    `table_name`     VARCHAR(32),
    `pk`             VARCHAR(36),
    `gmt_create`     DATETIME,
    `gmt_modified`   DATETIME,
    PRIMARY KEY (`row_key`),
    KEY `idx_branch_id` (`branch_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8;

 

接下来就是启动服务了 最后加一个 & 不然是当前脚本是以前台方式启动 就是窗口不能关闭 关闭了服务就完了

./bin/seata-server.sh &

这样就算启动成功了  默认 8091端口

去看看注册中心 有没有注册上seata的服务

好 服务端 正式安装完成 启动也OK了。

后续发现一个问题 nacos上找不到seata服务

io.seata.common.exception.FrameworkException: can not connect to services-server.
	at io.seata.core.rpc.netty.NettyClientBootstrap.getNewChannel(NettyClientBootstrap.java:182) ~[seata-all-1.4.0.jar:1.4.0]
	at io.seata.core.rpc.netty.NettyPoolableFactory.makeObject(NettyPoolableFactory.java:58) ~[seata-all-1.4.0.jar:1.4.0]
	at io.seata.core.rpc.netty.NettyPoolableFactory.makeObject(NettyPoolableFactory.java:34) ~[seata-all-1.4.0.jar:1.4.0]

 

上面是官方给出的解决方案 我按提示

求看了下nacos注册的seata服务器地址  注册到127.0.0.1:8091 下面去了

 

我按文档上的说明 

seata/bin/seata-server.sh -p 8091 -h 192.168.50.235 &

-p是指定端口 -h 是指定IP 现在好像还不支持域名 启动后就OK了,如果你是在一台机器上测试 应该不用改这个

 

 

 

——————————————————————————————————————————————————————————————————————————————

 

接下来将配置项注册到naocs上面(这个步骤的意思是把一些seta需要用到的配置项已脚本的形式添加到nacos配置中心 不然一个一个添加 那不的累死了)

nacos是配置+服务发现以及管理中心(这里不展开 nacos只是有空在写)

查看脚本

https://github.com/seata/seata/blob/1.4.0/script/config-center/nacos/nacos-config.sh

这个脚本是添加配置的脚本

#!/usr/bin/env bash
# Copyright 1999-2019 Seata.io Group.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at、
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

while getopts ":h:p:g:t:u:w:" opt
do
  case $opt in
  h)
    host=$OPTARG
    ;;
  p)
    port=$OPTARG
    ;;
  g)
    group=$OPTARG
    ;;
  t)
    tenant=$OPTARG
    ;;
  u)
    username=$OPTARG
    ;;
  w)
    password=$OPTARG
    ;;
  ?)
    echo " USAGE OPTION: $0 [-h host] [-p port] [-g group] [-t tenant] [-u username] [-w password] "
    exit 1
    ;;
  esac
done

if [[ -z ${host} ]]; then
    host=localhost
fi
if [[ -z ${port} ]]; then
    port=8848
fi
if [[ -z ${group} ]]; then
    group="SEATA_GROUP"
fi
if [[ -z ${tenant} ]]; then
    tenant=""
fi
if [[ -z ${username} ]]; then
    username=""
fi
if [[ -z ${password} ]]; then
    password=""
fi

nacosAddr=$host:$port
contentType="content-type:application/json;charset=UTF-8"

echo "set nacosAddr=$nacosAddr"
echo "set group=$group"

failCount=0
tempLog=$(mktemp -u)
function addConfig() {
  curl -X POST -H "${contentType}" "http://$nacosAddr/nacos/v1/cs/configs?dataId=$1&group=$group&content=$2&tenant=$tenant&username=$username&password=$password" >"${tempLog}" 2>/dev/null
  if [[ -z $(cat "${tempLog}") ]]; then
    echo " Please check the cluster status. "
    exit 1
  fi
  if [[ $(cat "${tempLog}") =~ "true" ]]; then
    echo "Set $1=$2 successfully "
  else
    echo "Set $1=$2 failure "
    (( failCount++ ))
  fi
}

count=0
for line in $(cat $(dirname "$PWD")/config.txt | sed s/[[:space:]]//g); do
  (( count++ ))
	key=${line%%=*}
    value=${line#*=}
	addConfig "${key}" "${value}"
done

echo "========================================================================="
echo " Complete initialization parameters,  total-count:$count ,  failure-count:$failCount "
echo "========================================================================="

if [[ ${failCount} -eq 0 ]]; then
	echo " Init nacos config finished, please start seata-server. "
else
	echo " init nacos config fail. "
fi

把上面的脚本保存为nacos-config.sh脚本 可以使用vim nacos-config.sh复制上面的脚本进去

chmod +x nacos-config.sh 添加可执行权限

./nacos-config.sh -h nacos.baidu.cn -p 80 -g SEATA_GROUP -u nacos -w nacos

参数解释

-h nacos注册中心地址

-p nacos注册中心端口

-g nacos中注册的分组(命名空间 分组 dataid 去了解nacos知识点 这里写SEATA_GROUP就行)

-u nacos注册中心账号

-w nacos注册中心密码

 

这里报错了 config.txt: No such file or directory  这个config.txt是真正的配置项(nacos-config.sh 是执行添加配置的脚本 真正的配置项目在这个config.txt文件里面)

[yangjie@localhost seata]$ ./nacos-config.sh -h nacos..cn -p 80 -g SEATA_GROUP -u nacos -w nacos
set nacosAddr=nacos.baidu.cn:80
set group=SEATA_GROUP
cat: /home/yangjie/config.txt: No such file or directory
=========================================================================
 Complete initialization parameters,  total-count:0 ,  failure-count:0 
=========================================================================
 Init nacos config finished, please start seata-server. 

去下载 https://github.com/seata/seata/blob/1.4.0/script/config-center/config.txt 

我把配置文件放在下面

transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.enableClientBatchSendRequest=false
transport.threadFactory.bossThreadPrefix=NettyBoss
transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker
transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler
transport.threadFactory.shareBossWorker=false
transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector
transport.threadFactory.clientSelectorThreadSize=1
transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread
transport.threadFactory.bossThreadSize=1
transport.threadFactory.workerThreadSize=default
transport.shutdown.wait=3
service.vgroupMapping.my_test_tx_group=default
service.default.grouplist=127.0.0.1:8091
service.enableDegrade=false
service.disableGlobalTransaction=false
client.rm.asyncCommitBufferLimit=10000
client.rm.lock.retryInterval=10
client.rm.lock.retryTimes=30
client.rm.lock.retryPolicyBranchRollbackOnConflict=true
client.rm.reportRetryCount=5
client.rm.tableMetaCheckEnable=false
client.rm.sqlParserType=druid
client.rm.reportSuccessEnable=false
client.rm.sagaBranchRegisterEnable=false
client.tm.commitRetryCount=5
client.tm.rollbackRetryCount=5
client.tm.defaultGlobalTransactionTimeout=60000
client.tm.degradeCheck=false
client.tm.degradeCheckAllowTimes=10
client.tm.degradeCheckPeriod=2000
store.mode=file
store.file.dir=file_store/data
store.file.maxBranchSessionSize=16384
store.file.maxGlobalSessionSize=512
store.file.fileWriteBufferCacheSize=16384
store.file.flushDiskMode=async
store.file.sessionReloadReadSize=100
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true
store.db.user=username
store.db.password=password
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
store.redis.host=127.0.0.1
store.redis.port=6379
store.redis.maxConn=10
store.redis.minConn=1
store.redis.database=0
store.redis.password=null
store.redis.queryLimit=100
server.recovery.committingRetryPeriod=1000
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
server.recovery.timeoutRetryPeriod=1000
server.maxCommitRetryTimeout=-1
server.maxRollbackRetryTimeout=-1
server.rollbackRetryTimeoutUnlockEnable=false
client.undo.dataValidation=true
client.undo.logSerialization=jackson
client.undo.onlyCareUpdateColumns=true
server.undo.logSaveDays=7
server.undo.logDeletePeriod=86400000
client.undo.logTable=undo_log
client.log.exceptionRate=100
transport.serialization=seata
transport.compressor=none
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898

 

放到提示的位置 我就放在了 /home/yangjie/config.txt 位置

注册完成后提示

Set metrics.exporterPrometheusPort=9898 successfully 
=========================================================================
 Complete initialization parameters,  total-count:80 ,  failure-count:0 
=========================================================================
 Init nacos config finished, please start seata-server. 

看起来像是让我先注册 在启动seata-server 我们已经启动了 暂时不管 (后续有问题在说)

这里配置也配置也添加到nacos配置中心了

————————————————————————————————————————

后记  后续发现需要修改config.txt的一些配置 这里面的配置项意义后续在研究这里暂时只修改这两个地方

修改完需要重新执行 ./nacos-config.sh -h nacos.baidu.cn -p 80 -g SEATA_GROUP -u nacos -w nacos 脚本配置到nacos的配置中心

修改service.vgroupMapping和数据库地址

 

service.vgroupMapping.my_test_tx_group=default 中的my_test_tx_group 需要改成项目中yml中的配置

 

 

 

 

——————————————————————————————————————————————————————————

接下来就是客户端使用的配置了

好像有点多啊 12点了 明天搭建 客户端使用的时候在写吧,在下一篇写。有点杂乱 就是一个安装笔记,大家将就着看。希望能帮助到其他人。

使用教程链接

https://blog.csdn.net/xt_yangjie/article/details/112555198

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值