安装Golang
可以直接使用 yum 这个包管理器安装Golang
yum install golang
下载以太坊源码(Go Ethereum)
首先下载geth源码go-ethereum,这里以 go-ethereum-1.10.3.tar.gz 为例:
https://github.com/ethereum/go-ethereum/archive/refs/tags/v1.10.3.tar.gz
安装以太坊源码(安装Geth)
接下来解压缩源码:
tar -xzf go-ethereum-1.9.7.tar.gz
用下面的命令编译:
cd go-ethereum-1.9.7
make geth
[code]
make geth 也可以用make all 进行替代,make all 还会编译一些其他的程序套件
如果国内用户安装超时,可设置代理,再进行安装。
[code]
go env -w GOPROXY=https://goproxy.cn
编译完成后,此时会在 go-ethereum-1.9.7/build/bin 中生成geth可执行文件。
输入 geth help 命令,会显示geth所有的命令和选项:
cd build/bin
./geth help
配置geth
直接使用geth命令可能出现:
-bash: geth: command not found
解决方法一:可以为其的安装路径建立软连接
ln -s /data/go-ethereum-1.9.7/build/bin/geth /usr/local/bin/geth
解决方法二:也可以为其创建全局配置(对所有系统用户生效,永久生效,推荐)
通过vim 打开编辑器
vim /etc/profile
在最后一行追加以下内容:
export PATH=$PATH:/data/go-ethereum-1.9.7/build/bin/
然后让配置立即生效:
source /etc/profile
用 geth version 测试一下:
geth version
同步的几种方式
Full同步
geth --syncmode "full"
获取区块的header
获取区块的body
从创始块开始校验没一个元素
PS:下载所有区块数据信息
Fast同步
geth --syncmode "fast"
获取区块的header
获取区块的body
在同步到当前块之前不处理任何事务,然后获得一个快照,像full节点一样进行后面的同步操作。沿着区块下载最近数据库中的交易,有可能丢失历史数据。比如,你的账户地址A上面有10个ETH,但转入的的交易存在于较老的历史交易中,此同步模式无法获取到交易的详细情况。
使用此模式时注意需要设置–cache,默认16M,建议设置为1G(1024)到2G(2048)。
Ligth同步
geth --syncmode "light"
仅获取当前状态。验证元素需要向full节点发起相应的请求。
开启本地RPC端口
# light模式同步区块并开启RCP:rpcaddr:rpcport
geth --rpc --rpcaddr localhost --rpcport "8545" --syncmode "light"
获取与RCP相关的命令
geth --help | grep rpc
--rpc Enable the HTTP-RPC server
--rpcaddr "127.0.0.1" HTTP-RPC server listening interface
--rpcport "8545" HTTP-RPC server listening port
--rpcapi "db,eth,net,web3" API's offered over the HTTP-RPC interface
--rpccorsdomain Domains from which to accept cross origin requests (browser enforced)
geth –cache=2048 –goerli –rpc –rpcaddr 0.0.0.0 –rpcport=8545 –rpcvhosts=* –rpcapi=’eth,net,rpc’
启动geth开始后台同步区块
nohup geth --rpc --rpcapi web3,eth,net,db,personal --rpcaddr 0.0.0.0 --rpcport 8545 &
进入geth控制台
# geth attach rpc:http://127.0.0.1:8545
查看区块同步情况
> eth.syncing
{
currentBlock: 513872,
highestBlock: 8985345,
knownStates: 806036,
pulledStates: 794270,
startingBlock: 0
}
可以直接使用 yum 这个包管理器安装Golang
yum install golang
下载以太坊源码(Go Ethereum)
首先下载geth源码go-ethereum,这里以 go-ethereum-1.10.3.tar.gz 为例:
https://github.com/ethereum/go-ethereum/archive/refs/tags/v1.10.3.tar.gz
安装以太坊源码(安装Geth)
接下来解压缩源码:
tar -xzf go-ethereum-1.9.7.tar.gz
用下面的命令编译:
cd go-ethereum-1.9.7
make geth
[code]
make geth 也可以用make all 进行替代,make all 还会编译一些其他的程序套件
如果国内用户安装超时,可设置代理,再进行安装。
[code]
go env -w GOPROXY=https://goproxy.cn
编译完成后,此时会在 go-ethereum-1.9.7/build/bin 中生成geth可执行文件。
输入 geth help 命令,会显示geth所有的命令和选项:
cd build/bin
./geth help
配置geth
直接使用geth命令可能出现:
-bash: geth: command not found
解决方法一:可以为其的安装路径建立软连接
ln -s /data/go-ethereum-1.9.7/build/bin/geth /usr/local/bin/geth
解决方法二:也可以为其创建全局配置(对所有系统用户生效,永久生效,推荐)
通过vim 打开编辑器
vim /etc/profile
在最后一行追加以下内容:
export PATH=$PATH:/data/go-ethereum-1.9.7/build/bin/
然后让配置立即生效:
source /etc/profile
用 geth version 测试一下:
geth version
同步的几种方式
Full同步
geth --syncmode "full"
获取区块的header
获取区块的body
从创始块开始校验没一个元素
PS:下载所有区块数据信息
Fast同步
geth --syncmode "fast"
获取区块的header
获取区块的body
在同步到当前块之前不处理任何事务,然后获得一个快照,像full节点一样进行后面的同步操作。沿着区块下载最近数据库中的交易,有可能丢失历史数据。比如,你的账户地址A上面有10个ETH,但转入的的交易存在于较老的历史交易中,此同步模式无法获取到交易的详细情况。
使用此模式时注意需要设置–cache,默认16M,建议设置为1G(1024)到2G(2048)。
Ligth同步
geth --syncmode "light"
仅获取当前状态。验证元素需要向full节点发起相应的请求。
开启本地RPC端口
# light模式同步区块并开启RCP:rpcaddr:rpcport
geth --rpc --rpcaddr localhost --rpcport "8545" --syncmode "light"
获取与RCP相关的命令
geth --help | grep rpc
--rpc Enable the HTTP-RPC server
--rpcaddr "127.0.0.1" HTTP-RPC server listening interface
--rpcport "8545" HTTP-RPC server listening port
--rpcapi "db,eth,net,web3" API's offered over the HTTP-RPC interface
--rpccorsdomain Domains from which to accept cross origin requests (browser enforced)
geth –cache=2048 –goerli –rpc –rpcaddr 0.0.0.0 –rpcport=8545 –rpcvhosts=* –rpcapi=’eth,net,rpc’
启动geth开始后台同步区块
nohup geth --rpc --rpcapi web3,eth,net,db,personal --rpcaddr 0.0.0.0 --rpcport 8545 &
进入geth控制台
# geth attach rpc:http://127.0.0.1:8545
查看区块同步情况
> eth.syncing
{
currentBlock: 513872,
highestBlock: 8985345,
knownStates: 806036,
pulledStates: 794270,
startingBlock: 0
}