1.1 安装配置Seata服务端
在Seata服务端下载页面提供了服务端的压缩包,也可以直接通过命令来下载seata-server-1.4.2
wget https://github.com/seata/seata/releases/download/v1.4.2/seata-server-1.4.2.tar.gz
压缩包解压后的目录如下:
[root@lizhi seata-server-1.4.2]# ll
total 24
drwxr-xr-x 3 root root 90 Feb 14 17:57 bin
drwxr-xr-x 4 502 games 156 Feb 14 17:57 conf
drwxr-xr-x 3 502 games 8192 Feb 14 13:35 lib
-rw-r--r-- 1 502 games 11365 May 13 2019 LICENSE
drwxr-xr-x 2 502 games 136 Feb 14 17:58 logs
进入到conf/
目录中,修改配置文件
-rw-r--r-- 1 502 games 1859 Feb 14 13:27 file.conf
-rw-r--r-- 1 502 games 3112 Apr 25 2021 file.conf.example
drwxr-xr-x 2 502 games 114 Feb 14 10:50 logback
-rw-r--r-- 1 502 games 2222 Apr 25 2021 logback.xml
drwxr-xr-x 3 502 games 22 Apr 25 2021 META-INF
-rw-r--r-- 1 502 games 1324 Apr 25 2021 README.md
-rw-r--r-- 1 502 games 1327 Apr 25 2021 README-zh.md
-rw-r--r-- 1 502 games 1976 Feb 14 17:57 registry.conf
修改registry.conf
文件,配置nacos
作为注册中心和配置中心
# 注册中心
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos"
nacos {
application = "seata-server"
serverAddr = "127.0.0.1:8848"
group = "SEATA_GROUP"
namespace = "24712b7c-05ad-4b79-af97-1d202431f521"
cluster = "default"
username = ""
password = ""
}
}
# 配置中心
config {
# file、nacos 、apollo、zk、consul、etcd3
type = "nacos"
nacos {
serverAddr = "127.0.0.1:8848"
namespace = ""
group = "SEATA_GROUP"
username = ""
password = ""
dataId = "seataServer.properties"
}
}
除了配置注册中心和配置中心外,还需要配置数据存储方式,修改file.conf
文件,将存储模式改为db
,并修改数据库的连接信息
store {
## store mode: file、db、redis
mode = "db"
## rsa decryption public key
publicKey = ""
## 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.cj.jdbc.Driver"
## if using mysql to store the data, recommend add rewriteBatchedStatements=true in jdbc connection param
url = "jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true"
user = "root"
password = "lz123"
minConn = 5
maxConn = 100
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
注意:如果使用的是MySQL8.0以上,需要将数据库驱动类的名称改为com.mysql.cj.jdbc.Driver
,并在lib
目录中下载mysql-connector-java-8.0.27.jar
wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.27/mysql-connector-java-8.0.27.jar
1.2 配置初始化参数
方法一:
在较低的版本中,seata-server解压完之后,在conf
目录下还有一个config.txt
文件,里面记录了Seata启动时必须的初始化参数,但seata-server-1.4.2中并没有这个文件
我们可以在https://github.com/seata/seata/tree/develop/script/config-center
中看到这个配置文件,下载这个配置,修改里面的参数
如果配置了Nacos
作为配置中心,然后再下载https://github.com/seata/seata/tree/develop/script/config-center/nacos
中的nacos-config.sh
,然后执行脚本,将config.txt
中的初始化参数加载到nacos的配置中心
https://github.com/seata/seata/tree/develop/script/config-center
下面,为每种配置中心的启动脚本都有详细的参数介绍
方法二:
方法一这种方式,相对来说是比较复杂的,在seata-server-1.4.2以后的版本中,我们可以在registry.conf
中配置配置中心时,就可以通过dataId
来创建配置
registry.conf
的nacos配置中心的dataId
默认为seataServer.properties
,我们在Nacos的控制台就可以直接创建一个这样的配置,其中的配置的内容就是config.txt
的内容