Linux中安装seata

一、准备

1、环境

因为要在 nacos 中配置,要求安装并启动 nacos 。可以参考这篇博客

我的 nacos 版本是 2.2.1 ,演示安装的 seata 版本是 1.6.1 。

2、下载

seata的下载地址如下:

https://seata.apache.org/zh-cn/unversioned/download/seata-server

在这里插入图片描述

开发环境的 seata 的版本为 1.6.1 ,为了保证版本一致,这里也下载 1.6.1 版本。

3、上传到服务器

这里上传到 /usr/local/seata 目录

在这里插入图片描述

4、解压

解压 seata ,使用如下命令:

tar -zxvf seata-server-1.6.1.tar.gz

在这里插入图片描述
在这里插入图片描述

解压后的目录为 seata ,这里将它修改为 seata-1.6.1 ,命令如下:

mv seata seata-1.6.1

在这里插入图片描述

二、配置

配置文件在根目录的 conf 文件夹下,这里是 /usr/local/seata/seata-1.6.1/conf 目录
在这里插入图片描述

1、备份配置文件

先备份一下配置文件,防止误修改,命令如下:

cp application.yml application_bk.yml

在这里插入图片描述

2、导入sql

这里选用 mysql 存储模式,所以导入 mysql 的sql,数据库脚本的地址如下:

https://github.com/apache/incubator-seata/tree/master/script/server/db

先创建一个数据库,名称可以自定义,这里为 seata ,命令如下:

CREATE DATABASE `seata`

然后再执行sql,这是对应的sql:

-- -------------------------------- 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_status_gmt_modified` (`status` , `gmt_modified`),
    KEY `idx_transaction_id` (`transaction_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

-- 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 = utf8mb4;

-- the table to store lock data
CREATE TABLE IF NOT EXISTS `lock_table`
(
    `row_key`        VARCHAR(128) NOT NULL,
    `xid`            VARCHAR(128),
    `transaction_id` BIGINT,
    `branch_id`      BIGINT       NOT NULL,
    `resource_id`    VARCHAR(256),
    `table_name`     VARCHAR(32),
    `pk`             VARCHAR(36),
    `status`         TINYINT      NOT NULL DEFAULT '0' COMMENT '0:locked ,1:rollbacking',
    `gmt_create`     DATETIME,
    `gmt_modified`   DATETIME,
    PRIMARY KEY (`row_key`),
    KEY `idx_status` (`status`),
    KEY `idx_branch_id` (`branch_id`),
    KEY `idx_xid` (`xid`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

CREATE TABLE IF NOT EXISTS `distributed_lock`
(
    `lock_key`       CHAR(20) NOT NULL,
    `lock_value`     VARCHAR(20) NOT NULL,
    `expire`         BIGINT,
    primary key (`lock_key`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0);
INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0);

如果是AT模式,AT模式也是seata建议的模式,需要加上这张事务回滚表,具体sql如下:

DROP TABLE IF EXISTS `undo_log`;
CREATE TABLE `undo_log`  (
  `branch_id` bigint(0) NOT NULL COMMENT 'branch transaction id',
  `xid` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'global transaction id',
  `context` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'undo_log context,such as serialization',
  `rollback_info` longblob NOT NULL COMMENT 'rollback info',
  `log_status` int(0) NOT NULL COMMENT '0:normal status,1:defense status',
  `log_created` datetime(6) NOT NULL COMMENT 'create datetime',
  `log_modified` datetime(6) NOT NULL COMMENT 'modify datetime',
  UNIQUE INDEX `ux_undo_log`(`xid`, `branch_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'AT transaction mode undo table' ROW_FORMAT = Dynamic;

在这里插入图片描述

3、修改配置前

主要修改这部分:

在这里插入图片描述

这是原来的完整配置:

#  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.

server:
  port: 7091

spring:
  application:
    name: seata-server

logging:
  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: file
  registry:
    # support: nacos, eureka, redis, zk, consul, etcd3, sofa
    type: file
  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

4、修改配置后

已经在修改的地方做好了注释,初次配置不建议跳过

#  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.

server:
  port: 7091

spring:
  application:
    name: seata-server

logging:
  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:
      server-addr: 127.0.0.1:8848   # nacos的访问地址,因为是在docker中,ip地址改为宿主机地址
      namespace:
      group: SEATA_GROUP  # nacos的分组
      username: nacos     # nacos的用户名
      password: nacos     # nacos的密码
      context-path:
      ##if use MSE Nacos with auth, mutex with username/password attribute
      #access-key:
      #secret-key:
      data-id: seata.properties  # nacos中的配置文件名称
  registry:
    # support: nacos, eureka, redis, zk, consul, etcd3, sofa
    type: nacos
    nacos:
      application: seata-server       # seata启动后在nacos的服务名
      server-addr: 127.0.0.1:8848  # nacos的访问地址,如果是在docker中,ip地址改为宿主机地址
      group: SEATA_GROUP   # nacos的分组
      namespace:
      cluster: default     # 这个参数在每个微服务seata时会用到
      username: nacos      # nacos的用户名
      password: nacos      # nacos的密码
      context-path:
      ##if use MSE Nacos with auth, mutex with username/password attribute
      #access-key:
      #secret-key:
  store:
    # support: file 、 db 、 redis
    mode: db
    db:
      datasource: druid
      db-type: mysql
      driver-class-name: com.mysql.jdbc.Driver
      url: jdbc:mysql://127.0.0.1:3306/seata?characterEncoding=utf8&connectTimeout=10000&socketTimeout=30000&autoReconnect=true&useUnicode=true&useSSL=false
      user: root
      password: 123456
      min-conn: 10                # db 模式数据库初始连接数
      max-conn: 100               # db 模式数据库最大连接数
      global-table: global_table  # db 模式全局事务表名
      branch-table: branch_table  # db 模式分支事务表名
      lock-table: lock_table      # db 模式全局锁表名
      distributed-lock-table: distributed_lock  # db 模式 Sever 端事务管理全局锁存储表名
      query-limit: 1000    # db 模式查询全局事务一次的最大条数,默认100
      max-wait: 5000   # db 模式获取连接时最大等待时间,默认5000
#  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

5、在nacos中配置

需要在 nacos 中创建 SEATA_GROUP 分组,增加名为 seata.properties 的配置:

在这里插入图片描述

具体配置如下:

store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true
store.db.user=root
store.db.password=123456
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

三、使用

1、启动

启动 seata ,需要到根目录下的 bin 目录,这里是 /usr/local/seata/seata-1.6.1/bin ,使用如下命令:

sh seata-server.sh

在这里插入图片描述

然后到 nacos 中查看:

在这里插入图片描述

在浏览器中访问

在这里插入图片描述

可以看到 seata 已经启动。

2、关闭

因为 seata 没有提供关闭的命令,至少我这版本没有,先查询 seata 的进程id,命令如下:

ps -ef | grep seata

在这里插入图片描述

然后再杀掉这个进程,命令如下:

kill -9 370711

在这里插入图片描述

回到 nacos 发现 seata 服务也消失了

在这里插入图片描述

成功关闭。

  • 13
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 1. 下载seata安装包,解压到指定目录。 2. 配置seata的相关参数,包括注册心地址、事务日志存储方式等。 3. 启动seata服务,可以使用命令行启动或者使用系统服务管理工具启动。 4. 在应用程序集成seata客户端,使用seata提供的API进行分布式事务管理。 5. 测试分布式事务功能,确保seata的正确安装和配置。 ### 回答2: Seata 是一个分布式事务解决方案,能够让用户在分布式环境实现 ACID 事务。对于需要保证数据一致性的分布式系统来说,Seata 是一个非常有价值的工具。下面我们来看一下如何在 Linux 操作系统安装 Seata。 一、安装 Java 在安装 Seata 之前,我们需要先安装 Java 运行环境。可以通过以下命令检查本地是否已经安装 Java: ```bash java -version ``` 如果电脑上没有安装 Java,可以使用如下命令安装: ```bash sudo apt install openjdk-8-jdk-headless ``` 二、下载 Seata 可以前往 Seata 官网(https://seata.io/zh-cn/)下载最新版的 Seata。在下载结束后,使用如下命令解压: ```bash tar -zxvf seata-server-1.4.2.tar.gz ``` 三、启动 Seata Server 解压后,在 seata/conf 文件夹下编辑 file.conf 文件,需要注意的是,file.conf 以下三个配置项需要按照实际情况进行修改: ```properties # 日志存放路径 store.file.root.dir = file_store/data # TC 服务端地址 store.tc.service = 172.16.16.16:8091 # 日志刷盘批量大小 store.file.flushatmost = 1 ``` 编辑完 file.conf 文件后,可以启动 Seata Server。进入 seata/bin 目录,使用如下命令启动 Seata: ```bash sh seata-server.sh -p 8091 -h 172.16.16.16 ``` 其 `-p` 参数指定端口,`-h` 参数指定服务器 IP 地址。如果 IP 地址不好确定,可以使用 `0.0.0.0` 代替。 以上是在 Linux安装 Seata 的步骤。安装完毕后,建议使用 Seata 官方提供的示例代码进行验证。Seata 的文档十分详细,包括了使用示例和配置选项等,希望这篇文章能对你有所帮助。 ### 回答3: 什么是SeaT? SeaT是一个面向游戏社区的开源Web应用程序,它主要用于管理和控制各种类型的在线游戏服务器。它支持多语言和多平台,并具有丰富的功能,如服务器和玩家管理、服务器状态检测、服务器和玩家统计、成员和组织管理等等。由于其灵活性、稳定性和安全性等因素,在开发人员和游戏管理员非常受欢迎,特别是在Linux操作系统上。以下是有关在Linux安装SeaT的详细步骤。 步骤 1:准备工作 在开始安装Seata之前,您需要安装以下先决条件: •Apache Web服务器 • PHP编程语言(建议安装PHP 7.0或以上版本) •MySQL数据库 •Git版本控制 命令 步骤 2:下载SeaT 访问Github的SeaT存储库以查找最新版本,使用git clone命令将其下载到本地计算机: $ git clone https://github.com/Seat-Web/seat.git 然后切换至Seat目录并使用composer进行依赖性安装: $ cd seat $ composer install 步骤 3:进行配置 接下来,您需要为Seat配置Web服务器和数据库信息。将seat.env.example文件复制到seat.env文件: $ cp .env.example .env 使用nano或vim编辑器打开seat.env文件并根据您的需求进行编辑: APP_ENV=production APP_DEBUG=false APP_URL=https://your-sever-domain DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=seat DB_USERNAME=seat DB_PASSWORD=you-password 然后运行以下命令以生成应用程序密钥: $ php artisan key:generate 步骤 4:设置数据库 在配置Seat之后,请创建MySQL数据库并授予seat 用户对数据库的访问权限: $ mysql -u root -p > CREATE DATABASE seat; > GRANT ALL ON seat.* TO 'seat'@'localhost' IDENTIFIED BY 'you-password'; > FLUSH PRIVILEGES; 步骤 5:运行数据库迁移 将Seat数据库所需的表和关系迁移至MySQL数据库: $ php artisan migrate 如果上述命令执行成功,将输出“Migrating: 20xx_xx_xx_xxxxxx_create_XXXXX_table” 步骤 6:启用队列 在运行Seat应用程序之前,请在服务器上启动队列。您可以使用以下命令完成此操作: $ php artisan horizon 步骤 7:启动Web服务器 最后,启动Apache Web服务器以运行Seat应用程序: $ sudo service apache2 start 现在,您可以使用Web浏览器访问Seat Web应用程序,并根据需要进行用户配置和服务器管理。 总结 安装Seat通常是相当简单的,但需要注意许多细节和依赖关系。在Linux安装Seata的过程,首先需要完成先决条件的安装,然后下载最新版本的Seat,编辑和配置相关文件并启用队列。最后,您应启动Web服务器并使用浏览器访问Seat应用程序以确保其能够正常工作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值