阿里云上的虚拟机玩转Neo私链
李悔之2015
发表于 2022-12-18 07:08:21
155
0
0
NEO 私有链的部署至少需要 4 台服务器才能取得共识,每台服务器对应一个共识节点。在阿里云上可以买按量付费的虚拟机(机器都是window server)。+ |1 ~, M# r+ x
记录下四台机器的内网IP地址,后面要用。; {- L3 Z1 K# z* q* e+ x% y$ ^
172.xxx.xxx.142
端口4 S2 D9 {# Z6 T
如果你想让外部程序访问该节点的 API 需要开放防火墙端口:10331-10334, 20331-20334
阿里云的vpc如果在一个安全组内就不需要设置。也可以通过安全组开放所有入口。
阿里云安全组
安装运行时4 K) g$ \1 Q: c, U' q9 D4 |
运行环境
运行 NEO 节点需要安装 .NET Core Runtime,需要安装 1.0.1 或以上版本 F4 u* u/ O% m: U5 y% N
Windows 系统下的安装方法4 Q: {+ j+ R; a$ Q
在 Windows 系统下安装 .NET Core 非常方便,直接下载运行即可。
NOTE
Windows可能还需要安装Microsoft Visual C++ 2015 Redistributable Update 3(https://www.microsoft.com/en-us/download/details.aspx?id=53840) ,否则后面无法启动Neo-CLI。" g' X" G! Q( x8 e
创建钱包" j ^, t4 S3 t1 @4 d- f
在四台机器上分别创建钱包数据库,数据库文件会默认生成在neo-cli的目录下面
create wallet wallet.json3 U0 Q( G6 l5 o1 `# k" U
db3后缀名的数据库文件不支持了# r) @/ [8 Q1 X- R! m6 d- ?
neo17 J. h( E" @. [9 o, U- o; {
neo> create wallet wallet.db3
Wallet files in db3 format are not supported, please use a .json file extension.
neo> create wallet wallet.json
password: ********$ i2 c, a( Y S. R+ c6 j" v$ c% x; y
password: ********
address: AS43TUy7VtuGpNJh2YC2NM3asTv3s6piyk
pubkey: 02d57c9bbc42b45943867dff0180cb9df266b46db7d027a283eabc7c4b8819c86c
记录下另外几台机器的钱包公钥
neo2! [* D2 ]; D; \1 ]8 _, h0 ^
address: AY35ZjJayg9JfmCeHg1nySN4LSMntFEq2h
pubkey: 035022ce81faca930ebe6b9f8e830526150e47692f19f58affe1311e42cd0d43bb) |: G9 U) A# k6 D; p" Q
neo3- I g! N4 J8 Z& o! j# S& r
address: AQZNtdGVXbfot5fSaR4ijBqrEwbnFQspmH
pubkey: 029f21d56f9422e55f0ef7cf75c092854e01c99aeee73f0effeaa489a96fc7d2b1# b/ J8 i& T. d i* V J
neo4
address: AXctyT8ctWTXtWaUFM9o5FJas8BWdBbiqe( U8 `# g, ~" e! o) i
pubkey: 02dc0e750e21c386537618079d89836eea39fad396206e2e56cfba16bdc014dc5d
修改节点的配置文件
{. }6 t. J3 V' z
"ProtocolConfiguration": {& x+ }( {* f. ?9 ?1 {
"Magic": 1,3 F2 t9 l. T1 z0 ^! ]2 p
"AddressVersion": 23,
"StandbyValidators": [
"02d57c9bbc42b45943867dff0180cb9df266b46db7d027a283eabc7c4b8819c86c",2 ?" G$ [. Y5 X' a
"035022ce81faca930ebe6b9f8e830526150e47692f19f58affe1311e42cd0d43bb",
"029f21d56f9422e55f0ef7cf75c092854e01c99aeee73f0effeaa489a96fc7d2b1",
"02dc0e750e21c386537618079d89836eea39fad396206e2e56cfba16bdc014dc5d"
],
"SeedList": [
"172.24.198.142:10333",; }+ b. D. \2 w* e1 ?7 O4 Z4 i1 h
"172.24.198.141:10333",+ z d2 G9 F( r9 f$ ~ r# Q: D6 i7 I
"172.24.198.140:10333",& Z+ A- `& e5 c2 U
"172.24.198.139:10333"
],
"SystemFee": {
"EnrollmentTransaction": 0,2 n% A2 V$ a8 B& M% u$ a
"IssueTransaction": 0,! \. }! z' X8 d0 S' O. w
"PublishTransaction": 0,
"RegisterTransaction": 0
}9 |/ T3 w v( W
}
}
打开钱包,开启共识' c& \7 w3 U' g8 Q/ K, c
open wallet wallet.json start consensus
如果前面打开过cli,请删除chain目录下的文件,这样区块链高度会从1开始。
截取其中一个打印,后面方便调试的时候研究2 ?& ~( C- {. e3 ^+ i0 {8 G( i# y ^
neo> open wallet wallet.json
password: ********
neo> start consensus
[18:04:31] OnStart( T7 J# m/ R# d; p
[18:04:31] initialize: height=1 view=0 index=0 role=Backup
[18:04:47] OnChangeViewReceived: height=1 view=0 index=2 nv=2
[18:05:01] timeout: height=1 view=0 state=Backup
[18:05:01] request change view: height=1 view=0 nv=1 state=Backup, ViewChanging' d/ b5 N7 V! z* d" a8 J: O8 d
[18:05:58] OnPrepareRequestReceived: height=1 view=0 index=1 tx=1
[18:05:58] send perpare response
[18:06:01] OnPrepareResponseReceived: height=1 view=0 index=2
[18:06:01] relay block: 0x8515184285fa2e454b0eca441580b5cce01cc0e5cb5dd6d7ff53ef13ec7f665e1 D% P7 B" s) {1 K" ^( o
[18:06:01] persist block: 0x8515184285fa2e454b0eca441580b5cce01cc0e5cb5dd6d7ff53ef13ec7f665e/ U% G: U1 a6 ^
[18:06:01] initialize: height=2 view=0 index=0 role=Backup: l6 Q+ r2 l3 B6 |
[18:06:16] OnPrepareRequestReceived: height=2 view=0 index=2 tx=1
[18:06:16] send perpare response1 F9 i: B; ]5 O5 |. ]
[18:06:19] OnPrepareResponseReceived: height=2 view=0 index=1+ V! \3 C- Z/ G& o# [5 D
[18:06:19] relay block: 0x35b163f4f524a1ebcc1ef3053e878f9bb37b1f4a8531a060ef18cfd6efefdf45& h! J, P; r9 z* Q( X2 z+ m6 c/ G
[18:06:19] persist block: 0x35b163f4f524a1ebcc1ef3053e878f9bb37b1f4a8531a060ef18cfd6efefdf45
[18:06:19] initialize: height=3 view=0 index=0 role=Backup
[18:06:49] timeout: height=3 view=0 state=Backup
[18:06:49] request change view: height=3 view=0 nv=1 state=Backup, ViewChanging# {6 e' o# f8 F; p4 a6 o4 }
[18:06:49] OnChangeViewReceived: height=3 view=0 index=1 nv=1
[18:06:53] OnChangeViewReceived: height=3 view=0 index=2 nv=1
[18:06:53] initialize: height=3 view=1 index=0 role=Backup! B. |+ `" d M3 {3 x# z- G T
[18:06:55] OnPrepareRequestReceived: height=3 view=1 index=2 tx=19 k$ H2 g, ]+ R. ?+ @ J8 A1 K
[18:06:55] send perpare response
[18:06:55] OnPrepareResponseReceived: height=3 view=1 index=1
[18:06:55] relay block: 0x1766a0602903f513f76561c93fddf312f70d30801310abfecacc89feace5c412
[18:06:55] persist block: 0x1766a0602903f513f76561c93fddf312f70d30801310abfecacc89feace5c412
[18:06:55] initialize: height=4 view=0 index=0 role=Primary
[18:07:10] timeout: height=4 view=0 state=Primary8 x& X& q, H4 I( n
[18:07:10] send perpare request: height=4 view=0
[18:07:13] OnPrepareResponseReceived: height=4 view=0 index=38 f9 ~9 Y' J9 m! A) C5 a2 r) A% }* r. A
[18:07:13] OnPrepareResponseReceived: height=4 view=0 index=2
[18:07:13] relay block: 0x5233d9086db97e59f86d73e8735093c1b3fe4569759697ff8a04e0eb8f389091
[18:07:13] persist block: 0x5233d9086db97e59f86d73e8735093c1b3fe4569759697ff8a04e0eb8f389091
[18:07:13] initialize: height=5 view=0 index=0 role=Backup
% I& C1 r: Q8 l& W
提取Neo
原来文章中有提取neo和gas的方法,但是我现在还不知道为什么要提取Neo,有什么意义,先跟着文档跑着看看。我用的window server会遇到crash,详情请看https://github.com/neo-project/neo-gui/issues/171: {1 W4 F: l! N! Q
希望Neo社区的大牛能解决一下这个问题。3 J% r8 r! ` g, [
一天后,社区给出的解决方案https://github.com/neo-project/neo-gui/issues/171,需要下载两个包2 x2 S) ~9 N5 K8 r4 w0 f. I
结论
虽然配置成功了,但是还不知道能干吗,需要进一步研究。提取Neo也遇到崩溃的情况,发现这个问题,也算做贡献了。
成为第一个吐槽的人