日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Docker安裝Seata分布式鎖

作者:Abraxs 更新時間: 2022-07-22 編程語言

零:相關問題解決

一般容易忘比如云服務器安全組的開放
docker ps 查看運行中的容器

        [root@VM-12-7-centos resources]# docker ps 
CONTAINER ID   IMAGE                         COMMAND                  CREATED        STATUS      PORTS                                                  NAMES
406794a01181   seataio/seata-server:1.4.2    "java -Djava.securit…"   7 days ago     Up 7 days   0.0.0.0:8091->8091/tcp                                 seata-server
a374ab5f1856   nacos/nacos-server:1.3.1      "bin/docker-startup.…"   8 days ago     Up 7 days   0.0.0.0:8848->8848/tcp                                 nacos
0059b1e18df8   zookeeper:3.7.0               "/docker-entrypoint.…"   3 weeks ago    Up 8 days   2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, 8080/tcp   zookeeper
a4d77b20c42d   xuxueli/xxl-job-admin:2.1.2   "sh -c 'java -jar /a…"   6 months ago   Up 8 days   0.0.0.0:8010->8080/tcp                                 xxl-job-admin

查看日志
docker logs 406794a01181

09:59:45.280  INFO --- [ettyServerNIOWorker_1_3_4] i.s.c.r.n.AbstractNettyRemotingServer    : channel exx:Adjusted frame length exceeds 8388608: 539959368 - discarded,channel:[id: 0x33f60f16, L:/172.17.0.4:8091 - R:/180.163.220.3:38428]
09:59:45.280  WARN --- [ettyServerNIOWorker_1_3_4] io.netty.channel.DefaultChannelPipeline  : An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
==>

報錯信息是netty 解碼大小相關,百度上搜了一下有說是版本號的,也有說是沒有注冊到nacos相關原因;
宿主機相關配置檢查了一下是沒問題的;
然后到容器里查看配置,如下;
發現并沒有生效,估計是中間運行了幾次容器,容器掛載目錄可能失效了,手動修改一下:
registry和file配置文件

[root@VM-12-7-centos resources]# docker exec -it 406794a01181 /bin/sh
/seata-server # ls 
classes       libs          resources     sessionStore
/seata-server # cd resources/
/seata-server/resources # ks 
/bin/sh: ks: not found
/seata-server/resources # ks 
/bin/sh: ks: not found
/seata-server/resources # ls 
META-INF           README-zh.md       README.md          file.conf          file.conf.example  io                 logback            logback.xml        registry.conf
/seata-server/resources # vi registry.conf 

registry {
  # file ...nacos ...eureka...redis...zk...consul...etcd3...sofa
  type = "file"

  nacos {
    application = "seata-server"

保存重啟seata和nacos服務,查看日志和nacos客戶端,已經有了剛剛的服務
在這里插入圖片描述

一:拉取Seata鏡像

docker pull seataio/seata-server:1.4.2

二:創建Seata容器并指定掛載目錄

docker run -d \
--restart always \
--name seata-server \
-p 8091:8091 \
-v /docker-data/seata:/seata-server \
-e SEATA_IP=IP-ADDRESS \
-e SEATA_IP=101.****.62 \
-e SEATA_PORT=8091 \
seataio/seata-server:1.4.2


docker run -d \
--restart always \
--name seata-server \
-p 8091:8091 \
-v /docker-data/seata:/seata-server \
-e SEATA_IP=101.****.62 \
-e SEATA_PORT=8091 \
seataio/seata-server:1.4.2

三:拉取Nacos鏡像

docker pull nacos/nacos-server -----拉取nacos鏡像

四:創建Nacos容器

大致能運行打開;
docker  run \
--name nacos -d \
-p 8848:8848 \
--privileged=true \
--restart=always \
-e JVM_XMS=256m \
-e JVM_XMX=256m \
-e MODE=standalone \
-e PREFER_HOST_MODE=hostname \
nacos/nacos-server

五:創建Seata相關表

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for undo_log
-- ----------------------------
DROP TABLE IF EXISTS `undo_log`;
CREATE TABLE `undo_log`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `branch_id` bigint(20) NOT NULL,
  `xid` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `context` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `rollback_info` longblob NOT NULL,
  `log_status` int(11) NOT NULL,
  `log_created` datetime(0) NOT NULL,
  `log_modified` datetime(0) NOT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `ux_undo_log`(`xid`, `branch_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = 'seata操作記錄表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for branch_table
-- ----------------------------
DROP TABLE IF EXISTS `branch_table`;
CREATE TABLE `branch_table`  (
  `branch_id` bigint(20) NOT NULL,
  `xid` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `transaction_id` bigint(20) NULL DEFAULT NULL,
  `resource_group_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `resource_id` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `branch_type` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `status` tinyint(4) NULL DEFAULT NULL,
  `client_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `application_data` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `gmt_create` datetime(6) NULL DEFAULT NULL,
  `gmt_modified` datetime(6) NULL DEFAULT NULL,
  PRIMARY KEY (`branch_id`) USING BTREE,
  INDEX `idx_xid`(`xid`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = 'seata分支事務表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for global_table
-- ----------------------------
DROP TABLE IF EXISTS `global_table`;
CREATE TABLE `global_table`  (
  `xid` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `transaction_id` bigint(20) NULL DEFAULT NULL,
  `status` tinyint(4) NOT NULL,
  `application_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `transaction_service_group` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `transaction_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `timeout` int(11) NULL DEFAULT NULL,
  `begin_time` bigint(20) NULL DEFAULT NULL,
  `application_data` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `gmt_create` datetime(0) NULL DEFAULT NULL,
  `gmt_modified` datetime(0) NULL DEFAULT NULL,
  PRIMARY KEY (`xid`) USING BTREE,
  INDEX `idx_gmt_modified_status`(`gmt_modified`, `status`) USING BTREE,
  INDEX `idx_transaction_id`(`transaction_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = 'seata全局事務表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for lock_table
-- ----------------------------
DROP TABLE IF EXISTS `lock_table`;
CREATE TABLE `lock_table`  (
  `row_key` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `xid` varchar(96) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `transaction_id` bigint(20) NULL DEFAULT NULL,
  `branch_id` bigint(20) NOT NULL,
  `resource_id` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `table_name` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `pk` varchar(36) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `gmt_create` datetime(0) NULL DEFAULT NULL,
  `gmt_modified` datetime(0) NULL DEFAULT NULL,
  PRIMARY KEY (`row_key`) USING BTREE,
  INDEX `idx_branch_id`(`branch_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = 'seata鎖表' ROW_FORMAT = Dynamic;

SET FOREIGN_KEY_CHECKS = 1;

六:編輯Seata和Nacos相關配置

  編輯配置相關文件 vim registry.conf
  編輯以下兩部分:
  注冊中心相關指向;
 registry {
      type = "nacos"
      nacos {
    		#  應用名
			application = "seata-server"
			#  nacos ip 地址
			serverAddr = "101.****:8848"
			#  nacos創建的分組
			group = "SEATA_GROUP"
			#  nacos 創建的命名空間名
			namespace = "seata-naming"
			cluster = "default"
			#   nacos登錄的賬號和密碼
			username = "nacos"
			password = "nacos"
  }
  config {
	  # file、nacos 、apollo、zk、consul、etcd3
	  type = "nacos"
	  nacos {
            #  nacos ip 地址
		    serverAddr = "101.****:8848"
		    #  nacos 創建的命名空間名
		    namespace = "seata-naming"
		    #  nacos創建的分組
		    group = "SEATA_GROUP"
		    #   nacos登錄的賬號和密碼
		    username = "nacos"
		    password = "nacos"
		    #   nacos配置相當于主鍵id,唯一標識配置
		    dataId = "seataServer.properties"
	  }
	  file {
	     name = "file.conf"
	  }
  }
  編輯Seata存儲數據的相關配置文件 vim file.conf;
  這里面連接的庫就是上面執行腳本的庫;
## transaction log store, only used in seata-server
store {
  ## store mode: file、db、redis
  mode = "db"
  ## database store property
  db {
    ## the implement of javax.sql.DataSource, such as       DruidDataSource(druid)/BasicDataSource(dbcp)/HikariDataSource(hikari) etc.
    datasource = "druid"
    ## mysql/oracle/postgresql/h2/oceanbase etc.
    dbType = "mysql"
    driverClassName = "com.mysql.cn.jdbc.Driver"
    ## if using mysql to store the data, recommend add rewriteBatchedStatements=true in jdbc connection param
    url = "jdbc:mysql://182.****:3307/order-info"
    user = "****"
    password = "****"
    minConn = 5
    maxConn = 100
    globalTable = "global_table"
    branchTable = "branch_table"
    lockTable = "lock_table"
    queryLimit = 100
    maxWait = 5000
  }
}

七:進入Nacos配置Seata相關信息

    根據上一步注釋可以看到需要修改補充哪些字段屬性;
    先在配置管理里面進行相應操作:
    填寫:Data Id = seataServer.properties
               GROUP = SEATA_GROUP

在這里插入圖片描述
在這里插入圖片描述

    配置內容:
    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.storage-service-group=default
	service.vgroupMapping.order-service-group=default
	service.vgroupMapping.account-service-group=default
	service.default.grouplist=192.168.23.3: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.tableMetaCheckerInterval=60000
	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=db
	store.publicKey=
	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.cj.jdbc.Driver
	store.db.url=jdbc:mysql://182.****:3307/order-info?useUnicode=true&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai
	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.mode=single
	store.redis.single.host=127.0.0.1
	store.redis.single.port=6379
	store.redis.sentinel.masterName=
	store.redis.sentinel.sentinelHosts=
	store.redis.maxConn=10
	store.redis.minConn=1
	store.redis.maxTotal=100
	store.redis.database=0
	store.redis.password=
	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.undo.compress.enable=true
	client.undo.compress.type=zip
	client.undo.compress.threshold=64k
	log.exceptionRate=100
	transport.serialization=seata
	transport.compressor=none
	metrics.enabled=false
	metrics.registryType=compact
	metrics.exporterList=prometheus
	metrics.exporterPrometheusPort=9898

創建命名空間:
用于后面區分唯一服務和配置 ->
命名空間ID(不填則自動生成):seata-naming
命名空間名:seata
描述:desc
在這里插入圖片描述

八:容器啟動

     docker stop seata-container-id 停掉
     docker start seata-container-id 開啟
     
     docker ps 查看運行中的容器
     docker logs containerid 啟動打印日志

    我遇到的問題放到了開頭 第0點

原文鏈接:https://blog.csdn.net/Abraxs/article/details/125762857

欄目分類
最近更新