# seata-server启动(可选) ## 官方文档: [https://seata.io/](https://seata.io/) # 安装&启动: 1. [官网](https://github.com/seata/seata/releases) 下载 1.7.1 版本后解压(群文件里面的配置已经调整过了) 。 版本一定要一致!!! ![](https://img.kancloud.cn/8b/a5/8ba5132a654ad782bf0e5809da8b9ca4_498x507.png) 2. 创建数据库 ``` CREATE DATABASE `lamp_seata` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; ``` 3. 向lamp_seata库 导入 qq群文件下载压缩包里面 `script/server/db/mysql.sql` . 若是官方下载的包, sql文件要去[官方github仓库下载](https://github.com/seata/seata/blob/develop/script/server/db/mysql.sql) . 4. 修改安装包 `conf/registry.conf ` 文件内容: ~~~ registry { type = "nacos" nacos { application = "seata-server" serverAddr = "localhost:8848" group = "SEATA_GROUP" namespace = "3cca7d98-3b1c-44d3-90e5-86abaaf0048a" cluster = "default" username = "nacos" password = "nacos" } } config { type = "nacos" nacos { serverAddr = "localhost:8848" namespace = "3cca7d98-3b1c-44d3-90e5-86abaaf0048a" group = "SEATA_GROUP" username = "nacos" password = "nacos" dataId = "seataServer.properties" } } ~~~ 5. 将 [https://github.com/seata/seata/blob/develop/script/config-center](https://github.com/seata/seata/blob/develop/script/config-center) 里面的配置文件: `config.txt` 和 `nacos/nacos-config.sh` 2个文件下载下来,按照官方的目录结构存放,并修改`config.txt`。 我这里只列出了,修改过的值: ~~~ service.vgroup_mapping.lamp_cloud_seata_tx_group=default store.mode=db store.db.driver-class-name=com.mysql.jdbc.Driver # 数据库连接信息需要自行修改一下 store.db.url=jdbc:mysql://127.0.0.1:3306/lamp_seata?useUnicode=true store.db.user=root store.db.password=root ~~~ 6. 在naocs中新建命名空间 - 命名空间ID:`3cca7d98-3b1c-44d3-90e5-86abaaf0048a` - 命名空间名: lamp-seata - 描述: lamp-cloud 分布式事务 7. 在新建的命名空间新建 `seataServer.properties` ![](https://img.kancloud.cn/49/56/49565744bff2d3393b92536b43a155ea_1200x820.png) ``` transport.type=TCP transport.server=NIO transport.heartbeat=true transport.enableClientBatchSendRequest=true transport.threadFactory.bossThreadPrefix=NettyBoss transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler transport.threadFactory.shareBossWorker=false transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector transport.threadFactory.clientSelectorThreadSize=1 transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread transport.threadFactory.bossThreadSize=1 transport.threadFactory.workerThreadSize=default transport.shutdown.wait=3 service.vgroupMapping.lamp_cloud_seata_tx_group=default service.default.grouplist=127.0.0.1:8091 service.enableDegrade=false service.disableGlobalTransaction=false client.rm.asyncCommitBufferLimit=10000 client.rm.lock.retryInterval=10 client.rm.lock.retryTimes=30 client.rm.lock.retryPolicyBranchRollbackOnConflict=true client.rm.reportRetryCount=5 client.rm.tableMetaCheckEnable=false client.rm.tableMetaCheckerInterval=60000 client.rm.sqlParserType=druid client.rm.reportSuccessEnable=false client.rm.sagaBranchRegisterEnable=false client.rm.tccActionInterceptorOrder=-2147482648 client.tm.commitRetryCount=5 client.tm.rollbackRetryCount=5 client.tm.defaultGlobalTransactionTimeout=60000 client.tm.degradeCheck=false client.tm.degradeCheckAllowTimes=10 client.tm.degradeCheckPeriod=2000 client.tm.interceptorOrder=-2147482648 store.mode=db store.lock.mode=file store.session.mode=file store.publicKey= store.file.dir=file_store/data store.file.maxBranchSessionSize=16384 store.file.maxGlobalSessionSize=512 store.file.fileWriteBufferCacheSize=16384 store.file.flushDiskMode=async store.file.sessionReloadReadSize=100 store.db.datasource=druid store.db.dbType=mysql store.db.driverClassName=com.mysql.cj.jdbc.Driver store.db.url=jdbc:mysql://127.0.0.1:3306/lamp_seata?useUnicode=true&rewriteBatchedStatements=true store.db.user=root store.db.password=root store.db.minConn=5 store.db.maxConn=30 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 store.redis.mode=single store.redis.single.host=127.0.0.1 store.redis.single.port=6379 store.redis.sentinel.masterName= store.redis.sentinel.sentinelHosts= store.redis.maxConn=10 store.redis.minConn=1 store.redis.maxTotal=100 store.redis.database=0 store.redis.password= store.redis.queryLimit=100 server.recovery.committingRetryPeriod=1000 server.recovery.asynCommittingRetryPeriod=1000 server.recovery.rollbackingRetryPeriod=1000 server.recovery.timeoutRetryPeriod=1000 server.maxCommitRetryTimeout=-1 server.maxRollbackRetryTimeout=-1 server.rollbackRetryTimeoutUnlockEnable=false server.distributedLockExpireTime=10000 client.undo.dataValidation=true client.undo.logSerialization=jackson client.undo.onlyCareUpdateColumns=true server.undo.logSaveDays=7 server.undo.logDeletePeriod=86400000 client.undo.logTable=undo_log client.undo.compress.enable=true client.undo.compress.type=zip client.undo.compress.threshold=64k log.exceptionRate=100 transport.serialization=seata transport.compressor=none metrics.enabled=false metrics.registryType=compact metrics.exporterList=prometheus metrics.exporterPrometheusPort=9898 ``` > 注意: 一定是在新建的命名空间中创建配置 8. 导入成功后,确定下命名空间: `3cca7d98-3b1c-44d3-90e5-86abaaf0048a` 下是否有1个配置文件 ![](https://img.kancloud.cn/59/4b/594b4668e336aef96b693b1137ca9fd6_1380x435.png) 10. 启动seata-server: ~~~ sh bin/seata-server.sh -p 8091 -h 192.168.1.34 -m db -n 1 参数解释: -p 指定端口 -h 指定ip, 需要修改成`自己的ip ,切记,不能使用127.0.0.1 和localhost !!! -m db 存储到数据库 -m file 存储到文件 window: 双击或者cmd下面执行: bin/seata-server.bat -p 8091 -h 192.168.1.34 -m db -n 1 ~~~ 11. 验证是否启动成功:打开nacos, 【服务管理】 -> 【服务列表】 ->【lamp-seata】-> 有一个服务名为 `server-server` 的服务 即表示成功