Commit 9d276a91 authored by harrylee2015's avatar harrylee2015 Committed by vipwzw

Safety measures for raft

parent 5ad1d431
......@@ -42,8 +42,14 @@ func (ln stoppableListener) Accept() (c net.Conn, err error) {
case err := <-errc:
return nil, err
case tc := <-connc:
tc.SetKeepAlive(true)
tc.SetKeepAlivePeriod(3 * time.Minute)
err := tc.SetKeepAlive(true)
if err != nil {
return tc, err
}
err = tc.SetKeepAlivePeriod(3 * time.Minute)
if err != nil {
return tc, err
}
return tc, nil
}
}
......@@ -152,7 +152,11 @@ func (rc *raftNode) startRaft() {
ErrorC: make(chan error),
}
rc.transport.Start()
err := rc.transport.Start()
if err != nil {
rlog.Error(fmt.Sprintf("raft:transport.Start()", err.Error()))
panic(err)
}
for i := range rc.bootstrapPeers {
if i+1 != rc.id {
rc.transport.AddPeer(typec.ID(i+1), []string{rc.bootstrapPeers[i]})
......@@ -225,7 +229,10 @@ func (rc *raftNode) serveChannels() {
if err != nil {
rlog.Error(fmt.Sprintf("failed to marshal block:%v ", err.Error()))
}
rc.node.Propose(context.TODO(), out)
err = rc.node.Propose(context.TODO(), out)
if err != nil {
rlog.Error(fmt.Sprintf("rc.node.Propose:%v", err.Error()))
}
}
case cc, ok := <-rc.confChangeC:
......@@ -234,7 +241,10 @@ func (rc *raftNode) serveChannels() {
} else {
confChangeCount++
cc.ID = confChangeCount
rc.node.ProposeConfChange(context.TODO(), cc)
err = rc.node.ProposeConfChange(context.TODO(), cc)
if err != nil {
rlog.Error(fmt.Sprintf("rc.node.ProposeConfChange:%v", err.Error()))
}
}
}
}
......
#!/usr/bin/env bash
#这是一个build 构建脚本,用于编译打包chain33
echo "-----start build chain33-----"
SHELL_FOLDER=$(
cd "$(dirname "$0")" || exit 1
pwd
)
echo "cur dir:$SHELL_FOLDER"
cd "$SHELL_FOLDER"/../../../../../cmd/chain33/ || exit 1
echo "---go build -o chain33---"
go build -o chain33
mv chain33 "$SHELL_FOLDER"
curDir=$(pwd)
echo "cur dir:$curDir"
cd "$SHELL_FOLDER" || exit 1
#dos2unix *.sh
tar cvf chain33.tgz chain33 chain33.toml raft_conf.sh run.sh
rm -rf chain33
echo "---- chain33 build success!----- "
Title="chain33"
TestNet=false
[log]
# 日志级别,支持debug(dbug)/info/warn/error(eror)/crit
loglevel = "debug"
logConsoleLevel = "info"
# 日志文件名,可带目录,所有生成的日志文件都放到此目录下
logFile = "logs/chain33.log"
# 单个日志文件的最大值(单位:兆)
maxFileSize = 300
# 最多保存的历史日志文件个数
maxBackups = 100
# 最多保存的历史日志消息(单位:天)
maxAge = 28
# 日志文件名是否使用本地事件(否则使用UTC时间)
localTime = true
# 历史日志文件是否压缩(压缩格式为gz)
compress = true
# 是否打印调用源文件和行号
callerFile = false
# 是否打印调用方法
callerFunction = false
[blockchain]
defCacheSize=512
maxFetchBlockNum=128
timeoutSeconds=5
batchBlockNum=128
driver="leveldb"
dbPath="datadir"
dbCache=64
isStrongConsistency=true
singleMode=true
batchsync=false
[p2p]
seeds=["114.55.149.144:13802","139.224.19.175:13802","139.224.82.165:13802"]
enable=true
isSeed=true
serverStart=true
innerSeedEnable=false
useGithub=false
innerBounds=300
msgCacheSize=10240
driver="leveldb"
dbPath="datadir/addrbook"
dbCache=4
grpcLogFile="grpc33.log"
version=15
verMix=15
verMax=16
[rpc]
jrpcBindAddr="localhost:8801"
grpcBindAddr="localhost:8802"
whitlist=["127.0.0.1"]
[mempool]
poolCacheSize=10240
minTxFee=100000
[consensus]
# 共识驱动名,支持solo/raft/ticket/tendermint/pbft
name="raft"
minerstart=true
genesis="14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
# =============== raft共识配置参数 ===========================
# 共识节点ID,raft共识用到,不同的节点设置不同的nodeId(目前只支持1,2,3这种设置)
nodeId=1
# raft共识用到,通过这个端口进行节点的增加和删除
raftApiPort=9121
# raft共识用到,指示这个节点是否新增加节点
isNewJoinNode=false
# raft共识用到,指示raft集群中的服务器IP和端口
peersURL="http://114.55.149.144:9021,http://139.224.19.175:9021,http://139.224.82.165:9021"
# raft共识用到,指示raft集群中只读节点的IP(只同步日志,不参与raft共识)
readOnlyPeersURL=""
addPeersURL=""
#raft共识用到,默认raft中多少条记录打包一个snapshot
defaultSnapCount=1000
# =============== raft共识配置参数 ===========================
genesisBlockTime=1514533394
hotkeyAddr="12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
[store]
name="kvdb"
driver="leveldb"
dbPath="datadir/kvdb"
dbCache=128
[wallet]
minFee=100000
driver="leveldb"
dbPath="datadir/wallet"
dbCache=16
signType="secp256k1"
minerdisable=true
[exec]
isFree=true
minExecFee=0
#!/usr/bin/env bash
#这是个用于分发部署chain33的脚本
#Program:
# This is a chain33 deploy scripts!
SHELL_FOLDER=$(
cd "$(dirname "$0")" || exit 1
pwd
)
echo "curl dir:$SHELL_FOLDER"
if [ "$1" == "start" ]; then
cd "$SHELL_FOLDER"/go-scp/ || exit 1
go build -o go_scp
cp go_scp servers.toml ../
rm -rf go_scp
cd "$SHELL_FOLDER" || exit 1
./go_scp start all
#rm -rf go_scp
#rm -rf servers.toml
rm -rf chain33.tgz
elif [ "$1" == "stop" ]; then
./go_scp stop all
elif [ "$1" == "clear" ]; then
./go_scp clear all
else
echo "Usage: ./raft_deploy.sh [start,stop,clear]"
fi
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"log"
"net"
"os"
"path"
"time"
"io"
"github.com/pkg/sftp"
"golang.org/x/crypto/ssh"
//"io/ioutil"
"errors"
"flag"
tml "github.com/BurntSushi/toml"
)
var configPath = flag.String("f", "servers.toml", "configfile")
// ScpInfo struct
type ScpInfo struct {
UserName string
PassWord string
HostIP string
Port int
LocalFilePath string
RemoteDir string
}
// CmdInfo struct
type CmdInfo struct {
userName string
passWord string
hostIP string
port int
cmd string
remoteDir string
}
// TomlConfig struct
type TomlConfig struct {
Title string
Servers map[string]ScpInfo
}
func sshconnect(user, password, host string, port int) (*ssh.Session, error) {
var (
auth []ssh.AuthMethod
addr string
clientConfig *ssh.ClientConfig
client *ssh.Client
session *ssh.Session
err error
)
// get auth method
auth = make([]ssh.AuthMethod, 0)
auth = append(auth, ssh.Password(password))
clientConfig = &ssh.ClientConfig{
User: user,
Auth: auth,
Timeout: 30 * time.Second,
//需要验证服务端,不做验证返回nil就可以
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
return nil
},
}
// connet to ssh
addr = fmt.Sprintf("%s:%d", host, port)
if client, err = ssh.Dial("tcp", addr, clientConfig); err != nil {
return nil, err
}
// create session
if session, err = client.NewSession(); err != nil {
return nil, err
}
return session, nil
}
func sftpconnect(user, password, host string, port int) (*sftp.Client, error) {
var (
auth []ssh.AuthMethod
addr string
clientConfig *ssh.ClientConfig
sshClient *ssh.Client
sftpClient *sftp.Client
err error
)
// get auth method
auth = make([]ssh.AuthMethod, 0)
auth = append(auth, ssh.Password(password))
clientConfig = &ssh.ClientConfig{
User: user,
Auth: auth,
Timeout: 30 * time.Second,
//需要验证服务端,不做验证返回nil就可以
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
return nil
},
}
// connet to ssh
addr = fmt.Sprintf("%s:%d", host, port)
if sshClient, err = ssh.Dial("tcp", addr, clientConfig); err != nil {
return nil, err
}
// create sftp client
if sftpClient, err = sftp.NewClient(sshClient); err != nil {
return nil, err
}
return sftpClient, nil
}
// ScpFileFromLocalToRemote copy local file to remote
func ScpFileFromLocalToRemote(si *ScpInfo) {
sftpClient, err := sftpconnect(si.UserName, si.PassWord, si.HostIP, si.Port)
if err != nil {
fmt.Println("sftconnect have a err!")
log.Fatal(err)
panic(err)
}
defer sftpClient.Close()
srcFile, err := os.Open(si.LocalFilePath)
if err != nil {
log.Fatal(err)
panic(err)
}
defer srcFile.Close()
var remoteFileName = path.Base(si.LocalFilePath)
fmt.Println("remoteFileName:", remoteFileName)
dstFile, err := sftpClient.Create(path.Join(si.RemoteDir, remoteFileName))
if err != nil {
log.Fatal(err)
}
defer dstFile.Close()
//bufReader := bufio.NewReader(srcFile)
//b := bytes.NewBuffer(make([]byte,0))
buf := make([]byte, 1024000)
for {
//n, err := bufReader.Read(buf)
n, _ := srcFile.Read(buf)
if err != nil && err != io.EOF {
panic(err)
}
if n == 0 {
break
}
dstFile.Write(buf[0:n])
}
fmt.Println("copy file to remote server finished!")
}
// RemoteExec run cmd in remote
func RemoteExec(cmdInfo *CmdInfo) error {
//A Session only accepts one call to Run, Start or Shell.
session, err := sshconnect(cmdInfo.userName, cmdInfo.passWord, cmdInfo.hostIP, cmdInfo.port)
if err != nil {
return err
}
defer session.Close()
session.Stdout = os.Stdout
session.Stderr = os.Stderr
err = session.Run(cmdInfo.cmd)
return err
}
func remoteScp(si *ScpInfo, reqnum chan struct{}) {
defer func() {
reqnum <- struct{}{}
}()
ScpFileFromLocalToRemote(si)
//session, err := sshconnect("ubuntu", "Fuzamei#123456", "raft15258.chinacloudapp.cn", 22)
fmt.Println("remoteScp file successfully!:")
}
// InitCfg init config
func InitCfg(path string) *TomlConfig {
var cfg TomlConfig
if _, err := tml.DecodeFile(path, &cfg); err != nil {
fmt.Println(err)
os.Exit(0)
}
return &cfg
}
func main() {
conf := InitCfg(*configPath)
start := time.Now()
if len(os.Args) == 1 || os.Args[1] == "-h" {
LoadHelp()
return
}
argsWithoutProg := os.Args[1:]
switch argsWithoutProg[0] {
case "-h": //使用帮助
LoadHelp()
case "start":
if len(argsWithoutProg) != 2 {
fmt.Print(errors.New("参数错误").Error())
return
}
if argsWithoutProg[1] == "all" {
startAll(conf)
}
case "stop":
if len(argsWithoutProg) != 2 {
fmt.Print(errors.New("参数错误").Error())
return
}
if argsWithoutProg[1] == "all" {
stopAll(conf)
}
case "clear":
if len(argsWithoutProg) != 2 {
fmt.Print(errors.New("参数错误").Error())
return
}
if argsWithoutProg[1] == "all" {
clearAll(conf)
}
}
////读取当前目录下的文件
//dir_list, e := ioutil.ReadDir("ID:/Repository/src/github.com/33cn/chain33/consensus/drivers/raft/tools/scripts")
//if e != nil {
// fmt.Println("read dir error")
// return
//}
//for i, v := range dir_list {
// fmt.Println(i, "=", v.Name())
//}
timeCommon := time.Now()
log.Printf("read common cost time %v\n", timeCommon.Sub(start))
}
// LoadHelp show available commands
func LoadHelp() {
fmt.Println("Available Commands:")
fmt.Println(" start : 启动服务 ")
fmt.Println(" stop : 停止服务")
fmt.Println(" clear : 清空数据")
}
func startAll(conf *TomlConfig) {
//fmt.Println(getCurrentDirectory())
arrMap := make(map[string]*CmdInfo)
//多协程启动部署
reqC := make(chan struct{}, len(conf.Servers))
for index, sc := range conf.Servers {
cmdInfo := &CmdInfo{}
cmdInfo.hostIP = sc.HostIP
cmdInfo.userName = sc.UserName
cmdInfo.port = sc.Port
cmdInfo.passWord = sc.PassWord
cmdInfo.cmd = fmt.Sprintf("mkdir -p %s", sc.RemoteDir)
cmdInfo.remoteDir = sc.RemoteDir
RemoteExec(cmdInfo)
go remoteScp(&sc, reqC)
arrMap[index] = cmdInfo
}
for i := 0; i < len(conf.Servers); i++ {
<-reqC
}
for i, cmdInfo := range arrMap {
cmdInfo.cmd = fmt.Sprintf("cd %s;tar -xvf chain33.tgz;bash raft_conf.sh %s;bash run.sh start", cmdInfo.remoteDir, i)
RemoteExec(cmdInfo)
}
}
func stopAll(conf *TomlConfig) {
//执行速度快,不需要多起多协程工作
for _, sc := range conf.Servers {
cmdInfo := &CmdInfo{}
cmdInfo.hostIP = sc.HostIP
cmdInfo.userName = sc.UserName
cmdInfo.port = sc.Port
cmdInfo.passWord = sc.PassWord
cmdInfo.cmd = fmt.Sprintf("cd %s;bash run.sh stop", sc.RemoteDir)
cmdInfo.remoteDir = sc.RemoteDir
RemoteExec(cmdInfo)
}
}
func clearAll(conf *TomlConfig) {
for _, sc := range conf.Servers {
cmdInfo := &CmdInfo{}
cmdInfo.hostIP = sc.HostIP
cmdInfo.userName = sc.UserName
cmdInfo.port = sc.Port
cmdInfo.passWord = sc.PassWord
cmdInfo.cmd = fmt.Sprintf("cd %s;bash run.sh clear", sc.RemoteDir)
cmdInfo.remoteDir = sc.RemoteDir
RemoteExec(cmdInfo)
}
}
title = "raft"
[servers]
#按实际需求依次配置
[servers.1]
userName="ubuntu"
hostIp="raft15258.chinacloudapp.cn"
passWord="Fuzamei#123456"
port=22
localFilePath="chain33.tgz"
remoteDir="/home/ubuntu/deploy"
# [servers.2]
# userName="ubuntu"
# hostIp="raft15258.chinacloudapp.cn22222"
# passWord="Fuzamei#123456"
# port=22
# localFilePath=""
# remoteDir=""
# [servers.3]
# userName="ubuntu"
# hostIp="raft15258.chinacloudapp.cn22222"
# passWord="Fuzamei#123456"
# port=22
# localFilePath=""
# remoteDir=""
\ No newline at end of file
#!/bin/bash
cmd=$(sed -n '/^[# ]*\[.*\][ ]*/p' servers.conf)
fileName="servers.conf"
serverStr="servers."
getSections() {
sections="$cmd"
}
getInfoByIndex() {
index=$1
nextIndex=$((index + 1))
info=$(cat <"$fileName" | sed -n "/^[# ]*\\[servers.${index}/,/^[# ]*\\[servers.${nextIndex}/p")
}
getInfoByIndexAndKey() {
index=$1
key=$2
info=$(cat <"$fileName" | sed -n "/^[# ]*\\[servers.${index}/,/^[# ]*\\[servers.${nextIndex}/p" | grep -i "$key" | awk -F '=' '{print $2}')
}
main() {
getSections
for line in $sections; do
if [[ $line =~ $serverStr ]]; then
index=$(echo "$line" | awk -F '.' '{print $2}' | awk -F ']' '{print$1}')
getInfoByIndexAndKey "$index" "userName"
echo "servers.$index: userName->$info"
getInfoByIndexAndKey "$index" "hostIp"
echo "servers.$index: hostIp->$info"
getInfoByIndexAndKey "$index" "port"
echo "servers.$index: port->$info"
fi
done
}
main
[servers]
#按实际需求依次配置
[servers.1]
userName=root
hostIp=114.55.149.144
passWord=Fuzamei#123456
pemFilePath=yiliaolian.pem
port=22
localFilePath=chain33.tgz
remoteDir=/root/deploy
[servers.2]
userName=root
hostIp=139.224.19.175
passWord=Fuzamei#123456
pemFilePath=yiliaolian.pem
port=22
localFilePath=chain33.tgz
remoteDir=/root/deploy
[servers.3]
userName=root
hostIp=139.224.82.165
passWord=Fuzamei#123456
pemFilePath=yiliaolian.pem
port=22
localFilePath=chain33.tgz
remoteDir=/root/deploy
\ No newline at end of file
#!/usr/bin/env bash
#这是一个修改配置文件的脚本
nodeId=$1
function echo_green() {
echo -e "\\033[32m$1\\033[0m"
}
function main() {
sed -i "s/singleMode=true/singleMode=true/g" chain33.toml
sed -i "s/nodeId=1/nodeId=$nodeId/g" chain33.toml
}
main
echo_green "修改完成"
#!/usr/bin/env bash
# shellcheck disable=SC2029
########################################################################################################################
##########################chain33自动部署脚本###########################################################################
########################################################################################################################
##############################解析配置文件#######################################################
pemFile=$1
cmd=$(sed -n '/^[# ]*\[.*\][ ]*/p' servers.conf)
fileName="servers.conf"
serverStr="servers."
getSections() {
sections=$cmd
}
getInfoByIndex() {
index=$1
nextIndex=$((index + 1))
info=$(cat <"$fileName" | sed -n "/^[# ]*\\[servers.${index}/,/^[# ]*\\[servers.${nextIndex}/p")
}
getInfoByIndexAndKey() {
index=$1
key=$2
info=$(cat <"$fileName" | sed -n "/^[# ]*\\[servers.${index}/,/^[# ]*\\[servers.${nextIndex}/p" | grep -i "$key" | awk -F '=' '{print $2}')
}
main() {
getSections
for line in $sections; do
if [[ $line =~ $serverStr ]]; then
index=$(echo "$line" | awk -F '.' '{print $2}' | awk -F ']' '{print$1}')
getInfoByIndexAndKey "$index" "userName"
echo "servers.$index: userName->$info"
getInfoByIndexAndKey "$index" "hostIp"
echo "servers.$index: hostIp->$info"
getInfoByIndexAndKey "$index" "port"
echo "servers.$index: port->$info"
fi
done
}
############################从本地copy文件到远程主机上#####################################################################
scpFileFromLocal() {
hostIP=$1
echo "hostIp:$hostIP"
port=$2
echo "port:$port"
userName=$3
echo "userName:$userName"
pemFile=$4
echo "pemFile:$pemFile"
scpFile=$5
deployDir=$6
ssh -i "$pemFile" -p "$port" "$userName"@"$hostIP" "mkdir -p $deployDir"
echo "scp -i $pemFile -P $port $scpFile $userName@$hostIP:$deployDir"
scp -i "$pemFile" -P "$port" "$scpFile" "$userName"@"$hostIP":"$deployDir"
}
####################################解压和启动chain33#################################################################
startChain33() {
hostIP=$1
port=$2
userName=$3
pemFile=$4
deployDir=$5
nodeId=$6
ssh -i "$pemFile" -p "$port" "$userName"@"$hostIP" "cd $deployDir;tar -xvf chain33.tgz;bash raft_conf.sh $nodeId;bash run.sh start"
echo done!
}
stopChain33() {
hostIP=$1
port=$2
userName=$3
pemFile=$4
deployDir=$5
nodeId=$6
ssh -i "$pemFile" -p "$port" "$userName"@"$hostIP" "cd $deployDir;bash run.sh stop"
echo done!
}
clearChain33() {
hostIP=$1
port=$2
userName=$3
pemFile=$4
deployDir=$5
ssh -i "$pemFile" -p "$port" "$userName"@"$hostIP" "cd $deployDir;bash run.sh clear"
echo done!
}
##########################################批量copy本地文件到多个远程主机上面####################################################################
batchScpFileFromLocal() {
getSections
for line in $sections; do
if [[ $line =~ $serverStr ]]; then
index=$(echo "$line" | awk -F '.' '{print $2}' | awk -F ']' '{print$1}')
getInfoByIndexAndKey "$index" "userName"
echo "servers.$index: userName->$info"
userName=$info
getInfoByIndexAndKey "$index" "hostIp"
echo "servers.$index: hostIp->$info"
hostIP=$info
getInfoByIndexAndKey "$index" "port"
echo "servers.$index: port->$info"
port=$info
getInfoByIndexAndKey "$index" "localFilePath"
echo "servers.$index: localFilePath->$info"
localFilePath=$info
getInfoByIndexAndKey "$index" "remoteDir"
echo "servers.$index: remoteDir->$info"
remoteDir=$info
scpFileFromLocal "$hostIP" "$port" "$userName" "$pemFile" "$localFilePath" "$remoteDir"
echo "the servers.$index:scp file successfully!"
fi
done
}
######################################批量执行解压和启动chain33#################################################################################
batchStartChain33() {
getSections
for line in $sections; do
if [[ $line =~ $serverStr ]]; then
index=$(echo "$line" | awk -F '.' '{print $2}' | awk -F ']' '{print$1}')
getInfoByIndexAndKey "$index" "userName"
echo "servers.$index: userName->$info"
userName=$info
getInfoByIndexAndKey "$index" "hostIp"
echo "servers.$index: hostIp->$info"
hostIP=$info
getInfoByIndexAndKey "$index" "port"
echo "servers.$index: port->$info"
port=$info
getInfoByIndexAndKey "$index" "localFilePath"
echo "servers.$index: localFilePath->$info"
localFilePath=$info
getInfoByIndexAndKey "$index" "port"
echo "servers.$index: remoteDir->$info"
remoteDir=$info
startChain33 "$hostIP" "$port" "$userName" "$pemFile" "$remoteDir" "$index"
echo "the servers.$index:start chain33 successfully!"
fi
done
}
######################################批量停止chain33服务######################################################################################
batchStopChain33() {
getSections
for line in $sections; do
if [[ $line =~ $serverStr ]]; then
index=$(echo "$line" | awk -F '.' '{print $2}' | awk -F ']' '{print$1}')
getInfoByIndexAndKey "$index" "userName"
echo "servers.$index: userName->$info"
userName=$info
getInfoByIndexAndKey "$index" "hostIp"
echo "servers.$index: hostIp->$info"
hostIP=$info
getInfoByIndexAndKey "$index" "port"
echo "servers.$index: port->$info"
port=$info
getInfoByIndexAndKey "$index" "localFilePath"
echo "servers.$index: localFilePath->$info"
localFilePath=$info
getInfoByIndexAndKey "$index" "remoteDir"
echo "servers.$index: remoteDir->$info"
remoteDir=$info
stopChain33 "$hostIP" "$port" "$userName" "$pemFile" "$remoteDir"
echo "the servers.$index:stop chain33 successfully!"
fi
done
}
######################################批量清理chain33拥有数据##################################################################################
batchClearChain33() {
getSections
for line in $sections; do
if [[ $line =~ $serverStr ]]; then
index=$(echo "$line" | awk -F '.' '{print $2}' | awk -F ']' '{print$1}')
getInfoByIndexAndKey "$index" "userName"
echo "servers.$index: userName->$info"
userName=$info
getInfoByIndexAndKey "$index" "hostIp"
echo "servers.$index: hostIp->$info"
hostIP=$info
getInfoByIndexAndKey "$index" "port"
echo "servers.$index: port->$info"
port=$info
getInfoByIndexAndKey "$index" "localFilePath"
echo "servers.$index: localFilePath->$info"
localFilePath=$info
getInfoByIndexAndKey "$index" "remoteDir"
echo "servers.$index: remoteDir->$info"
remoteDir=$info
clearChain33 "$hostIP" "$port" "$userName" "$pemFile" "$remoteDir"
echo "the servers.$index:clear chain33 data successfully!"
fi
done
}
######################################本脚本使用指导##################################################################################
#Program:
# This is a chain33 deploy scripts!
if [ "$2" == "start" ]; then
batchStartChain33
elif [ "$2" == "scp" ]; then
batchScpFileFromLocal
elif [ "$2" == "stop" ]; then
batchStopChain33
elif [ "$2" == "clear" ]; then
batchClearChain33
else
echo "Usage: ./raft_deploy.sh [pemFile:认证文件] [scp,start,stop,clear]"
fi
#!/usr/bin/env bash
#Program:
# This is a chain33 deploy scripts!
if [ "$1" == "start" ]; then
nohup ./chain33 >console.log 2>&1 &
echo $! >chain33.pid
elif [ "$1" == "stop" ]; then
PID=$(cat chain33.pid)
kill -9 "$PID"
rm -rf chain33.pid
elif [ "$1" == "clear" ]; then
rm -rf console.log
rm -rf logs/
rm -rf grpc33.log
rm -rf chain33_raft*
rm -rf datadir/
else
echo "Usage: ./run.sh [start,stop,clear]"
fi
[servers]
#按实际需求依次配置
[servers.1]
userName=root
hostIp=114.55.149.144
passWord=Fuzamei#123456
pemFilePath=yiliaolian.pem
port=22
localFilePath=chain33.tgz
remoteDir=/root/deploy
[servers.2]
userName=root
hostIp=139.224.19.175
passWord=Fuzamei#123456
pemFilePath=yiliaolian.pem
port=22
localFilePath=chain33.tgz
remoteDir=/root/deploy
[servers.3]
userName=root
hostIp=139.224.82.165
passWord=Fuzamei#123456
pemFilePath=yiliaolian.pem
port=22
localFilePath=chain33.tgz
remoteDir=/root/deploy
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment