Hyperledger Fabric 2.0.1多机部署流程
(2.0版本及以上应该都是可以的,虽然我没有试过哈哈)
说明:本篇文章是静态IP部署,没有使用docker swarm或者k8s,不过后面会尝试的。(静态部署我都卡了N久,遇到巨多错误,然后结合网上其他人的博客和官方的fabric-sample配置文件写的)
环境:两台主机,ubuntu18.04(非虚拟机)
名称 | 版本 |
---|---|
Fabric | 2.0.1 |
go | 1.15 |
docker | 19.03.6 |
docker-compose | 1.12.6 |
部署方式:3个orderer(实现raft共识的最少数量),2个组织,每个组织2个节点(其中一个锚节点)。主机1两个orderer,一个组织;主机2一个orderer,一个组织。静态IP。
1. 安装相关环境:go, docker, docker-compose,fabric-samples,二进制文件和相关镜像并跑通first-network
自动化脚本,二进制自行vpn下载放置与/home下
#!/bin/bash
#versions fabric2.0.1 docker19.03.6 go1.15
#install corresponding depencies for fabric from scratch
# echo print with color
function echoColor()
{
echo -e "\033[35;1m$1\033[0m"
}
function installssh()
{
echoColor "installing ssh service"
sudo apt-get update
sudo apt-get install openssh-server -y
sudo service ssh start
echoColor "finish installed ssh service"
echo
}
# update os
function updateOS()
{
echoColor "Updating system to newest version"
sudo apt-get update -y --fix-missing
echo
}
#synchoronize time
function syntime()
{
echoColor "synchorize time of different area"
# 移除当前的时区信息
sudo rm -rf /etc/localtime
# 修改时区
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echoColor "finish synchorized time of different area"
}
# install some useful tools
function installtools()
{
echoColor "-----------------------------------------------------------------"
echoColor "Start installing, please wait......."
# 安装git
echoColor "Start Install git"
apt-get install -y git
# 安装cURL
echoColor "Start Install curl"
apt-get install curl -y
# 安装jq
echoColor "Start Install jq"
apt-get install jq -y
echoColor "Finish installed tools."
echoColor "-----------------------------------------------------------------"
}
# 安装 Golang
function installGolang()
{
echo
echoColor "-----------------------------------------------------------------"
echoColor "Start install Golang,please wait......."
# 下载Go
echo
wget https://studygolang.com/dl/golang/go1.15.5.linux-amd64.tar.gz
#wget https://storage.googleapis.com/golang/go1.15.5.linux-amd64.tar.gz
tar xfz go1.15.5.linux-amd64.tar.gz -C /usr/local
# 设置环境变量
echoColor "Create Go Environment"
echo
echoColor "Set golang environment"
echo -e "export GOPATH=/usr/local/gopath
export GOROOT=/usr/local/go
export PATH=\$GOROOT/bin:\$PATH">>/etc/profile
source /etc/profile
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
source /etc/profile
go version
echo
echoColor "Finish install Golang "
echoColor "-----------------------------------------------------------------"
}
# 安装 docker和docker compose
function installDocker()
{
echo
echoColor "-----------------------------------------------------------------"
echoColor "Start install docker,please wait......."
if [ ! -f "/usr/bin/docker" ];then
echoColor "Install dependency items for https"
sudo apt-get install apt-transport-https ca-certificates software-properties-common -y
echoColor "Set stable repo for docker"
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable" >> /etc/apt/sources.list
sudo apt-get update
echoColor "Install docker and start service"
sudo apt-get install docker-ce=5:19.03.6~3-0~ubuntu-bionic docker-ce-cli=5:19.03.6~3-0~ubuntu-bionic containerd.io -y
echoColor "Set accelerate registry-mirrors"
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://rl4uepop.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart do