docker安装seata单节点的详细教程

一、环境部署

1、在自己的数据库新建seata数据库

2、利用seata官方提供的seata数据库sql脚本创建所需数据库seata以及表,脚本地址如下:

seata/mysql.sql at 1.4.1 · seata/seata · GitHub

3、查看docker官方镜像仓库版本

4、拉取seata安装镜像

docker pull seataio/seata-server:1.6.0

我这里拉取的是1.6.0版本的。

5、创建/seata目录

mkdir /seata

docker安装seata单节点的详细教程_第1张图片

6、在seata目录下创建conf目录

mkdir conf

如图

7、创建file.conf文件并编辑

touch file.conf

然后

vim file.conf

##transaction log store, only used in seata-server
store {
  ## store mode: file、db、redis
  mode = "db" ## 默认是file
  ## file store property
  file {
    ## store location dir
    dir = "sessionStore"
    # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
    maxBranchSessionSize = 16384
    # globe session size , if exceeded throws exceptions
    maxGlobalSessionSize = 512
    # file buffer size , if exceeded allocate new buffer
    fileWriteBufferCacheSize = 16384
    # when recover batch read size
    sessionReloadReadSize = 100
    # async, sync
    flushDiskMode = async
  }
  ##database store property
db {
    datasource = "druid"
    ## mysql/oracle/postgresql/h2/oceanbase etc.
    dbType = "mysql"
    driverClassName = "com.mysql.cj.jdbc.Driver"
    url = "jdbc:mysql://数据库地址:端口/seata?serverTimezone=GMT%2B8"
    user = "数据库名字"
    password = "数据库密码"
    minConn = 5
    maxConn = 30
    globalTable = "global_table"
    branchTable = "branch_table"
    lockTable = "lock_table"
    queryLimit = 100
    maxWait = 5000
  }

保存并退出

:wq!

8、创建registry.conf文件并编辑

touch  registry.conf

并编辑

vim registry.conf 

##transaction log store, only used in seata-server
store {
  ## store mode: file、db、redis
  mode = "db" ## 默认是file

  ## file store property  
file {
    ## store location dir
    dir = "sessionStore"
    maxBranchSessionSize = 16384
    # globe session size , if exceeded throws exceptions
    maxGlobalSessionSize = 512
    # file buffer size , if exceeded allocate new buffer
    fileWriteBufferCacheSize = 16384
    # when recover batch read size
   }
}
#服务,将type从file改成nacos,将seata服务配置进nacos
registry {
  type = "nacos"
  nacos {
    application = "seata-server"
    serverAddr = "ip:8848"
    group = "SEATA_GROUP"
    namespace = "seata_namespace"
    cluster = "default"
    username = "用户名"
    password = "密码"
  }
}
config {
  # file、nacos 、apollo、zk、consul、etcd3
  type = "file"

  nacos {
    serverAddr = "ip:8848"
    namespace = "seata_namespace"
    group = "SEATA_GROUP"
    cluster = "default"
    username = "用户名"
    password = "密码"
  }

  file {
    name = "file.conf"
  }
}

保存并退出

:wq!

9、在seata目录下创建config.txt配置文件

touch config.txt

&

vim comfig.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.dekun_my_gyl_group=default
service.default.grouplist=服务器ip: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.degradeCheck=false
client.tm.degradeCheckAllowTimes=10
client.tm.degradeCheckPeriod=2000
store.mode=db
store.file.dir=seata/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.cj.jdbc.Driver
store.db.url=jdbc:mysql://数据库链接地址:端口/seata?useUnicode=true
store.db.user=用户名
store.db.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

 10、创建并编辑nacos-config.sh文件

touch nacos-config.sh

&

vim nacos-config.sh

#!/usr/bin/env bash 
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

 注意:config.txt与nacos-config.sh文件不能在同一个目录下,否则执行不了。本文config.txt文件放在seata目录下,nacos-config.sh在seata/bin目录下

11、进入bin目录运行nacos-config.sh文件

sh nacos-config.sh -h 127.0.0.1 -p 8848 -g SEATA_GROUP -t seata_namespace_id -u nacos -w nacos
 

上面的ip换成自己实际的nacos服务器ip, nacos的账户密码按实际替换,回车执行,完成后会在nacos指定namespace下创建对应配置。如图:

docker安装seata单节点的详细教程_第2张图片

看到上面的的列表表示执行成功

12、启动seata

docker run -d --name seata-server --restart=always -h 120.79.32.155 -p 8091:8091 -e SEATA_IP=120.79.32.155 -v /seata/conf/registry.conf:/seata-server/resources/registry.conf -v /seata/logs:/root/logs seataio/seata-server:1.6.0

13、seata注册到nacos

 13.1、从运行的seata镜像中复制文件到seata目录下进行修改

docker cp seata-server:/seata-server/resources/application.yml /seata

  13.2、编辑application.yml文件

vim application.yml

config: classpath:logback-spring.xml
  file:
    path: ${user.home}/logs/seata
  extend:
    logstash-appender:
      destination: 127.0.0.1:4560
    kafka-appender:
      bootstrap-servers: 127.0.0.1:9092
      topic: logback_to_logstash

console:
  user:
    username: seata
    password: seata

seata:
  config:
    # support: nacos, consul, apollo, zk, etcd3
    type: nacos
    nacos:
      application: seata-server
      server-addr: 120.79.32.155:8848
      namespace: seata_namespace
      group: SEATA_GROUP
      username: dekun_dev_test
      password: dk_Etms_Mg
  registry:
    # support: nacos, eureka, redis, zk, consul, etcd3, sofa
    type: nacos
    nacos:
      application: seata-server
      server-addr: 120.79.32.155:8848
      namespace: seata_namespace
      group: SEATA_GROUP
      username: dekun_dev_test
      password: dk_Etms_Mg
    #  store:
    # support: file 、 db 、 redis
    #    mode: file
#  server:
#    service-port: 8091 #If not configured, the default is '${server.port} + 1000'
  security:
    secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
    tokenValidityInMilliseconds: 1800000
    ignore:
      urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login

 编辑完成后复制回docker部署的seata容器中

docker cp application.yml seata-server:/seata-server/resources

重启seata

docker restart 容器id 

二、项目应用

1、配置bootstrap.yml

seata:
  enabled: true
  enable-auto-data-source-proxy: false
  tx-service-group: dekun_my_gyl_group
  service:
    disable-global-transaction: false
    vgroup-mapping:
      dekun_my_gyl_group: default
  #    grouplist:
  #      default: ip:8091
  registry:
    type: nacos
    nacos:
      application: seata-server
      server-addr: ip:8848
      namespace: seata_namespace
      group: SEATA_GROUP
      username: dekun_dev_test
      password: dk_Etms_Mg
      # 可选  默认
      cluster: default
  config:
    nacos:
      application: seata-server
      server-addr: ip:8848
      namespace: seata_namespace
      group: SEATA_GROUP
      username: dekun_dev_test
      password: dk_Etms_Mg
#  client:
#    rm:
#      report-success-enable: false

启动成功

docker安装seata单节点的详细教程_第3张图片

 

你可能感兴趣的:(中间件专栏,容器)