一、下载并安装
github官网地址:
因下载比较慢,我将下载好的资源上传了CSDN:https://download.csdn.net/download/JackRen_Developer/11982282
下载好后上传ubuntu自己的路径:
这是我自己的路经
二、导入配置
本文使用nacos作为配置中心和服务发现,file、apollo、redis、zk、consul等也可以举一反三。
我们这里用默认的导入先让seata-server跑起来,过后对着file.conf和java程序启动后的报错调整,重新导入即可。
vim /root/work/ziyun56.seata/seata-server-0.9.0/conf/nacos-config.txt
transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.thread-factory.boss-thread-prefix=NettyBoss
transport.thread-factory.worker-thread-prefix=NettyServerNIOWorker
transport.thread-factory.server-executor-thread-prefix=NettyServerBizHandler
transport.thread-factory.share-boss-worker=false
transport.thread-factory.client-selector-thread-prefix=NettyClientSelector
transport.thread-factory.client-selector-thread-size=1
transport.thread-factory.client-worker-thread-prefix=NettyClientWorkerThread
transport.thread-factory.boss-thread-size=1
transport.thread-factory.worker-thread-size=8
transport.shutdown.wait=3
service.vgroup_mapping.my_test_tx_group=default
service.vgroup_mapping.user-web-fescar-service-group=default
service.vgroup_mapping.user-fescar-service-group=default
service.vgroup_mapping.order-fescar-service-group=default
service.vgroup_mapping.business-service-fescar-service-group=default
service.vgroup_mapping.account-service-fescar-service-group=default
service.vgroup_mapping.storage-service-fescar-service-group=default
service.vgroup_mapping.order-service-fescar-service-group=default
service.default.grouplist=172.16.10.122:8091
service.enableDegrade=false
service.disable=false
service.max.commit.retry.timeout=-1
service.max.rollback.retry.timeout=-1
client.async.commit.buffer.limit=10000
client.lock.retry.internal=10
client.lock.retry.times=30
client.lock.retry.policy.branch-rollback-on-conflict=true
client.table.meta.check.enable=true
client.report.retry.count=5
client.tm.commit.retry.count=1
client.tm.rollback.retry.count=1
store.mode=file
store.file.dir=file_store/data
store.file.max-branch-session-size=16384
store.file.max-global-session-size=512
store.file.file-write-buffer-cache-size=16384
store.file.flush-disk-mode=async
store.file.session.reload.read_size=100
store.db.datasource=dbcp
store.db.db-type=mysql
store.db.driver-class-name=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://172.16.10.105:3307/seata?useUnicode=true
store.db.user=root
store.db.password=root
store.db.min-conn=1
store.db.max-conn=3
store.db.global.table=global_table
store.db.branch.table=branch_table
store.db.query-limit=100
store.db.lock-table=lock_table
recovery.committing-retry-period=1000
recovery.asyn-committing-retry-period=1000
recovery.rollbacking-retry-period=1000
recovery.timeout-retry-period=1000
transaction.undo.data.validation=true
transaction.undo.log.serialization=jackson
transaction.undo.log.save.days=7
transaction.undo.log.delete.period=86400000
transaction.undo.log.table=undo_log
transport.serialization=seata
transport.compressor=none
metrics.enabled=false
metrics.registry-type=compact
metrics.exporter-list=prometheus
metrics.exporter-prometheus-port=9898
support.spring.datasource.autoproxy=false
vim /root/work/ziyun56.seata/seata-server-0.9.0/conf/nacos-config.sh
for line in $(cat nacos-config.txt)
改为
for line in $(cat /root/work/ziyun56.seata/seata-server-0.9.0/conf/nacos-config.txt)
导入配置到nacos。
格式为:
sh nacos-config.sh $Nacos-Server-IP
因为nacos-config.sh脚本中已经把8848端口写死,如果你的nacos-server不是8848端口,请修改nacos-config.sh
bash /root/work/ziyun56.seata/seata-server-0.9.0/conf/nacos-config.sh 172.16.10.121
其中172.16.10.121是nacos的ip
脚本执行最后输出 “init nacos config finished, please start seata-server.” 说明推送配置成功。若想进一步确认可登陆Nacos控制台->配置列表->筛选查询Group为FESCAR_GROUP的配置项。
三、启动seata-server(事务协调器)
修改日志目录(非必须)
vim /root/work/ziyun56.seata/seata-server-0.9.0/conf/logback.xml
修改为:
<!--<property name="LOG_HOME" value="${user.home}/logs/seata"/>-->
<property name="LOG_HOME" value="/root/work/ziyun56.seata/seata-server-0.9.0/logs"/>
配置修改:
vim /root/work/ziyun56.seata/seata-server-0.9.0/conf/registry.conf
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos"
nacos {
serverAddr = "172.16.10.121"
namespace = "public"
cluster = "default"
}
eureka {
serviceUrl = "http://localhost:8761/eureka"
application = "default"
weight = "1"
}
redis {
serverAddr = "localhost:6379"
db = "0"
}
zk {
cluster = "default"
serverAddr = "127.0.0.1:2181"
session.timeout = 6000
connect.timeout = 2000
}
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 = "172.16.10.121"
namespace = "public"
cluster = "default"
}
consul {
serverAddr = "127.0.0.1:8500"
}
apollo {
app.id = "seata-server"
apollo.meta = "http://192.168.1.204:8801"
}
zk {
serverAddr = "127.0.0.1:2181"
session.timeout = 6000
connect.timeout = 2000
}
etcd3 {
serverAddr = "http://localhost:2379"
}
file {
name = "file.conf"
}
}
其中修改的:
只需要修改这两处,其他的地方不需要动
注:serverAddr不要填端口号 public为小写
启动格式sh seata-server.sh $LISTEN_PORT $PATH_FOR_PERSISTENT_DATA $IP(此参数可选)
$IP参数 用于多IP环境下指定 Fescar-Server 注册服务的IP 虽然是可选,但还是要填,之前我偷懒没填,一大堆虚拟ip各种乱定位。
命令启动
sh /root/work/ziyun56.seata/seata-server-0.9.0bin/seata-server.sh -p 8091 -h 172.16.10.121
方便启动,定义服务,先写个启动脚本:
#!/bin/bash
export JAVA_HOME=/root/work/jdk1.8.0_92/
sh /root/work/ziyun56.seata/seata-server-0.9.0/bin/seata-server.sh -p 8091 -h 172.16.10.121
第一个命令是我ubuntu没有安装jdk环境,所以我下载了一个传上去了
然后编辑服务:
vim /lib/systemd/system/seata-server.service
[Unit]
Description=seata-server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=simple
ExecStart=/root/work/ziyun56.seata/seata-server-0.9.0/startup.sh
Restart=always
PrivateTmp=true
[Install]
WantedBy=multi-user.target
赋予权限
chmod 777 /root/work/ziyun56.seata/seata-server-0.9.0r/startup.sh
chmod 777 /lib/systemd/system/seata-server.service
启用服务
systemctl enable seata-server.service
systemctl daemon-reload
运行
systemctl start seata-server.service
查看状态
systemctl status seata-server.service
查看进程
ps -ef|grep seata-server
运行成功后可在Nacos控制台的 服务列表 看到 服务名serverAddr的条目