系统城装机大师 - 固镇县祥瑞电脑科技销售部宣传站!

当前位置:首页 > server > anz > 详细页面

CentOS 7 部署以太坊私有链 go1.13.2 + go-ethereum1.9.12

时间:2020-03-09来源:电脑系统城作者:电脑系统城

###1.安装基础工具

yum update -y && yum install git bzip2 gcc-c++ ntp epel-release nodejs -y

###2.安装cmake

wget https://cmake.org/files/v3.15/cmake-3.15.2.tar.gz
tar zxvf cmake-3.15.2.tar.gz
mv cmake-3.15.2 /usr/local/
cd /usr/local/cmake-3.15.2
./bootstrap
gmake
gmake install

###3.配置环境变量

echo "export PATH=/usr/local/cmake-3.15.2/bin:$PATH" >> /etc/profile
source /etc/profile
cmake -version

[root@192 ~]# cmake -version
cmake version 3.15.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

###4.安装go语言

wget https://storage.googleapis.com/golang/go1.13.2.linux-amd64.tar.gz
tar -C /usr/local -zxzf go1.13.2.linux-amd64.tar.gz
echo "export GOROOT=/usr/local/go" >> /etc/profile
echo "export PATH=/usr/local/go/bin:$PATH" >> /etc/profile
source /etc/profile

[root@192 ~]# go version
go version go1.13.2 linux/amd64

###5.克隆并编译go-ethereum项目

cd /usr/local
git clone https://github.com/ethereum/go-ethereum.git  
cd go-ethereum/
make all
echo "export PATH=$PATH:/usr/local/go-ethereum/build/bin" >> /etc/profile
source /etc/profile

[root@192 ~]# geth version
Geth
Version: 1.9.12-unstable
Git Commit: 556888c4a971d4fd02be15f09cba7a65c5c0d930
Git Commit Date: 20200303
Architecture: amd64
Protocol Versions: [65 64 63]
Go Version: go1.13.2
Operating System: linux
GOPATH=
GOROOT=/usr/local/go

###6.开启网络时间同步

systemctl enable ntpd 
systemctl start ntpd

###7.创建geth工作目录

mkdir -pv /test/chain
vim /test/genesis.json

[root@192 ~]# cat /test/genesis.json 
{
  "config": {
    "chainId": 666,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0,
    "ethash": {}
  },
  "nonce": "0x0",
  "timestamp": "0x5ddf8f3e",
  "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x47b760",
  "difficulty": "0x00002",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "alloc": {
    "0x1e82968C4624880FD1E8e818421841E6DB8D1Fa4" : {"balance" : "30000000000000000000"}
  },
  "number": "0x0",
  "gasUsed": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}

###8.启动geth命令

[root@localhost test]# geth --port '30303' --datadir "./chain" --nodiscover console 2>>eth_output.log
Welcome to the Geth JavaScript console!

instance: Geth/v1.9.12-unstable-556888c4-20200303/linux-amd64/go1.13.2
coinbase: 0x60b50043de183a439c96891416c003c46623f528
at block: 109 (Mon Mar 09 2020 16:18:37 GMT+0800 (CST))
 datadir: /test/chain
 modules: admin:1.0 debug:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
>

CentOS 7 部署以太坊私有链 go1.13.2 + go-ethereum1.9.12

###9.账户的添加和查看(在启动私有链后的Geth javascript console中操作

> web3.eth.accounts
[]

创建帐户的方式有两种,第一种创建帐户时直接初始化密码

> web3.personal.newAccount("123456")
"0x60b50043de183a439c96891416c003c46623f528"

其中返回的0x60b50043de183a439c96891416c003c46623f528是帐户,123456是帐户的密码

  
  第二种方法是先创建账户,然后输入密码

> web3.personal.newAccount()
Passphrase: 
Repeat passphrase: 
"0xdb66c9c37efabab160f5453d27676e7930153eec"

  
  这时我们再查看帐户,能够看到刚才创建的两个帐户已经存在了

> web3.eth.accounts
["0x60b50043de183a439c96891416c003c46623f528", "0xdb66c9c37efabab160f5453d27676e7930153eec"]  

###10.开始和停止
  执行以下命令:

> miner.start(1)

  
  执行以后,通过刚才查看日志的方法tail -f eth_output.log,能够看到类似下面的日志,说明程序已经在进行.

INFO [03-09|16:18:31.770] 
分享到:

相关信息

  • Nginx主机域名配置实现

    一、配置多个端口访问不同文件 二、配置不同域名访问不同文件 三、配置不同域名访问同个文件...

    2023-03-17

  • Nginx配置-日志格式配置方式

    上线了一个小的预约程序,配置通过Nginx进行访问入口,默认的日志是没有请求时间的,因此需要配置一下,将每一次的请求的访问响应时间记录出来,备查与优化使用....

    2023-03-17

系统教程栏目

栏目热门教程

人气教程排行

站长推荐

热门系统下载