24
24
25
25
26
26
## 2. 安装git
27
- > apt-get update
28
-
29
- > apt-get install git
27
+ ``` shell
28
+ apt-get update
29
+ apt-get install git
30
+ ```
30
31
31
32
![ image] ( https://note.youdao.com/yws/public/resource/95c087db9c2f4249616a4058c521ca13/xmlnote/B81421F12EF749859012A426ED493736/159 )
32
33
33
34
34
35
## 3. 安装docker-ce
35
36
请不要直接apt安装旧版本的docker
36
37
37
- [阿里云安装docker教程](https://yq.aliyun.com/articles/110806?spm=5176.8351553.0.0.5d4e1991URD8Ia)
38
+ [ 阿里云安装docker教程] ( https://yq.aliyun.com/articles/110806?spm=5176.8351553.0.0.5d4e1991URD8Ia )
38
39
39
- ```
40
+ ``` shell
40
41
# step 1: 安装必要的一些系统工具
41
42
sudo apt-get update
42
43
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
@@ -63,27 +64,32 @@ sudo apt-get -y install docker-ce
63
64
64
65
65
66
ubuntu14.04系统采用不支持systemctl
66
- > service docker restart
67
-
68
- 重启docker服务
67
+ ``` shell
68
+ # 重启docker服务
69
+ service docker restart
70
+ ```
69
71
70
72
71
73
## 5. 安装hyperledger的工具和docker镜像
72
74
73
75
点击官方[ 参考文档] ( http://hyperledger-fabric.readthedocs.io/en/release-1.1/samples.html#binaries )
74
76
75
- 注意: 按照官方文档执行, 需要全局翻墙才行
77
+ * 注意: 按照官方文档执行, 需要全局翻墙才行
76
78
77
79
![ image] ( https://note.youdao.com/yws/public/resource/95c087db9c2f4249616a4058c521ca13/xmlnote/BB783CDD52B842A4A1BDAE19923FBA5E/225 )
78
80
81
+ * 安装完检查目录结构和docker镜像:
79
82
80
- 安装完检查目录结构和docker镜像:
81
83
![ image] ( https://note.youdao.com/yws/public/resource/95c087db9c2f4249616a4058c521ca13/xmlnote/AC3A8997B51C4C65AF9E1D4CF7F3FCD1/232 )
82
84
83
85
84
86
## 6. 下载官方的示例代码 fabric sample
85
87
86
- > git clone https://github.com/hyperledger/fabric-samples.git
88
+ ``` shell
89
+ git clone https://github.com/hyperledger/fabric-samples.git
90
+ ```
91
+
92
+
87
93
88
94
![ image] ( https://note.youdao.com/yws/public/resource/95c087db9c2f4249616a4058c521ca13/xmlnote/DA434F1251A342F99E1BACC24C208524/240 )
89
95
@@ -97,7 +103,7 @@ ubuntu14.04系统采用不支持systemctl
97
103
98
104
## 8. 启动fabric ledger的第一个网络
99
105
运行如下命令:
100
- ```
106
+ ``` shell
101
107
# 1. 配置环境变量, fabirc的二进制工具
102
108
export PATH=/root/bin:$PATH
103
109
# 2. 生成hyperledger fabric的各种区块链配置
@@ -119,7 +125,7 @@ chmod +x /usr/local/bin/docker-compose
119
125
> /etc/resolv.conf
120
126
注释掉 options timeout:2 attempts:3 rotate single-request-reopen
121
127
重新执行
122
- ```
128
+ ``` shell
123
129
./byfn.sh -m down
124
130
./byfn.sh -m up
125
131
```
@@ -136,21 +142,26 @@ chmod +x /usr/local/bin/docker-compose
136
142
> 看到上面的截图,说明你的开发环境已经准备好, 接下来我们就可以搭建自己的组织结构,编写nodejs的链码了.
137
143
138
144
139
- ## 11. 停止网络请使用命令
140
145
141
- > ./byfn.sh -m down
146
+ ## 11. 停止网络请使用命令
142
147
148
+ ``` shell
149
+ ./byfn.sh -m down
150
+ ```
143
151
144
152
145
153
146
154
## 12. 切换到basic-network目录
155
+
147
156
来到fabirc-sample目录的basic-network文件夹
148
157
158
+
159
+
149
160
## 13. 修改 basic-network的docker-compose.yml
161
+
150
162
![ image] ( https://note.youdao.com/yws/public/resource/95c087db9c2f4249616a4058c521ca13/xmlnote/14483191ED1C41A7991A62E954BE79BD/298 )
151
163
> 说明: 启用开发者模式,这样加快调试部署,减少资源开销
152
- 开启7052端口, 开发模式下不使用tls会减少出错的概率,生产环境需要启用tls
153
-
164
+ > 开启7052端口, 开发模式下不使用tls会减少出错的概率,生产环境需要启用tls
154
165
155
166
156
167
@@ -163,13 +174,14 @@ chmod +x /usr/local/bin/docker-compose
163
174
164
175
## 15. 启动脚本 'start.h'
165
176
![ image] ( https://note.youdao.com/yws/public/resource/95c087db9c2f4249616a4058c521ca13/xmlnote/EAD0F21FA9394D5CB8E6394758C2BB26/326 )
166
- 可以看到启动了ca节点,peer节点,order节点,cli节点和couchdb,创建了channel,peer加入了channel
177
+
178
+ > 可以看到启动了ca节点,peer节点,order节点,cli节点和couchdb,创建了channel,peer加入了channel
167
179
168
180
169
181
## 16. 查看状态
170
182
![ image] ( https://note.youdao.com/yws/public/resource/95c087db9c2f4249616a4058c521ca13/xmlnote/FAF8C3A10DF14B47B8AF757A6FBE8989/337 )
171
183
172
- ```
184
+ ``` shell
173
185
docker ps
174
186
# 可以看到当前运行的docker容器, peer,order,couchdb,ca,cli节点
175
187
docker exec -it bash
@@ -179,19 +191,21 @@ peer channel list
179
191
```
180
192
181
193
194
+
182
195
## 17. chaincode编写需要使用nodejs
196
+
183
197
请安装>8.0版本的nodejs
184
198
185
199
官网连接 [ 点我直达] ( https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions )
186
- ```
200
+ ``` shell
187
201
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
188
202
sudo apt-get install -y nodejs
189
203
```
190
204
191
205
192
206
193
207
## 18.编写nodejs的chaincode
194
- ```
208
+ ``` shell
195
209
# 1.创建mycc文件夹
196
210
mkdir mycc
197
211
# 2. 初始化package.json文件
@@ -207,7 +221,7 @@ npm install --save fabric-shim --registry=https://registry.npm.taobao.org
207
221
208
222
209
223
## 19. 编写nodejs链码
210
- ```
224
+ ``` javascript
211
225
const shim = require (' fabric-shim' );
212
226
const Chaincode = class {
213
227
// 链码初始化操作
@@ -242,7 +256,7 @@ shim.start(new Chaincode());
242
256
243
257
## 20. 把chaincode注册给peer
244
258
他们之间通过grcp协议通信
245
- ```
259
+ ``` shell
246
260
CORE_CHAINCODE_ID_NAME=" mycc:v0" npm start -- --peer.address grpc://192.168.0.1:7052
247
261
```
248
262
![ image] ( https://note.youdao.com/yws/public/resource/95c087db9c2f4249616a4058c521ca13/xmlnote/94BCB93C2A2C4187865814C0844C15AD/390 )
@@ -252,7 +266,7 @@ CORE_CHAINCODE_ID_NAME="mycc:v0" npm start -- --peer.address grpc://192.168.0.1
252
266
## 21. 在peer上install安装链码
253
267
这是peer上chaincode的生命周期
254
268
255
- ```
269
+ ``` shell
256
270
CORE_PEER_LOCALMSPID=Org1MSP CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/
[email protected] /msp peer chaincode install -l node -n mycc -v v0 -p /opt/gopath/src/github.com/mycc/
257
271
258
272
```
@@ -262,7 +276,7 @@ CORE_PEER_LOCALMSPID=Org1MSP CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/
262
276
263
277
## 22. 在peer上实例化链码
264
278
265
- ```
279
+ ``` shell
266
280
CORE_PEER_LOCALMSPID=Org1MSP CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/
[email protected] /msp peer chaincode instantiate -l node -n mycc -v v0 -C mychannel -c
' {"args":["init","zzh","100","czbk","100"]}' -o 192.168.0.1:7050
267
281
```
268
282
@@ -272,7 +286,7 @@ CORE_PEER_LOCALMSPID=Org1MSP CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/
272
286
## 23. 测试链码调用
273
287
274
288
275
- ```
289
+ ``` shell
276
290
CORE_PEER_LOCALMSPID=Org1MSP CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/
[email protected] /msp peer chaincode invoke -n mycc -C mychannel -c
' {"args":["query","zzh"]}' -o 192.168.0.1:7050
277
291
```
278
292
@@ -287,11 +301,16 @@ CORE_PEER_LOCALMSPID=Org1MSP CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/
287
301
试着自己实现一下transfer方法吧
288
302
289
303
## 25. 停止网络使用
290
- > ./stop.sh ./teardown.sh
304
+ ``` shell
305
+ ./stop.sh ./teardown.sh
306
+ ```
307
+
308
+
291
309
292
310
293
311
## 26. 查看环境是否清理干净
294
- > docker ps 无内容就说明环境清理干净
312
+ ``` shell
313
+ docker ps
295
314
```
296
315
297
- ```
316
+ > 无内容就说明环境清理干净
0 commit comments