seata-server为seata中的事务协调器。

参考:http://seata.io/en-us/docs/ops/deploy-server.html

只能在jdk8环境

seata的wiki

https://github.com/seata/seata/wiki/Home_Chinese

一、下载并安装

wget -P /opt/downloads https://github.com/seata/seata/releases/download/v0.9.0/seata-server-0.9.0.tar.gz
mkdir /opt/seata-server
tar zxvf /opt/downloads/seata-server-0.9.0.tar.gz -C /opt/seata-server
mv /opt/seata-server/seata/* /opt/seata-server
rm -r /opt/seata-server/seata/

二、导入配置

本文使用nacos作为配置中心和服务发现,file、apollo、redis、zk、consul等也可以举一反三。

我们这里用默认的导入先让seata-server跑起来,过后对着file.conf和java程序启动后的报错调整,重新导入即可。

vim /opt/seata-server/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-seata-service-group=default
service.vgroup_mapping.user-seata-service-group=default
service.vgroup_mapping.order-seata-service-group=default
service.vgroup_mapping.user2-seata-service-group=default
service.vgroup_mapping.order2-seata-service-group=default
service.vgroup_mapping.business-service-seata-service-group=default
service.vgroup_mapping.account-service-seata-service-group=default
service.vgroup_mapping.storage-service-seata-service-group=default
service.vgroup_mapping.order-service-seata-service-group=default
service.default.grouplist=192.168.0.101: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=db
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=druid
store.db.db-type=mysql
store.db.driver-class-name=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://192.168.0.101:3306/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

ha见https://github.com/seata/seata-samples/tree/master/ha

service.default.grouplist为seata集群地址集

建立集群数据库

https://github.com/seata/seata/blob/v0.9.0/server/src/main/resources/db_store.sql

注意版本对应分支,官方链接指向了develop分支sql不同是会报错的

-- the table to store GlobalSession data
drop table if exists `global_table`;
create table `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_gmt_modified_status` (`gmt_modified`, `status`),
key `idx_transaction_id` (`transaction_id`)
); -- the table to store BranchSession data
drop table if exists `branch_table`;
create table `branch_table` (
`branch_id` bigint not null,
`xid` varchar(128) not null,
`transaction_id` bigint ,
`resource_group_id` varchar(32),
`resource_id` varchar(256) ,
`lock_key` varchar(128) ,
`branch_type` varchar(8) ,
`status` tinyint,
`client_id` varchar(64),
`application_data` varchar(2000),
`gmt_create` datetime,
`gmt_modified` datetime,
primary key (`branch_id`),
key `idx_xid` (`xid`)
); -- the table to store lock data
drop table if exists `lock_table`;
create table `lock_table` (
`row_key` varchar(128) not null,
`xid` varchar(96),
`transaction_id` long ,
`branch_id` long,
`resource_id` varchar(256) ,
`table_name` varchar(32) ,
`pk` varchar(36) ,
`gmt_create` datetime ,
`gmt_modified` datetime,
primary key(`row_key`)
);

store.db.datasource的选择 ## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp) etc.

store.db.driver-class-name = "com.mysql.jdbc.Driver"   store.db.driver-class-name = "com.mysql.cj.jdbc.Driver"

选择druid和com.mysql.jdbc.Driver(目前seata驱动为5.1.30)

导入配置到nacos。

格式为sh nacos-config.sh $Nacos-Server-IP

因为nacos-config.sh脚本中已经把8848端口写死,如果你的nacos-server不是8848端口,请修改nacos-config.sh。

cd /opt/seata-server/conf/
bash /opt/seata-server/conf/nacos-config.sh nacosserver
nacosserver是nacos的ip

脚本执行最后输出 "init nacos config finished, please start seata-server." 说明推送配置成功。若想进一步确认可登陆Nacos控制台->配置列表->筛选查询Group为SEATA_GROUP的配置项。

将/opt/seata-server/conf/nacos-config.txt 脚本修改后重新导入即可。

三、启动seata-server(事务协调器)

修改日志目录(非必须)

vim /opt/seata-server/conf/logback.xml

改为

    <!--<property name="LOG_HOME" value="${user.home}/logs/seata"/>-->
<property name="LOG_HOME" value="/var/log/seata-server"/>

sudo mkdir -p /var/log/seata-server;sudo chmod -R 777 /var/log/seata-server

配置修改

vim /opt/seata-server/conf/registry.conf 并复制到java代码的properties目录下

registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos" nacos {
serverAddr = "nacosserver"
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 = "nacosserver"
namespace = ""
}
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为小写

有处BUG:config.nacos.namespace="public"的值要去掉public写成""

启动格式sh seata-server.sh $LISTEN_PORT $PATH_FOR_PERSISTENT_DATA $IP(此参数可选)

$IP参数 用于多IP环境下指定 Seata-Server 注册服务的IP    虽然是可选,但还是要填,之前我偷懒没填,一大堆虚拟ip各种乱定位。

命令启动

sh /opt/seata-server/bin/seata-server.sh -p 8091 -h 192.168.0.101 -m db -n 1

守护进程启动

vim /opt/seata-server/startup.sh

填入

#!/bin/bash
sh /opt/seata-server/bin/seata-server.sh -p 8091 -h 192.168.0.101 -m db -n 1

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=/opt/seata-server/startup.sh
Restart=always
PrivateTmp=true [Install]
WantedBy=multi-user.target

赋予权限

chmod  /opt/seata-server/startup.sh
chmod /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的条目

查看日志
sudo journalctl -u seata-server
sudo journalctl -u seata-server --since="2019-11-11 11:11:11"
sudo journalctl -u seata-server --since "30 min ago"
sudo journalctl -u seata-server --since yesterday
sudo journalctl -u seata-server --since "2019-11-10" --until "2018-11-11 11:11"
sudo journalctl -u seata-server --since 04:00 --until "2 hour ago"

四、创建数据表

(创建mysql数据库略)

UNDO_LOG table is required by SEATA AT mode.

-- for AT mode you must to init this sql for you business databese. the seata server not need it.
drop table `undo_log`;
CREATE TABLE `undo_log` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'increment id',
`branch_id` bigint(20) NOT NULL COMMENT 'branch transaction id',
`xid` varchar(100) NOT NULL COMMENT 'global transaction id',
`context` varchar(128) NOT NULL COMMENT 'undo_log context,such as serialization',
`rollback_info` longblob NOT NULL COMMENT 'rollback info',
`log_status` int(11) NOT NULL COMMENT '0:normal status,1:defense status',
`log_created` datetime NOT NULL COMMENT 'create datetime',
`log_modified` datetime NOT NULL COMMENT 'modify datetime',
`ext` varchar(100) DEFAULT NULL COMMENT 'reserved field',
PRIMARY KEY (`id`),
UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='AT transaction mode undo table';

每个业务数据库都要建一个undo_log表

seata-server安装、运行(ubuntu)的更多相关文章

  1. ubuntu server 安装 question2answer 及 汉化包

    ubuntu server 安装 question2answer 及 汉化包 question2answer 是一个非常简洁方便的问答系统,可以用它快速的部署一个问答社区,提高在开发中的交流沟通效率: ...

  2. ubuntu Server 安装 php5

    ubuntu Server 安装 php5 1:如果你的服务器已经安装了apache2组件,那么在安装php5时,可以把对应apache2的php5组件一起安装 sudo apt-get instal ...

  3. 联想ThinkPad S3-S440虚拟机安装,ubuntu安装,Hadoop(2.7.1)详解及WordCount运行,spark集群搭建

    下载ubuntu操作系统版本 ubuntu-14.10-desktop-amd64.iso(64位) 安装过程出现错误: This kernel requires an X86-64 CPU,but ...

  4. Ubuntu server 安装及jdk+mysql安装教程

    Ubuntu server 安装教程 1.查找及下载Ubuntu镜像文件 可以在以下页面下载想要的版本,我这里选择19.04 server版的iso镜像文件: http://mirrors.163.c ...

  5. 关于SQL Server 安装程序在运行 Windows Installer 文件时遇到错误

    前几日安装sql server2008r2 的时候碰到这个问题: 出现以下错误: SQL Server 安装程序在运行 Windows Installer 文件时遇到错误. Windows Insta ...

  6. Ubuntu Server安装R和Rstudio(zz)

    Ubuntu Server安装R和Rstudio 发表于 技术天堂 2014-03-15 21:03 字数: 534 阅读量: 205 R是一个在科研领域很常用的工具,经常用R的年轻人或者经常上统计之 ...

  7. cmd运行sql server安装

    cmd运行sql server安装 SQL2012非群集安装_更新到最新版本.bat setup.exe /UpdateSource=.\hotfix\Latest /ACTION="Ins ...

  8. Ubuntu Server安装图形界面全过程

    转载自:http://blog.csdn.net/sunbaigui/article/details/6624110, http://mikewolfli.blog.163.com/blog/stat ...

  9. Zend Server安装后首次运行就出现Internal Server Error的解决

    无论是使用哪个版本的Zend Server来搭建PHP服务器,首次运行都会出现Internal Server Error的错误,对很多新手而言,每当看到这种错误时,那一刻内心绝对都是崩溃的.然而,这个 ...

  10. Zend Server安装后首次运行就出现Internal Server Error的解决(转)

    新近学习php,结果装了Zend Server上来就报错,网上找到了解决方法,照着做果然可行,转之. 刚才安装了Zend Server,安装后首次运行就爆出了一个Internal Server Err ...

随机推荐

  1. Android学习第十天

    计算机表示图形的几种方式 a)         Bmp:以高质量保存,用于计算机 b)         Jpg:以良好的质量保存,用于计算机或网络 c)         Png:以高质量保存 d)   ...

  2. redis jedis使用

    jedis就是集成了redis的一些命令操作,封装了redis的java客户端.提供了连接池管理.一般不直接使用jedis,而是在其上再封装一层,作为业务的使用.如果用spring的话,可以看看spr ...

  3. 继续沿用旧的网络访问模式Apache HTTP 客户端,防止Android9闪退

    注意位置,在application 节点里面.

  4. JavaProperties类、序列化流与反序列化流、打印流、commons-IO整理

    Properties类 Properties 类表示了一个持久的属性集.Properties 可保存在流中或从流中加载.属性列表中每个键及其对应值都是一个字符串. 特点: 1.Hashtable的子类 ...

  5. js的几大重点

    闭包,:作用域(函数创建),上下文环境(函数执行,会销毁) 匿名函数,:没有函数名的函数,function(){} 自执行函数,:立即调用的匿名函数,(function(){})() 原型链,:继承的 ...

  6. solr的搜索

    主要讲一下solr面板的使用: 查询 q:     查询用  语法: name:刘中华      支持通配符 ? 表示单个任意字符的通配 * 表示多个任意字符的通配(不能在检索的项开始使用*或者?符号 ...

  7. admin 后台操作表格

    1. app下创建 templates  运行的时候 先找全局的templates——> 按照app的注册顺序找templates中的文件 2. app下在创建一个urls.py include ...

  8. 第四节:跨域请求的解决方案和WebApi特有的处理方式

    一. 简介 前言: 跨域问题发生在Javascript发起Ajax调用,其根本原因是因为浏览器对于这种请求,所给予的权限是较低的,通常只允许调用本域中的资源, 除非目标服务器明确地告知它允许跨域调用. ...

  9. react实战项目开发(2) react几个重要概念以及JSX语法

    前言 前面我们已经学习了利用官方脚手架搭建一套可以应用在生产环境下的React开发环境.那么今天这篇文章主要先了解几个react重要的概念,以及讲解本文的重要知识JSX语法 React重要概念 [思想 ...

  10. SpringBoot系列: 所有配置属性和官方文档

    Spring Boot 通用配置参数https://docs.spring.io/spring-boot/docs/current/reference/html/common-application- ...