wsl2搭建fabric单机samples网络

0.安装ubuntu for Win10

在Microsoft store安装就好,不赘述啦。


1.配置源&安装ssh

清华镜像站:

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

vim /etc/apt/sources.list
sudo apt update

默认安装了ssh,配置一下允许账号密码登录:

vim /etc/ssh/sshd_config
#PasswordAuthentication yes
sudo service ssh restart

如果连接失败尝试重装ssh:

sudo apt-get remove openssh-server  openssh-client --purge -y
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get update
sudo apt-get install openssh-server openssh-client

在win10防火墙中开启22入站端口:


2.安装环境配置

CURL安装

apt-get install curl

DOCKER安装

#安装基本库
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

#添加官方秘钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

#设置存储库地址
sudo add-apt-repository \
   "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

#更新包和安装
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io


#compose安装
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

GO安装&环境配置

为了和教程配套,就用他的GO版本粑。

# 下载go1.11.linux-amd64.tar.gz并将其解压到指定目录(此处为/usr/local)
wget https://studygolang.com/dl/golang/go1.11.linux-amd64.tar.gz
tar xzvf go1.11.linux-amd64.tar.gz -C /usr/local

#goenvset.sh文件内容如下所示:

mkdir /home/xiaoyue/gopath
cat >> /etc/profile << EOF
export GOROOT=/usr/local/go
export GOARCH=amd64
export GOOS=linux
export GOPATH=/home/xiaoyue/gopath
export GOBIN=$GOPATH/bin
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
EOF

# 执行已有的goenvset.sh向/etc/profile中写入相应的环境变量
sudo chmod 705 goenvset.sh      # 更改goenvset.sh的权限使其可执行
sudo ./goenvset.sh				# 执行goenvset.sh脚本

# 使环境变量生效
source /etc/profile
#我在这里一步不能通过$GOPATH这样的格式写入环境变量。大家可以自行修改。/etc/profile

如果以上环境下载较慢,可通过proxychains+you_tz配置代理

sudo apt-get install proxychains
vim /etc/proxychains.conf 
#如果提示无法加载libproxychains.so.3库的话。
#在 /etc/bin/proxychains下改这个为你的目录不知道就用find找
export LD_PRELOAD=libproxychains.so.3

#使用方法
proxychains curl www.google.com

3.fabric安装

下载samples环境

mkdir -p $GOPATH/src/github.com/hyperledger
cd $GOPATH/src/github.com/hyperledger
# 克隆fabric-samples项目并切换到v1.4tag
git clone https://github.com/hyperledger/fabric-samples.git
cd fabric-samples
git checkout -b sample v1.4.0
cd $GOPATH/src/github.com/hyperledger/fabric-samples/scripts

手动下载docker镜像

#这两个文件访问不了了,我备份放到了CSDN上,不需要积分。
#https://download.csdn.net/download/xiaoyue2019/12661573
wget https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/linux-amd64-1.4.0/hyperledger-fabric-linux-amd64-1.4.0.tar.gz
wget https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/linux-amd64-1.4.0/hyperledger-fabric-ca-linux-amd64-1.4.0.tar.gz

tar xzvf hyperledger-fabric-linux-amd64-1.4.0.tar.gz -C $GOPATH/src/github.com/hyperledger/fabric-samples/
tar xzvf hyperledger-fabric-ca-linux-amd64-1.4.0.tar.gz -C $GOPATH/src/github.com/hyperledger/fabric-samples/

#向/etc/profile中写入环境变量
sudo echo 'export PATH=$GOPATH/src/github.com/hyperledger/fabric-samples/bin:$PATH' >> /etc/profile

#使环境变量生效
source /etc/profile

下载相关Docker镜像

#更改docker源
vim /etc/docker/daemon.json
{
  "registry-mirrors": ["https://youtoken.mirror.aliyuncs.com"]
}
#wsl需要用管理员身份启动!不然会报错:
#Cannot connect to the Docker daemon at unix:///var/run/docker.sock

# 下载Fabric相关镜像(fabric-peer、fabric-orderer、fabric-ccenv、fabric-tools),此处以fabric-peer镜像为例,其他镜像同理
docker pull hyperledger/fabric-peer:1.4.0
docker tag hyperledger/fabric-peer:1.4.0 hyperledger/fabric-peer:latest

# 下载Fabric第三方镜像(fabric-couchdb、fabric-kafka、fabric-zookeeper),此处以fabric-couchdb为例,其他镜像同理
docker pull hyperledger/fabric-couchdb:0.4.14
docker tag hyperledger/fabric-couchdb:0.4.14 hyperledger/fabric-couchdb:latest

# 下载Fabric CA镜像
docker pull hyperledger/fabric-ca:1.4.0
docker tag hyperledger/fabric-ca:1.4.0 hyperledger/fabric-ca:latest

通过运行Build your first network样例来进行测试

cd $GOPATH/src/github.com/hyperledger/fabric-samples/first-network
# 编译通过Golang开发的chaincode并启动相关的容器
./byfn.sh up

./byfn.sh up -l node

./byfn.sh up -o kafka

#停止first-network网络中所有的容器,删除crypto材料和4个artifacts(genesis.block、mychannel.block、Org1MSPanchor.tx、Org2MSPanchor.tx)以及chaincode镜像
./byfn.sh down

虽然说最终成功了,但是这个虚拟化开起来占用了我98%的内存。还不如用vm。我还是去下载ubuntu的镜像吧。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值