准备工作
1 系统环境准备 :Ubuntu 20.02 LTC
2 apt 更换镜像源
3 辅助工具安装
4 安装go
5 安装容器docker和docker compose
Hyperledger Fabric安装
方法1: 以bootstrap.sh脚本方式进行环境的安装,优点是简单、方便,能够快速上手;需要虚拟机已配置科学上网工具
方法2:手动安装,以Fabric源码方式进行编译;较繁琐,但可以更加深入理解搭建过程
1. 下载并编译二进制文件(源码)
2. 下载fabric-samples
3. fabric-ca编译
4. Fabric docker镜像下载
5. 开发客户端安装golang-sdk
启动测试网络测试
系统环境:Ubuntu20.02 LTC
安装成功后输入刚才新建的用户和密码,进去即可,鼠标右键,选择Open in Terminal,即打开终端窗口:
输入命令sudo passwd
再次输入命令su root
,便切换到root用户
接下来给用户添加sudo权限,依次输入下面的命令:
第一,先给 /etc/sudoers 文件赋予可写的权限:chmod u+w /etc/sudoers
第二,接着编写 /etc/sudoers文件:vi /etc/sudoers
第三,在root ALL=(ALL:ALL) ALL
下面添加XXX(用户名) ALL=(ALL) ALL
语句
第四、恢复 /etc/sudoers 原来只读的权限:chmod u-w /etc/sudoers
cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo vim /etc/apt/sources.list
进入界面
使用清华镜像源全部替换
HTTPS有时需要替换为http;# 后面为注释,可忽略
修改后保存
esc
:wq!
运行 sudo apt-get upgrade
作用:已经安装软件和软件列表对比,提示更新软件
工具 | 命令 |
---|---|
vim | sudo apt-get install vim |
git | sudo apt install git |
cURL | sudo apt install curl |
wget | sudo apt-get install wget |
libtool libltdl-dev | sudo apt install libtool libltdl-dev |
jq | apt install jq |
GO官网地址 Download and install - The Go Programming Language (google.cn)
进入到Download文件夹,下载Golang压缩包-注意需要下载的版本
cd ~
cd Download
wget https://storage.googleapis.com/golang/go1.20.5.linux-amd64.tar.gz
切换到root模式;移除先前的go文件,并将安装包解压到指定文件夹;删除原有安装包;
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.20.5.linux-amd64.tar.gz
root下输入命令
vim ~/.bashrc
输入i,进入编辑模式,在文件后面添加
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$HOME/go/bin
使文件生效
source ~/.bashrc
打开profile 文件
vim ~/.profile
文档末尾添加并保存
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$HOME/go/bin
使修改后的profile文件立即生效
source ~/.profile
export PATH=$PATH:/usr/local/go/bin
go version
go env –w GO111MODULE=on
go env –w GOPROXY=https://goproxy.cn,direct
docker --version
卸载docker
sudo apt-get remove docker docker-engine docker.io
sudo apt update
sudo apt install docker
sudo apt install docker-compose
sudo service docker start
docker --version && docker-compose --version
sudo systemctl enable docker
sudo groupadd docker
sudo usermod –a –G docker <username>
docker images
安装结果示例
安装docker加速器(阿里云镜像)
输入命令:cd /etc/docker
,进入/etc/docker目录
增加权限
sudo chmod -R 777 /var/run/docker.sock
查看docker状态
systemctl status docker
mkdir -p $GOPATH/src/github.com/hyperledger/
cd $GOPATH/src/github.com/hyperledger/
git clone https:// github.com/hyperledger/fabric.git
cd $GOPATH/src/github.com/hyperledger/fabric/
git tag
git checkout -b v2.2.10 #根据需求选择版本号,建议使用LTC版本
sudo apt install make
sudo apt install make-guile
cd ~/go/src/github.com/hyperledger/fabric
make release
./release/linux-amd64/bin/peer version
./release/linux-amd64/bin/orderer version
./release/linux-amd64/bin/configtxgen -version
./release/linux-amd64/bin/configtxlator version
./release/linux-amd64/bin/cryptogen version
./release/linux-amd64/bin/osnadmin version
sudo cp $GOPATH/src/github.com/hyperledger/fabric/release/linux-amd64/bin/* /usr/local/bin
sudo chmod -R 775 /usr/local/bin/configtxgen
sudo chmod -R 775 /usr/local/bin/configtxlator
sudo chmod -R 775 /usr/local/bin/cryptogen
sudo chmod -R 775 /usr/local/bin/discover
sudo chmod -R 775 /usr/local/bin/ledgerutil
sudo chmod -R 775 /usr/local/bin/peer
sudo chmod -R 775 /usr/local/bin/orderer
sudo chmod -R 775 /usr/local/bin/osnadmin
mkdir -p $GOPATH/src/github.com/hyperledger
cd $GOPATH/src/github.com/hyperledger
git clonehttps://github.com/hyperledger/fabric-samples.git
cd fabric-samples
切换版本号
sudo git checkout -b v2.2.10
查看当前版本
sudo git branch
目录:回到hyperledger目录下
cd $GOPATH/src/github.com/hyperledger/ #目录:回到hyperledger目录下
下载fabric-ca源码
cd $GOPATH/src/github.com/hyperledger
git clone [email protected]:hyperledger/fabric-ca.git
fabric 与fabric-ca 对应版本号可在fabric/scripts/bootstrap.sh中查看
编译安装fabric-ca组件
cd $GOPATH/src/github.com/hyperledger/fabric-ca
make fabric-ca-server
make fabric-ca-client
安装编译好的可执行文件,输入以下命令:
cd $GOPATH/src/github.com/hyperledger/fabric-ca/bin
sudo cp * /usr/local/bin/
chmod -R 755 /usr/local/bin/fabric-ca-server
chmod -R 755 /usr/local/bin/fabric-ca-client
检查是否可执行:
fabric-ca-server version
fabric-ca-client version
cd $GOPATH/src/github.com/hyperledger/fabric/scripts
./bootstrap.sh
docker images # 查看镜像信息
cd $GOPATH/src/github.com/hyperledger
git clone https://github.com/hyperledger/fabric-sdk-go
# github不行就换gitee
官方文档: Using the Fabric test network — hyperledger-fabricdocs main documentation
cd $GOPATH/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network
启动测试网络
./network.sh up
创建通道
./network.sh createChannel
在通道上启动链码
./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go