在Ubuntu18.04中搭建Hyperledger Explorer

一、环境准备(本节是紧接着上一篇博客编写:https://note.youdao.com/share/?id=08cba7c7957649ad31049483b42f3067&type=note#/

参考官方文档:https://github.com/hyperledger/blockchain-explorer

1、nodejs安装(nodejs 8.11.x (Note that v9.x is not yet supported)),由于上一篇博客已经安装了nvm,所以只需用nvm安装指定版本即可(此处安装8.11.4版本)

root@ubuntu:~# nvm install 8.11.4
Downloading and installing node v8.11.4...
Downloading https://nodejs.org/dist/v8.11.4/node-v8.11.4-linux-x64.tar.xz...
################################################################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v8.11.4 (npm v5.6.0)
root@ubuntu:~# node -v
v8.11.4
root@ubuntu:~# 

2、postgresql安装(PostgreSQL 9.5 or greater),这里以docker的形式进行安装

docker pull postgres:9.5
docker run --name postgres1 -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres:9.5 #postgres镜像默认的用户名为postgres,设置一个密码postgres

3、安装jq

sudo apt-get install jq

二、具体步骤

1、下载blockchain-explorer源码

cd /root/demo
git clone https://github.com/hyperledger/blockchain-explorer.git
cd blockchain-explorer

2、数据库初始化

root@iZq0c7mivu8vrvZ:~# docker exec -it b88997d1aad3 /bin/bash    #进入postgresql容器:b88997d1aad3
root@b88997d1aad3:/# su postgres   #切换用户
postgres@b88997d1aad3:/$ psql   #进入命令行客户端
psql (9.5.15)
Type "help" for help.

postgres=# CREATE DATABASE fabricexplorer owner postgres; #创建fabricexplorer数据库并指定用户fabricexplorer

数据库创建好后执行初始化sql语句(也可以用postgresql相关桌面客户端连接数据库),以下数据库脚本参考官方https://github.com/hyperledger/blockchain-explorer/blob/master/app/persistence/fabric/postgreSQL/db/explorerpg.sql:
-- ----------------------------
--  Table structure for `blocks`
-- ----------------------------
DROP TABLE IF EXISTS blocks;

CREATE TABLE blocks (
  id SERIAL PRIMARY KEY,
  blocknum integer DEFAULT NULL,
  datahash character varying(256) DEFAULT NULL,
  prehash character varying(256) DEFAULT NULL,
  txcount integer DEFAULT NULL,
  createdt Timestamp DEFAULT NULL,
  prev_blockhash character varying(256) DEFAULT NULL,
  blockhash character varying(256) DEFAULT NULL,
  channel_genesis_hash character varying(256) DEFAULT NULL
);

ALTER table blocks owner to postgres;

-- ----------------------------
--  Table structure for `chaincodes`
-- ----------------------------
DROP TABLE IF EXISTS chaincodes;

CREATE TABLE chaincodes (
  id SERIAL PRIMARY KEY,
  name character varying(255) DEFAULT NULL,
  version character varying(255) DEFAULT NULL,
  path character varying(255) DEFAULT NULL,
  channel_genesis_hash character varying(256) DEFAULT NULL,
  txcount integer DEFAULT 0,
  createdt Timestamp DEFAULT NULL
);

ALTER table chaincodes owner to postgres;
Alter sequence chaincodes_id_seq restart with 10;

-- ---------------------------
--  Table structure for `peer_ref_chaincode`
-- ----------------------------
DROP TABLE IF EXISTS peer_ref_chaincode;

CREATE TABLE peer_ref_chaincode (
  id SERIAL PRIMARY KEY,
  peerid varchar(64) DEFAULT NULL,
  chaincodeid varchar(64) DEFAULT NULL,
  cc_version varchar(64) DEFAULT NULL,
  channelid character varying(256) DEFAULT NULL,
  createdt Timestamp DEFAULT NULL
);
ALTER table peer_ref_chaincode owner to postgres;

-- ----------------------------
--  Table structure for `channel`
-- ----------------------------
DROP TABLE IF EXISTS channel;

--   state character(1) NOT NULL DEFAULT A CHECK (state in (A, D, S))

CREATE TABLE channel (
  id SERIAL PRIMARY KEY,
  name varchar(64) DEFAULT NULL,
  blocks integer DEFAULT NULL,
  trans integer DEFAULT NULL,
  createdt Timestamp DEFAULT NULL,
  channel_genesis_hash character varying(256) DEFAULT NULL,
  channel_hash character varying(256) DEFAULT NULL,
  channel_config  bytea default NULL,
  channel_block  bytea DEFAULT NULL,
  channel_tx  bytea DEFAULT NULL,
  channel_version character varying(128) DEFAULT NULL
);

ALTER table channel owner to postgres;
Alter sequence channel_id_seq restart with 3;
-- ----------------------------
--  Table structure for `peer`
-- ----------------------------
DROP TABLE IF EXISTS peer;

--   state character(1) NOT NULL DEFAULT A CHECK (state in (A, D, S))

CREATE TABLE peer (
  id SERIAL PRIMARY KEY,
  org integer DEFAULT NULL,
  channel_genesis_hash character varying(256) DEFAULT NULL,
  mspid varchar(64) DEFAULT NULL,
  requests varchar(64) DEFAULT NULL,
  events varchar(64) DEFAULT NULL,
  server_hostname varchar(64) DEFAULT NULL,
  createdt timestamp DEFAULT NULL,
  peer_type character varying(64) DEFAULT NULL
);
ALTER table peer owner to postgres;
-- ---------------------------
--  Table structure for `peer_ref_channel`
-- ----------------------------
DROP TABLE IF EXISTS peer_ref_channel;

CREATE TABLE peer_ref_channel (
  id SERIAL PRIMARY KEY,
  createdt Timestamp DEFAULT NULL,
  peerid varchar(64),
  channelid character varying(256),
  peer_type character varying(64) DEFAULT NULL
);
ALTER table peer_ref_channel owner to postgres;

-- ====================Orderer BE-303=====================================
-- ----------------------------
--  Table structure for `orderer`
-- ----------------------------
DROP TABLE IF EXISTS orderer;

--   state character(1) NOT NULL DEFAULT A CHECK (state in (A, D, S))

CREATE TABLE orderer (
  id SERIAL PRIMARY KEY,
  requests varchar(64) DEFAULT NULL,
  server_hostname varchar(64) DEFAULT NULL,
  createdt timestamp DEFAULT NULL
);
ALTER table orderer owner to postgres;

--// ====================Orderer BE-303=====================================
-- ----------------------------
--  Table structure for `transactions`
-- ----------------------------
DROP TABLE IF EXISTS transactions;
CREATE TABLE transactions (
  id SERIAL PRIMARY KEY,
  blockid integer DEFAULT NULL,
  txhash character varying(256) DEFAULT NULL,
  createdt timestamp DEFAULT NULL,
  chaincodename character varying(255) DEFAULT NULL,
  status  integer DEFAULT NULL,
  creator_msp_id character varying(128) DEFAULT NULL,
  endorser_msp_id character varying(800) DEFAULT NULL,
  chaincode_id character varying(256) DEFAULT NULL,
  type character varying(128) DEFAULT NULL,
  read_set  json default NULL,
  write_set  json default NULL,
  channel_genesis_hash character varying(256) DEFAULT NULL,
  validation_code character varying(50) DEFAULT NULL,
  envelope_signature character varying DEFAULT NULL,
  payload_extension character varying DEFAULT NULL,
  creator_id_bytes character varying DEFAULT NULL,
  creator_nonce character varying DEFAULT NULL,
  chaincode_proposal_input character varying DEFAULT NULL,
  tx_response character varying DEFAULT NULL,
  payload_proposal_hash character varying DEFAULT NULL,
  endorser_id_bytes character varying DEFAULT NULL,
  endorser_signature character varying DEFAULT NULL
  );

ALTER table transactions owner to postgres;
Alter sequence transactions_id_seq restart with 6;

DROP TABLE IF EXISTS write_lock;
CREATE TABLE write_lock (
  write_lock SERIAl PRIMARY KEY
);

ALTER table write_lock owner to postgres;
Alter sequence write_lock_write_lock_seq restart with 2;

DROP INDEX IF EXISTS blocks_blocknum_idx;
CREATE INDEX ON Blocks (blocknum);

DROP INDEX IF EXISTS blocks_channel_genesis_hash_idx;
CREATE INDEX ON Blocks (channel_genesis_hash);

DROP INDEX IF EXISTS blocks_createdt_idx;
CREATE INDEX ON Blocks (createdt);

DROP INDEX IF EXISTS transaction_txhash_idx;
CREATE INDEX ON Transactions (txhash);

DROP INDEX IF EXISTS transaction_channel_genesis_hash_idx;
CREATE INDEX ON Transactions (channel_genesis_hash);

DROP INDEX IF EXISTS transaction_createdt_idx;
CREATE INDEX ON Transactions (createdt);

DROP INDEX IF EXISTS transaction_blockid_idx;
CREATE INDEX ON Transactions (blockid);

DROP INDEX IF EXISTS transaction_chaincode_proposal_input_idx;
CREATE INDEX ON Transactions ((md5(chaincode_proposal_input)));

DROP INDEX IF EXISTS channel_channel_genesis_hash_idx;
CREATE INDEX ON channel (channel_genesis_hash);

DROP INDEX IF EXISTS channel_channel_hash_idx;
CREATE INDEX ON channel (channel_hash);

GRANT SELECT, INSERT, UPDATE,DELETE ON ALL TABLES IN SCHEMA PUBLIC to postgres;

3、blockchain-explorer中数据库设置

cd blockchain-explorer/app
vi explorerconfig.json
    配置数据库
    "postgreSQL": {
        "host": "127.0.0.1",
        "port": "5432",
        "database": "fabricexplorer",
        "username": "postgres",
        "passwd": "postgres"
    }

4、启动fabric-samples中first-networkc网络(参考:https://note.youdao.com/share/?id=08cba7c7957649ad31049483b42f3067&type=note#/)

5、修改blockchain-explorer/app/platform/fabric/config.json文件

{
  "network-configs": {
    "network-1": {
      "version": "1.0",
      "clients": {
        "client-1": {
          "tlsEnable": true,
          "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": true,
          "adminPrivateKey": {
            "path": "/root/demo/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore"
          },
          "signedCert": {
            "path": "/root/demo/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts"
          }
        },
        "Org2MSP": {
          "mspid": "Org2MSP",
          "adminPrivateKey": {
            "path": "/root/demo/fabric-samples/first-network/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/keystore"
          },
          "signedCert": {
            "path": "/root/demo/fabric-samples/first-network/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/signcerts"
          }
        },
        "OrdererMSP": {
          "mspid": "OrdererMSP",
          "adminPrivateKey": {
            "path": "/root/demo/fabric-samples/first-network/crypto-config/ordererOrganizations/example.com/users/Admin@example.com/msp/keystore"
          }
        }
      },
      "peers": {
        "peer0.org1.example.com": {
          "tlsCACerts": {
            "path": "/root/demo/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
          },
          "url": "grpcs://localhost:7051",
          "eventUrl": "grpcs://localhost:7053",
          "grpcOptions": {
            "ssl-target-name-override": "peer0.org1.example.com"
          }
        },
        "peer1.org1.example.com": {
          "url": "grpcs://localhost:8051"
        },
        "peer0.org2.example.com": {
          "url": "grpcs://localhost:9051"
        },
        "peer1.org2.example.com": {
          "url": "grpcs://localhost:10051"
        }
      },
      "orderers": {
        "orderer.example.com": {
          "url": "grpcs://localhost:7050"
        }
      }
    },
    "network-2": {}
  },
  "configtxgenToolPath": "/root/demo/fabric-samples/bin",
  "license": "Apache-2.0"
}

6、包引入并测试(包引入过程可能很慢,一定要注意nodejs的版本)

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

7、打开防火墙端口并启动服务

# 打开端口
root@ubuntu:~# sudo ufw enable   #激活ufw
root@ubuntu:~# sudo ufw allow 8080/tcp   #开启8080/tcp端口

# 启动服务
root@ubuntu:~# cd blockchain-explorer
root@ubuntu:~/demo/blockchain-explorer# ./start.sh    #启动
************************************************************************************
**************************** Hyperledger Explorer **********************************
************************************************************************************
***** Please check the log [logs/console/console-2018-12-26.log] for any error *****
************************************************************************************
root@ubuntu:~/demo/blockchain-explorer# cat logs/console/console-2018-12-26.log   #查看启动日志,若没有报错且提示:Please open web browser to access :http://localhost:8080/

8、访问。输入:http://localhost:8080
在这里插入图片描述

三、总结
1、搭建大体过程参照官网或者相关博客
2、nodejs和postgresql的版本得符合要求,特别是nodejs
3、配置文件严格按照要求,不然的话服务启动不起来
4、本次没有对fabric的版本和explorer的版本进行操作,都是用的默认的最新版本
5、再次启动网络的步骤(1、产生fabric证书文件;2、启动fabric网络;3、启动explorer,注意配置文件,多试几次)
附本人笔记:https://note.youdao.com/share/?id=4ec81cc743f386d3000865cb9390e2f8&type=note#/

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
Ubuntu 18.04 上搭建 Samba 服务器可以通过以下步骤完成: 1. 首先,确保你的系统是最新的,可以运行以下命令进行系统更新: ``` sudo apt update sudo apt upgrade ``` 2. 安装 Samba 服务器软件包,可以运行以下命令进行安装: ``` sudo apt install samba ``` 3. 在安装完成后,编辑 Samba 的主配置文件 `/etc/samba/smb.conf`,可以使用以下命令进行编辑: ``` sudo nano /etc/samba/smb.conf ``` 4. 在配置文件,你可以定义共享的文件夹和访问权限。在文件的末尾,你可以添加以下示例配置来创建一个共享名为 "share" 的文件夹: ``` [share] comment = Shared Folder path = /path/to/shared/folder browsable = yes guest ok = yes read only = no create mask = 0777 directory mask = 0777 ``` 请确保将 `/path/to/shared/folder` 替换为你实际要共享的文件夹路径。 5. 保存并关闭文件。然后,重新启动 Samba 服务以使更改生效: ``` sudo service smbd restart ``` 6. 默认情况下,Samba 使用的是系统用户认证。你可以使用以下命令为 Samba 创建一个用户,并为该用户设置密码: ``` sudo smbpasswd -a username ``` 将 "username" 替换为你要创建的用户名。 7. 最后,你可以通过其他计算机上的文件管理器或命令行窗口访问 Samba 共享。输入以下地址进行访问: ``` smb://<ip-address>/share ``` 将 "<ip-address>" 替换为运行 Samba 的 Ubuntu 18.04 的 IP 地址。 这样,你就可以在 Ubuntu 18.04 上成功搭建一个 Samba 服务器,并共享文件夹。希望对你有所帮助!如有其他问题,请随时提问。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值