- 注:
BigchainDB单节点是可以运行的,但是如果想消除单点故障,网络内必须有四个节点。
1、环境准备
- 任意物理机或虚拟机
- 节点所需的软件都部署在一个机器上
- 操作系统Ubuntu Server 18.04及以上版本
- 开放端口
- 22 (SSH)
- 80 (HTTP)
- 443 (HTTPS)
- 26656 (Tendermint P2P)
更新操作系统
sudo apt update
sudo apt full-upgrade
- 1
- 2
2、安装NGINX
如果不使用HTTPS,可以不安装NGINX。
2.1 、安装NGINX
sudo apt update
sudo apt install nginx
- 1
- 2
2.2、配置NGINX
取得节点子域名的SSL证书(如:bnode.example.com)
- 将SSL私钥放到 /etc/nginx/ssl/cert.key
- 根据SSL证书创建PEM文件(文本文件)
- 将PEM文件放到 /etc/nginx/ssl/cert.pem
- 在GitHub的 bigchaindb/bigchaindb 仓库中找到 nginx/nginx.conf 文件并放到 ==/etc/nginx/nginx.conf ==
- 编辑 nginx/nginx.conf 文件,并将文件中的 example.testnet2.com 替换为 bnode.example.com(以实际域名为准)
- 重启NGINX
sudo service nginx reload
- 1
3、安装BigchainDB Server
3.1、安装Python 3.6+
BigchainDB Server需要Python 3.6以上。
# For Ubuntu 18.04:
sudo apt install -y python3-pip libssl-dev
# Ubuntu 16.04, and other Linux distros, may require other packages or more packages
- 1
- 2
- 3
3.2、安装BigchainDB Server
# Change 2.0.0b9 to the latest version as explained above:
sudo pip3 install bigchaindb==2.0.0b9
- 1
- 2
3.3、配置BigchainDB Server
命令行输入:
bigchaindb configure
- 1
个问题是 API Server bind? (默认值: localhost:9984)
- 如果使用了NGINX,则回答:
localhost:9984
- 未使用NGINX,则回答:
0.0.0.0:9984
如果使用NGINX,需要编辑文件$HOME/.bigchaindb
的"wsserver"
下面更改:
"advertised_scheme": "wss",
"advertised_host": "bnode.example.com",
"advertised_port": 443
- 1
- 2
- 3
4、安装MongoDB
BigchainDB需要MongoDB的版本在3.4以上
sudo apt install mongodb
- 1
5、安装Tendermint
BigchainDB Server使用Tendermint版本0.22.8 。
sudo apt install -y unzip
wget https://github.com/tendermint/tendermint/releases/download/v0.22.8/tendermint_0.22.8_linux_amd64.zip
unzip tendermint_0.22.8_linux_amd64.zip
rm tendermint_0.22.8_linux_amd64.zip
sudo mv tendermint /usr/local/bin
- 1
- 2
- 3
- 4
- 5
Tendermint初始化
tendermint init
- 1
6、建立BigchainDB网络
协调器(Coordinator)-特殊的节点成员,用于协调每一个节点
6.1、节点成员:分享hostname、pub_key.value 和 node_id
每一个节点都有:
- hostname, 域名(
bnode.example.com
)或IP地址(46.145.17.32
) - Tendermint
pub_key.value
- Tendermint
node_id
pub_key.value
在文件$HOME/.tendermint/config/priv_validator.json
中。就像:
{
"address": "E22D4340E5A92E4A9AD7C62DA62888929B3921E9",
"pub_key": {
"type": "tendermint/PubKeyEd25519",
"value": "P+aweH73Hii8RyCmNWbwPsa9o4inq3I+0fSfprVkZa0="
},
"last_height": "0",
"last_round": "0",
"last_step": 0,
"priv_key": {
"type": "tendermint/PrivKeyEd25519",
"value": "AHBiZXdZhkVZoPUAiMzClxhl0VvUp7Xl3YT6GvCc93A/5rB4fvceKLxHIKY1ZvA+xr2jiKercj7R9J+mtWRlrQ=="
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
node_id
可以通过命令tendermint show_node_id
获得。
6.2、协调器:产生共享genesis.json文件
协调器接收所有成员的数据,并将它们组合在文件$HOME/..mint/config/genesis.json
中。
{
"genesis_time":"0001-01-01T00:00:00Z",
"chain_id":"test-chain-la6HSr",
"consensus_params":{
"block_size_params":{
"max_bytes":"22020096",
"max_txs":"10000",
"max_gas":"-1"
},
"tx_size_params":{
"max_bytes":"10240",
"max_gas":"-1"
},
"block_gossip_params":{
"block_part_size_bytes":"65536"
},
"evidence_params":{
"max_age":"100000"
}
},
"validators":[
{
"pub_key":{
"type":"AC26791624DE60",
"value":"<Member 1 public key>"
},
"power":10,
"name":"<Member 1 name>"
},
{
"pub_key":{
"type":"AC26791624DE60",
"value":"<Member 2 public key>"
},
"power":10,
"name":"<Member 2 name>"
},
{
"...":{
},
},
{
"pub_key":{
"type":"AC26791624DE60",
"value":"<Member N public key>"
},
"power":10,
"name":"<Member N name>"
}
],
"app_hash":""
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
协调器需要将新的genesis.json
共享给所有成员。(如何共享?
)
6.3、成员:连接到其他成员
- 各个成员将
genesis.json
文件拷贝到$HOME/.tendermint/config
目录。 - 编辑
$HOME/.tendermint/config/config.toml
文件
moniker = "Name of our node"
create_empty_blocks = false
log_level = "main:info,state:info,*:error"
persistent_peers = "<Member 1 node id>@<Member 1 hostname>:26656,\
<Member 2 node id>@<Member 2 hostname>:26656,\
<Member N node id>@<Member N hostname>:26656,"
send_rate = 102400000
recv_rate = 102400000
recheck = false
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
persistent_peers列表不必包括网络中的所有节点
6.4、成员:启动MongoDB
几个有用的命令:
sudo apt install mongodb #安装MongoDB
systemctl status mongodb #查看服务状态
mongod --fork --logpath /var/log/mongodb.log
- 1
- 2
- 3
6.5、成员:用Monit启动BigchainDB和Tendermint
- 安装monit
sudo apt install monit
- 运行BigchainDB的Monit配置
bigchaindb-monit-config
- 以守护进程运行Monit,每秒唤醒一次检查进程:
monit -d 1
当BigchainDB和Tendermint进程crash时,Monit将重启BigchainDB和Tendermint进程。当bigchaindb_进程crash时也会重启Tendermint进程。
monit status #检查monit状态
monit summary
- 1
- 2
日志在~/.bigchaindb-monit/logs
下。
使用bigchaindb-monit-config -h
命令可更改相关设置。
6.7、访问节点
https://hostname
或 http://hostname:9984
Tips
1、清空节点
如果需要清空一个节点,好是关闭节点在新的机器上重新部署,如果不重新部署,需要:
- 使用
bigchaindb drop
命令卸载MongoDB中的bigchain
数据库 - 使用
tendermint unsafe_reset_all
命令重置Tendermint - 删除目录
$HOME/.tendermint
2、关闭BigchainDB
$ nohup bigchaindb start 2>&1 > bigchaindb.log &
$ # Check the PID of the main BigchainDB process
$ ps -ef | grep bigchaindb
<user> *<pid> <ppid> <C> <STIME> <tty> <time> bigchaindb
<user> <pid> <ppid>* <C> <STIME> <tty> <time> gunicorn: master [bigchaindb_gunicorn]
<user> <pid> <ppid>* <C> <STIME> <tty> <time> bigchaindb_ws
<user> <pid> <ppid>* <C> <STIME> <tty> <time> bigchaindb_ws_to_tendermint
<user> <pid> <ppid>* <C> <STIME> <tty> <time> bigchaindb_exchange
<user> <pid> <ppid> <C> <STIME> <tty> <time> gunicorn: worker [bigchaindb_gunicorn]
<user> <pid> <ppid> <C> <STIME> <tty> <time> gunicorn: worker [bigchaindb_gunicorn]
<user> <pid> <ppid> <C> <STIME> <tty> <time> gunicorn: worker [bigchaindb_gunicorn]
<user> <pid> <ppid> <C> <STIME> <tty> <time> gunicorn: worker [bigchaindb_gunicorn]
<user> <pid> <ppid> <C> <STIME> <tty> <time> gunicorn: worker [bigchaindb_gunicorn]
...
$ # Send any of the above mentioned signals to the parent/root process(marked with `*` for clarity)
# Sending SIGINT
$ kill -2 <bigchaindb_parent_pid>
$ # OR
# Sending SIGTERM
$ kill -15 <bigchaindb_parent_pid>
$ # OR
# Sending SIGQUIT
$ kill -3 <bigchaindb_parent_pid>
# If you want to kill all the processes by name yourself
$ pgrep bigchaindb | xargs kill -9
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
3、成员:动态增加删除协调器
一个成员可以提出建议,要求进行选举以添加验证器、删除验证器或更改验证器的投票权。然后他们和其他成员分享选举/提案ID。一旦超过三分之二的投票权通过,提议的改变就生效了。创建新的选举/提案、批准选举/提案以及获得选举/提案的当前状态的命令可以在有关bigchaindb选举子命令的文档中找到。
来自:https://blog.csdn.net/nbhwg/article/details/85090432