Article directory
background
Since Seata needs to configure a lot of items, and the YAML file format is more hypocritical, although a nanny-level installation tutorial is provided, various problems are still encountered during the deployment process, causing Seata installation to fail. Please ask for help. Provide an interactive shell script to automatically deploy once and for all.
For manual deployment, see: [Seata] seata-server-1.5.1-direct deployment (integrating nacos)
Environmental description
- Operating systemCentos7.9
- The seata version is
seata-1.5.1
- database
MySQL5.7
- Nacos-2.0.4
离线
Installation, because some production environments cannot access the Internet, so the script is directly made into an offline version
script analysis
If you are not interested in the content of the script, you can skip this link directly, scroll to the bottom of the instruction manual and download link, and use it directly after downloading
Variable definition and default value
######################## Properties #######################
# 数据库设置===========
_MYSQL_IP=127.0.0.1
_MYSQL_PORT=3306
_MYSQL_USER=root
_MYSQL_PASSWORD=root
_SEATA_DATABASES_NAME=seata
# Nacos设置===========
_NACOS_IP=127.0.0.1
_NACOS_PORT=8848
_NACOS_USER=nacos
_NACOS_PASSWORD=nacos
_NACOS_GROUP=SEATA_GROUP
# 命名空间,配置中心和注册中心共用
_NACOS_NAMESPACE=
# Seata设置===========
# 安装路径
BASE_DIR=/app
# 事务分组
_SEATA_TX_SERVICE_GROUP=xxx_group
# Seata控制台用户名
_SEATA_CONSOLE_USER_NAME=seata
# Seata控制台密码
_SEATA_CONSOLE_USER_PASSWORD=seata
MySQL settings
# 设置数据库配置
setDBConfigs(){
read -p "请输入MySQL的IP,默认: [$_MYSQL_IP] " MYSQL_IP
while [ "${MYSQL_IP}" != "" ] && ! (echo "${MYSQL_IP}" | grep -iE "^((1[0-9]{
0,2}|2([0-4][0-9]|5[0-5])|2[0-9]{
0,1}|[3-9][0-9]{
0,1}|0)\.(1[0-9]{
0,2}|2([0-4][0-9]|5[0-5])|2[0-9]{
0,1}|[3-9][0-9]{
0,1}|0)\.(1[0-9]{
0,2}|2([0-4][0-9]|5[0-5])|2[0-9]{
0,1}|[3-9][0-9]{
0,1}|0)\.(1[0-9]{
0,2}|2([0-4][0-9]|5[0-5])|2[0-9]{
0,1}|[3-9][0-9]{
0,1}|0))$")
do
read -p ">>>>>>>> 请输入正确MySQL的IP,默认: [$_MYSQL_IP] " MYSQL_IP
done
if ! echo $MYSQL_IP | grep -qe '^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$' ; then
MYSQL_IP=$_MYSQL_IP
fi
echo "$MYSQL_IP"
read -p "请输入MySQL的端口号,默认: [$_MYSQL_PORT] " MYSQL_PORT
while [ "${MYSQL_PORT}" != "" ] && ! ( echo "${MYSQL_PORT}" | grep -E "^([1-9][0-9]{1,3}|[1-5][0-9]{4}|6([0-4][0-9]{3}|5([0-4][0-9]{2}|5([0-2][0-9]|3[0-5]))))$" )
do
read -p ">>>>>>>> 请输入正确的MySQL端口号,默认: [$_MYSQL_PORT]: " MYSQL_PORT
done
if ! echo $MYSQL_PORT | grep -qe '^[0-9]\{4,\}$' ; then
MYSQL_PORT=$_MYSQL_PORT
fi
echo "$MYSQL_PORT"
read -p "请输入MySQL的用户名,默认: [$_MYSQL_USER] " MYSQL_USER
if [ -z $MYSQL_USER ]; then
MYSQL_USER=$_MYSQL_USER
fi
echo "$MYSQL_USER"
read -p "请输入MySQL的密码,默认: [$_MYSQL_PASSWORD] " MYSQL_PASSWORD
if [ -z $MYSQL_PASSWORD ]; then
MYSQL_PASSWORD=$_MYSQL_PASSWORD
fi
echo "$MYSQL_PASSWORD"
read -p "请输入要创建的Seata的数据库名称,默认: [$_SEATA_DATABASES_NAME] " SEATA_DATABASES_NAME
if [ -z $SEATA_DATABASES_NAME ]; then
SEATA_DATABASES_NAME=$_SEATA_DATABASES_NAME
fi
echo "$SEATA_DATABASES_NAME"
}
Nacos service settings
# 初始化Naco服务s配置
setNacosConfigs(){
read -p "请输入Nacos的IP,默认: [$_NACOS_IP] " NACOS_IP
while [ "${NACOS_IP}" != "" ] && ! (echo "${NACOS_IP}" | grep -iE "^((1[0-9]{
0,2}|2([0-4][0-9]|5[0-5])|2[0-9]{
0,1}|[3-9][0-9]{
0,1}|0)\.(1[0-9]{
0,2}|2([0-4][0-9]|5[0-5])|2[0-9]{
0,1}|[3-9][0-9]{
0,1}|0)\.(1[0-9]{
0,2}|2([0-4][0-9]|5[0-5])|2[0-9]{
0,1}|[3-9][0-9]{
0,1}|0)\.(1[0-9]{
0,2}|2([0-4][0-9]|5[0-5])|2[0-9]{
0,1}|[3-9][0-9]{
0,1}|0))$")
do
read -p ">>>>>>>> 请输入正确Nacos的IP,默认: [$_NACOS_IP] " NACOS_IP
done
if [ -z $NACOS_IP ]; then
NACOS_IP=$_NACOS_IP
fi
echo "$NACOS_IP"
read -p "请输入Nacos的端口号,默认: [$_NACOS_PORT] " NACOS_PORT
while [ "${NACOS_PORT}" != "" ] && ! ( echo "${NACOS_PORT}" | grep -E "^([1-9][0-9]{1,3}|[1-5][0-9]{4}|6([0-4][0-9]{3}|5([0-4][0-9]{2}|5([0-2][0-9]|3[0-5]))))$" )
do
read -p ">>>>>>>> 请输入正确的Nacos端口,默认端口[$_NACOS_PORT]: " NACOS_PORT
done
if [ -z $NACOS_PORT ]; then
NACOS_PORT=$_NACOS_PORT
fi
echo "$NACOS_PORT"
read -p "请输入Nacos的用户名,默认: [$_NACOS_USER] " NACOS_USER
if [ -z $NACOS_USER ]; then
NACOS_USER=$_NACOS_USER
fi
echo "$NACOS_USER"
read -p "请输入Nacos的密码,默认: [$_NACOS_PASSWORD] " NACOS_PASSWORD
if [ -z $NACOS_PASSWORD ]; then
NACOS_PASSWORD=$_NACOS_PASSWORD
fi
echo "$NACOS_PASSWORD"
read -p "请输入Seata所在Nacos的命名空间ID,默认: [$_NACOS_NAMESPACE] " NACOS_NAMESPACE
if [ -z $NACOS_NAMESPACE ]; then
NACOS_NAMESPACE=$_NACOS_NAMESPACE
fi
echo "$NACOS_NAMESPACE"
read -p "请输入Seata所在Nacos的分组,默认: [$_NACOS_GROUP] " NACOS_GROUP
if [ -z $NACOS_GROUP ]; then
NACOS_GROUP=$_NACOS_GROUP
fi
echo "$NACOS_GROUP"
}
Generate Seata's application.yml configuration
# application.yml
creataSeataApplicationYml(){
# 事务分组
read -p "请输入Seata的事务分组名称,默认: [$_SEATA_TX_SERVICE_GROUP] " SEATA_TX_SERVICE_GROUP
if [ -z $SEATA_TX_SERVICE_GROUP ]; then
SEATA_TX_SERVICE_GROUP=$_SEATA_TX_SERVICE_GROUP
fi
echo "$SEATA_TX_SERVICE_GROUP"
# seata控制台用户名
read -p "请输入Seata控制台用户名,默认: [$_SEATA_CONSOLE_USER_NAME] " SEATA_CONSOLE_USER_NAME
if [ -z $SEATA_CONSOLE_USER_NAME ]; then
SEATA_CONSOLE_USER_NAME=$_SEATA_CONSOLE_USER_NAME
fi
echo "$SEATA_CONSOLE_USER_NAME"
# seata控制台密码
read -p "请输入Seata控制台密码,默认: [$_SEATA_CONSOLE_USER_PASSWORD] " SEATA_CONSOLE_USER_PASSWORD
if [ -z $SEATA_CONSOLE_USER_PASSWORD ]; then
SEATA_CONSOLE_USER_PASSWORD=$_SEATA_CONSOLE_USER_PASSWORD
fi
echo "$SEATA_CONSOLE_USER_PASSWORD"
# 备份并配置application.yml
mv $BASE_DIR/seata/conf/application.yml $BASE_DIR/seata/conf/application.yml.bak
cat > $BASE_DIR/seata/conf/application.yml <<EOF
server:
port: 7091
spring:
application:
name: seata-server
logging:
config: classpath:logback-spring.xml
file:
path: \${user.home}/logs/seata
console:
user:
username: $SEATA_CONSOLE_USER_NAME
password: $SEATA_CONSOLE_USER_PASSWORD
seata:
config:
type: nacos
nacos:
server-addr: $NACOS_IP:$NACOS_PORT
namespace: $NACOS_NAMESPACE
group: $NACOS_GROUP
username: $NACOS_USER
password: $NACOS_PASSWORD
# nacos配置文件 data-id
data-id: seataServer.properties
registry:
type: nacos
nacos:
application: seata-server
server-addr: $NACOS_IP:$NACOS_PORT
group: $NACOS_GROUP
namespace: $NACOS_NAMESPACE
cluster: default
username: $NACOS_USER
password: $NACOS_PASSWORD
store:
# support: file 、 db 、 redis
mode: db
server:
service-port: 8091 #If not configured, the default is '\${server.port} + 1000'
security:
secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
tokenValidityInMilliseconds: 1800000
ignore:
urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login
EOF
}
Generate seataServer.properties and upload Nacos
# seataServer.properties
creataSeataServerProperties(){
content=$(cat << EOF
#Transaction routing rules configuration, only for the client
# xxx_group 为事务分组,需要和客户端 vgroupMapping 保持一致
# default 为 application.yml中的 cluster的值,默认default
service.vgroupMapping.$SEATA_TX_SERVICE_GROUP=default
# default为service.vgroupMapping.xxx_group的值。
service.default.grouplist=$LOCAL_IP:8091
service.enableDegrade=false
service.disableGlobalTransaction=false
# application.yml 中如果配置了store,此处可以不配,看个人喜好
#Transaction storage configuration, only for the server. The file, DB, and redis configuration values are optional.
store.mode=db
store.lock.mode=db
store.session.mode=db
#These configurations are required if the \`store mode\` is \`db\`. If \`store.mode,store.lock.mode,store.session.mode\` are not equal to \`db\`, you can remove the configuration block.
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://$MYSQL_IP:$MYSQL_PORT/$SEATA_DATABASES_NAME?useUnicode=true
store.db.user=$MYSQL_USER
store.db.password=$MYSQL_PASSWORD
store.db.minConn=5
store.db.maxConn=30
# global_table、branch_table、distributed_lock、lock_table 四张表需要手动创建
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.distributedLockTable=distributed_lock
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
EOF
)
result=`curl -X POST "http://$NACOS_IP:$NACOS_PORT/nacos/v1/cs/configs" -d "username=$NACOS_USER&password=$NACOS_PASSWORD&dataId=seataServer.properties&group=$NACOS_GROUP&type=properties&content=$content"`
if [ "$result"x == "true"x ]; then
echo "seataServer.properties配置上传Nacos成功!"
else
die "seataServer.properties配置上传Nacos失败!"
fi
}
Install
########################## Install ############################
echo -e "\033[31m\n安装前请先确认MySQL中seata依赖的数据库和表已创建完成,Nacos已启动!\033[0m"
read -p ">>>>>>>> 确认是否继续执行: [y/n]" GO_ON
if !( echo "${GO_ON}" | grep -qwi "y" )
then
die "取消安装!"
fi
# 1、解压
if [ ! -d $BASE_DIR ];then
mkdir -p $BASE_DIR
fi
tar -xf packages/seata/seata-server-1.5.1.tar.gz -C $BASE_DIR
# 2、设置MySQL库参数
setDBConfigs
# 3、设置Nacos配置中心参数
setNacosConfigs
# 4、初始化Seata配置文件application.yml
creataSeataApplicationYml
# 5、获取本机IP
LOCAL_IP=`ip addr | grep inet | grep -v inet6 | grep -v 127.0.0.1 | awk '{print $2}'| cut -f 1 -d /`
# 6、Seata配置seataServer.properties上传Nacos
creataSeataServerProperties
# 7、启动Seata
$BASE_DIR/seata/bin/seata-server.sh
echo "查看启动日志命令:"
echo -e "\033[31m\n tail -100f $BASE_DIR/seata/logs/start.out \033[0m \n"
# 8、输出安装信息
echo "输出Seata安装信息到 install-info.txt !"
cat >> install-info.txt <<EOF
======================== Seata ========================
1、控制台地址: http://$LOCAL_IP:7091
2、安装路径: $BASE_DIR/
3、单机启动命令: $BASE_DIR/seata/bin/seata-server.sh
4、查看日志命令: tail -100f $BASE_DIR/seata/logs/start.out
EOF
script download
address
https://download.csdn.net/download/weixin_43582081/87554401
Download package directory and instructions
Table of contents
Table of contents | illustrate |
---|---|
seata-install.sh | screenplay |
packages | Offline installation package |
└─seata | seata-related |
└─seata-server-1.5.1.tar.gz | seata installation package |
└─seata-server-mysql.sql | seata-server database script |
use
需要提前手动创建seata的数据库
. You can perform extensions to increase the automatic creation logic of the seata library in MySQL. Considering that the deployment machine (the server where Seata is located) may not necessarily be installedmysql-client
, this part of the content is removed in this article- When uploading scripts and offline packages, ensure that
seata-install.sh
andpackages
are in the same directory (the relative path remains unchanged), and the relative path used in the shell script - Give the shell script the execution permission:
chmod +x seata-install.sh
- Execute the installation
./seata-install.sh
- In addition to prompting whether to continue execution at the beginning, in order to prevent misoperation, you must manually enter
y
, you can always use the default value deployment - The installation information is output at the same level as seata-install.sh
install-info.txt
deploy:
View deployment information records:cat install-info.txt
Nacos Configuration Center
Nacos Registration Center
Seata console