标签:_id rgs 延迟 keyword str 设计 解压 release ref
项目约定共同遵守的 基本原则 为:重视模块化设计,包括交易、合同、一致性、身份、存储等技术场景;代码可读性,保障新功能和模块都可以很容易添加和扩展;演化路线,随着需求的深入和更多的应用场景,不断增加和演化新的项目。
curl -sSL https://get.daocloud.io/docker | sh
docker -v
先安装Python-pip,具体安装步奏如下:
sudo yum -y install epel-release
sudo yum -y install python-pip
sudo yum clean all
下面开始安装Docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
配置以下docker镜像加速,目的是下载镜像速度更快:
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://860eaa91.m.daocloud.io
重启docker服务:
sudo service docker restart
docker pull hyperledger/fabric-peer:x86_64-0.6.1-preview && docker pull hyperledger/fabric-membersrvc:x86_64-0.6.1-preview && docker pull yeasy/blockchain-explorer:latest && docker tag hyperledger/fabric-peer:x86_64-0.6.1-preview hyperledger/fabric-peer && docker tag hyperledger/fabric-peer:x86_64-0.6.1-preview hyperledger/fabric-baseimage && docker tag hyperledger/fabric-membersrvc:x86_64-0.6.1-preview hyperledger/fabric-membersrvc
1.安装依赖包:
sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
2.下载Git源码并解压安装:
$ wget https://github.com/git/git/archive/v2.3.0.zip
$ unzip v2.3.0.zip
$ cd git-2.3.0
3.编译安装:
make prefix=/usr/local/git all
sudo make prefix=/usr/local/git install
4.修改环境变量:
sudo vim /etc/profile
然后在文件的最后一行,添加下面的内容,然后保存退出。
export PATH=/usr/local/git/bin:$PATH
5.使用source命令立即保存:
source /etc/profile
6.查看版本
git version
PBFT 是经典的分布式一致性算法,也是 hyperledger 目前最推荐的算法,该算法至少需要 4 个节点。
git clone https://github.com/yeasy/docker-compose-files
以下节点可以快速启动的详细情况:
4-peers.yml: 启动 4 个 PBFT peer 节点。
4-peers-with-membersrvc.yml: 启动 4 个 PBFT peer 节点 + 1 个 CA 节点,并启用 CA 功能。
4-peers-with-explorer.yml: 启动 4 个 PBFT peer 节点 + 1 个 Blockchain-explorer,可以通过 Web 界面监控集群状态。
4-peers-with-membersrvc-explorer.yml: 启动 4 个 PBFT peer 节点 + 1 个 CA 节点 + 1 个 Blockchain-explorer,并启用 CA 功能。
docker-compose -f 4-peers-with-membersrvc-explorer.yml up
docker exec -it pbft_vp0_1 bash
peer chaincode deploy -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c ‘{"Function":"init", "Args": ["a","100", "b", "200"]}‘
CC_ID="ee5b24a1f17c356dd5f6e37307922e39ddba12e5d2e203ed93401d7d05eb0dd194fb9070549c5dc31eb63f4e654dbd5a1d86cbb30c48e3ab1812590cd0f78539"
peer chaincode query -n ${CC_ID} -c ‘{"Function": "query", "Args": ["a"]}‘
peer chaincode invoke -n ${CC_ID} -c ‘{"Function": "invoke", "Args": ["a", "b", "10"]}‘
peer chaincode query -n ${CC_ID} -c ‘{"Function": "query", "Args": ["a"]}‘
到此已经完成超级账本的 转账的实例,每转一次,都会记录一个块。
当启用了权限管理后,首先需要登录,例如以内置账户 jim 账户登录。
登录 vp0,并执行登录命令。
docker exec -it pbft_vp0_1 bash
用内置jim账户登录
peer network login jim
内置密码为:
6avZQLwcUe9b
登录情况如下图:
登录成功后,以下为具体操作。
peer chaincode deploy -u jim -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c ‘{"Function":"init", "Args": ["a","100", "b", "200"]}‘
说明:部署时给a,b各初始值100 200
部署之后会产生一个name 值为:
name:"ee5b24a1f17c356dd5f6e37307922e39ddba12e5d2e203ed93401d7d05eb0dd194fb9070549c5dc31eb63f4e654dbd5a1d86cbb30c48e3ab1812590cd0f78539"
把name值 赋给变量 CC_ID
CC_ID=ee5b24a1f17c356dd5f6e37307922e39ddba12e5d2e203ed93401d7d05eb0dd194fb9070549c5dc31eb63f4e654dbd5a1d86cbb30c48e3ab1812590cd0f78539
查询下赋值结果:
echo ${CC_ID}
重要说明:部署成功后,会创建docker容器,创建docker容器会有延迟,所以有时查询不出来,等创建好了,在查询就可以啦。
可以看到创建了很多容器,如下图:
下面咱们来执行查询操作试试,查下a的值:
peer chaincode query -u jim -n ${CC_ID} -c ‘{"Function": "query", "Args": ["a"]}‘
查下b的值:
peer chaincode query -u jim -n ${CC_ID} -c ‘{"Function": "query", "Args": ["b"]}‘
下面咱们来执行下 转账操作:
如:a向b转账10元
peer chaincode invoke -u jim -n ${CC_ID} -c ‘{"Function": "invoke", "Args": ["a", "b", "10"]}‘
转账成功后,咱们来执行下查询 a和b的值是多少:
peer chaincode query -u jim -n ${CC_ID} -c ‘{"Function": "query", "Args": ["b"]}‘
peer chaincode query -u jim -n ${CC_ID} -c ‘{"Function": "query", "Args": ["a"]}‘
权限管理能正确 转账查询。
下面使用REST方式咱们来执行下查询:
CC_ID=ee5b24a1f17c356dd5f6e37307922e39ddba12e5d2e203ed93401d7d05eb0dd194fb9070549c5dc31eb63f4e654dbd5a1d86cbb30c48e3ab1812590cd0f78539
用这个CC_ID来做查询
POST HOST:7050/chaincode
Request:
{
"jsonrpc": "2.0",
"method": "query",
"params": {
"type": 1,
"chaincodeID":{
"name":"ee5b24a1f17c356dd5f6e37307922e39ddba12e5d2e203ed93401d7d05eb0dd194fb9070549c5dc31eb63f4e654dbd5a1d86cbb30c48e3ab1812590cd0f78539"
},
"ctorMsg": {
"function":"query",
"args":["a"]
},
"secureContext": "jim"
},
"id": 3
}
查询a的值为:
Request:
{
"jsonrpc": "2.0",
"method": "query",
"params": {
"type": 1,
"chaincodeID":{
"name":"ee5b24a1f17c356dd5f6e37307922e39ddba12e5d2e203ed93401d7d05eb0dd194fb9070549c5dc31eb63f4e654dbd5a1d86cbb30c48e3ab1812590cd0f78539"
},
"ctorMsg": {
"function":"query",
"args":["b"]
},
"secureContext": "jim"
},
"id": 3
}
查询b的值为:
这时,a是145,b是155
{
"jsonrpc": "2.0",
"method": "invoke",
"params": {
"type": 1,
"chaincodeID":{
"name":"ee5b24a1f17c356dd5f6e37307922e39ddba12e5d2e203ed93401d7d05eb0dd194fb9070549c5dc31eb63f4e654dbd5a1d86cbb30c48e3ab1812590cd0f78539"
},
"ctorMsg": {
"function":"invoke",
"args":["a","b","35"]
},
"secureContext": "jim"
},
"id": 3
}
如图:
下面执行 查询 a,和 b的值,请求参数 如上,直接上图啦。
a的值为 120
b的值为180
下面查询以下区块信息:
GET HOST:7050/chain/blocks/2
Response:
{
"transactions": [
{
"type": 2,
"chaincodeID": "EoABNzhjYTMyZmMxMjlmMDExMjllMDEwYzM3YTc4ZDU2ODhiODEyNjY1NWI5NDU2MTNkMjFiMmM2MGJjYjNlMTFkYTFjZGViYTljMjM1NjNjMzhmYTQ3MTc3YWYwZGU2ZTNkOTRmNjc4MWQzMDlhMzBlN2QxOTBhNjU1NWU3YWU0ZWY=",
"payload": "Cp0BCAESgwESgAE3OGNhMzJmYzEyOWYwMTEyOWUwMTBjMzdhNzhkNTY4OGI4MTI2NjU1Yjk0NTYxM2QyMWIyYzYwYmNiM2UxMWRhMWNkZWJhOWMyMzU2M2MzOGZhNDcxNzdhZjBkZTZlM2Q5NGY2NzgxZDMwOWEzMGU3ZDE5MGE2NTU1ZTdhZTRlZhoTCgZpbnZva2UKAWEKAWIKAzEwMA==",
"txid": "8616608f-9762-44cc-bc09-ef93b88eb770",
"timestamp": {
"seconds": 1484792805,
"nanos": 467224609
},
"nonce": "QTKtub7Nu/JJFXV5LhjcDYsxIViB27YF",
"cert": "MIICQTCCAeegAwIBAgIQW9A+u+4IT7CRRcHJPxU1ZjAKBggqhkjOPQQDAzAxMQswCQYDVQQGEwJVUzEUMBIGA1UEChMLSHlwZXJsZWRnZXIxDDAKBgNVBAMTA3RjYTAeFw0xNzAxMTkwMjI0MjBaFw0xNzA0MTkwMjI0MjBaMEUxCzAJBgNVBAYTAlVTMRQwEgYDVQQKEwtIeXBlcmxlZGdlcjEgMB4GA1UEAxMXVHJhbnNhY3Rpb24gQ2VydGlmaWNhdGUwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQylvGqiwlIwjfef1J0o+2lBPEs0PQc90mooN/iQeJesX3Gw7hvX51NQ0R9Azhs3HzqwDT6/0oUJ5881BGCGufjo4HMMIHJMA4GA1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8EAjAAMA0GA1UdDgQGBAQBAgMEMA8GA1UdIwQIMAaABAECAwQwTQYGKgMEBQYHAQH/BEArLNyVnxK3ZTvPvUStqnu90Soz7fkorQD0znFSKd32vwi8nVzKPLKuziDfULFQskeHV7UAVL28xjKPXjpa4tOUMDoGBioDBAUGCAQwdCe6zf7KXUkQavqTErscZyXjnx3YI1QbmuNIiYXptTkzhPCI+tKPa5nMxwlBbqbNMAoGCCqGSM49BAMDA0gAMEUCIQC/tJPRxcPq4l4F3hWoLT6OWO5f1A9HG1aPyurduM4oowIgbTibDjL98J7Dt7fw3TBCMVBSDska9FwlddqdSE/3bWA=",
"signature": "MEUCIQCTxcHIu3kL5AuTOS11tnV4wp35pDtdQ7QCfXMr9txPBAIgH64AARCnRinLNN7V69ha75sdVqOKn/OPKYDWHxofsFM="
}
],
"stateHash": "zHYqtOW0tZ9g1jbfaWgXB9udEETDocwet6HcsonKEJ9ncYZaCjLNAJS4Fao9W6AQR6FOkZR7FR7bvmocjtF00w==",
"previousBlockHash": "Q3b82oFuJu0God7J4QGllDlAA4iW7cwu2yg6/oNnNQCAwYJXs/4WFgKXo75FGfdmvmeDputIQMdjc4vmrvkw8w==",
"consensusMetadata": "CAI=",
"nonHashData": {
"localLedgerCommitTimestamp": {
"seconds": 1484794929,
"nanos": 31349065
},
"chaincodeEvents": [
{}
]
}
}
如图:
到这里 REST请求完成。以上是权限管理的具体操作。
下面我们来看下节点的端口,如下图:
这时我们在谷歌浏览器里就可以访问啦,
HOST:9090
访问正常页面为:
查询的具体的信息,如下图:
查看交易详情,如下图:
到此,整个Hyperledger Fabric超级账本环境已经部署完成。
Hyperledger fablic 0.6 在centos7环境下的安装与部署
标签:_id rgs 延迟 keyword str 设计 解压 release ref
原文地址:http://www.cnblogs.com/wangmo/p/6836371.html