搭建以太坊私有链(PoA)--CentOS7.6 on 阿里云ECS、macOS Catalina on Mac、Ubuntu20.04 on Raspberry Pi 4B

搭建以太坊私有链(PoA)

环境说明:

  1. 阿里云ECS上配置了 CentOS 7.6,上面运行了两个 node,其中 node1 用来做 bootnode, 创建一个账户,并分配一定的 ether;node2 创建一个账户,但是没钱。
  2. macOS Catalina 上运行了一个 node,创建一个账号,没钱。
  3. Raspberry Pi 4B model 上运行了 Ubuntu 20.04.1 for ARM64,运行一个nodePi4,创建一个账户,没钱。

1 阿里云ECS上的操作步骤

1.1 准备环境

通过SSH登录到阿里云服务器上,并执行系统更新以及必备软件安装命令

[root@Aliyun ~]# yum update -y && yum install git wget bzip2 vim gcc-c++ ntp epel-release nodejs tree -y

配置CentOS的防火墙,允许 30303、30304、8545、8645 可以被访问。

[root@Aliyun ~]# firewall-cmd --zone=public --add-port=8545/tcp --permanent
[root@Aliyun ~]# firewall-cmd --zone=public --add-port=30303/tcp --permanent
[root@Aliyun ~]# firewall-cmd --zone=public --add-port=8645/tcp --permanent
[root@Aliyun ~]# firewall-cmd --zone=public --add-port=30304/tcp --permanent
[root@Aliyun ~]# firewall-cmd --reload

1.2 安装Geth及Tools

Ethereum 在 这里 提供了针对各种版本的Geth及工具包的可执行文件下载,根据阿里云的服务器配置,选择下图所示的版本。

Geth & Tools for Linux 64bit

复制该版本的下载地址,然后在终端输入以下命令,将压缩包下载到当前路径中。

[root@Aliyun ~]# wget -c https://gethstore.blob.core.windows.net/builds/geth-alltools-linux-amd64-1.9.24-cc05b050.tar.gz ./

解压该压缩包

[root@Aliyun ~]# tar -zxvf geth-alltools-linux-amd64-1.9.24-cc05b050.tar.gz

于是在当前路径下出现了 geth-alltools-linux-amd64-1.9.24-cc05b050 文件夹,进入该文件夹,会看到以下文件。

在这里插入图片描述

将图片中看到的所有绿色的文件依次复制到 /usr/local/bin 目录下,这样可以全局调用,也省得配置环境变量。

[root@Aliyun geth-alltools-linux-amd64-1.9.24-cc05b050]# cp ./abigen /usr/local/bin/abigen
[root@Aliyun geth-alltools-linux-amd64-1.9.24-cc05b050]# cp ./bootnode /usr/local/bin/bootnode
[root@Aliyun geth-alltools-linux-amd64-1.9.24-cc05b050]# cp ./clef /usr/local/bin/clef
[root@Aliyun geth-alltools-linux-amd64-1.9.24-cc05b050]# cp ./evm /usr/local/bin/evm
[root@Aliyun geth-alltools-linux-amd64-1.9.24-cc05b050]# cp ./geth /usr/local/bin/geth
[root@Aliyun geth-alltools-linux-amd64-1.9.24-cc05b050]# cp ./puppeth /usr/local/bin/puppeth
[root@Aliyun geth-alltools-linux-amd64-1.9.24-cc05b050]# cp ./rlpdump /usr/local/bin/rlpdump

然后回到用户目录下,测试 geth 命令是否可用。

[root@Aliyun geth-alltools-linux-amd64-1.9.24-cc05b050]# cd ~
[root@Aliyun ~]# geth version
Geth
Version: 1.9.24-stable
Git Commit: cc05b050df5f88e80bb26aaf6d2f339c49c2d702
Git Commit Date: 20201112
Architecture: amd64
Protocol Versions: [65 64 63]
Go Version: go1.15.5
Operating System: linux
GOPATH=
GOROOT=go

如果看到以上的输出,就表示 Geth 安装成功了。

1.3 创建以太坊私有链的数据文件夹

创建两个node的文件夹

[root@Aliyun ~]# mkdir -p Ursamjnor/node1
[root@Aliyun ~]# mkdir -p Ursamjnor/node2

为 node1 创建账户

[root@Aliyun ~]# cd Ursamjnor
[root@Aliyun Ursamjnor]# geth --datadir node1/ account new

这里执行后会要求我们输入新建账户的密码(两次输入),这里假设我们设定密码是“pwdfornode1”,然后终端会出现我们创建的账户地址,这个地址以及刚才的密码最好存放在文本文件中,便于以后使用。

[root@Aliyun Ursamjnor]# echo "node1的账户地址" >> accounts.txt
[root@Aliyun Ursamjnor]# echo "pwdfornode1" >> node1/password.txt

为 node2 创建账户的操作步骤跟node1的一样

1.4 用puppeth配置以太坊私有链

以下是在终端进行的操作,按照提示输入数字或者信息后完成配置。

[root@Aliyun Ursamjnor]# puppeth
Please specify a network name to administer (no spaces, hyphens or capital letters please)
> ursamjnor
Sweet, you can set this via --network=ursamjnor next time!
INFO [09-17|11:43:03.307] Administering Ethereum network       	name=ursamjnor
WARN [09-17|11:43:03.367] No previous configurations found     	path=/root/.puppeth/ursamjnor
What would you like to do? (default = stats)
 1. Show network stats
 2. Configure new genesis
 3. Track new remote server
 4. Deploy network components
> 2
What would you like to do? (default = create)
 1. Create new genesis from scratch
 2. Import already existing genesis
> 1
Which consensus engine to use? (default = clique)
 1. Ethash - proof-of-work
 2. Clique - proof-of-authority
> 2
How many seconds should blocks take? (default = 15)
> 10
Which accounts are allowed to seal? (mandatory at least one)
> 0x //这里是node1的账户地址
> 0x
Which accounts should be pre-funded? (advisable at least one)
> 0x //再输入一遍node1的账户地址
> 0x
Should the precompile-addresses (0x1 .. 0xff) be pre-funded with 1 wei? (advisable yes)
> yes
Specify your chain/network ID if you want an explicit one (default = random)
> 8848 //这里输入一个大于2018的整数
INFO [09-20|10:07:39.675] Configured new genesis block
What would you like to do? (default = stats)
 1. Show network stats
 2. Manage existing genesis
 3. Track new remote server
 4. Deploy network components
> 2
 1. Modify existing configurations
 2. Export genesis configurations
 3. Remove genesis configuration
> 2
Which folder to save the genesis specs into? (default = current)
  Will create ursamjnor.json, ursamjnor-aleth.json, ursamjnor-harmony.json, ursamjnor-parity.json
>
INFO [09-20|10:07:58.879] Saved native genesis chain spec      	path=ursamjnor.json
ERROR[09-20|10:07:58.879] F

猜你喜欢

转载自blog.csdn.net/ursamjnor/article/details/109709695