docker 安装nacos+seata
1、安装mysql
创建文件夹
mkdir -p /data/mysql/{logs,conf/db}
创建配置文件
vim /data/mysql/conf/mysql.cnf
【
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
skip-character-set-client-handshake
max_connections=4096
lower_case_table_names=1
#skip-grant-tables
】
启动容器
docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 -v /data/mysql/conf/mysql.cnf:/etc/mysql/conf.d/mysql.cnf -v /data/mysql/db:/var/lib/mysql -v /data/mysql/logs:/var/log/mysql --privileged=true -d mysql
进入容器创建nacos_config和seata数据库
>create database nacos_config;
>create database seata;
创建nacos和seata用户
>CREATE USER 'nacos'@'%' IDENTIFIED BY '123456';
>GRANT ALL PRIVILEGES ON nacos_config.* TO 'nacos'@'%';
>CREATE USER 'seata'@'%' IDENTIFIED BY '123456';
>GRANT ALL PRIVILEGES ON seata.* TO 'seata'@'%';
导入数据
nacos_config:https://github.com/alibaba/nacos/blob/develop/distribution/conf/nacos-mysql.sql 官网数据,编辑成sql文件,直接执行
>use nacos_config;
>source sql文件
seata:
seata.sql
【
CREATE TABLE IF NOT EXISTS `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`)
) ENGINE = InnoDB;
-- the table to store BranchSession data
CREATE TABLE IF NOT EXISTS `branch_table`
(
`branch_id` BIGINT NOT NULL,
`xid` VARCHAR(128) NOT NULL,
`transaction_id` BIGINT,
`resource_group_id` VARCHAR(32),
`resource_id` VARCHAR(256),
`branch_type` VARCHAR(8),
`status` TINYINT,
`client_id` VARCHAR(64),
`application_data` VARCHAR(2000),
`gmt_create` DATETIME(6),
`gmt_modified` DATETIME(6),
PRIMARY KEY (`branch_id`),
KEY `idx_xid` (`xid`)
) ENGINE = InnoDB;
-- the table to store lock data
CREATE TABLE IF NOT EXISTS `lock_table`
(
`row_key` VARCHAR(128) NOT NULL,
`xid` VARCHAR(128),
`transaction_id` BIGINT,
`branch_id` BIGINT NOT NULL,
`resource_id` VARCHAR(256),
`table_name` VARCHAR(32),
`pk` VARCHAR(36),
`gmt_create` DATETIME,
`gmt_modified` DATETIME,
PRIMARY KEY (`row_key`),
KEY `idx_branch_id` (`branch_id`)
) ENGINE = InnoDB;
】
>use seata;
>source sql文件
2、安装nacos
创建目录
mkdir -p /data/nacos/{logs,init.d}
创建配置文件custom.properties
vim /data/nacos/init.d/custom.properties
【
server.contextPath=/nacos
server.servlet.contextPath=/nacos
server.port=8848
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://192.168.59.102:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&serverTimezone=UTC
db.user=nacos
db.password=123456
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.eventTaskInterval=10
nacos.cmdb.labelTaskInterval=300
nacos.cmdb.loadDataAtStart=false
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i
nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/console/health/**,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/**,/v1/console/server/**
nacos.naming.distro.taskDispatchThreadCount=1
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
nacos.naming.distro.syncRetryDelay=5000
nacos.naming.data.warmup=true
nacos.naming.expireInstance=true
】
启动容器
docker run -d -p 8848:8848 -e MODE=standalone -e PREFER_HOST_MODE=xinchan-dev-03 -v /data/nacos/init.d/custom.properties:/home/nacos/init.d/custom.properties -v /data/nacos/logs:/home/nacos/logs --name nacos nacos/nacos-server:2.0.2
配置文件custom.properties有说明mysql的环境变量,如果没有custom.properties,用下面的命令
docker run -d -p 8848:8848 -e MODE=standalone -e PREFER_HOST_MODE=xinchan-dev-03 -e SPRING_DATASOURCE_PLATFORM=mysql -e MYSQL_SERVICE_HOST=192.168.11.82 -e MYSQL_SERVICE_PORT=3316 -e MYSQL_SERVICE_DB_NAME=nacos_config -e MYSQL_SERVICE_USER=nacos -e MYSQL_SERVICE_PASSWORD="123456" -e MYSQL_DATABASE_NUM=1 -v /data/nacos/init.d/custom.properties:/home/nacos/init.d/custom.properties -v /data/nacos/logs:/home/nacos/logs --name nacos nacos/nacos-server:2.0.2
3、安装seata
创建目录
mkdir -p /data/seata/resources
创建配置文件file.conf
vim /data/seata/resources/file.conf
【
## transaction log store, only used in seata-server
store {
## store mode: file、db、redis
mode = "db"
## 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.jdbc.Driver"
url = "jdbc:mysql://IP:3306/seata?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai"
user = "seata"
password = "123456"
minConn = 5
maxConn = 100
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
}
】
创建配置文件registry.conf
vim /data/seata/resources/registry.conf
【
#seata 的注册中心使用nacos 还可以使用eureka等
type = "nacos"
nacos {
#seata server名字
application = "seata-server"
#注册中心地址 现在是nacos
serverAddr = "192.168.59.102:8848"
#分组名
group = "SEATA_GROUP"
#集群名称 默认default
cluster = "default"
}
}
config {
#seata 的配置中心使用nacos 还可以使用file本地配置等
type = "file"
file {
name = "file:/seata-server/resources/file.conf"
}
}
】
启动容器
docker run --name seata -d -e SEATA_IP=192.168.59.102 -e SEATA_PORT=8091 -v /data/seata/resources/registry.conf:/seata-server/resources/registry.conf --privileged=true -p 8091:8091 seataio/seata-server:1.3.0