在centos7上搭建以太坊私有链

先总体说一下步骤:

1.操作系统准备

2. golang安装

3.下载以太坊

4. 安装以太坊

5. 创世区块文件的准备

6. 创世区块初始化

7. 以太坊启动

一 操作系统准备

首先确认下linux版本(本人做测试时用的CentOS7.5)

命令:cat /etc/redhat-release

CentOS Linux release 7.5.1804 (Core) 

二 安装golang

1 使用yum命令安装golang语言

命令:yum install golang

三 下载以太坊源码

1:安装wget

命令:yum -y install wget
2:下载以太坊

命令:wget https://github.com/ethereum/go-ethereum/archive/v1.8.13.tar.gz
3:解压

命令:tar -zxvf v1.8.13.tar.gz 

四 安装以太坊

1:进入解压后的目录

cd go-ethereum-1.8.13/
2:编译
make
执行完这个之后geth就会在当前目录/build/bin里面
3:配置环境变量
3.1:vim
输入 rpm -qa|grep vim 命令, 如果 vim 已经正确安装,会返回下面的三行代码

vim-minimal-7.0.109-6.el5

vim-common-7.0.109-7.2.el5

vim-enhanced-7.0.109-7.2.el5

如果少了其中的某一条,比如 vim-enhanced 的,就用命令 yum -y install vim-enhanced 来安装:

yum -y install vim-enhanced

如果上面的三条都沒有返回, 可以直接用 yum -y install vim* 命令

yum -y install vim*

3.2:

sudo vim /etc/profile
export PATH=$PATH:/home/blockchain/eth/go-ethereum-1.8.13/build/bin
source /etc/profile

五. 创世区块文件的准备

1:创建eth-private

mkdir eth-private

2:进入eth-private

cd eth-private

3:创建genesis.json文件,内容如下:

{
"nonce":"0x0000000000000042",
"mixhash":"0x0000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x4000",
"alloc": {
    "b9bdee383b931e48ef941ee58039c474e5fa45f9": { "balance": "500000000000000000000000000" },
    "37b33bee561ae7054b49624b14d374fd0fbc0734": { "balance": "500000000000000000000000000" }
},
"coinbase":"0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x",
"gasLimit":"0x2fefd8",
"config": {
        "chainId": 1888,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
        }
}

 

六. 创世区块初始化

1 执行以下命令以完成创世区块的创建:

[root@localhost bin]# geth  --datadir "/app/chain" init genesis.json

注意:上面命令中–datadir后面的 /app/chain可以任意指定,无需提前创建,但是一定要保证有足够的磁盘空间。init.json是我们在上一步创建的文件,注意文件名要一致。

2 执行完成后,将会出现类似以下信息:

I0927 14:31:07.374864 ethdb/database.go:82] Alloted 16MB cache and 16 file handles to /app/chain/chaindata
I0927 14:31:07.402544 cmd/geth/main.go:299] successfully wrote genesis block and/or chain rule set: 244469eaad4c9c7a245fa4962a6ed7346e9925317f222b580e7f3113f9722657

这样,创世区块就初始化完成了,下面将要进行最后一步,以太坊的启动。

七 以太坊启动

执行的命令是:

[root@localhost bin]# geth --rpc --rpccorsdomain "*" --datadir "/app/chain" --port "30303" --rpcapi "db,eth,net,web3" --networkid 100000 console

注意:上面命令中–datadir 后的”/app/chain”要跟我们上一步的–datadir 参数一致。

执行完此命令后将会出现类似以下信息:

I0927 14:32:17.538013 ethdb/database.go:82] Alloted 128MB cache and 1024 file handles to /app/chain/chaindata
I0927 14:32:17.554665 ethdb/database.go:169] closed db:/app/chain/chaindata
I0927 14:32:17.554722 cmd/utils/flags.go:592] WARNING: No etherbase set and no accounts found as default
I0927 14:32:17.555722 ethdb/database.go:82] Alloted 128MB cache and 1024 file handles to /app/chain/chaindata
I0927 14:32:17.575639 eth/backend.go:621] upgrading db log bloom bins
I0927 14:32:17.575767 eth/backend.go:629] upgrade completed in 138.089µs
I0927 14:32:17.575802 ethdb/database.go:82] Alloted 16MB cache and 16 file handles to /app/chain/dapp
I0927 14:32:17.580530 eth/backend.go:172] Protocol Versions: [63 62], Network Id: 100000
I0927 14:32:17.580584 eth/backend.go:201] Blockchain DB Version: 3
I0927 14:32:17.581103 core/blockchain.go:206] Last header: #0 [244469ea…] TD=0
I0927 14:32:17.581122 core/blockchain.go:207] Last block: #0 [244469ea…] TD=0
I0927 14:32:17.581131 core/blockchain.go:208] Fast block: #0 [244469ea…] TD=0
I0927 14:32:17.582008 p2p/server.go:313] Starting Server
I0927 14:32:19.644094 p2p/discover/udp.go:217] Listening, enode://e1f793e06289097df035e55d68f7667658630b48c1e7fd70b5dee7445db5bec9d808b6f329b774954e7800d3498a2e6307aa989b53a0758eed8f3d7cd5d584e4@[::]:30303
I0927 14:32:19.650870 node/node.go:366] HTTP endpoint opened: http://localhost:8545
I0927 14:32:19.652471 p2p/server.go:556] Listening on [::]:30303
I0927 14:32:19.652892 node/node.go:296] IPC endpoint opened: /app/chain/geth.ipc
Welcome to the Geth JavaScript console!

一直到出现Welcome to the Geth JavaScript console! 句话,并自动进入geth的命令行则说明以太坊私有链安装成功了。

注意:以上命令中 –datadir参数后面的”/app/chain”要和上一步保持一致。

到目前为止,我们的私有链就搭建成功了。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值