【第一篇】Hyperledger Explorer 部署步驟與踩坑記錄 2019-06-12

部署流程

本次選用的Hyperledger-explorer版本為最新的release版本v0.3.9.1
github地址: https://github.com/hyperledger/blockchain-explorer

這里沒有寫如何部署Fabric網(wǎng)絡(luò) 以及 連接Fabric提供的例子: first-nework, 后面可以考慮分享,直接使用的例子網(wǎng)上也蠻多的清寇,提供幾個(gè)參考鏈接:
https://medium.com/@thanawitsupinnapong/setting-up-hyperledger-explorer-on-fabric-5f1f7cda73b3
https://medium.com/coinmonks/hyperledger-explorer-quick-start-50a49c6d7957

這篇文章主要介紹安裝環(huán)境喘漏,部署運(yùn)行护蝶,及我的一些踩坑記錄华烟,有一些我也還沒有解決,如果你解決過持灰,感恩你跟我分享?盔夜。如果你有遇到其他的問題,也歡迎評論。

一喂链、安裝環(huán)境

安裝要求說明:

Requirements
The following are prerequisites for installing the required development tools.

nodejs 8.11.x (Note that v9.x is not yet supported)
PostgreSQL 9.5 or greater
Jq [https://stedolan.github.io/jq/]

Hyperledger Explorer works with Hyperledger Fabric 1.2. Install the following software dependencies to manage fabric network.

docker-ce [https://www.docker.com/community-edition]
docker-compose [https://docs.docker.com/compose/]
GO [https://golang.org/dl/]

我的環(huán)境:

# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)

# node -v
v8.11.2

# npm -v
5.6.0

# git --version
git version 2.9.5

# jq --version
jq-1.5

# psql --version
psql (PostgreSQL) 9.2.24

那就按照要求安裝吧返十!

1. 安裝Git

步驟1. 安裝依賴包
Git 的工作需要調(diào)用 curl,zlib椭微,openssl洞坑,expat,libiconv 等庫的代碼蝇率,所以需要先安裝這些依賴工具迟杂。在有 yum 的系統(tǒng)上(比如 Fedora),可以用下面的命令安裝:

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum install  gcc perl-ExtUtils-MakeMaker

步驟2. 下載&解壓: 之后本慕,從下面的 Git 官方站點(diǎn)下載最新版本源代碼

cd /usr/src
wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz
tar -zxvf git-2.9.5.tar.gz

注意. 如果之前有安裝過舊版本git排拷,先刪除

 yum remove git

步驟3. 安裝并添加環(huán)境變量

# cd git-2.9.5
# make prefix=/usr/local/git all
# make prefix=/usr/local/git install
# vim /etc/profile
//添加一行
# export PATH=$PATH:/usr/local/git/bin
# source /etc/profile

步驟4. 查看git版本

# git --version
git version 2.9.5

2. 安裝nodejs

//1.下載
wget https://nodejs.org/download/release/v8.11.2/node-v8.11.2-linux-x64.tar.gz
//2.解壓
tar --strip-components 1 -xzvf node-v* -C /usr/local
//3.查看版本
# node –v
v8.11.2

3. 安裝PostgreSQL

  1. 安裝依賴
yum install postgresql-server postgresql-contrib
  1. 初始化DB
postgresql-setup initdb
  1. 啟動DB
systemctl start postgresql
  1. 暫停服務(wù)(可選)
systemctl enable postgresql
  1. 修改配置/var/lib/pgsql/data/pg_hba.conf 信任指定服務(wù)器連接
將:
host    all             all             127.0.0.1/32            ident
修改為:
host    all             all             127.0.0.1/32            trust
 # IPv4 local connections:
    host    all            all      127.0.0.1/32      trust
后面增加
    host    all             all      0.0.0.0/0          trust

  1. 開啟遠(yuǎn)程訪問
 vi /var/lib/pgsql/data/postgresql.conf
    修改#listen_addresses = 'localhost'  為  listen_addresses='*'
    當(dāng)然,此處‘*’也可以改為任何你想開放的服務(wù)器IP

  1. 重啟PostgreSQL數(shù)據(jù)服務(wù)
systemctl restart postgresql

4. 安裝JQ

jq linux json格式化工具
1锅尘、添加epel源

>wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
>rpm -ivh epel-release-latest-7.noarch.rpm
>yum repolist

2监氢、安裝

yum install jq
  1. 查看版本
>jq --version
jq-1.5

二、開始部署

準(zhǔn)備代碼和工具:
我們需要的工具

?  bin git:(bb39b6e) ? pwd
/fabric-samples/bin   # 部署Fabric網(wǎng)絡(luò)的時(shí)候生成的藤违,在配置config.json的時(shí)候會用到:  "configtxgenToolPath": "/data/fabric/bin", 把他都copy到需要使用的路徑下面浪腐,比如我這里是"/data/fabric/bin"
?  bin git:(bb39b6e) ? tree
.
├── configtxgen
├── configtxlator
├── cryptogen
├── discover
├── fabric-ca-client
├── get-docker-images.sh
├── idemixgen
├── orderer
└── peer

把證書密鑰等相關(guān)內(nèi)容copy到本地,我這里是放到/data/fabric/crypto-config/ 配置config.json的時(shí)候需要使用纺弊。

[ansible@rocketmq-test-2 crypto-config]$ tree -L 3
.
├── ordererOrganizations
│   └── example.com
│       ├── ca
│       ├── msp
│       ├── orderers
│       ├── tlsca
│       └── users
└── peerOrganizations
    ├── org1.example.com
    │   ├── ca
    │   ├── msp
    │   ├── peers
    │   ├── tlsca
    │   └── users
    └── org2.example.com
        ├── ca
        ├── msp
        ├── peers
        ├── tlsca
        └── users 

2.1. 設(shè)置數(shù)據(jù)庫

vim blockchain-explorer/app/explorerconfig.json

你可以更新explorerconfig.json來更新postgresql的配置牛欢,我這邊先不改

{
  "persistence": "postgreSQL",
  "platforms": ["fabric"],
  "postgreSQL": {
    "host": "127.0.0.1",
    "port": "5432",
    "database": "fabricexplorer",
    "username": "hppoc",
    "passwd": "password"
  },
  "sync": {
    "type": "local",
    "platform": "fabric",
    "blocksSyncTime": "3"
  }
}

有些情況下,你需要給db/文件賦予權(quán)限 當(dāng)前目錄blockchain-explorer/

 chmod -R 775 app/persistence/fabric/postgreSQL/db

執(zhí)行數(shù)據(jù)庫腳本

//切換到postgres淆游,在安裝postgresql的過程中就會默認(rèn)創(chuàng)建postgres用戶
sudo su - postgres
cd /data/fabric/blockchain-explorer-0.3.9.1/app/persistence/fabric/postgreSQL/db
./createdb.sh

查看創(chuàng)建數(shù)據(jù)

//退出postgres用戶
exit
//連接psql  \l 查看數(shù)據(jù)  \d 查看表格  \q退出
[ansible@rocketmq-test-2 blockchain-explorer-0.3.9.1]$ sudo -u postgres psql
psql (9.2.24)
Type "help" for help.

postgres=# \l
                                    List of databases
      Name      |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
----------------+----------+----------+-------------+-------------+-----------------------
 fabricexplorer | hppoc    | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 postgres       | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0      | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                |          |          |             |             | postgres=CTc/postgres
 template1      | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                |          |          |             |             | postgres=CTc/postgres

(4 rows)

嘗試連接成功

 psql postgres://hppoc:password@127.0.0.1:5432/fabricexplorer

2.2. 修改配置文件config.json

當(dāng)前目錄blockchain-explorer/

vim app/platform/fabric/config.json

修改內(nèi)容

  1. 所有g(shù)rpcs 改為 grpc
  2. tlsEnable 從true 改為false //第1.2步都是因?yàn)檫B接的Fabric網(wǎng)絡(luò)禁用了Tls傍睹,如果使用first-network默認(rèn)是不禁用的,就不用改犹菱。
  3. path修改拾稳,修改成本地的證書密鑰路徑,我這里是/data/fabric/crypto-config/
{
  "network-configs": {
    "network-1": {
      "version": "1.0",
      "clients": {
        "client-1": {
          "tlsEnable": false,
          "organization": "Org1MSP",
          "channel": "mychannel",
          "credentialStore": {
            "path": "./tmp/credentialStore_Org1/credential",
            "cryptoStore": {
              "path": "./tmp/credentialStore_Org1/crypto"
            }
          }
        }
      },
      "channels": {
        "mychannel": {
          "peers": {
            "peer0.org1.example.com": {}
          },
          "connection": {
            "timeout": {
              "peer": {
                "endorser": "6000",
                "eventHub": "6000",
                "eventReg": "6000"
              }
            }
          }
        }
      },
      "organizations": {
        "Org1MSP": {
          "mspid": "Org1MSP",
          "fullpath": false,
          "adminPrivateKey": {
            "path": "/data/fabric/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore"
          },
          "signedCert": {
            "path": "/data/fabric/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts"
          }
        },
        "OrdererMSP": {
          "mspid": "OrdererMSP",
          "adminPrivateKey": {
            "path": "/data/fabric/crypto-config/ordererOrganizations/example.com/users/Admin@example.com/msp/keystore"
          }
        }
      },
      "peers": {
        "peer0.org1.example.com": {
          "tlsCACerts": {
            "path": "/data/fabric/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
          },
          "url": "grpc://192.168.22.246:7051",
          "eventUrl": "grpc://192.168.22.246:7053",
          "grpcOptions": {
            "ssl-target-name-override": "peer0.org1.example.com"
          }
        },
       
        "peer0.org2.example.com": {
          "url": "grpc://192.168.22.249:7051"
        }
      },
      "orderers": {
        "orderer.example.com": {
          "url": "grpc://localhost:7050"
        }
      }
    },
    "network-2": {}
  },
  "configtxgenToolPath": "/data/fabric/bin",
  "license": "Apache-2.0"
}

2.3. 編譯啟動

cd blockchain-explorer
npm install
cd blockchain-explorer/app/test
npm install
npm run test
cd client/
npm install
npm test -- -u --coverage
npm run build

2.4. 訪問服務(wù)

默認(rèn)訪問鏈接是:http://localhost:8080
如果8080被占用腊脱,想要修改端口號访得,可以修改/blockchain-explorer/appconfig.json

{
  "host": "localhost",
  "port": "8080",  # 修改端口號
  "license": "Apache-2.0"
}
image.png

也可以通過右上角開關(guān)切換顏色:


image.png

三、 那些我踩到的坑

3.1. gcc未安裝

make: Entering directory `/data/fabric/blockchain-explorer-0.3.9.1/node_modules/pkcs11js/build'
  CXX(target) Release/obj.target/pkcs11/src/main.o

make: g++: Command not found

image.png

解決方案:

yum install -y gcc-c++

3.2. mlocate 未安裝

報(bào)錯:

[ansible@rocketmq-test-2 blockchain-explorer-0.3.9.1]$ tail -222f logs/console/console-2019-06-11.log
postgres://hppoc:password@127.0.0.1:5432/fabricexplorer
/bin/sh: locate: command not found
/bin/sh: locate: command not found
/bin/sh: locate: command not found
image.png

解決:

> yum install mlocate
> updatedb

注意:若用sudo install 那么updatedb 也需要用1sudo updatedb

測試:

> locate mysql
/usr/share/mysql/charsets/macce.xml
/usr/share/mysql/charsets/macroman.xml
/usr/share/mysql/charsets/swe7.xml
/usr/share/mysql/czech/errmsg.sys
/usr/share/mysql/danish/errmsg.sys
/usr/share/mysql/dutch/errmsg.sys
...

3.3. grpc未安裝

提示需要npm rebuild

解決方案:

npm rebuild

3.4. Fabric禁用tls,但是配置用了grpcs ,需要改為grpc

報(bào)錯:

(node:3648) DeprecationWarning: grpc.load: Use the @grpc/proto-loader module with grpc.loadPackageDefinition instead
E0606 06:13:02.106104472    3648 ssl_transport_security.cc:1227] Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number.
E0606 06:13:03.106865936    3648 ssl_transport_security.cc:1227] Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number.
E0606 06:13:04.647205386    3648 ssl_transport_security.cc:1227] Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number.
2019-06-06T10:13:05.104Z - error: [Remote.js]: Error: Failed to connect before the deadline URL:grpcs://192.168.110.246:7051
2019-06-06T10:13:05.105Z - error: [Channel.js]: Error: Failed to connect before the deadline URL:grpcs://192.168.110.246:7051
<<<<<<<<<<<<<<<<<<<<<<<<<< Explorer Error >>>>>>>>>>>>>>>>>>>>>
Error: Failed to discover ::Error: Failed to connect before the deadline URL:grpcs://192.168.110.246:7051
    at Channel._initialize (/data/fabric/blockchain-explorer-0.3.9.1/node_modules/fabric-client/lib/Channel.js:347:11)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
Received kill signal, shutting down gracefully

3.5. 配置了兩個(gè)節(jié)點(diǎn)陕凹,但是只顯示了一個(gè)節(jié)點(diǎn) - 未解決

3.6. Error: 2 UNKNOWN: Stream removed - 未解決

報(bào)錯信息如下悍抑,這個(gè)網(wǎng)上說有可能是grpc版本的問題,但是我替換了幾個(gè)grpc版本還是不行杜耙,而這在我另一臺服務(wù)器上是沒有問題的搜骡,所以我猜測很可能還是環(huán)境問題,具體的是哪個(gè)有問題佑女,網(wǎng)上找了下也沒有答案记靡。

?  blockchain-explorer-0.3.9.1 tail -222f logs/console/console-2019-06-11.log
postgres://hppoc:password@127.0.0.1:5432/fabricexplorer
(node:20923) DeprecationWarning: grpc.load: Use the @grpc/proto-loader module with grpc.loadPackageDefinition instead
<<<<<<<<<<<<<<<<<<<<<<<<<< Explorer Error >>>>>>>>>>>>>>>>>>>>>
{ Error: 2 UNKNOWN: Stream removed
    at Object.exports.createStatusError (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/node_modules/grpc/src/common.js:87:15)
    at ClientDuplexStream._emitStatusIfDone (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/node_modules/grpc/src/client.js:235:26)
    at ClientDuplexStream._receiveStatus (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/node_modules/grpc/src/client.js:213:8)
    at Object.onReceiveStatus (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/node_modules/grpc/src/client_interceptors.js:1290:15)
    at InterceptingListener._callNext (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/node_modules/grpc/src/client_interceptors.js:564:42)
    at InterceptingListener.onReceiveStatus (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/node_modules/grpc/src/client_interceptors.js:614:8)
    at /home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/node_modules/grpc/src/client_interceptors.js:1110:18
  code: 2,
  metadata: Metadata { _internal_repr: {} },
  details: 'Stream removed' }
Received kill signal, shutting down gracefully

Closed out connections

3.7. TypeError: Channel's second argument must be a ChannelCredentials - 未解決

grpc版本是1.14.2時(shí)谈竿,報(bào)的錯誤是:UNKNOWN: Stream removed 把grpc版本降到1.7.1之后報(bào)的錯誤是這個(gè)。而在我另一臺服務(wù)器上摸吠,grpc版本是1.14.2的時(shí)候空凸,是可以正常使用的,所以也不太清楚具體是什么原因寸痢。

<<<<<<<<<<<<<<<<<<<<<<<<<< Explorer Error >>>>>>>>>>>>>>>>>>>>>
TypeError: Channel's second argument must be a ChannelCredentials
    at ServiceClient.Client (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/node_modules/grpc/src/client.js:472:19)
    at new ServiceClient (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/node_modules/grpc/src/client.js:884:12)
    at new AdminPeer (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/app/platform/fabric/AdminPeer.js:65:30)
    at FabricClient.newAdminPeer (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/app/platform/fabric/FabricClient.js:546:25)
    at FabricClient.initializeChannelFromDiscover (/home/linfang/workspace/fabric/blockchain-explorer-0.3.9.1/app/platform/fabric/FabricClient.js:499:38)
    at <anonymous>
Received kill signal, shutting down gracefully

Closed out connections

3.8. orderer節(jié)點(diǎn)url配置的是遠(yuǎn)程服務(wù)的地址呀洲,但是日志里面還是顯示訪問 grpc://localhost:7050 - 未解決

因?yàn)楸镜貨]有order服務(wù),所以這個(gè)問題沒解決啼止,目前是通過部署在Orderer服務(wù)上暫時(shí)啟動了這個(gè)服務(wù), 部署在orderer服務(wù)器上后两嘴,把url改為grpc://localhost:7050 是可以訪問的
我的Order url的配置是:

 ...
  "peers": {
        "peer0.org1.example.com": {
          "tlsCACerts": {
            "path": "/data/fabric/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
          },
          "url": "grpc://192.168.110.246:7051",
          "eventUrl": "grpc://192.168.110.246:7053",
          "grpcOptions": {
            "ssl-target-name-override": "peer0.org1.example.com"
          }
        },
       
        "peer0.org2.example.com": {
          "url": "grpc://192.168.110.249:7051"
        }
      },
      "orderers": {
        "orderer.example.com": {
          "url": "grpc://192.168.110.245:7050"
        }
      }
    },
    ...

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市族壳,隨后出現(xiàn)的幾起案子憔辫,更是在濱河造成了極大的恐慌,老刑警劉巖仿荆,帶你破解...
    沈念sama閱讀 221,548評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件贰您,死亡現(xiàn)場離奇詭異,居然都是意外死亡拢操,警方通過查閱死者的電腦和手機(jī)锦亦,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,497評論 3 399
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來令境,“玉大人杠园,你說我怎么就攤上這事√蚴” “怎么了抛蚁?”我有些...
    開封第一講書人閱讀 167,990評論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長惕橙。 經(jīng)常有香客問我瞧甩,道長,這世上最難降的妖魔是什么弥鹦? 我笑而不...
    開封第一講書人閱讀 59,618評論 1 296
  • 正文 為了忘掉前任肚逸,我火速辦了婚禮,結(jié)果婚禮上彬坏,老公的妹妹穿的比我還像新娘朦促。我一直安慰自己,他們只是感情好栓始,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,618評論 6 397
  • 文/花漫 我一把揭開白布务冕。 她就那樣靜靜地躺著,像睡著了一般混滔。 火紅的嫁衣襯著肌膚如雪洒疚。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,246評論 1 308
  • 那天坯屿,我揣著相機(jī)與錄音油湖,去河邊找鬼。 笑死领跛,一個(gè)胖子當(dāng)著我的面吹牛乏德,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播吠昭,決...
    沈念sama閱讀 40,819評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼喊括,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了矢棚?” 一聲冷哼從身側(cè)響起郑什,我...
    開封第一講書人閱讀 39,725評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎蒲肋,沒想到半個(gè)月后蘑拯,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,268評論 1 320
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡兜粘,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,356評論 3 340
  • 正文 我和宋清朗相戀三年申窘,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片孔轴。...
    茶點(diǎn)故事閱讀 40,488評論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡剃法,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出路鹰,到底是詐尸還是另有隱情贷洲,我是刑警寧澤,帶...
    沈念sama閱讀 36,181評論 5 350
  • 正文 年R本政府宣布晋柱,位于F島的核電站恩脂,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏趣斤。R本人自食惡果不足惜俩块,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,862評論 3 333
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望浓领。 院中可真熱鬧玉凯,春花似錦、人聲如沸联贩。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,331評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽泪幌。三九已至盲厌,卻和暖如春署照,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背吗浩。 一陣腳步聲響...
    開封第一講書人閱讀 33,445評論 1 272
  • 我被黑心中介騙來泰國打工建芙, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人懂扼。 一個(gè)月前我還...
    沈念sama閱讀 48,897評論 3 376
  • 正文 我出身青樓禁荸,卻偏偏與公主長得像,于是被迫代替她去往敵國和親阀湿。 傳聞我的和親對象是個(gè)殘疾皇子赶熟,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,500評論 2 359

推薦閱讀更多精彩內(nèi)容