五、安装Seata

GitEgg...大约 2 分钟环境准备环境准备安装使用Seata

1. 我们将服务安装到 CentOS 环境上,所以这里我们下载 tar.gz 版本,下载地址:https://github.com/seata/seata/releasesopen in new window

2. 上传到 CentOS 服务器,执行解压命令

tar -zxvf seata-server-1.4.1.tar.gz

3. 下载 Seata 需要的 SQL 脚本,新建 Seata 数据库并将需要使用的数据库脚本 seata-1.4.1\seata-1.4.1\script\server\db\mysql.sql 刷进去

4. 修改 Seata 配置文件,将 seata 服务端的注册中心和配置中心设置为 Nacos

vi /bigdata/soft_home/seata/conf/registry.conf
registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "nacos"
  loadBalance = "RandomLoadBalance"
  loadBalanceVirtualNodes = 10

  nacos {
    application = "seata-server"
    serverAddr = "127.0.0.1:8848"
    group = "SEATA_GROUP"
    namespace = ""
    cluster = "default"
    username = "nacos"
    password = "nacos"
  }
  eureka {
    serviceUrl = "http://localhost:8761/eureka"
    application = "default"
    weight = "1"
  }
  redis {
    serverAddr = "localhost:6379"
    db = 0
    password = ""
    cluster = "default"
    timeout = 0
  }
  zk {
    cluster = "default"
    serverAddr = "127.0.0.1:2181"
    sessionTimeout = 6000
    connectTimeout = 2000
    username = ""
    password = ""
  }
  consul {
    cluster = "default"
    serverAddr = "127.0.0.1:8500"
  }
  etcd3 {
    cluster = "default"
    serverAddr = "http://localhost:2379"
  }
  sofa {
    serverAddr = "127.0.0.1:9603"
    application = "default"
    region = "DEFAULT_ZONE"
    datacenter = "DefaultDataCenter"
    cluster = "default"
    group = "SEATA_GROUP"
    addressWaitTime = "3000"
  }
  file {
    name = "file.conf"
  }
}

config {
  # file、nacos 、apollo、zk、consul、etcd3
  type = "nacos"

  nacos {
    serverAddr = "127.0.0.1:8848"
    namespace = ""
    group = "SEATA_GROUP"
    username = "nacos"
    password = "nacos"
  }
  consul {
    serverAddr = "127.0.0.1:8500"
  }
  apollo {
    appId = "seata-server"
    apolloMeta = "http://192.168.1.204:8801"
    namespace = "application"
    apolloAccesskeySecret = ""
  }
  zk {
    serverAddr = "127.0.0.1:2181"
    sessionTimeout = 6000
    connectTimeout = 2000
    username = ""
    password = ""
  }
  etcd3 {
    serverAddr = "http://localhost:2379"
  }
  file {
    name = "file.conf"
  }
}

5. 在 Nacos 添加 Seata 配置文件,修改 script/config-center/config.txt,将 script 目录上传到 CentOS 服务器,执行 script/config-center/nacos/nacos-config.sh 命令

service.vgroupMapping.gitegg_seata_tx_group=default

service.default.grouplist=127.0.0.1:8091

store.mode=db

store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true
store.db.user=root
store.db.password=root
chmod 777 nacos-config.sh

sh nacos-config.sh -h 127.0.0.1 -p 8848

6. 在 CentOS 上进去到 Seata 安装目录的 bin 目录执行命令,启动 Seata 服务端

nohup ./seata-server.sh -h 127.0.0.1 -p 8091 >log.out 2>1 &

######如果服务器有多网卡,存在多个 ip 地址,-h 后面一定要加可以访问的 ip 地址

7. 在 Nacos 上可以看到配置文件和服务已经注册成功