fabric V1.1 网络及sdk nodejs搭建手册

0.权限
获取管理员权限:
$ sudo passwd #设置root密码
$ su #切换到root用户

1.基础工具准备
1.1.git
$ apt install git
1.2.curl
$ apt install curl
1.3.pip
$ apt install python-pip
$ pip install --upgrade pip
1.4.vim
$ apt install vim

2.安装docker和docker compose
2.0.卸载旧版本
如果有的话,卸载旧版本
$ apt remove docker docker-engine docker.io
2.1.安装docker
1].设置docker存储库
$ apt -y install apt-transport-https ca-certificates
2].添加docker的GPG密钥,并添加仓库
$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add
$ sudo add-apt-repository “deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable”
3].更新apt软件包
$ apt update
4].安装
$ apt install docker-ce
5].docker版本
$ docker version
2.2.安装docker-compose
从github下载docker-compose二进制文件
$ curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-uname -s-uname -m -o /usr/local/bin/docker-compose
$ chmod +x /usr/local/bin/docker-compose
检查docker-compose版本
$ docker-compose version
2.3.docker 常用命令
删除一个容器:docker rm
强制删除一个容器:docker rm -f
强制删除全部容器:docker rm -f $(docker ps -aq)
杀死所有正在运行的容器:docker kill $(docker ps -a -q)
删除所有已经停止的容器:docker rm $(docker ps -a -q)
删除所有镜像:docker rmi $(docker images -q)
强制删除所有镜像:docker rmi -f $(docker images -q)
2.4.添加国内镜像下载源
修改docker hub的镜像,编辑/etc/docker/daemon.json文件,没有就创建一个,需要管理员提权,写入以下内容:
{
“registry-mirrors”: [“https://registry.docker-cn.com”]
}
重启docker服务生效: sudo service docker restart,这样docker就可以从国内镜像站进行pull操作,大大提高了pull image的速度。

3.安装go
3.1.下载安装包
可前往这里下载最新版安装包,当前版本为go1.10.3.linux-amd64.tar.gz
3.2.解压
$ tar -C /usr/local -zxf go1.10.3.linux-amd64.tar.gz
3.3.配置环境变量
1].打开/etc/profile
$ vim /etc/profile
2].写入环境变量

Go environment

export PATH=$PATH:/usr/local/go/bin
export GOPATH=/opt/gopath
然后ESC,:wq保存退出。
3].环境变量生效
$ source /etc/profile
3.4.查看go版本
$ go version

4.安装nodejs
4.1 更新ubuntu软件源
sudo apt-get update
sudo apt-get install -y python-software-properties software-properties-common
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
4.2 安装nodejs
sudo apt-get install nodejs
sudo apt install nodejs-legacy
sudo apt install npm
4.3 更新npm的包镜像源,方便快速下载
sudo npm config set registry https://registry.npm.taobao.org
sudo npm config list
4.4全局安装n管理器(用于管理nodejs版本)
sudo npm install n -g
4.5安装最新的nodejs(stable版本)
sudo n stable
sudo node -v
v10.8.0
5.下载fabric代码和fabric-samples代码
5.1.构建文件夹目录
$ mkdir -p /opt/gopath/src/github.com/hyperledger/
5.2.下载代码
5.2.1.fabric
1].下载fabric代码
$ cd /opt/gopath/src/github.com/hyperledger/
$ git clone https://github.com/hyperledger/fabric.git
2].进入fabric
$ cd fabric
3].切换代码分之
$ git checkout release-1.1
5.2.2 fabric-simples
1].下载fabric-simples代码
$ cd /opt/gopath/src/github.com/hyperledger/
$ git clone https://github.com/hyperledger/fabric-samples.git
2].进入fabric-samples
$ cd fabric-samples
3].切换代码分支
$ git checkout release-1.1
5.3.下载docker镜像
$ cd /opt/gopath/src/github.com/hyperledger/fabric/scripts
$ ./bootstrap.sh
5.4.查看已安装的docker images
$ docker images
5.5.拉取二进制执行程序
1].手动下载文件
$ cd /opt/gopath/src/github.com/hyperledger/fabric-samples
$ wget https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/linux-amd64-1.1.0/hyperledger-fabric-linux-amd64-1.1.0.tar.gz
$ tar -zxvf hyperledger-fabric-linux-amd64-1.1.0.tar.gz
2].将二进制文件写入环境变量
$ cd bin
$ pwd
$ vim /etc/profile
写入如下内容:
export PATH=/opt/gopath/src/github.com/hyperledger/fabric-samples/bin:$PATH
3].使环境变量生效
$ source /etc/profile
6.测试fabric-simples
6.1.启动
$ cd /opt/gopath/src/github.com/hyperledger/fabric-simaples/fabcar
$ ./startFabric.sh
6.2 安装sdk
npm install node-gyp
npm install node-pre-gyp
npm install grpc
sudo npm install
6.3.测试
1].添加管理员
$ node enrollAdmin.js
结果:
root@lzj-ThinkCentre-M910t-D562:/opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar# node enrollAdmin.js
Store path:/opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar/hfc-key-store
Successfully enrolled admin user “admin”
Assigned the admin user to the fabric client

2].注册用户
$ node registerUser.js
结果:
root@lzj-ThinkCentre-M910t-D562:/opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar# node registerUser.js
Store path:/opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar/hfc-key-store
Successfully loaded admin from persistence
Successfully registered user1 - secret:YuarHrEEygUw
Successfully enrolled member user “user1”
User1 was successfully registered and enrolled and is ready to intreact with the fabric network
3].查询docker
$ node query.js docker
结果:
root@lzj-ThinkCentre-M910t-D562:/opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar# node query.js docker
Store path:/opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar/hfc-key-store
Successfully loaded user1 from persistence
Query has completed, checking results

你可能感兴趣的:(fabric V1.1 网络及sdk nodejs搭建手册)