阿里云上的虚拟机玩转Neo私链
李悔之2015
发表于 2022-12-18 07:08:21
183
0
0
NEO 私有链的部署至少需要 4 台服务器才能取得共识,每台服务器对应一个共识节点。在阿里云上可以买按量付费的虚拟机(机器都是window server)。$ Q6 t1 n* m2 B& H! o
记录下四台机器的内网IP地址,后面要用。
172.xxx.xxx.142
端口
如果你想让外部程序访问该节点的 API 需要开放防火墙端口:10331-10334, 20331-20334. i9 I# A7 x- D; s( j
阿里云的vpc如果在一个安全组内就不需要设置。也可以通过安全组开放所有入口。
阿里云安全组2 k: M, J' p3 S" i! g/ o
安装运行时 N4 f3 Z& s# [
运行环境
运行 NEO 节点需要安装 .NET Core Runtime,需要安装 1.0.1 或以上版本
Windows 系统下的安装方法
: N& n% N4 T. R& V: m) T& Z
在 Windows 系统下安装 .NET Core 非常方便,直接下载运行即可。2 R4 R0 G% Q: C7 z8 e0 I
NOTE$ O& o8 b9 u$ P L9 K
Windows可能还需要安装Microsoft Visual C++ 2015 Redistributable Update 3(https://www.microsoft.com/en-us/download/details.aspx?id=53840) ,否则后面无法启动Neo-CLI。
创建钱包
在四台机器上分别创建钱包数据库,数据库文件会默认生成在neo-cli的目录下面) ~; w, q3 e; }! U- \
create wallet wallet.json9 j8 d8 {: i; C* W, T
db3后缀名的数据库文件不支持了, m( |% o E- V* q. ? A
neo1
neo> create wallet wallet.db3* r; I. L/ H. V2 ]
Wallet files in db3 format are not supported, please use a .json file extension.$ j G5 s1 D G& E( L" M- t- s
neo> create wallet wallet.json
password: ********
password: ********
address: AS43TUy7VtuGpNJh2YC2NM3asTv3s6piyk/ C! T% ~3 w, N6 q( I" R
pubkey: 02d57c9bbc42b45943867dff0180cb9df266b46db7d027a283eabc7c4b8819c86c0 h) F+ t/ s" u1 Z: G; H: j' P5 w
记录下另外几台机器的钱包公钥; x; }) {% Q, d* S: Q$ d
neo2
address: AY35ZjJayg9JfmCeHg1nySN4LSMntFEq2h! A) g0 h0 I+ Z$ U# c ~. p* K
pubkey: 035022ce81faca930ebe6b9f8e830526150e47692f19f58affe1311e42cd0d43bb
neo3
address: AQZNtdGVXbfot5fSaR4ijBqrEwbnFQspmH
pubkey: 029f21d56f9422e55f0ef7cf75c092854e01c99aeee73f0effeaa489a96fc7d2b1
neo4
address: AXctyT8ctWTXtWaUFM9o5FJas8BWdBbiqe
pubkey: 02dc0e750e21c386537618079d89836eea39fad396206e2e56cfba16bdc014dc5d
修改节点的配置文件
{* V. ]% O' p5 P m9 O& Z. T4 r# Y
"ProtocolConfiguration": {
"Magic": 1,
"AddressVersion": 23,
"StandbyValidators": [7 m# L) ^* g" b$ I5 q$ l
"02d57c9bbc42b45943867dff0180cb9df266b46db7d027a283eabc7c4b8819c86c",
"035022ce81faca930ebe6b9f8e830526150e47692f19f58affe1311e42cd0d43bb",6 s8 B( u) B8 g9 i" e: [2 m
"029f21d56f9422e55f0ef7cf75c092854e01c99aeee73f0effeaa489a96fc7d2b1",
"02dc0e750e21c386537618079d89836eea39fad396206e2e56cfba16bdc014dc5d"
],
"SeedList": [ Q( E( D- u! z% w1 \- x9 {4 X
"172.24.198.142:10333",* ?/ ?8 }3 Q. u
"172.24.198.141:10333",
"172.24.198.140:10333",
"172.24.198.139:10333"
],
"SystemFee": {
"EnrollmentTransaction": 0,
"IssueTransaction": 0,( e6 B; P) n2 H1 }: b7 q' q
"PublishTransaction": 0,3 I+ b# g S7 e. d
"RegisterTransaction": 0
}" `0 g6 a. I9 v# \ C
}
}
打开钱包,开启共识: M G+ j) v0 |; h9 ~# w$ f
open wallet wallet.json start consensus% L2 G! A" [& B) g
如果前面打开过cli,请删除chain目录下的文件,这样区块链高度会从1开始。
截取其中一个打印,后面方便调试的时候研究+ V9 I. u' Y9 y
neo> open wallet wallet.json
password: ********
neo> start consensus
[18:04:31] OnStart
[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=Backup2 e1 _; c$ I# t: P" S2 A! W
[18:05:01] request change view: height=1 view=0 nv=1 state=Backup, ViewChanging
[18:05:58] OnPrepareRequestReceived: height=1 view=0 index=1 tx=1
[18:05:58] send perpare response* f( w* O0 h8 i& B! u
[18:06:01] OnPrepareResponseReceived: height=1 view=0 index=2: R0 g, K. V: O1 w1 I
[18:06:01] relay block: 0x8515184285fa2e454b0eca441580b5cce01cc0e5cb5dd6d7ff53ef13ec7f665e E4 a+ Z) y+ m. ?1 x
[18:06:01] persist block: 0x8515184285fa2e454b0eca441580b5cce01cc0e5cb5dd6d7ff53ef13ec7f665e
[18:06:01] initialize: height=2 view=0 index=0 role=Backup
[18:06:16] OnPrepareRequestReceived: height=2 view=0 index=2 tx=1, g% t7 F/ e1 ?2 R s8 d8 U
[18:06:16] send perpare response
[18:06:19] OnPrepareResponseReceived: height=2 view=0 index=16 u8 w t1 C0 ?% |0 D/ b
[18:06:19] relay block: 0x35b163f4f524a1ebcc1ef3053e878f9bb37b1f4a8531a060ef18cfd6efefdf45
[18:06:19] persist block: 0x35b163f4f524a1ebcc1ef3053e878f9bb37b1f4a8531a060ef18cfd6efefdf45, X* E4 y5 Y* u9 V3 u4 j5 ]) V
[18:06:19] initialize: height=3 view=0 index=0 role=Backup1 @; W0 P* T+ A* h) c7 \) P7 i
[18:06:49] timeout: height=3 view=0 state=Backup& @ ?- y7 e; l8 x5 b" y$ W
[18:06:49] request change view: height=3 view=0 nv=1 state=Backup, ViewChanging( e) l+ N; J& q1 t2 s P9 B
[18:06:49] OnChangeViewReceived: height=3 view=0 index=1 nv=13 d' R0 Y" D; L3 U$ a. s* [
[18:06:53] OnChangeViewReceived: height=3 view=0 index=2 nv=1
[18:06:53] initialize: height=3 view=1 index=0 role=Backup. [! d6 D% K" ~4 Z7 p9 c) y
[18:06:55] OnPrepareRequestReceived: height=3 view=1 index=2 tx=1
[18:06:55] send perpare response* y. Q3 S/ w7 S2 U+ c# D8 o5 D
[18:06:55] OnPrepareResponseReceived: height=3 view=1 index=11 N( l& c; ~' x7 K" x2 z6 O
[18:06:55] relay block: 0x1766a0602903f513f76561c93fddf312f70d30801310abfecacc89feace5c412: l! H2 d v8 ] B7 _* P6 A) u6 o
[18:06:55] persist block: 0x1766a0602903f513f76561c93fddf312f70d30801310abfecacc89feace5c4128 ?: P! N6 T4 p$ r: ]
[18:06:55] initialize: height=4 view=0 index=0 role=Primary. s8 }, e+ @; R& `0 \
[18:07:10] timeout: height=4 view=0 state=Primary% i9 V4 q2 t1 E/ d$ B4 G) P n) r
[18:07:10] send perpare request: height=4 view=0: q& J1 U+ E: n- _6 \7 {. N
[18:07:13] OnPrepareResponseReceived: height=4 view=0 index=33 j: f) }% L' R0 Z, _ k) A( [
[18:07:13] OnPrepareResponseReceived: height=4 view=0 index=2' h5 _- p. X# x3 S) R" \
[18:07:13] relay block: 0x5233d9086db97e59f86d73e8735093c1b3fe4569759697ff8a04e0eb8f389091
[18:07:13] persist block: 0x5233d9086db97e59f86d73e8735093c1b3fe4569759697ff8a04e0eb8f3890910 Y" W: Z, A& B, `
[18:07:13] initialize: height=5 view=0 index=0 role=Backup
, A5 d% R- k* N0 ~ {
# S! H k3 E4 i# u
提取Neo, S1 g& C# p2 {0 l5 Y; q) p8 D
原来文章中有提取neo和gas的方法,但是我现在还不知道为什么要提取Neo,有什么意义,先跟着文档跑着看看。我用的window server会遇到crash,详情请看https://github.com/neo-project/neo-gui/issues/171
希望Neo社区的大牛能解决一下这个问题。
一天后,社区给出的解决方案https://github.com/neo-project/neo-gui/issues/171,需要下载两个包
结论, f# o3 ?) r- R2 m
虽然配置成功了,但是还不知道能干吗,需要进一步研究。提取Neo也遇到崩溃的情况,发现这个问题,也算做贡献了。
成为第一个吐槽的人