Centos7 部署单节点 Hyperledger Fabric 1.4.0

Hyperledger Fabric 是什么

Hyperledger Fabric 是 Linux 基金会所主导的 Hyperledger(超级账本)的项目之一。Hyperledger Fabric 旨在作为开发模块化体系结构的区块链应用程序的基础,以便诸如共识和会员服务等组件可以即插即用。它使用容器技术来托管构成系统应用逻辑的智能合约(也称为链代码)。 简而言之,Hyperledger Fabric 是为企业构建的领先的开源、通用区块链结构。


机器硬件配置

2核 CPU
4G 内存
200G SSD 磁盘


系统版本

Centos 7


分区状况

/ 30G
/data 165.8G
/boot 200MB
swap 4096MB


机器IP

10.18.193.31


关闭防火墙和 selinux

[[email protected] ~]# systemctl stop firewalld.service 
[[email protected] ~]# systemctl disable firewalld.service 
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[[email protected] ~]# setenforce 0
[[email protected] ~]# vim /etc/selinux/config
SELINUX=disabled

安装必要工具

[[email protected] ~]# curl https://download.docker.com/linux/centos/docker-ce.repo -o  /etc/yum.repos.d/docker.repo
[[email protected] ~]# curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
[[email protected] ~]# chmod +x /usr/local/bin/docker-compose
[[email protected] ~]# yum -y install vim git wget docker-ce.x86_64 yum-utils device-mapper-persistent-data lvm2 epel-release python-pip gcc gcc-c++
[[email protected] ~]# wget https://curl.haxx.se/download/curl-7.65.1.tar.gz
[[email protected] ~]# wget https://www.openssl.org/source/openssl-1.1.1c.tar.gz
[[email protected] ~]# tar xvf openssl-1.1.1c.tar.gz
[[email protected] ~]# cd openssl-1.1.1c/
[[email protected] openssl-1.1.1c]# ./config --prefix=/usr/local/ssl/
[[email protected] openssl-1.1.1c]# ./config -t
[[email protected] openssl-1.1.1c]# make && make install
[[email protected] openssl-1.1.1c]# ln -s /usr/local/ssl/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1
[[email protected] openssl-1.1.1c]# ln -s /usr/local/ssl/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
[[email protected] openssl-1.1.1c]# cd
[[email protected] ~]# tar xvf curl-7.65.1.tar.gz
[[email protected] ~]# cd curl-7.65.1/
[[email protected] curl-7.65.1]# ./configure --with-ssl=/usr/local/ssl
[[email protected] curl-7.65.1]# make && make install
[[email protected] openssl-1.1.1c]# cd

安装 go

[[email protected] ~]# wget https://studygolang.com/dl/golang/go1.12.5.linux-amd64.tar.gz
[[email protected] ~]# tar xvf go1.12.5.linux-amd64.tar.gz
[[email protected] ~]# mv go /usr/local/
[[email protected] ~]# vim /etc/profile
export  PATH=$PATH:/usr/local/go/bin
export  GOROOT=/usr/local/go
export  GOPATH=$HOME/go
export  PATH=$PATH:$HOME/go/bin
[[email protected] ~]# source /etc/profile
[[email protected] ~]# mkdir -p /usr/local/go/src/github.com/hyperledger/fabric
[[email protected] ~]# chmod -R 777 /usr/local/go

把 docker 相关目录转移到 /data 分区,启动 docker

[[email protected] ~]# mv /var/lib/docker /data/
[[email protected] ~]# ln -sf /data/docker /var/lib/docker
[[email protected] ~]# systemctl start docker
[[email protected] ~]# systemctl enable docker.service

安装 nodejs 8.9.2

[[email protected] ~]# wget https://nodejs.org/dist/v8.9.2/node-v8.9.2-linux-x64.tar.xz
[[email protected] ~]# tar xvf node-v8.9.2-linux-x64.tar.xz
[[email protected] ~]# mv node-v8.9.2-linux-x64 /usr/local/nodejs-v8.9.2
[[email protected] ~]# ln -sf /usr/local/nodejs-v8.9.2/bin/node /usr/local/bin/
[[email protected] ~]# ln -sf /usr/local/nodejs-v8.9.2/bin/npm /usr/local/bin/
[[email protected] ~]# node -v
v8.9.2
[[email protected] ~]# npm -v
5.5.1
[[email protected] ~]# reboot

部署 fabric

[[email protected] ~]# cd /usr/local/go/src/github.com/hyperledger/fabric/
[[email protected] fabric]# curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh | bash -s -- 1.4.0 1.4.0 0.4.15

运行 fabric BYFN 测试是否正确部署,默认网络名为 mychannel

[[email protected] fabric]# cd fabric-samples/first-network/
[[email protected] first-network]# ./byfn.sh -m generate
Generating certs and genesis block for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
/usr/local/go/src/github.com/hyperledger/fabric/fabric-samples/bin/cryptogen

##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################
···············································
···············································
+ res=0
+ set +x
[[email protected] first-network]# ./byfn.sh up
Starting for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
WARNING: IPv4 forwarding is disabled. Networking will not work.
LOCAL_VERSION=1.4.0
DOCKER_IMAGE_VERSION=1.4.0
Creating network "net_byfn" with the default driver
Creating volume "net_orderer.example.com" with default driver
Creating volume "net_peer0.org1.example.com" with default driver
Creating volume "net_peer1.org1.example.com" with default driver
Creating volume "net_peer0.org2.example.com" with default driver
Creating volume "net_peer1.org2.example.com" with default driver
Creating peer1.org2.example.com ... done
Creating peer1.org1.example.com ... done
Creating orderer.example.com    ... done
Creating peer0.org2.example.com ... done
Creating peer0.org1.example.com ... done
Creating cli                    ... done

 ____    _____      _      ____    _____ 
/ ___|  |_   _|    / \    |  _ \  |_   _|
\___ \    | |     / _ \   | |_) |   | |  
 ___) |   | |    / ___ \  |  _ <    | |  
|____/    |_|   /_/   \_\ |_| \_\   |_|  
···············································
···············································
========= All GOOD, BYFN execution completed =========== 

 _____   _   _   ____   
| ____| | \ | | |  _ \  
|  _|   |  \| | | | | | 
| |___  | |\  | | |_| | 
|_____| |_| \_| |____/  

检查是否正确启动,有 peer 相关进程即为正确启动

[[email protected] lib]# top -n 1
top - 18:17:46 up  3:02,  3 users,  load average: 2.74, 1.19, 0.66
Tasks: 212 total,   2 running, 210 sleeping,   0 stopped,   0 zombie
%Cpu(s):  2.8 us, 11.1 sy,  0.0 ni, 86.1 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  3881272 total,   484156 free,   708716 used,  2688400 buff/cache
KiB Swap:  4194300 total,  4193780 free,      520 used.  2724768 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                              
22011 root      20   0  598552 149096  14572 S  12.5  3.8   0:04.97 peer                                                                                 
21811 root      20   0  336408  96516  14636 S   6.2  2.5   0:04.88 peer                                                                                 
21912 root      20   0  401880 142044  14804 S   6.2  3.7   0:04.94 peer                                                                                 
22003 root      20   0  533336  55720  14000 S   6.2  1.4   0:03.09 peer 

关闭 fabric BYFN

[[email protected] first-network]# ./byfn.sh down
Stopping for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
Stopping cli                    ... done
Stopping peer0.org2.example.com ... done
Stopping orderer.example.com    ... done
Stopping peer0.org1.example.com ... done
Stopping peer1.org1.example.com ... done
Stopping peer1.org2.example.com ... done
Removing cli                    ... done
Removing peer0.org2.example.com ... done
Removing orderer.example.com    ... done
Removing peer0.org1.example.com ... done
Removing peer1.org1.example.com ... done
Removing peer1.org2.example.com ... done
Removing network net_byfn
Removing volume net_orderer.example.com
Removing volume net_peer0.org1.example.com
Removing volume net_peer1.org1.example.com
Removing volume net_peer0.org2.example.com
Removing volume net_peer1.org2.example.com
Removing volume net_peer0.org3.example.com
WARNING: Volume net_peer0.org3.example.com not found.
Removing volume net_peer1.org3.example.com
WARNING: Volume net_peer1.org3.example.com not found.
WARNING: IPv4 forwarding is disabled. Networking will not work.
e20898753e5e
c427bbc3efd4
12ee38bdbd70
Untagged: dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab:latest
Deleted: sha256:b5300b7a31eb086052027d3b11112cc90f0ca0b529f409e6495b07a6587b38c3
Deleted: sha256:4590a28c144593870327f91b96b735bf60713ca31c119429bd66ebb10843c8ba
Deleted: sha256:093ae0188291e36c64c211de6e2fb1c54f6ebad6c84eeaf97dac7fa6d749758e
Deleted: sha256:383186be1c4041aa2f0f731ba6c35c04ba0463afd29bea207fa650d3452e8365
Untagged: dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9:latest
Deleted: sha256:f57ddf81de29d31fa536acd64700ce7f317ee32a3eec1f4c349719cb6e949633
Deleted: sha256:27e179cafa9eaab830c19bd6e710d04b961976ea5ef0af6cf70108fadf458259
Deleted: sha256:87ceffd390625aa645f77567b435c18809f2b306493114566821bb18e5b722b4
Deleted: sha256:dbccf8206fe161014f4eef2a6898aeacb2353cd5376b6e538e8a5e4c3a066f84
Untagged: dev-peer0.org2.example.com-mycc-1.0-15b571b3ce849066b7ec74497da3b27e54e0df1345daff3951b94245ce09c42b:latest
Deleted: sha256:a9e6a711abe39b5b001ff14f5177b015747bc8a67df441dcf9eb3f49774a09d3
Deleted: sha256:9a0059e14966e83b0e03770f0e199299a960b88a91fab56f36d35b75ca1d6225
Deleted: sha256:2bf482745da5a80d3eae2dea86719bfbe91dbaaf659823967fb00659b3f74869
Deleted: sha256:db17ee9e153dfd115b79f99624e92c0b78c60704debb4d0e3c59fdbb5393b370

常用操作

生成 fabric 网络相关文件
cd /usr/local/go/src/github.com/hyperledger/fabric/fabric-samples/first-network/
./byfn.sh -m generate -c 自定义网络名
启动 fabric 网络
cd /usr/local/go/src/github.com/hyperledger/fabric/fabric-samples/first-network/
./byfn.sh up -c 自定义网络名
关闭 fabric 网络
cd /usr/local/go/src/github.com/hyperledger/fabric/fabric-samples/first-network/
./byfn.sh down -c 自定义网络名
linuxCentos7Blockchainbcfabric单节点Hyperledger Fabric

我来吐槽

*

*