Skip to content

Commit

Permalink
upload quickstart script
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwindworld committed Aug 11, 2017
1 parent 09485e9 commit 91118bc
Show file tree
Hide file tree
Showing 16 changed files with 266 additions and 60 deletions.
56 changes: 56 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#
# 一键安装脚本说明
#1 build.sh在centos和Ubuntu版本测试成功;
#2 所有Linux发行版本请确保yum和git已安装,并能正常使用;
#3 如遇到中途依赖库下载失败,一般和网络状况有关,请到https://github.com/bcosorg/lib找到相应的库,手动安装成功后,再执行此脚本
#

#!/bin/sh

#install nodejs
sudo yum install -y nodejs
sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
sudo cnpm install -g babel-cli babel-preset-es2017
echo '{ "presets": ["es2017"] }' > ~/.babelrc


#install solc
wget https://github.com/ethereum/solidity/releases/download/v0.4.13/solc-static-linux
sudo cp solc-static-linux /usr/bin/solc
sudo chmod +x /usr/bin/solc

#install console
sudo cnpm install -g ethereum-console

#install deps
sudo yum -y install cmake3
sudo yum install -y openssl openssl-devel
chmod +x scripts/install_deps.sh
./scripts/install_deps.sh

#build bcos
mkdir -p build
cd build/
if grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; then
cmake -DEVMJIT=OFF -DTESTS=OFF -DMINIUPNPC=OFF ..
else
cmake3 -DEVMJIT=OFF -DTESTS=OFF -DMINIUPNPC=OFF ..
fi

make -j2

make install

cd ..
cd ./tool
cnpm install

cd ..
cd ./systemcontractv2
cnpm install

if [ ! -f "/usr/local/bin/bcoseth" ]; then
echo 'bcoseth build fail!'
else
echo 'bcoseth build succ! path: /usr/local/bin/bcoseth'
fi
34 changes: 0 additions & 34 deletions sample-node/config.json

This file was deleted.

1 change: 0 additions & 1 deletion sample-node/data/keys.info

This file was deleted.

1 change: 0 additions & 1 deletion sample-node/data/keys.info.salt

This file was deleted.

1 change: 0 additions & 1 deletion sample-node/data/network.rlp

This file was deleted.

1 change: 0 additions & 1 deletion sample-node/data/network.rlp.pub

This file was deleted.

12 changes: 0 additions & 12 deletions sample-node/genesis.json

This file was deleted.

3 changes: 0 additions & 3 deletions sample-node/start.sh

This file was deleted.

29 changes: 29 additions & 0 deletions sample/config.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"sealEngine": "PBFT",
"systemproxyaddress":"0x0",
"systemproxyaddressDfsFile":"",
"systemproxyaddressDfsServer":"",
"listenip":"{ip}",
"rpcport":"{rpcport}",
"p2pport":"{p2pport}",
"wallet":"{nodedir}keys.info",
"keystoredir":"{nodedir}keystore/",
"datadir":"{nodedir}data/",
"vm":"interpreter",
"networkid":"{networkid}",
"logverbosity":"4",
"coverlog":"OFF",
"eventlog":"ON",
"logconf":"{nodedir}log.conf",
"dfsNode":"",
"dfsGroup":"group1",
"dfsStorage":"filestorage",
"params": {
"accountStartNonce": "0x0",
"maximumExtraDataSize": "0x0",
"tieBreakingGas": false,
"blockReward": "0x0",
"networkID" : "0x0"
},
"NodeextraInfo":{nodeextrainfo}
}
13 changes: 13 additions & 0 deletions sample/genesis.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"nonce": "0x0",
"difficulty": "0x0",
"mixhash": "0x0",
"coinbase": "0x0",
"timestamp": "0x0",
"parentHash": "0x0",
"extraData": "0x0",
"gasLimit": "0x13880000000000",
"god":"{admin}",
"alloc": {},
"initMinerNodes":{initMinerNodes}
}
137 changes: 137 additions & 0 deletions sample/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
var fs=require('fs');
var execSync =require('child_process').execSync;

var options = process.argv;
if( options.length < 3 )
{
console.log('Usage: node init.js node0.sample node1.sample node2.sample... ');
process.exit(0);
}

var nodeconfiglength=0;
var nodeconfig=[];
while(nodeconfig.length<options.length-2 ){
var node=JSON.parse(fs.readFileSync(options[2+nodeconfig.length], 'utf-8'));
nodeconfig.push(node);
}

console.log("开始检查配置...");
var check=true;
for( var i=0;i<nodeconfig.length;i++){
for( var j=0;j<nodeconfig.length;j++){
if( i!=j ){
if( nodeconfig[i].networkid != nodeconfig[j].networkid){
check=false;
console.log('节点'+i+'和节点'+j+' networkid不一致,请检查!');
}
if( nodeconfig[i].ip == nodeconfig[j].ip ){
if( nodeconfig[i].nodedir == nodeconfig[j].nodedir ){
console.log('节点'+i+',和节点'+j+' IP相同且datadir相同,请检查!');
check=false;
}
if( nodeconfig[i].rpcport == nodeconfig[j].rpcport ){
console.log('节点'+i+',和节点'+j+' IP相同且rpcport相同,请检查!');
check=false;
}
if( nodeconfig[i].p2pport == nodeconfig[j].p2pport ){
console.log('节点'+i+',和节点'+j+' IP相同且p2pport相同,请检查!');
check=false;
}
}
}
}
}
if( !check ){
process.exit(1);
}
else{
console.log('配置检查成功!!!');
}

var admin;
try{
admin=execSync("node ../tool/accountManager.js");
console.log('生成管理员账户成功!!!即将拷贝备份到每个节点目录的admin.message文件中,请注意保管!!!');
}catch(e){
console.log('管理员账户生成失败!!!');
process.exit(1);
}

var nodeid=[];
console.log('开始初始化节点配置...');
for( var i=0;i<nodeconfig.length;i++){
try{
execSync("mkdir -p "+nodeconfig[i].nodedir);
execSync("mkdir -p "+nodeconfig[i].nodedir+"log/");
execSync("mkdir -p "+nodeconfig[i].nodedir+"data/");
execSync("mkdir -p "+nodeconfig[i].nodedir+"keystore/");
execSync("bcoseth --gennetworkrlp "+nodeconfig[i].nodedir+"data/network.rlp");
nodeid.push(fs.readFileSync(nodeconfig[i].nodedir+"data/network.rlp.pub", 'utf-8'));

var logconfig=fs.readFileSync("log.conf.template", 'utf-8');
fs.writeFileSync(nodeconfig[i].nodedir+'log.conf',logconfig.replace(/{nodedir}/g,nodeconfig[i].nodedir));

var startsh=fs.readFileSync("start.sh.template", 'utf-8');
startsh=startsh.replace(/{genesis}/g,nodeconfig[i].nodedir+'genesis.json');
fs.writeFileSync(nodeconfig[i].nodedir+'start'+i+'.sh',startsh.replace(/{config}/g,nodeconfig[i].nodedir+'config.json'));
execSync("chmod -x "+nodeconfig[i].nodedir+'start'+i+'.sh');

fs.writeFileSync(nodeconfig[i].nodedir+'admin.message',admin);
console.log('节点'+i+'目录生成成功!!!');
}catch(e){
console.log('节点'+i+'目录生成失败!'+e);
}

}//for

admin=fs.readFileSync(nodeconfig[0].nodedir+'admin.message','utf-8');
admin=(admin.split(/\n/)[2].split(/ /)[2]);

var genesis=fs.readFileSync("genesis.json.template", 'utf-8');
genesis=genesis.replace(/{initMinerNodes}/g,JSON.stringify(nodeid));
genesis=genesis.replace(/{admin}/g,admin);
console.log('创世文件生成成功!!!');

var nodeextrainfo=[];
for( var i=0;i<nodeconfig.length;i++){
nodeextrainfo.push({
"Nodeid":nodeid[i],
"Nodedesc": "node"+i,
"Agencyinfo": "node"+i,
"Peerip": nodeconfig[i].ip,
"Identitytype": 1,
"Port":nodeconfig[i].p2pport,
"Idx":i
});
}
console.log('记账节点列表生成成功!!!');

for( var i=0;i<nodeconfig.length;i++){
try{
fs.writeFileSync(nodeconfig[i].nodedir+'genesis.json',genesis);
console.log('节点'+i+' genesis.json生成成功!!!');


var config=fs.readFileSync("config.json.template", 'utf-8');
config=config.replace(/{nodedir}/g,nodeconfig[i].nodedir);
config=config.replace(/{networkid}/g,nodeconfig[i].networkid);
config=config.replace(/{ip}/g,nodeconfig[i].ip);
config=config.replace(/{rpcport}/g,nodeconfig[i].rpcport);
config=config.replace(/{p2pport}/g,nodeconfig[i].p2pport);
config=config.replace(/{nodeextrainfo}/g,JSON.stringify(nodeextrainfo));

fs.writeFileSync(nodeconfig[i].nodedir+'config.json',config);

console.log('节点'+i+' config.json生成成功!!!');
}catch(e){
console.log('节点'+i+' 配置生成失败!'+e);
}

}//for
console.log('恭喜!已全部构建成功!');

for( var i=0;i<nodeconfig.length;i++){
console.log('执行 '+nodeconfig[i].nodedir+'start'+i+'.sh 即可启动节点'+i);
}


15 changes: 8 additions & 7 deletions sample-node/data/log.conf → sample/log.conf.template
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@
TO_FILE = true
TO_STANDARD_OUTPUT = false
FORMAT = "%level|%datetime{%Y-%M-%d %H:%m:%s}|%msg"
FILENAME = "./log/log_%datetime{%Y%M%d%H}.log"
FILENAME = "{nodedir}log/log_%datetime{%Y%M%d%H}.log"
MILLISECONDS_WIDTH = 3
PERFORMANCE_TRACKING = false
MAX_LOG_FILE_SIZE = 209715200 ## 200MB - Comment starts with two hashes (##)
LOG_FLUSH_THRESHOLD = 100 ## Flush after every 100 logs

* TRACE:
FILENAME = "./log/trace_log_%datetime{%Y%M%d%H}.log"
FILENAME = "{nodedir}log/trace_log_%datetime{%Y%M%d%H}.log"
* DEBUG:
FILENAME = "./log/debug_log_%datetime{%Y%M%d%H}.log"
FILENAME = "{nodedir}log/debug_log_%datetime{%Y%M%d%H}.log"
* FATAL:
ENABLED = false
FILENAME = "{nodedir}log/fatal_log_%datetime{%Y%M%d%H}.log"

* ERROR:
FILENAME = "./log/error_log_%datetime{%Y%M%d%H}.log"
FILENAME = "{nodedir}log/error_log_%datetime{%Y%M%d%H}.log"

* WARNING:
ENABLED = false
FILENAME = "{nodedir}log/warn_log_%datetime{%Y%M%d%H}.log"

* INFO:
FILENAME = "./log/info_log_%datetime{%Y%M%d%H}.log"
FILENAME = "{nodedir}log/info_log_%datetime{%Y%M%d%H}.log"

* VERBOSE:
ENABLED = false
7 changes: 7 additions & 0 deletions sample/node0.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"networkid":"123456",
"nodedir":"/bcos-data/node0/",
"ip":"127.0.0.1",
"rpcport":8545,
"p2pport":30303
}
7 changes: 7 additions & 0 deletions sample/node1.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"networkid":"123456",
"nodedir":"/bcos-data/node1/",
"ip":"127.0.0.1",
"rpcport":8546,
"p2pport":30304
}
6 changes: 6 additions & 0 deletions sample/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
node init.js node0.sample node1.sample
chmod +x /bcos-data/node0/start0.sh
chmod +x /bcos-data/node1/start1.sh
sh /bcos-data/node0/start0.sh &
sh /bcos-data/node1/start1.sh &
3 changes: 3 additions & 0 deletions sample/start.sh.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
bcoseth --genesis {genesis} --config {config}

0 comments on commit 91118bc

Please sign in to comment.