文章目录
1.环境准备
2. 下载软件包和解压文件
2.1 下载
下载地址:https://github.com/seata/seata/releases.
1.4.2版本的apollo配置有bug,这里选择1.4.1版本。
通过xftp上传到目录/soft。
2.2 解压
tar -xvf seata-server-1.4.1.tar.gz -C /usr/local/
3. 修改配置文件
3.1 file.conf
路径:/usr/local/seata/conf/file.conf
Server端存储模式(store.mode)现有file、db、redis三种, db模式为高可用模式,全局事务会话信息通过db共享,相应性能差些。 这里使用db模式。(如果使用apollo配置,可以省略这一步)
## transaction log store, only used in seata-server
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://192.168.66.131:3306/seata_server?rewriteBatchedStatements=true"
user = "root"
password = "aws258369@L"
minConn = 5
maxConn = 100
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
}
3.2 registry.conf
路径:/usr/local/seata/conf/registry.conf
这里使用consul作为服务中心,apollo作为配置中心
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "consul"
consul {
cluster = "seata-server"
serverAddr = "192.168.66.131:8501"
aclToken = ""
}
}
config {
# file、nacos 、apollo、zk、consul、etcd3
type = "apollo"
apollo {
appId = "seata-server"
## apolloConfigService will cover apolloMeta
apolloMeta = "http://192.168.66.131:8080"
apolloConfigService = "http://192.168.66.131:8080"
namespace = "application"
apolloAccesskeySecret = ""
}
}
4. 服务端脚本
服务端脚本路径:可以到github找,\script\server\db。
执行完后:
5.上传配置至 Apollo 配置中心
5.1 apollo创建应用
创建第三方应用:
5.2 修改config.txt
参考本地工程目录/script/config-center 的config.txt并修改.(包含server和client端配置)
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=jdbc:mysql://192.168.66.131:3306/seata_server?useUnicode=true&rewriteBatchedStatements=true
store.db.user=root
store.db.password=aws258369@L
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
5.3 git bash执行shell
sh ${SEATAPATH}/script/config-center/apollo/apollo-config.sh -h 192.168.66.131 -p 8070 -e DEV -a seata-server -c default -n application -d apollo -r apollo -t 08778c7253b45163cecb3d61d3514cf63ae29a8a
Parameter Description:
-h: host, the default value is localhost.
-p: port, the default value is 8070.
-e: Managed configuration environment, the default value is DEV.
-a: AppId to which the namespace belongs, the default value is seata-server.
-c: Managed configuration cluster name, Generally, you can pass in default. If it is a special cluster, just pass in the name of the corresponding cluster,the default value is default.
-n: Name of the managed namespace, If the format is not properties, you need to add a suffix name, such as sample.yml, the default value is application.
-d: The creator of the item, in the format of a domain account, which is the User ID of the sso system.
-r: Publisher, domain account, note: if namespace.lock.switch in ApolloConfigDB.ServerConfig is set to true (default is false), Then the environment does not allow the publisher and editor to be the same person. So if the editor is zhangsan, the publisher can no longer be zhangsan.
-t: Apollo admin creates third-party applications in http://{portal_address}/open/manage.html, It is best to check whether this AppId has been created before creation. After successful creation, a token will be generated.(就是5.1生成的token)
6. 启动seata服务器
cd /usr/local/seata/bin
./seata-server.sh -h 192.168.66.131 -p 8091 -m db -n 1
cd /usr/local/seata/bin
./seata-server.sh -h 192.168.66.132 -p 8091 -m db -n 2
cd /usr/local/seata/bin
./seata-server.sh -h 192.168.66.133 -p 8091 -m db -n 3