linux(centos8):安装分布式事务服务seata(file单机模式,seata 1.3.0/centos 8.2)
一,什么是seata?
Seata:Simpe Extensible Autonomous Transcaction Architecture,
是阿里中间件,开源的分布式事务解决方案。
前身是阿里的Fescar
官方站:
http://seata.io/zh-cn/
官方代码地址:
https://github.com/seata/seata
官方文档站:
http://seata.io/zh-cn/docs/overview/what-is-seata.html
各版本的release下载地址:
https://github.com/seata/seata/releases
说明:刘宏缔的架构森林是一个专注架构的博客,
网站:https://blog.imgtouch.com
本文: https://blog.imgtouch.com/index.php/2023/05/24/centos8linux-an-zhuang-fen-bu-shi-shi-wu-fu-wu-seatafile-dan-ji-mo-shi-seata130centos82/
对应的源码可以访问这里获取: https://github.com/liuhongdi/
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,安装seata前准备java环境:
因为seata是基于java开发的,所以需要先在机器上准备java环境
1,下载java
从官方站下载:
https://www.oracle.com/cn/java/technologies/javase-downloads.html
下载完成后查看当前目录:
[root@localhost java]# pwd /usr/local/source/java [root@localhost java]# ls jdk-14.0.2_linux-x64_bin.tar.gz
2,解压和安装:
解压:
[root@localhost java]# tar -zxvf jdk-14.0.2_linux-x64_bin.tar.gz
把解压后的jdk目录,移动到安装目录/usr/local/soft目录下:
[root@localhost java]# mv jdk-14.0.2 /usr/local/soft/
3,配置java
编辑profile文件:
[root@localhost java]# vi /etc/profile
内容:
export JAVA_HOME=/usr/local/soft/jdk-14.0.2 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
使变量生效:
[root@localhost java]# source /etc/profile
4,测试java的安装效果
[root@localhost liuhongdi]# java --version java 14.0.2 2020-07-14 Java(TM) SE Runtime Environment (build 14.0.2+12-46) Java HotSpot(TM) 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing)
三,下载seata:
1,用wget命令下载
创建一个源文件存放目录:/usr/local/source/seata,
在这个目录下下载和解压
[root@localhost seata]# wget https://github.com/seata/seata/releases/download/v1.3.0/seata-server-1.3.0.tar.gz
2,解压后并移动到安装目录:
[root@localhost seata]# ls seata-server-1.3.0.tar.gz [root@localhost seata]# tar -zxvf seata-server-1.3.0.tar.gz [root@localhost seata]# mv seata /usr/local/soft/ [root@localhost seata]# cd /usr/local/soft/seata/
四,配置seata
1,生成日志目录:
[root@localhost seata]# mkdir /data/seata [root@localhost seata]# mkdir /data/seata/logs [root@localhost seata]# chmod 777 /data/seata/logs
2,进入安装目录下
[root@localhost seata]# cd conf/ [root@localhost conf]# vi logback.xml
修改内容:
修改LOG_HOME为我们创建的目录
<property name="LOG_HOME" value="/data/seata/logs”/>
3,创建seata的gc日志目录
[root@localhost seata]# pwd /usr/local/soft/seata [root@localhost seata]# mkdir logs
说明:seata默认会使用这个目录保存java运行时的gclog
五,启动并检测是否运行中
1,启动
[root@localhost seata]# nohup sh ./bin/seata-server.sh -p 8091 > /data/seata/logs/seata_runtime.out 2>&1 & [1] 2062
2,检查查端口是否在监听中:
[root@localhost bin]# telnet localhost 8091 Trying ::1... Connected to localhost. Escape character is '^]'. ^] telnet> quit Connection closed.
六,用systemctl管理seata
1,创建seata启动文件:保存到安装目录/bin目录下
[root@localhost seata]# cd bin/ [root@localhost bin]# vi seata-start.sh [root@localhost bin]# more seata-start.sh #!/bin/bash sh /usr/local/soft/seata/bin/seata-server.sh -p 8091 [root@localhost bin]# chmod +x seata-start.sh
2,创建service文件
[root@localhost bin]# vi /usr/lib/systemd/system/seata.service
内容:
[Unit] Description=seata-server After=syslog.target network.target [Service] Type=simple ExecStart=/usr/local/soft/seata/bin/seata-start.sh Restart=always PrivateTmp=true [Install] WantedBy=multi-user.target
3,启动service
[root@localhost bin]# systemctl daemon-reload
[root@localhost bin]# systemctl start seata.service
4,查看是否运行中?
[root@localhost ~]# systemctl status seata.service ● seata.service - seata-server Loaded: loaded (/usr/lib/systemd/system/seata.service; disabled; vendor preset: disabled) Active: active (running) since Sat 2020-08-15 09:59:03 CST; 2s ago Main PID: 1726 (seata-start.sh) Tasks: 29 (limit: 4642) Memory: 145.7M CGroup: /system.slice/seata.service ├─1726 /bin/bash /usr/local/soft/seata/bin/seata-start.sh └─1727 /usr/bin/java -server -Xmx2048m -Xms2048m -Xmn1024m -Xss512k -XX:SurvivorRatio=10 ...
可以看到状态为 active (running)
5,用ss查看端口:
[root@localhost ~]# ss -lntp State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 1024 *:8091 *:* users:(("java",pid=1727,fd=176))
七,查看seata-server可用的参数
用--help
[root@localhost ~]# /usr/local/soft/seata/bin/seata-server.sh --help
可以看到参数:
... Usage: sh seata-server.sh(for linux and mac) or cmd seata-server.bat(for windows) [options] Options: --host, -h The ip to register to registry center. --port, -p The port to listen. Default: 8091 --storeMode, -m log store mode : file, db --serverNode, -n server node id, such as 1, 2, 3.it will be generated according to the snowflake by default --seataEnv, -e The name used for multi-configuration isolation. --help
八,查看linux的版本 :
[root@localhost java]$ cat /etc/redhat-release CentOS Linux release 8.2.2004 (Core)