Skip to content

Commit

Permalink
添加文档“搭建私有链的简易方法” (neo-project#607)
Browse files Browse the repository at this point in the history
* 添加文档“搭建私有链的简易方法”

* Update private-chain2.md
  • Loading branch information
陈志同 authored Sep 5, 2018
1 parent fa31ed0 commit 5c3ed98
Show file tree
Hide file tree
Showing 4 changed files with 255 additions and 14 deletions.
Binary file added assets/privatechain_demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
# 用 NEO 节点搭建私有链

阅读完 [NEO 节点的安装部署](../node/cli/setup.md) 后,我们已经可以在 Windows 和 Linux 上部署 NEO 节点了,本篇教程会教你如何用 NEO 节点搭建私有链,并且如何从自己的私有链中提取 NEO 和 NeoGas。
阅读完 [NEO 节点的安装部署](../../node/cli/setup.md) 后,我们已经可以在 Windows 和 Linux 上部署 NEO 节点了,本篇教程会教你如何用 NEO 节点搭建私有链,并且如何从自己的私有链中提取 NEO 和 NeoGas。

NEO 私有链的部署至少需要 4 台服务器才能取得共识,每台服务器对应一个共识节点,每台服务器上有一个 NEO 钱包文件。

## 1、配置虚拟机

NEO 私有链的部署至少需要 4 台服务器才能取得共识,每台服务器对应一个共识节点。为了演示,我在 Azure 上创建了 4 台 Windows 虚拟机,大小为 Standard DS1 v2 (1 核心,3.5 GB 内存),你也可以在局域网中或虚拟机中部署私有链。

![](assets/privatechain_1.jpg)
![](../assets/privatechain_1.jpg)

创建好后,要开通 10331-10334 端口,具体方法为在系统的 `防火墙` `高级设置` `入站规则` 中新建规则,然后添加端口 10331-10334。

> [!Note]
> 如果你在云服务器上创建的虚拟机,还要登录虚拟机的管理后台,设置网络安全组
>
> Azure 上的设置方法为:`网络接口` `网络安全组` `入站安全规则` `添加` 添加端口 10331-10334。
> Azure 上的设置方法为:`网络` `入站端口规则` 添加端口 10331-10334。
创建好虚拟机后,将四台虚拟机的 IP 地址保存下来以备后用。

## 2、安装 NEO 节点

NEO 节点的安装过程上文已经详细介绍过了,安装过程请参考 [NEO 节点的安装部署](../node/cli/setup.md)
NEO 节点的安装过程上文已经详细介绍过了,安装过程请参考 [NEO 节点的安装部署](../../node/cli/setup.md)

## 3、创建钱包

我们首先创建 4 个钱包文件,依次为 wallet1.db3 - wallet4.db3,这一步在 PC 版钱包和命令行钱包都可以创建,下图是在命令行客户端创建钱包文件的截图。

![](assets/privatechain_3.jpg)

创建好钱包后将 4 个钱包的公钥保存下来(保存到一个 txt 文件中即可)以备后用。直接复制上面的公钥或者用 [CLI 命令](../node/cli/cli.md) 中的 ` list key` 命令查看公钥再复制均可。
创建好钱包后将 4 个钱包的公钥保存下来(保存到一个 txt 文件中即可)以备后用。直接复制上面的公钥或者用 [CLI 命令](../../node/cli/cli.md) 中的 ` list key` 命令查看公钥再复制均可。

然后将 4 个钱包分别复制到 4 个虚拟机的节点目录下。

Expand Down Expand Up @@ -81,7 +81,7 @@ SystemFee 是系统手续费,目前手续费如下(单位为 GAS):

最后将修改过的 protocol.json 复制到 4 个节点的客户端目录下,替换之前的 protocol.json 的文件。

然后在 4 台虚拟机上依次输入以下命令启动节点,打开钱包,开启共识。不记得命令的请参考 [CLI 命令参考](../node/cli/cli.md)
然后在 4 台虚拟机上依次输入以下命令启动节点,打开钱包,开启共识。不记得命令的请参考 [CLI 命令参考](../../node/cli/cli.md)

启动节点:

Expand All @@ -97,11 +97,11 @@ SystemFee 是系统手续费,目前手续费如下(单位为 GAS):

如果上述操作成功,可以运行show state来查看节点状态。若高度发生变化,则说明共识过程正常。4个节点的共识过程如图所示

![](../../assets/privatechain_8.png)
![](../../../assets/privatechain_8.png)

4 个节点即使关掉一台依然可以达成共识,如图所示

![](../../assets/privatechain_9.png)
![](../../../assets/privatechain_9.png)



Expand All @@ -113,11 +113,11 @@ SystemFee 是系统手续费,目前手续费如下(单位为 GAS):

在 PC 版客户端中打开钱包 wallet1.db3,添加多方签名地址,输入 protocol.json 中的 4 个公钥,设置最小签名数量为 3(共识节点数量 / 2 + 1),如图所示。

![](assets/privatechain_12.jpg)
![](../assets/privatechain_12.jpg)

确定,然后需要重建钱包索引,在菜单栏中点击 `钱包` `重建钱包索引` 然后你就会看到在合约地址中有 1 亿的 NEO 了。

![](assets/privatechain_14.jpg)
![](../assets/privatechain_14.jpg)

> [!Note]
> 4 个钱包都要执行这个操作:添加多方签名地址,重建钱包索引
Expand All @@ -126,14 +126,14 @@ SystemFee 是系统手续费,目前手续费如下(单位为 GAS):

然后系统会提示“交易构造完成,但没有足够的签名”,然后将代码复制下来,打开第二个钱包,点击 `交易` `签名` 粘贴刚才复制的代码,点击 `签名`, 然后将代码复制下来,打开第三个钱包,点击 `交易` `签名` 粘贴刚才复制的代码,点击 `签名`, 这时你会发现窗口中出现了一个 `广播` 按钮,代表交易已经签名完成(达到多方签名合约要求的最少签名数量)可以广播,点击 `广播` 后转账交易开始广播,约 15 秒后转账成功。

![](assets/privatechain_20.jpg)
![](../assets/privatechain_20.jpg)

提取 NeoGas 的操作方法也类似,点击 `高级` `提取 NeoGas` `提取` ,(记得这时所在的钱包 X,下文会用到),如图所示

![](assets/privatechain_21.jpg)
![](../assets/privatechain_21.jpg)

接下来的操作与转账 NEO 类似,将没有足够的签名的代码复制下来,打开第二个钱包,点击 `交易` `签名` 粘贴刚才复制的代码,点击 `签名`, 然后将代码复制下来,打开第三个钱包,点击 `交易` `签名` 粘贴刚才复制的代码,点击 `签名`,点击 `广播` 后提取 NeoGas 的交易开始广播,约 15 秒后提取成功。

提取成功后 NeoGas 会进入到你发起提取 NeoGas 的交易所在的钱包(即上方的 X 钱包)的第一个标准地址,如图所示

![](assets/privatechain_26.jpg)
![](../assets/privatechain_26.jpg)
237 changes: 237 additions & 0 deletions zh-cn/network/private-chain/private-chain2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
# 搭建私有链的简易方法

上篇文章介绍了标准的搭建私有链的方法,需要 4 台电脑或虚拟机,在 Windows 上可以用更简单的方式搭建私有链。

## 1、安装节点

首先安装 neo-cli,并将其复制 4 份,文件夹名分别命名为 node1、node2、node3、node4。

安装过程请参考 [NEO 节点的安装部署](../../node/cli/setup.md)

## 2、创建钱包文件

创建 4 个不同的钱包文件,命名为 1.json、2.json、3.json、4.json,分别放置于 4 个节点的文件夹中。

可以使用 neo-cli 或者 neo-gui 创建,具体方法可参照 neo-cli 或 neo-gui 的文档。

## 3、修改 config.json

修改每个节点下的 config.json,修改其端口,使每个端口不重复且不被其它程序占用。

修改 UnlockWallet 下面的 Path 为钱包路径,Password 为钱包密码,StartConsensus 和 IsActive 设置为 true。

可参照下面的配置:

**node1/config.json**

```json
{
"ApplicationConfiguration": {
"Paths": {
"Chain": "Chain_{0}",
"ApplicationLogs": "ApplicationLogs_{0}"
},
"P2P": {
"Port": 10001,
"WsPort": 10002
},
"RPC": {
"Port": 10003,
"SslCert": "",
"SslCertPassword": ""
},
"UnlockWallet": {
"Path": "1.json",
"Password": "11111111",
"StartConsensus": true,
"IsActive": true
}
}
}
```

**node2/config.json**

```json
{
"ApplicationConfiguration": {
"Paths": {
"Chain": "Chain_{0}",
"ApplicationLogs": "ApplicationLogs_{0}"
},
"P2P": {
"Port": 20001,
"WsPort": 20002
},
"RPC": {
"Port": 20003,
"SslCert": "",
"SslCertPassword": ""
},
"UnlockWallet": {
"Path": "2.json",
"Password": "11111111",
"StartConsensus": true,
"IsActive": true
}
}
}
```

**node3/config.json**

```json
{
"ApplicationConfiguration": {
"Paths": {
"Chain": "Chain_{0}",
"ApplicationLogs": "ApplicationLogs_{0}"
},
"P2P": {
"Port": 30001,
"WsPort": 30002
},
"RPC": {
"Port": 30003,
"SslCert": "",
"SslCertPassword": ""
},
"UnlockWallet": {
"Path": "3.json",
"Password": "11111111",
"StartConsensus": true,
"IsActive": true
}
}
}
```

**node4/config.json**

```json
{
"ApplicationConfiguration": {
"Paths": {
"Chain": "Chain_{0}",
"ApplicationLogs": "ApplicationLogs_{0}"
},
"P2P": {
"Port": 40001,
"WsPort": 40002
},
"RPC": {
"Port": 40003,
"SslCert": "",
"SslCertPassword": ""
},
"UnlockWallet": {
"Path": "4.json",
"Password": "11111111",
"StartConsensus": true,
"IsActive": true
}
}
}
```

## 4、修改 protocal.json

修改每个节点下的 protocal.json 并保持所有节点的 protocal.json 一致。

修改说明:

Magic 表示私有链的 ID,可以修改为 [0 - 4294967295] 区间内的任意整数。

StandbyValidators 表示备用共识节点的公钥,这里输入 4 个钱包的公钥

SeedList 表示种子节点的 IP 地址和端口号,IP 地址输入 localhost,端口为 config.json 中配置的 4 个 P2P Port

可参照下面的配置:

```json
{
"ProtocolConfiguration": {
"Magic": 123456,
"AddressVersion": 23,
"SecondsPerBlock": 15,
"StandbyValidators": [
"037ebe29fff57d8c177870e9d9eecb046b27fc290ccbac88a0e3da8bac5daa630d",
"03b34a4be80db4a38f62bb41d63f9b1cb664e5e0416c1ac39db605a8e30ef270cc",
"03cc384ca982168bf6f08922d27c8acc4357d52a7e8ad8281d4af6683e6f63e94d",
"03da4ed85a991134bf45592a5b04d6d71399f23a85843f43e6ac1a5d30f5473711"
],
"SeedList": [
"localhost:10001",
"localhost:20001",
"localhost:30001",
"localhost:40001"
],
"SystemFee": {
"EnrollmentTransaction": 10,
"IssueTransaction": 5,
"PublishTransaction": 5,
"RegisterTransaction": 100
}
}
}
```

## 5、创建快捷启动

为了方便启动,首先创建一个记事本文件,输入 `dotnet neo-cli.dll /rpc` 然后重命名为 1Run.cmd,然后将其复制到 4 个节点下。

到此,私有链已经搭建完成了,所有修改过的文件结构如下

```
├─node1
│ 1.json
│ 1Run.cmd
│ config.json
│ protocol.json
├─node2
│ 1Run.cmd
│ 2.json
│ config.json
│ protocol.json
├─node3
│ 1Run.cmd
│ 3.json
│ config.json
│ protocol.json
└─node4
1Run.cmd
4.json
config.json
protocol.json
```

## 6、启动私有链

进入 node1 目录,双击 `1Run.cmd`

进入 node2 目录,双击 `1Run.cmd`

进入 node3 目录,双击 `1Run.cmd`

进入 node4 目录,双击 `1Run.cmd`

如图所示:

![](../../../assets/privatechain_demo.png)

## 7、停止私有链

在任务栏中右击 `命令提示符`,点击 `关闭所有窗口`

## 8、提取私有链中的 NEO/GAS

参照 [提取 NEO、NeoGas](../private-chain.md#5提取-neoneogas)



最后:

[https://github.com/chenzhitong/NEO-Private-Net](https://github.com/chenzhitong/NEO-Private-Net) 这个项目中是已经配置好的私有链,已提取了 NEO 和 GAS,节点版本为 2.8.0,可以下载后直接使用。
6 changes: 5 additions & 1 deletion zh-cn/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@
- name: 测试网
href: network/testnet.md
- name: 搭建私有链
href: network/private-chain.md
items:
- name: 搭建私有链
href: network/private-chain/private-chain.md
- name: 搭建私有链(简易方法)
href: network/private-chain/private-chain2.md
- name: 快速同步区块
href: network/syncblocks.md
- name: 网络协议
Expand Down

0 comments on commit 5c3ed98

Please sign in to comment.