linux centos7 ETH私服搭建 源码编译方式

linux centos7 ETH私服搭建 源码编译方式

1、安装所需基础工具

其中git cmake nodejs gcc-c++是必须的.

yum install git
yum install wget
yum install bzip2 
yum install vim
yum install gcc-c++
yum install nodejs
yum install cmake 

2、安装Go

我的下的GO版本为1.13 ,其他版本可能有问题.

wget https://dl.google.com/go/go1.13.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.13.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.13 linux/amd64

3、克隆编译项目go-ethereum

当make all 时可能会报错,一定要注意版本 。go语言版本必须1.10以上,最好是1.13版本的

cd /usr/local
git clone https://github.com/ethereum/go-ethereum.git
cd go-ethereum
make geth

在path中加入geth路径

echo 'export PATH=$PATH:/usr/local/go-ethereum/build/bin' >> /etc/profile
source /etc/profile

验证

geth version
INFO [08-16|10:12:12.117] Bumping default cache on mainnet         provided=1024 updated=4096
Geth
Version: 1.9.10-unstable
Git Commit: 0218d7001d2a566b35072ee21b9f84f6b2711bbe
Git Commit Date: 20200108
Architecture: amd64
Protocol Versions: [64 63]
Go Version: go1.13
Operating System: linux
GOPATH=/home/go
GOROOT=/usr/local/go

此时已经安装成功

4、同步以太坊区块(私有链和公链)

说明私有链属于测试网络,没有与ETH网络连通
公链是属于正式网络,同步需要一定的时间。

一.创建(私有链)
1.创建密码 
mkdir /eth/app1
cd /eth/app1
vim /eth/app1/pass.txt
  输入password
保存
2.创建账号
geth --datadir=/eth/app1/node --password /eth/app1/pass.txt account new > /eth/app1/account.txt

3.配置genesis.json 
vim /eth/app1/genesis.json
	{ "config": { "chainId": 520, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0 }, "alloc" : {"主机账号(就是填写上面 account.txt 中的账号并且最前面要加上0x)":{"balance": "0x700000000000000000"}}, "coinbase" : "矿机账号(可以任意填)", "difficulty" : "0x400", "extraData" : "", "gasLimit" : "0x2fefd8", "nonce" : "0x0000000000000038", "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000", "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", "timestamp" : "0x00" }
保存

4.初始化传世块
geth --datadir "/eth/app1/node" init /opt/eth/app1/genesis.json

5.公开访问模式
vim /eth/app1/start.sh
	nohup geth  --networkid 520 --syncmode fast  --cache=4096 --datadir /eth/app/node --rpc --rpcapi "db,eth,net,web3,personal,admin,miner --rpcport 8546 --port 30303 --rpcaddr "0.0.0.0" --ipcpath /eth/app/node/geth.ipc  > output.log 2>&1 &
保存

6.赋权限
chmod 700 /eth/app1/start.sh
7.运行
./eth/app1/start.sh



----------------------------.同步公链
nohup geth --syncmode fast --datadir /eth/app/node --rpc --rpcapi db,eth,net,web3,personal,admin,miner --rpcport 8545 --port 30303 --rpcaddr 0.0.0.0  --ipcpath /eth/app/node/geth.ipc > output.log 2>&1 &

5、进入geth控制台 (连接eth)

geth attach ipc:/eth/app/node/geth.ipc
注意: 需要开启 上面配置的(854530303)两个端口

6、查看区块同步进度

> eth.syncing
{
  currentBlock: 4374446
  highestBlock: 4374446
  knownState: 1444
  pulledState: 1443
  startingBlock: 4374446
}

如果eth.syncing 一直为false, 说明没有同步成功! 检查一下之前的步骤是否有误。

7、创建账户

其中password为密码,任意改

personal.newAccount('password')
"0x1437ed0a0cc73d3eba2d7fe2008d3cd960afadeb"

8、查看账户余额

 eth.getBalance('0x1437ed0a0cc73d3eba2d7fe2008d3cd960afadeb')

常见问题

1. Error: authentication needed: password or unlock undefined

WARN [01-12|18:33:38.691] Served eth_signTransaction               conn=82.196.0.91:59925    reqid=462 t=18.504µs     err="authentication needed: password or unlock"
WARN [01-12|18:33:38.691] Served eth_signTransaction               conn=82.196.0.91:59925    reqid=463 t=15.55µs      err="authentication needed: password or unlock"
WARN [01-12|18:33:38.692] Served eth_signTransaction               conn=82.196.0.91:59925    reqid=464 t=644.396µs    err="authentication needed: password or unlock"
WARN [01-12|18:33:38.692] Served eth_signTransaction               conn=82.196.0.91:59925    reqid=465 t=15.168µs     err="authentication needed: password or unlock"
WARN [01-12|18:33:38.692] Served eth_signTransaction               conn=82.196.0.91:59925    reqid=466 t=13.143µs     err="authentication needed: password or unlock"
WARN [01-12|18:33:38.692] Served eth_signTransaction               conn=82.196.0.91:59925    reqid=467 t=14.242µs     err="authentication needed: password or unlock"

出现这样问题是因为:账户没有解锁,部署智能合约之前首先要给账户解锁。
解决方法

首先停止挖矿

>miner.stop()
true
检查挖矿是否已经停止,eth.mining 输出为false时表示挖矿已经停止
> eth.mining
false

查看当前用户

>eth.accounts

给用户解锁,这里是给第一个账户解锁

>user1=eth.accounts[0]

>personal.unlockAccount(user1)

重新部署智能合约,不会报错

解锁之后一直启动挖矿

>miner.start()

2.geth客户端:unlock with HTTP access is forbidden错误分析

解决方法
如果已经了解打开此功能的风险,可通启动命令中添加参数:
--allow-insecure-unlock

未经本人允许,禁止转载。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值