chore(project): 添加项目配置文件和忽略规则
- 添加 Babel 配置文件支持 ES6+ 语法转换 - 添加 ESLint 忽略规则和配置文件 - 添加 Git 忽略规则文件 - 添加 Travis CI 配置文件 - 添加 1.4.2 版本变更日志文件 - 添加 Helm 图表辅助模板文件 - 添加 Helm 忽略规则文件
This commit is contained in:
102
script/config-center/README.md
Normal file
102
script/config-center/README.md
Normal file
@@ -0,0 +1,102 @@
|
||||
# Script usage demo
|
||||

|
||||
|
||||
## important attributes
|
||||
|
||||
you only need to follow the instructions below and keep the corresponding configuration in 'config.txt' to run. For more configuration information, please visit [seata.io](https://seata.io/)
|
||||
|
||||
| server | client |
|
||||
| ------------------------ | ------------------------------------------------------------ |
|
||||
| store.mode: file,db | config.type: file、nacos 、apollo、zk、consul、etcd3、custom |
|
||||
| #only db: | #only file: |
|
||||
| store.db.driverClassName | service.default.grouplist |
|
||||
| store.db.url | #All: |
|
||||
| store.db.user | service.vgroupMapping.my_test_tx_group |
|
||||
| store.db.password | service.disableGlobalTransaction |
|
||||
|
||||
## Nacos
|
||||
shell:
|
||||
```bash
|
||||
sh ${SEATAPATH}/script/config-center/nacos/nacos-config.sh -h localhost -p 8848 -g SEATA_GROUP -t 5a3c7d6c-f497-4d68-a71a-2e5e3340b3ca -u username -w password
|
||||
```
|
||||
|
||||
Parameter Description:
|
||||
|
||||
-h: host, the default value is localhost.
|
||||
|
||||
-p: port, the default value is 8848.
|
||||
|
||||
-g: Configure grouping, the default value is 'SEATA_GROUP'.
|
||||
|
||||
-t: Tenant information, corresponding to the namespace ID field of Nacos, the default value is ''.
|
||||
|
||||
-u: username, nacos 1.2.0+ on permission control, the default value is ''.
|
||||
|
||||
-w: password, nacos 1.2.0+ on permission control, the default value is ''.
|
||||
|
||||
python:
|
||||
```bash
|
||||
python ${SEATAPATH}/script/config-center/nacos/nacos-config.py localhost:8848
|
||||
```
|
||||
|
||||
## Apollo
|
||||
```bash
|
||||
sh ${SEATAPATH}/script/config-center/apollo/apollo-config.sh -h localhost -p 8070 -e DEV -a seata-server -c default -n application -d apollo -r apollo -t 3aa026fc8435d0fc4505b345b8fa4578fb646a2c
|
||||
```
|
||||
Parameter Description:
|
||||
|
||||
-h: host, the default value is localhost.
|
||||
|
||||
-p: port, the default value is 8070.
|
||||
|
||||
-e: Managed configuration environment, the default value is DEV.
|
||||
|
||||
-a: AppId to which the namespace belongs, the default value is seata-server.
|
||||
|
||||
-c: Managed configuration cluster name, Generally, you can pass in default. If it is a special cluster, just pass in the name of the corresponding cluster,the default value is default.
|
||||
|
||||
-n: Name of the managed namespace, If the format is not properties, you need to add a suffix name, such as sample.yml, the default value is application.
|
||||
|
||||
-d: The creator of the item, in the format of a domain account, which is the User ID of the sso system.
|
||||
|
||||
-r: Publisher, domain account, note: if namespace.lock.switch in ApolloConfigDB.ServerConfig is set to true (default is false), Then the environment does not allow the publisher and editor to be the same person. So if the editor is zhangsan, the publisher can no longer be zhangsan.
|
||||
|
||||
-t: Apollo admin creates third-party applications in http://{portal_address}/open/manage.html, It is best to check whether this AppId has been created before creation. After successful creation, a token will be generated.
|
||||
|
||||
For details of the above parameter descriptions, please see:
|
||||
|
||||
https://github.com/ctripcorp/apollo/wiki/Apollo%E5%BC%80%E6%94%BE%E5%B9%B3%E5%8F%B0
|
||||
|
||||
## Consul
|
||||
```bash
|
||||
sh ${SEATAPATH}/script/config-center/consul/consul-config.sh -h localhost -p 8500
|
||||
```
|
||||
Parameter Description:
|
||||
|
||||
-h: host, the default value is localhost.
|
||||
|
||||
-p: port, the default value is 8500.
|
||||
|
||||
## Etcd3
|
||||
```bash
|
||||
sh ${SEATAPATH}/script/config-center/etcd3/etcd3-config.sh -h localhost -p 2379
|
||||
```
|
||||
|
||||
Parameter Description:
|
||||
|
||||
-h: host, the default value is localhost.
|
||||
|
||||
-p: port, the default value is 2379.
|
||||
|
||||
## ZK
|
||||
```bash
|
||||
sh ${SEATAPATH}/script/config-center/zk/zk-config.sh -h localhost -p 2181 -z "/Users/zhangchenghui/zookeeper-3.4.14"
|
||||
```
|
||||
Parameter Description:
|
||||
|
||||
-h: host, the default value is localhost.
|
||||
|
||||
-p: port, the default value is 2181.
|
||||
|
||||
-z: zk path.
|
||||
|
||||
155
script/config-center/apollo/apollo-config.sh
Normal file
155
script/config-center/apollo/apollo-config.sh
Normal file
@@ -0,0 +1,155 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 1999-2019 Seata.io Group.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at、
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
# apollo open api, click on the link for details:
|
||||
# https://github.com/ctripcorp/apollo/wiki/Apollo%E5%BC%80%E6%94%BE%E5%B9%B3%E5%8F%B0
|
||||
|
||||
# add config: http://{portal_address}/openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items
|
||||
# publish config: http://{portal_address}/openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases
|
||||
|
||||
while getopts ":h:p:e:a:c:n:d:r:t:" opt
|
||||
do
|
||||
case $opt in
|
||||
h)
|
||||
host=$OPTARG
|
||||
;;
|
||||
p)
|
||||
port=$OPTARG
|
||||
;;
|
||||
e)
|
||||
env=$OPTARG
|
||||
;;
|
||||
a)
|
||||
appId=$OPTARG
|
||||
;;
|
||||
c)
|
||||
clusterName=$OPTARG
|
||||
;;
|
||||
n)
|
||||
namespaceName=$OPTARG
|
||||
;;
|
||||
d)
|
||||
dataChangeCreatedBy=$OPTARG
|
||||
;;
|
||||
r)
|
||||
releasedBy=$OPTARG
|
||||
;;
|
||||
t)
|
||||
token=$OPTARG
|
||||
;;
|
||||
?)
|
||||
echo " USAGE OPTION: $0 [-h host] [-p port] [-e env] [a appId] [-c clusterName] [-n namespaceName] [-d dataChangeCreatedBy] [-r releasedBy] [-t token] "
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z ${host} ]]; then
|
||||
host=localhost
|
||||
fi
|
||||
if [[ -z ${port} ]]; then
|
||||
port=8070
|
||||
fi
|
||||
if [[ -z ${env} ]]; then
|
||||
env=DEV
|
||||
fi
|
||||
if [[ -z ${appId} ]]; then
|
||||
appId=seata-server
|
||||
fi
|
||||
if [[ -z ${clusterName} ]]; then
|
||||
clusterName=default
|
||||
fi
|
||||
if [[ -z ${namespaceName} ]]; then
|
||||
namespaceName=application
|
||||
fi
|
||||
if [[ -z ${dataChangeCreatedBy} ]]; then
|
||||
echo " dataChangeCreatedBy is empty, please usage option: [-d dataChangeCreatedBy] "
|
||||
exit 1
|
||||
fi
|
||||
if [[ -z ${releasedBy} ]]; then
|
||||
echo " releasedBy is empty, please usage option: [-r releasedBy] "
|
||||
exit 1
|
||||
fi
|
||||
if [[ -z ${token} ]]; then
|
||||
echo " token is empty, please usage option: [-t token] "
|
||||
exit 1
|
||||
fi
|
||||
|
||||
portalAddr=$host:$port
|
||||
contentType="content-type:application/json;charset=UTF-8"
|
||||
authorization="Authorization:$token"
|
||||
publishBody="{\"releaseTitle\":\"$(date +%Y%m%d%H%M%S)\",\"releaseComment\":\"\",\"releasedBy\":\"${releasedBy}\"}"
|
||||
|
||||
echo "portalAddr is ${portalAddr}"
|
||||
echo "env is ${env}"
|
||||
echo "appId is ${appId}"
|
||||
echo "clusterName is ${clusterName}"
|
||||
echo "namespaceName is ${namespaceName}"
|
||||
echo "dataChangeCreatedBy is ${dataChangeCreatedBy}"
|
||||
echo "releasedBy is ${releasedBy}"
|
||||
echo "token is ${token}"
|
||||
|
||||
failCount=0
|
||||
tempLog=$(mktemp -u)
|
||||
function addConfig() {
|
||||
curl -X POST -H "${1}" -H "${2}" -d "${3}" "http://${4}/openapi/v1/envs/${5}/apps/${6}/clusters/${7}/namespaces/${8}/items" >"${tempLog}" 2>/dev/null
|
||||
log=$(cat "${tempLog}")
|
||||
if [[ ${log} =~ ":401" || ${log} =~ ":403"
|
||||
|| ${log} =~ ":404" || ${log} =~ ":405"
|
||||
|| ${log} =~ ":500" || ! ${log} =~ "{" ]]; then
|
||||
echo "set $9=${10} failure "
|
||||
(( failCount++ ))
|
||||
else
|
||||
echo "set $9=${10} successfully "
|
||||
fi
|
||||
}
|
||||
|
||||
function publishConfig() {
|
||||
curl -X POST -H "${1}" -H "${2}" -d "${3}" "http://${4}/openapi/v1/envs/${5}/apps/${6}/clusters/${7}/namespaces/${8}/releases" >"${tempLog}" 2>/dev/null
|
||||
log=$(cat "${tempLog}")
|
||||
if [[ ${log} =~ ":401" || ${log} =~ ":403"
|
||||
|| ${log} =~ ":404" || ${log} =~ ":405"
|
||||
|| ${log} =~ ":500" || ! ${log} =~ "{" ]]; then
|
||||
echo " Publish fail "
|
||||
exit 1
|
||||
else
|
||||
echo " Publish successfully, please start seata-server. "
|
||||
fi
|
||||
}
|
||||
|
||||
count=0
|
||||
for line in $(cat $(dirname "$PWD")/config.txt | sed s/[[:space:]]//g); do
|
||||
(( count++ ))
|
||||
key=${line%%=*}
|
||||
value=${line#*=}
|
||||
body="{\"key\":\"${key}\",\"value\":\"${value}\",\"comment\":\"\",\"dataChangeCreatedBy\":\"${dataChangeCreatedBy}\"}"
|
||||
addConfig ${contentType} "${authorization}" "${body}" "${portalAddr}" "${env}" "${appId}" "${clusterName}" "${namespaceName}" "${key}" "${value}"
|
||||
done
|
||||
|
||||
echo "========================================================================="
|
||||
echo " Complete initialization parameters, total-count:$count , failure-count:$failCount "
|
||||
echo "========================================================================="
|
||||
|
||||
if [[ $failCount -eq 0 ]]; then
|
||||
read -p "Publish now, y/n: " result
|
||||
if [[ ${result} == "y" ]]; then
|
||||
publishConfig "${contentType}" "${authorization}" "${publishBody}" "${portalAddr}" "${env}" "${appId}" "${clusterName}" "${namespaceName}"
|
||||
else
|
||||
echo "Remember to publish later..."
|
||||
fi
|
||||
else
|
||||
echo " init apollo config fail. "
|
||||
fi
|
||||
89
script/config-center/config.txt
Normal file
89
script/config-center/config.txt
Normal file
@@ -0,0 +1,89 @@
|
||||
transport.type=TCP
|
||||
transport.server=NIO
|
||||
transport.heartbeat=true
|
||||
transport.enableClientBatchSendRequest=false
|
||||
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.my_test_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.tm.commitRetryCount=5
|
||||
client.tm.rollbackRetryCount=5
|
||||
client.tm.defaultGlobalTransactionTimeout=60000
|
||||
client.tm.degradeCheck=false
|
||||
client.tm.degradeCheckAllowTimes=10
|
||||
client.tm.degradeCheckPeriod=2000
|
||||
store.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.jdbc.Driver
|
||||
store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true&rewriteBatchedStatements=true
|
||||
store.db.user=username
|
||||
store.db.password=password
|
||||
store.db.minConn=5
|
||||
store.db.maxConn=30
|
||||
store.db.globalTable=global_table
|
||||
store.db.branchTable=branch_table
|
||||
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
|
||||
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
|
||||
75
script/config-center/consul/consul-config.sh
Normal file
75
script/config-center/consul/consul-config.sh
Normal file
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 1999-2019 Seata.io Group.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at、
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
while getopts ":h:p:" opt
|
||||
do
|
||||
case $opt in
|
||||
h)
|
||||
host=$OPTARG
|
||||
;;
|
||||
p)
|
||||
port=$OPTARG
|
||||
;;
|
||||
?)
|
||||
echo " USAGE OPTION: $0 [-h host] [-p port] "
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z ${host} ]]; then
|
||||
host=localhost
|
||||
fi
|
||||
if [[ -z ${port} ]]; then
|
||||
port=8500
|
||||
fi
|
||||
|
||||
consulAddr=$host:$port
|
||||
contentType="content-type:application/json;charset=UTF-8"
|
||||
echo "Set consulAddr=$consulAddr"
|
||||
|
||||
failCount=0
|
||||
tempLog=$(mktemp -u)
|
||||
function addConfig() {
|
||||
curl -X PUT -H "${1}" -d "${2}" "http://$3/v1/kv/$4" >"${tempLog}" 2>/dev/null
|
||||
if [[ -z $(cat "${tempLog}") ]]; then
|
||||
echo " Please check the cluster status. "
|
||||
exit 1
|
||||
fi
|
||||
if [[ $(cat "${tempLog}") =~ "true" ]]; then
|
||||
echo "Set $4=$2 successfully "
|
||||
else
|
||||
echo "Set $4=$2 failure "
|
||||
(( failCount++ ))
|
||||
fi
|
||||
}
|
||||
|
||||
count=0
|
||||
for line in $(cat $(dirname "$PWD")/config.txt | sed s/[[:space:]]//g); do
|
||||
(( count++ ))
|
||||
key=${line%%=*}
|
||||
value=${line#*=}
|
||||
addConfig "${contentType}" "${value}" "${consulAddr}" "${key}"
|
||||
done
|
||||
|
||||
echo "========================================================================="
|
||||
echo " Complete initialization parameters, total-count:$count , failure-count:$failCount "
|
||||
echo "========================================================================="
|
||||
|
||||
if [[ ${failCount} -eq 0 ]]; then
|
||||
echo " Init consul config finished, please start seata-server. "
|
||||
else
|
||||
echo " Init consul config fail. "
|
||||
fi
|
||||
79
script/config-center/etcd3/etcd3-config.sh
Normal file
79
script/config-center/etcd3/etcd3-config.sh
Normal file
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 1999-2019 Seata.io Group.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at、
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# etcd REST API v3.
|
||||
|
||||
while getopts ":h:p:" opt
|
||||
do
|
||||
case $opt in
|
||||
h)
|
||||
host=$OPTARG
|
||||
;;
|
||||
p)
|
||||
port=$OPTARG
|
||||
;;
|
||||
?)
|
||||
echo " USAGE OPTION: $0 [-h host] [-p port] "
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z ${host} ]]; then
|
||||
host=localhost
|
||||
fi
|
||||
if [[ -z ${port} ]]; then
|
||||
port=2379
|
||||
fi
|
||||
|
||||
etcd3Addr=$host:$port
|
||||
contentType="content-type:application/json;charset=UTF-8"
|
||||
echo "Set etcd3Addr=$etcd3Addr"
|
||||
|
||||
failCount=0
|
||||
tempLog=$(mktemp -u)
|
||||
function addConfig() {
|
||||
keyBase64=$(printf "%s""$2" | base64)
|
||||
valueBase64=$(printf "%s""$3" | base64)
|
||||
curl -X POST -H "${1}" -d "{\"key\": \"$keyBase64\", \"value\": \"$valueBase64\"}" "http://$4/v3/kv/put" >"${tempLog}" 2>/dev/null
|
||||
if [[ -z $(cat "${tempLog}") ]]; then
|
||||
echo " Please check the cluster status. "
|
||||
exit 1
|
||||
fi
|
||||
if [[ $(cat "${tempLog}") =~ "error" || $(cat "${tempLog}") =~ "code" ]]; then
|
||||
echo "Set $2=$3 failure "
|
||||
(( failCount++ ))
|
||||
else
|
||||
echo "Set $2=$3 successfully "
|
||||
fi
|
||||
}
|
||||
|
||||
count=0
|
||||
for line in $(cat $(dirname "$PWD")/config.txt | sed s/[[:space:]]//g); do
|
||||
(( count++ ))
|
||||
key=${line%%=*}
|
||||
value=${line#*=}
|
||||
addConfig "${contentType}" "${key}" "${value}" "${etcd3Addr}"
|
||||
done
|
||||
|
||||
echo "========================================================================="
|
||||
echo " Complete initialization parameters, total-count:$count , failure-count:$failCount "
|
||||
echo "========================================================================="
|
||||
|
||||
if [[ ${failCount} -eq 0 ]]; then
|
||||
echo " Init etcd3 config finished, please start seata-server. "
|
||||
else
|
||||
echo " Init etcd3 config fail. "
|
||||
fi
|
||||
37
script/config-center/nacos/nacos-config.py
Normal file
37
script/config-center/nacos/nacos-config.py
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
import http.client
|
||||
import sys
|
||||
import urllib.parse
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print ('python nacos-config.py nacosAddr')
|
||||
exit()
|
||||
|
||||
headers = {
|
||||
'content-type': "application/x-www-form-urlencoded"
|
||||
}
|
||||
|
||||
hasError = False
|
||||
for line in open('../config.txt'):
|
||||
pair = line.rstrip("\n").split('=')
|
||||
if len(pair) < 2:
|
||||
continue
|
||||
print (line),
|
||||
url_prefix = sys.argv[1]
|
||||
conn = http.client.HTTPConnection(url_prefix)
|
||||
if len(sys.argv) == 3:
|
||||
namespace=sys.argv[2]
|
||||
url_postfix = '/nacos/v1/cs/configs?dataId={0}&group=SEATA_GROUP&content={1}&tenant={2}'.format(urllib.parse.quote(str(pair[0])),urllib.parse.quote(str(pair[1])).strip(),namespace)
|
||||
else:
|
||||
url_postfix = '/nacos/v1/cs/configs?dataId={}&group=SEATA_GROUP&content={}'.format(urllib.parse.quote(str(pair[0])),urllib.parse.quote(str(pair[1]))).strip()
|
||||
conn.request("POST", url_postfix, headers=headers)
|
||||
res = conn.getresponse()
|
||||
data = res.read()
|
||||
if data.decode("utf-8") != "true":
|
||||
hasError = True
|
||||
if hasError:
|
||||
print ("init nacos config fail.")
|
||||
else:
|
||||
print ("init nacos config finished, please start seata-server.")
|
||||
112
script/config-center/nacos/nacos-config.sh
Normal file
112
script/config-center/nacos/nacos-config.sh
Normal file
@@ -0,0 +1,112 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 1999-2019 Seata.io Group.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at、
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
while getopts ":h:p:g:t:u:w:" opt
|
||||
do
|
||||
case $opt in
|
||||
h)
|
||||
host=$OPTARG
|
||||
;;
|
||||
p)
|
||||
port=$OPTARG
|
||||
;;
|
||||
g)
|
||||
group=$OPTARG
|
||||
;;
|
||||
t)
|
||||
tenant=$OPTARG
|
||||
;;
|
||||
u)
|
||||
username=$OPTARG
|
||||
;;
|
||||
w)
|
||||
password=$OPTARG
|
||||
;;
|
||||
?)
|
||||
echo " USAGE OPTION: $0 [-h host] [-p port] [-g group] [-t tenant] [-u username] [-w password] "
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
urlencode() {
|
||||
for ((i=0; i < ${#1}; i++))
|
||||
do
|
||||
char="${1:$i:1}"
|
||||
case $char in
|
||||
[a-zA-Z0-9.~_-]) printf $char ;;
|
||||
*) printf '%%%02X' "'$char" ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
if [[ -z ${host} ]]; then
|
||||
host=localhost
|
||||
fi
|
||||
if [[ -z ${port} ]]; then
|
||||
port=8848
|
||||
fi
|
||||
if [[ -z ${group} ]]; then
|
||||
group="SEATA_GROUP"
|
||||
fi
|
||||
if [[ -z ${tenant} ]]; then
|
||||
tenant=""
|
||||
fi
|
||||
if [[ -z ${username} ]]; then
|
||||
username=""
|
||||
fi
|
||||
if [[ -z ${password} ]]; then
|
||||
password=""
|
||||
fi
|
||||
|
||||
nacosAddr=$host:$port
|
||||
contentType="content-type:application/json;charset=UTF-8"
|
||||
|
||||
echo "set nacosAddr=$nacosAddr"
|
||||
echo "set group=$group"
|
||||
|
||||
failCount=0
|
||||
tempLog=$(mktemp -u)
|
||||
function addConfig() {
|
||||
curl -X POST -H "${contentType}" "http://$nacosAddr/nacos/v1/cs/configs?dataId=$(urlencode $1)&group=$group&content=$(urlencode $2)&tenant=$tenant&username=$username&password=$password" >"${tempLog}" 2>/dev/null
|
||||
if [[ -z $(cat "${tempLog}") ]]; then
|
||||
echo " Please check the cluster status. "
|
||||
exit 1
|
||||
fi
|
||||
if [[ $(cat "${tempLog}") =~ "true" ]]; then
|
||||
echo "Set $1=$2 successfully "
|
||||
else
|
||||
echo "Set $1=$2 failure "
|
||||
(( failCount++ ))
|
||||
fi
|
||||
}
|
||||
|
||||
count=0
|
||||
for line in $(cat $(dirname "$PWD")/config.txt | sed s/[[:space:]]//g); do
|
||||
(( count++ ))
|
||||
key=${line%%=*}
|
||||
value=${line#*=}
|
||||
addConfig "${key}" "${value}"
|
||||
done
|
||||
|
||||
echo "========================================================================="
|
||||
echo " Complete initialization parameters, total-count:$count , failure-count:$failCount "
|
||||
echo "========================================================================="
|
||||
|
||||
if [[ ${failCount} -eq 0 ]]; then
|
||||
echo " Init nacos config finished, please start seata-server. "
|
||||
else
|
||||
echo " init nacos config fail. "
|
||||
fi
|
||||
102
script/config-center/zk/zk-config.sh
Normal file
102
script/config-center/zk/zk-config.sh
Normal file
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 1999-2019 Seata.io Group.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at、
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
# The purpose is to sync the local configuration(config.txt) to zk.
|
||||
# This script need to rely on zk.
|
||||
|
||||
|
||||
while getopts ":h:p:z:" opt
|
||||
do
|
||||
case $opt in
|
||||
h)
|
||||
host=$OPTARG
|
||||
;;
|
||||
p)
|
||||
port=$OPTARG
|
||||
;;
|
||||
z)
|
||||
zkHome=$OPTARG
|
||||
;;
|
||||
?)
|
||||
echo " USAGE OPTION: $0 [-h host] [-p port] [-z zkHome] "
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z ${host} ]]; then
|
||||
host=localhost
|
||||
fi
|
||||
if [[ -z ${port} ]]; then
|
||||
port=2181
|
||||
fi
|
||||
if [[ -z ${zkHome} ]]; then
|
||||
echo " zk home is empty, please usage option: [-z zkHome] "
|
||||
exit 1
|
||||
fi
|
||||
|
||||
zkAddr=$host:$port
|
||||
|
||||
root="/seata"
|
||||
tempLog=$(mktemp -u)
|
||||
|
||||
echo "ZK address is $zkAddr"
|
||||
echo "ZK home is $zkHome"
|
||||
echo "ZK config root node is $root"
|
||||
|
||||
function check_node() {
|
||||
"$2"/bin/zkCli.sh -server "$1" ls ${root} >/dev/null 2>"${tempLog}"
|
||||
}
|
||||
|
||||
function create_node() {
|
||||
"$2"/bin/zkCli.sh -server "$1" create ${root} "" >/dev/null
|
||||
}
|
||||
|
||||
function create_subNode() {
|
||||
"$2"/bin/zkCli.sh -server "$1" create "${root}/$3" "$4" >/dev/null
|
||||
}
|
||||
|
||||
function delete_node() {
|
||||
"$2"/bin/zkCli.sh -server $1 rmr ${root} "" >/dev/null
|
||||
}
|
||||
|
||||
check_node "${zkAddr}" "${zkHome}"
|
||||
|
||||
if [[ $(cat "${tempLog}") =~ "No such file or directory" ]]; then
|
||||
echo " ZK home is error, please enter correct zk home! "
|
||||
exit 1
|
||||
elif [[ $(cat "${tempLog}") =~ "Exception" ]]; then
|
||||
echo " Exception error, please check zk cluster status or if the zk address is entered correctly! "
|
||||
exit 1
|
||||
elif [[ $(cat "${tempLog}") =~ "Node does not exist" ]]; then
|
||||
create_node "${zkAddr}" "${zkHome}"
|
||||
else
|
||||
read -p "${root} node already exists, now delete ${root} node in zk, y/n: " result
|
||||
if [[ ${result} == "y" ]]; then
|
||||
echo "Delete ${root} node..."
|
||||
delete_node "${zkAddr}" "${zkHome}"
|
||||
create_node "${zkAddr}" "${zkHome}"
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
for line in $(cat $(dirname "$PWD")/config.txt | sed s/[[:space:]]//g); do
|
||||
key=${line%%=*}
|
||||
value=${line#*=}
|
||||
echo "Set" "${key}" "=" "${value}"
|
||||
create_subNode "${zkAddr}" "${zkHome}" "${key}" "${value}"
|
||||
done
|
||||
Reference in New Issue
Block a user