這篇文章主要為大家展示了“Hyperledger Fabric如何實現(xiàn)基于ubuntu系統(tǒng)部署網(wǎng)絡(luò)”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“Hyperledger Fabric如何實現(xiàn)基于ubuntu系統(tǒng)部署網(wǎng)絡(luò)”這篇文章吧。
10年的石峰網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。網(wǎng)絡(luò)營銷推廣的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整石峰建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。成都創(chuàng)新互聯(lián)從事“石峰網(wǎng)站設(shè)計”,“石峰網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。
Hyperledger Composer 網(wǎng)絡(luò)要素
Business Network Definition
在我們動手執(zhí)行代碼之前,先來了解一下Business Network Definition的概念。因為這個概念貫穿在這個網(wǎng)絡(luò)系統(tǒng)中。BND為區(qū)塊鏈定義了 數(shù)據(jù)模型, 交易邏輯 和 訪問控制規(guī)則 。我們可以部署bna包到Fabric網(wǎng)絡(luò),為了生成bna,我們需要提前生成:
a set of model files
a set of JavaScript files
an Access Control file
所有的這些文件,都可以理解是對我們的網(wǎng)絡(luò)的描述文件。網(wǎng)絡(luò)根據(jù)我們的描述,來執(zhí)行。
BusinessNetworkFiles
那我們就動手搭建,并且部署一個網(wǎng)絡(luò)。 下面的代碼執(zhí)行于ubuntu系統(tǒng)。
(1)從命令行,創(chuàng)建一個新的dir,并且cd到該dir
amy@amy-wu:~/pg/sandbox/bnd$ yo hyperledger-composer:businessnetwork Welcome to the business network generator ? Business network name: tutorial-network ? Description: Here is a hello world example ? Author name: Amy Wu ? Author email: AmyWu@123abc.com ? License: Apache-2.0 ? Namespace: org.example.biznet ? Do you want to generate an empty template network ? No: generate a populated sample network create package.json create README.md create models/org.example.biznet.cto create permissions.acl create .eslintrc.yml create features/sample.feature create features/support/index.js create test/logic.js create lib/logic.js amy@amy-wu:~/pg/sandbox/bnd$
(2)查看剛剛的指令為了創(chuàng)建的文件
amy@amy-wu:~/pg/sandbox/bnd$ tree . └── tutorial-network ├── features │ ├── sample.feature │ └── support │ └── index.js ├── lib │ └── logic.js ├── models │ └── org.example.biznet.cto ├── package.json ├── permissions.acl ├── README.md └── test └── logic.js 6 directories, 8 files amy@amy-wu:~/pg/sandbox/bnd$
org.example.biznet.cto 定義了網(wǎng)絡(luò)里面的參與方,資產(chǎn)等信息
permission.acl 定義了訪問權(quán)限
(1)cd到 /tutorial-network 目錄下
需要提前安裝composer環(huán)境
升級Fabric Composer版本
錯誤提示
Cannot use v0.16.6 version of composer with fabric 1.1, v0.19 or higher is required
確認版本
composer -vv0.19.10
卸載現(xiàn)有版本
npm uninstall -g composer-cli npm uninstall -g composer-rest-server npm uninstall -g generator-hyperledger-composer
重新安裝最新版本版本
npm install -g composer-cli npm install -g composer-rest-server npm install -g generator-hyperledger-composer amy@amy-wu:~/pg/sandbox/bnd/tutorial-network$ composer archive create -t dir -n . Creating Business Network Archive Looking for package.json of Business Network Definition Input directory: /home/amy/pg/sandbox/bnd/tutorial-network Found: Description: Here is a hello world example Name: tutorial-network Identifier: tutorial-network@0.0.1 Written Business Network Definition Archive file to Output file: tutorial-network@0.0.1.bna Command succeeded
(2)查看生成的bna文件
amy@amy-wu:~/pg/sandbox/bnd$ tree. └── tutorial-network ├── features │ ├── sample.feature │ └── support │ └── index.js ├── lib │ └── logic.js ├── models │ └── org.example.biznet.cto ├── package.json ├── permissions.acl ├── README.md ├── test │ └── logic.js └── tutorial-network@0.0.1.bna 新生成的文件 6 directories, 9 files
在做部署之前,先要啟動一個Fabric網(wǎng)絡(luò)。
(1)下載fabric-dev-servers.zip
mkdir fabric-dev-servers && cd fabric-dev-servers curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.zip unzip fabric-dev-servers.zip
(2)第一次啟動Fabric網(wǎng)絡(luò)的時候
cd fabric-dev-servers ./downloadFabric.sh ./startFabric.sh ./createPeerAdminCard.sh
(3)結(jié)束的時候
./stopFabric.sh ./teardownFabric.sh
(4)初始化網(wǎng)路
amy@amy-wu:~/pg/sandbox/bnd/tutorial-network$ composer network install --card PeerAdmin@hlfv1 --archiveFile tutorial-network@0.0.1.bna ? Installing business network. This may take a minute...Successfully installed business network tutorial-network, version 0.0.1 Command succeeded amy@amy-wu:~/pg/sandbox/bnd/tutorial-network$
(5)查看docker containers
docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 27b30f42cc5e hyperledger/fabric-peer:x86_64-1.1.0 "peer node start" 5 minutes ago Up 5 minutes 0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp peer0.org1.example.com 2f62650005f4 hyperledger/fabric-orderer:x86_64-1.1.0 "orderer" 5 minutes ago Up 5 minutes 0.0.0.0:7050->7050/tcp orderer.example.com96ec8b462e0e hyperledger/fabric-couchdb:x86_64-0.4.6 "tini -- /docker-ent…" 5 minutes ago Up 5 minutes 4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp couchdb ecd55c74cb76 hyperledger/fabric-ca:x86_64-1.1.0 "sh -c 'fabric-ca-se…" 5 minutes ago Up 5 minutes 0.0.0.0:7054->7054/tcp ca.org1.example.com
(6)啟動網(wǎng)絡(luò)
amy@amy-wu:~/pg/sandbox/bnd/tutorial-network$ composer network start --networkName tutorial-network --networkVersion 0.0.1 --networkAdmin admin --networkAdminEnrollSecret adminpw --card PeerAdmin@hlfv1 --file networkadmin.card Starting business network tutorial-network at version 0.0.1 Processing these Network Admins: userName: admin ? Starting business network definition. This may take a minute... Successfully created business network card: Filename: networkadmin.card Command succeeded
(7)導(dǎo)入網(wǎng)絡(luò)管理員身份
amy@amy-wu:~/pg/sandbox/bnd/tutorial-network$ composer card import --file networkadmin.card Successfully imported business network card Card file: networkadmin.card Card name: admin@tutorial-network Command succeeded
(8)測試
amy@amy-wu:~/pg/sandbox/bnd/tutorial-network$ composer network ping --card admin@tutorial-network The connection to the network was successfully tested: tutorial-network Business network version: 0.0.1 Composer runtime version: 0.19.10 participant: org.hyperledger.composer.system.NetworkAdmin#admin identity: org.hyperledger.composer.system.Identity#d9e43201ca1bcc328e0e81ceaf96caf4f113019f41d26d292699151a50d0a3ac Command succeeded
amy@amy-wu:~$ composer-rest-server ? Enter the name of the business network card to use: admin@tutorial-network ? Specify if you want namespaces in the generated REST API: never use namespaces ? Specify if you want to use an API key to secure the REST API: No ? Specify if you want to enable authentication for the REST API using Passport: Yes ? Specify if you want to enable multiple user and identity management using wallets: No ? Specify if you want to enable event publication over WebSockets: Yes ? Specify if you want to enable TLS security for the REST API: No To restart the REST server using the same options, issue the following command: composer-rest-server -c admin@tutorial-network -n never -a true -w true Discovering types from business network definition ... Discovered types from business network definition Generating schemas for all types in business network definition ... Generated schemas for all types in business network definition Adding schemas for all types to Loopback ... Added schemas for all types to Loopback Web server listening at: http://localhost:3000 Browse your REST API at http://localhost:3000/explorer
查看API:http://localhost:3000/explorer
amy@amy-wu:~/pg/sandbox/bnd/tutorial-network$ yo hyperledger-composer:angular Welcome to the Hyperledger Composer Angular project generator ? Do you want to connect to a running Business Network? Yes ? Project name: angular-app ? Description: Hyperledger Composer Angular project ? Author name: Amy WU ? Author email: 123@gmail.com ? License: Apache-2.0? Name of the Business Network card: admin@tutorial-network ? Do you want to generate a new REST API or connect to an existing REST API ? Connect to an existing REST API ? REST server address: http://localhost ? REST server port: 3000? Should namespaces be used in the generated REST API? Namespaces are not used Created application! Completed generation process create app.js Binary found at /home/amy/pg/sandbox/bnd/tutorial-network/angular-app/node_modules/node-sass/vendor/linux-x64-59/binding.node Testing binary Binary is fine npm notice created a lockfile as package-lock.json. You should commit this file. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) added 1162 packages in 145.973s Application generated
(1)啟動應(yīng)用
amy@amy-wu:~/pg/sandbox/bnd/tutorial-network/angular-app$ npm start > angular-app@0.0.1 start /home/amy/pg/sandbox/bnd/tutorial-network/angular-app > ng serve --proxy-config proxy.conf.js --host 0.0.0.0 ** NG Live Development Server is running on http://0.0.0.0:4200 ** 10% building modules 4/4 modules 0 active[HPM] Proxy created: [ '/auth', '/api' ] -> http://localhost:3000 [HPM] Proxy created: / -> http://localhost:3000 Hash: a0d3dc89fcbecd8aa802 Time: 12249ms chunk {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 270 kB {5} [initial] [rendered] chunk {1} main.bundle.js, main.bundle.js.map (main) 101 kB {4} [initial] [rendered] chunk {2} styles.bundle.js, styles.bundle.js.map (styles) 184 kB {5} [initial] [rendered] chunk {3} scripts.bundle.js, scripts.bundle.js.map (scripts) 439 kB {5} [initial] [rendered] chunk {4} vendor.bundle.js, vendor.bundle.js.map (vendor) 4.12 MB [initial] [rendered] chunk {5} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered] webpack: Compiled successfully.
(2)查看應(yīng)用
http://0.0.0.0:4200
以上是“Hyperledger Fabric如何實現(xiàn)基于ubuntu系統(tǒng)部署網(wǎng)絡(luò)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!