CentOS 7 安装以太坊(Etherum)Geth尝试挖矿

本地私有链尝试以太坊挖矿功能

参考

http://blog.csdn.net/xc70203/article/details/77988473

http://blog.csdn.net/wo541075754/article/details/79260040

虚拟机环境

2C4G20G,CentOS Linux release 7.4.1708 (Core)

安装所需基础工具:
yum update -y && yum install git wget bzip2 vim gcc-c++ ntp epel-release nodejs cmake -y
安装Go
wget https://dl.google.com/go/go1.10.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.10.linux-amd64.tar.gz
echo 'export GOROOT=/usr/local/go' >> /etc/profile  
echo 'export PATH=$PATH:$GOROOT/bin' >> /etc/profile  
echo 'export GOPATH=/root/go' >> /etc/profile
echo 'export PATH=$PATH:$GOPATH/bin' >> /etc/profile
source /etc/profile

验证

$ go version
go version go1.10 linux/amd64
克隆编译项目go-ethereum
git clone https://github.com/ethereum/go-ethereum.git  
cd go-ethereum  
make all
在path中加入geth路径
echo 'export PATH=$PATH:/opt/go-ethereum/build/bin' >> /etc/profile
source /etc/profile

验证

$ geth version
Geth
Version: 1.8.2-unstable
Git Commit: bd6879ac518431174a490ba42f7e6e822dcb3ee1
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.10
Operating System: linux
GOPATH=/root/go
GOROOT=/usr/local/go
配置私有链初始状态,新建文件genesis.json
{ 
    "config": {
            "chainId": 22, 
            "homesteadBlock": 0, 
            "eip155Block": 0, 
            "eip158Block": 0 
    },
    "alloc" : {},
    "coinbase" : "0x0000000000000000000000000000000000000000", 
    "difficulty" : "0x400", 
    "extraData" : "", 
    "gasLimit" : "0x2fefd8", 
    "nonce" : "0x0000000000000038", 
    "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000", 
    "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", 
    "timestamp" : "0x00" 
}
初始化区块链,生成创世区块和初始状态
geth --datadir /opt/data init /opt/eth/genesis.json
启动节点,进入Geth的cli界面挖矿
geth --identity "TestNode" --rpc --rpcport "8545" --datadir /opt/data/ --port "30303" --nodiscover console

mine.start()总是null,挖不到,于是清空数据换一种方式启动节点,进入Geth的cli界面并直接开始挖矿

geth --identity "TestNode" --rpc --rpcport "8545" --datadir /opt/data/ --port "30303" --nodiscover --dev --dev.period 1 console

加了两个参数:--dev 表示自动创建一个账户并直接开始挖矿,--dev.period 1表示不用等有交易了才挖,如果设成0的话没有交易挖矿就是null

查看账号
personal.listAccounts
[]
新建账号,密码123456
personal.newAccount(123456)
"0x7d84a2638c9b25a758026446e67c822f34247bd8"
查看cionbase
eth.coinbase
"0x7d84a2638c9b25a758026446e67c822f34247bd8"
查看区块数量
eth.blockNumber
19
查看账号余额
myAddress = "0x7d84a2638c9b25a758026446e67c822f34247bd8"
"0x480086c9411cc3297c4aa6773a2e07c7b1efbafe"
eth.getBalance("0x7d84a2638c9b25a758026446e67c822f34247bd8")
1.15792089237316195423570985008687907853269984665640564039457584007913129639927e+77
换另一个用户挖矿
miner.setEtherbase("0x3e5b31e581546f2900c0f3289153c788c92a2b41")

报错

WARN [03-05|23:08:47] Block sealing failed err="authentication needed: password or unlock"

解锁挖矿用户

personal.unlockAccount(eth.coinbase)

再更换挖矿用户挖,又报错

WARN [03-05|23:18:48] Block sealing failed err=unauthorized

再用谁挖都是null,暂时不试了,再继续深入学习。

要在CentOS 7上安装以太坊,可以按照以下步骤进行操作: 1. 更新系统:使用以下命令更新系统软件包: ``` sudo yum update ``` 2. 安装依赖:以太坊需要一些依赖项,使用以下命令安装它们: ``` sudo yum install -y wget git gcc-c++ make ``` 3. 安装Go语言环境:以太坊使用Go语言编写,需要安装Go语言环境。可以按照以下步骤进行安装: - 前往Go语言官方网站(https://golang.org/dl/)下载适合你的操作系统的Go语言二进制文件。 - 使用以下命令下载并解压Go语言二进制文件: ``` wget https://dl.google.com/go/goX.X.X.linux-amd64.tar.gz sudo tar -C /usr/local -xzf goX.X.X.linux-amd64.tar.gz ``` - 添加Go语言到系统环境变量,打开`/etc/profile`文件并添加以下内容: ``` export PATH=$PATH:/usr/local/go/bin ``` - 执行以下命令使配置生效: ``` source /etc/profile ``` 4. 克隆以太坊源代码:使用以下命令克隆以太坊源代码: ``` git clone https://github.com/ethereum/go-ethereum.git ``` 5. 编译以太坊:进入`go-ethereum`目录,并使用以下命令编译以太坊: ``` cd go-ethereum make geth ``` 6. 安装以太坊客户端:使用以下命令将以太坊客户端安装到系统路径下: ``` sudo cp build/bin/geth /usr/local/bin/ ``` 现在,以太坊已经成功安装CentOS 7上。你可以使用`geth`命令来启动以太坊客户端,并进行相关的操作。请注意,安装过程可能需要一些时间,取决于你的系统和网络速度。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值