需要准备的环境:

1, Go 1.15.6

2, Node.js v12.13.1

3, jq

4, gcc-c++

5,postgresql-9.5

软件下载及安装方式:

这里我只列出jq,gcc-c++,postgresql-9.5的安装,其他软件请参考之前的文章完成

jq安装:

yum install -y jq

gcc-c++安装:

yum install -y gcc-c++

postgresql-9.5安装:

先安装yum源:

yum install -y https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7.4-x86_64/pgdg-redhat-repo-42.0-11.noarch.rpm

下来再安装postgresql-9.5

yum install -y postgresql95-server postgresql95-contrib
systemctl enable postgresql-9.5.service
systemctl start postgresql-9.5.service

修改postgresql的密码

su - postgres
psql -U postgres #默认用户
ALTER USER postgres WITH PASSWORD '123456' #密码
\q  #退出
exit

开启远程访问:

vim  /var/lib/pgsql/9.5/data/postgresql.conf  # 修改#listen_addresses = 'localhost' 为 listen_addresses='*'

信任远程连接:

vim /var/lib/pgsql/9.5/data/pg_hba.conf  #填加一行
host    all             all             0.0.0.0/0               trust

重启postgresql

systemctl restart postgresql-9.5.service

你可以通过navicat尝试去连接如果可以说明一切都配置正常

完成后就可以了,下面是我的软件安装的路径:

 

其中有些软件不需要,可以不用安装

我的工作目录是/usr/local下,所以后面所有的操作及配置也都会基于此目录

安装完成nodejs和go以后记得去配置环境变量

到这里环境就准备好了

下载fabric-simple 和fabric-explorer

此下载需要Git,没有的提前装,这里不过多介绍

cd /usr/local/gopath/src/github.com/hyperledger
git clone -b v1.1.4 https://github.com/hyperledger/blockchain-explorer.git

我选择这个版本是因为在我安装时这个版本是最新的,一面出现版本不兼容这里特别记录出来

 

 

 我的gopath是在/usr/local/下

 

 

fabric-simple 我下载在了/usr/local/下,当然你也可以放到gopath 下,会和blockchain-explorer同级

cd /usr/local
git clone -b v.1.4.3 https://github.com/hyperledger/fabric-samples.git

我这里用的是v1.4.3的版本

启动fabric-simple

cd /usr/local/fabric-samples/first-network
./byfn.sh generate 
./byfn.sh up

修改blockchain-explorer的配置信息

cd /usr/local/gopath/src/github.com/hyperledger/blockchain-explorer/app
vim appconfig.json  #修改"host": "localhost", 为"host": "虚拟机ip", 端口修改为8089
[root@bogon app]# cat appconfig.json 
{
    "sslEnabled": false,
    "sslCertsPath": "ssl-certs",
    "host": "192.168.56.19",
    "port": "8089",
    "license": "Apache-2.0"
}
[root@bogon app]# 
vim explorerconfig.json  #改文件和上面的文件同级,修改postgresql的连接信息
[root@bogon app]# cat explorerconfig.json 
{
    "persistence": "postgreSQL",
    "platforms": ["fabric"],
    "postgreSQL": {
        "host": "127.0.0.1",
        "port": "5432",
        "database": "postgres",
        "username": "postgres",
        "passwd": "123456"
    },
    "sync": {
        "type": "local",
        "platform": "fabric",
        "blocksSyncTime": "1"
    },
    "jwt": {
        "secret": "a secret phrase!!",
        "expiresIn": "2h"
    }
}
[root@bogon app]# 

导入数据库信息:

cd /usr/local/gopath/src/github.com/hyperledger/blockchain-explorer/app/persistence/fabric/postgreSQL/db
./createdb.sh

完成后查看数据库可以看到多了一些表

 

 

explorer和fabric-simple例子结合

cd /usr/local/gopath/src/github.com/hyperledger/blockchain-explorer/app/platform/fabric
vim config.json
[root@bogon fabric]# cat config.json 
{
    "network-configs": {
        "first-network": {
            "name": "first Network",
            "profile": "./connection-profile/first-network.json"
        }
    },
    "license": "Apache-2.0"
}

编辑first-network.json文件,此文件原来是不存在的,我们需要将test-network.json文件复制一份进行改动

cd /usr/local/gopath/src/github.com/hyperledger/blockchain-explorer/app/platform/fabric/connection-profile
cp test-network.json first-network.json
[root@bogon connection-profile]# cat first-network.json 
{
    "name": "first-network",
    "version": "1.0.0",
    "license": "Apache-2.0",
    "client": {
        "tlsEnable": true,
        "adminCredential": {
            "id": "admin",   #explorer登录界面的用户名
            "password": "adminpw"  #explorer登录界面的用户密码
        },
        "enableAuthentication": true,
        "organization": "Org1MSP",
        "connection": {
            "timeout": {
                "peer": {
                    "endorser": "300"
                },
                "orderer": "300"
            }
        }
    },
    "channels": {
        "mychannel": {
            "peers": {
                "peer0.org1.example.com": {}
            },
            "connection": {
                "timeout": {
                    "peer": {
                        "endorser": "6000",
                        "eventHub": "6000",
                        "eventReg": "6000"
                    }
                }
            }
        }
    },
    "organizations": {
        "Org1MSP": {
            "mspid": "Org1MSP",
            "adminPrivateKey": {
                "path": "/usr/local/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/b49114d6639e75919bf70ed24b5eaadaa253321b41d24af5deb217b300b2d03a_sk"
            },
            "peers": ["peer0.org1.example.com"],
            "signedCert": {
                "path": "/usr/local/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts/Admin@org1.example.com-cert.pem"
            }
        }
    },
    "peers": {
        "peer0.org1.example.com": {
            "tlsCACerts": {
                "path": "/usr/local/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
            },
            "url": "grpcs://192.168.56.19:7051",
            "grpcOptions": {
                "ssl-target-name-override": "peer0.org1.example.com"
            }
        }
    }
}
[root@bogon connection-profile]# 

需要修改的地方我都标红和可以根据自己安装的fabric-simple进行配置

下来我们来打包部署explorer

cd /usr/local/gopath/src/github.com/hyperledger/blockchain-explorer
npm install
cd client/
npm install
npm run build

以上命令如果出现权限问题可以用以下方式解决

npm config set unsafe-perm true

然后再执行上面的命令

完成后我们就可以启动exporer了

用下面的命令启动

cd /usr/local/gopath/src/github.com/hyperledger/blockchain-explorer
npm start

启动输出:

[root@bogon blockchain-explorer]# npm start

> hyperledger-explorer@1.1.4 start /usr/local/gopath/src/github.com/hyperledger/blockchain-explorer
> run-s build app-start


> hyperledger-explorer@1.1.4 build /usr/local/gopath/src/github.com/hyperledger/blockchain-explorer
> tsc


> hyperledger-explorer@1.1.4 app-start /usr/local/gopath/src/github.com/hyperledger/blockchain-explorer
> ./start.sh

************************************************************************************
**************************** Hyperledger Explorer **********************************
************************************************************************************
[root@bogon blockchain-explorer]# 

 

用下面的命令停止

npm run app-stop

停止输出

[root@bogon blockchain-explorer]# npm run app-stop

> hyperledger-explorer@1.1.4 app-stop /usr/local/gopath/src/github.com/hyperledger/blockchain-explorer
> ./stop.sh

Stopping node process hyperledger-explorer, id  19062

 

 

参考文档:

https://blog.csdn.net/qq_32675427/article/details/99946945

https://www.bbsmax.com/A/8Bz8q83yJx/

posted on 2021-02-25 09:40  EZgod  阅读(220)  评论(0编辑  收藏  举报