返回顶部

Hyperledger_Fabric

Fabric


fabric主机地址

192.168.1.93
10.141.67.60:2642

安装预备环境

安装NVM,通过NVM安装node和npm

由于某些你懂的因素,导致GitHub的raw.githubusercontent.com域名解析被污染了。通过修改hosts解决此问题。

  1. https://www.ipaddress.com/查询raw.githubusercontent.com的真实IP。

  2. 修改hosts

    sudo vim /etc/hosts
    

    添加如下内容:

    199.232.96.133 raw.githubusercontent.com
    
  3. 在终端执行以下命令,将自动进行nvm的安装:

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash

nvm将被安装到 $HOME/.nvm 目录中。

查看所有可供安装的node版本
nvm ls-remote
选择自己想要的版本进行安装
nvm install v11.11.0
查看本地已安装的node
nvm ls
其他nvm的相关指令,参见 nvm --help
安装完node后,默认会安装 npm,但不是最新版本,需要手动更新。
查看npm版本
npm -v
更新npm到最新版本
npm install -g npm
更新到指定版本,@版本号
npm -g install npm@5.6.0
修改npm包的全局安装位置:
查看 npm 的配置
npm config ls
prefix为当前包的全局安装位置,为了方便管理,设置为自己的路径
npm config set prefix "new_path"
修改npm为国内镜像
npm config set registry "http://registry.npm.taobao.org/"

Linux基础知识

su是申请切换root用户,需要申请root用户密码。有些Linux发行版,例如ubuntu,默认没有设置root用户的密码,所以需要我们先使用sudo passwd root设置root用户密码。

sudo su是当前用户暂时申请root权限,所以输入的不是root用户密码,而是当前用户的密码。sudo是用户申请管理员权限执行一个操作,而此处的操作就是变成管理员。

rm -rf+文件夹名

例子:将目录A重命名为B

mv A B

例子:将/a目录移动到/b下,并重命名为c

mv /a /b/c


安装Fabric及测试网络

由于已知的原因,执行下列代码出错

curl -sSL https://bit.ly/2ysbOFE | bash -s
注:
可使用https://ddl.ink/nwo代替

在本地新建bootstrap.sh,手动将该脚本的文本复制到新文件中,就相当于下载下来了。

执行shell脚本时发现,输入./bootstrap.sh时报-bash: bootstrap.sh: Permission denied这个错。原因是shell脚本时不可执行的,通过在命令行输入ll或者ls -l查看文件的访问权限。

此时你的脚本文件是r可读w可写,但是不可执行,执行以下命令,就可执行了。

chmod u+x bootstrap.sh

再输入bootstrap.sh就可以运行shell脚本了。后面的星号是可执行的标志。

sudo ./bootstrap.sh 2.3.2 1.5.0 -s

出现以下错误

Pull Hyperledger Fabric binaries

===> Downloading version 2.3.2 platform specific fabric binaries
===> Downloading:  https://github.com/hyperledger/fabric/releases/download/v2.3.2/hyperledger-fabric-linux-amd64-2.3.2.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   649  100   649    0     0    940      0 --:--:-- --:--:-- --:--:--   941
100 73.5M  100 73.5M    0     0  2267k      0  0:00:33  0:00:33 --:--:-- 2397k
==> Done.
===> Downloading version 1.5.0 platform specific fabric-ca-client binary
===> Downloading:  https://github.com/hyperledger/fabric-ca/releases/download/v1.5.0/hyperledger-fabric-ca-linux-amd64-1.5.0.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:02:00 --:--:--     0
curl: (35) gnutls_handshake() failed: The TLS connection was non-properly terminated.

gzip: stdin: unexpected end of file
tar: Child returned status 1
tar: Error is not recoverable: exiting now
==> There was an error downloading the binary file.

------> 1.5.0 fabric-ca-client binary is not available to download  (Available from 1.1.0-rc1) <----

查看脚本源码,对照错误提示

if [ "$SAMPLES" == "true" ]; then
    echo
    echo "Clone hyperledger/fabric-samples repo"
    echo
    cloneSamplesRepo
fi
if [ "$BINARIES" == "true" ]; then
    echo
    echo "Pull Hyperledger Fabric binaries"
    echo
    pullBinaries
fi
if [ "$DOCKER" == "true" ]; then
    echo
    echo "Pull Hyperledger Fabric docker images"
    echo
    pullDockerImages
fi

在其他电脑上下载好对应的文件后,用SCP命令传输到主机上

scp -P 2642 /mnt/c/Users/admin/Desktop/hyperledger-fabric-ca-linux-amd64-1.5.0.tar.gz allan@10.141.67.60:/home/allan/go/src/github.com/yangangao
scp -P 2642 /mnt/c/Users/admin/Desktop/hyperledger-fabric-linux-amd64-2.3.2.tar.gz allan@10.141.67.60:/home/allan/go/src/github.com/yangangao
scp -P 2642 -r /mnt/c/Users/admin/Desktop/fabric-samples-main allan@10.141.67.60:/home/allan/go/src/github.com/yangangao

在脚本对应位置注释掉相关的下载部分(因为已经手动下载好了)

pullBinaries() {
    echo "===> Downloading version ${FABRIC_TAG} platform specific fabric binaries"
    echo "Allan already done you buster!!! "
#    download "${BINARY_FILE}" "https://github.com/hyperledger/fabric/releases/download/v${VERSION}/${BINARY_FILE}"
#    if [ $? -eq 22 ]; then
#        echo
#        echo "------> ${FABRIC_TAG} platform specific fabric binary is not available to download <----"
#        echo
#        exit
#    fi

    echo "===> Downloading version ${CA_TAG} platform specific fabric-ca-client binary"
    echo "Allan already done, too  you buster!!!"
#    download "${CA_BINARY_FILE}" "https://github.com/hyperledger/fabric-ca/releases/download/v${CA_VERSION}/${CA_BINARY_FILE}"
#    if [ $? -eq 22 ]; then
#        echo
#        echo "------> ${CA_TAG} fabric-ca-client binary is not available to download  (Available from 1.1.0-rc1) <----"
#        echo
#        exit
#    fi
}

代码分析

进入bin文件夹下,这里是Fabric组件的目录,使用这些文件可以设置Fabric网络:

allan@allan-virtual-machine:~/go/src/github.com/yangangao/bin$ ll
total 205772
drwxr-xr-x 2  1001  1001     4096 4月  24 04:29 ./
drwxrwxr-x 5 allan allan     4096 8月   8 23:45 ../
-rwxr-xr-x 1  1001  1001 18780048 4月  24 04:28 configtxgen* 
【用于生成共识服务启动以及通道创建所需的配置数据】
【configtx.yaml -> 包含了Fabric节点网络的定义】
-rwxr-xr-x 1  1001  1001 15520685 4月  24 04:28 configtxlator*
【将通道配置信息转换为可读形式】
-rwxr-xr-x 1  1001  1001 10454817 4月  24 04:28 cryptogen*
【生成x509证书,用于实现身份识别等鉴权功能】
【crypto-config.yaml -> 包含需要部署的fabric网络的拓扑结构,cryptogen根据网络结构生成所需要的证书库以及秘钥】
-rwxr-xr-x 1  1001  1001 15814642 4月  24 04:28 discover*
【新的 不知道】
-rwxr-xr-x 1 allan allan 22316982 3月   9 14:17 fabric-ca-client*
【新的 不知道】
-rwxr-xr-x 1 allan allan 25719706 3月   9 14:17 fabric-ca-server*
【新的 不知道】
-rwxr-xr-x 1  1001  1001  9016425 4月  24 04:28 idemixgen*
【新的 不知道】
-rwxr-xr-x 1  1001  1001 30829072 4月  24 04:28 orderer*
【共识服务程序,fabric中共识服务独立为一个节点,负责将交易事务打包进区块,并使用通道机制订阅给其他的对等节点/账本节点】
-rwxr-xr-x 1  1001  1001 14845472 4月  24 04:28 osnadmin*
【新的 不知道】
-rwxr-xr-x 1  1001  1001 47385832 4月  24 04:29 peer*
【账本节点/对等节点程序,用于维护账本数据并运行智能合约】

Docker仓库分析

allan@allan-virtual-machine:~/go/src/github.com/yangangao$ sudo docker images
REPOSITORY                   TAG       IMAGE ID       CREATED        SIZE
hyperledger/fabric-tools     2.3       a206a1593b4c   3 months ago   448MB
hyperledger/fabric-tools     2.3.2     a206a1593b4c   3 months ago   448MB
hyperledger/fabric-tools     latest    a206a1593b4c   3 months ago   448MB
【fabric工具库】
hyperledger/fabric-peer      2.3       85c825d4769f   3 months ago   54.2MB
hyperledger/fabric-peer      2.3.2     85c825d4769f   3 months ago   54.2MB
hyperledger/fabric-peer      latest    85c825d4769f   3 months ago   54.2MB
【对等节点】
hyperledger/fabric-orderer   2.3       7cad713cbfea   3 months ago   37.8MB
hyperledger/fabric-orderer   2.3.2     7cad713cbfea   3 months ago   37.8MB
hyperledger/fabric-orderer   latest    7cad713cbfea   3 months ago   37.8MB
【共识服务节点】
hyperledger/fabric-ccenv     2.3       627c556b15ca   3 months ago   514MB
hyperledger/fabric-ccenv     2.3.2     627c556b15ca   3 months ago   514MB
hyperledger/fabric-ccenv     latest    627c556b15ca   3 months ago   514MB
【智能合约环境】
hyperledger/fabric-baseos    2.3       e50ea411d694   3 months ago   6.86MB
hyperledger/fabric-baseos    2.3.2     e50ea411d694   3 months ago   6.86MB
hyperledger/fabric-baseos    latest    e50ea411d694   3 months ago   6.86MB
【新的 不知道】
hyperledger/fabric-ca        1.5       24a7c19a9fd8   5 months ago   70.8MB
hyperledger/fabric-ca        1.5.0     24a7c19a9fd8   5 months ago   70.8MB
hyperledger/fabric-ca        latest    24a7c19a9fd8   5 months ago   70.8MB
【fabric证书管理组件】
allan@allan-virtual-machine:~/go/src/github.com/yangangao/fabric-samples/test-network$ sudo ./network.sh up
Starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb' 
LOCAL_VERSION=2.3.2
DOCKER_IMAGE_VERSION=2.3.2
ERROR: Version in "./docker/docker-compose-test-net.yaml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a version of "2" (or "2.0") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/
allan@allan-virtual-machine:~/go/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network$ sudo ./network.sh up
Starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb' 
LOCAL_VERSION=2.3.2
DOCKER_IMAGE_VERSION=2.3.2
ERROR: Version in "./docker/docker-compose-test-net.yaml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a version of "2" (or "2.0") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
# 错误:“./docker/docker-compose-test-net.yaml”中的版本不受支持。 您可能会看到此错误,因为您使用了错误的 Compose 文件版本。 指定版本“2”(或“2.0”)并将您的服务定义放在 `services` 键下,或者省略 `version` 键并将您的服务定义放在文件的根目录以使用版本 1。
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/
posted @ 2022-09-01 23:01  港澳  阅读(222)  评论(0)    收藏  举报