文章目录
- 环境准备
- 服务器
- Go Ethereum下载安装
- 时间同步(时间错误导致无法同步节点)
- 同步网络时间
- 定时同步网络时间
- 配置Geth
- 配置启动
- 选项说明
- 参数参见
- 基本指令
- 登录控制台
- 创建账户
- 查看账户余额
- 其他指令
- 查看日志
- 查看同步日志
- 同步结束
- 附
环境准备 服务器 一般要求服务器:4核-8G-500G
[root@localhost opt]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
Go Ethereum下载安装
下载地址:https://geth.ethereum.org/downloads/
选择需要下载的客户端:geth-linux-amd64-1.8.27-4bcc0a37.tar.gz
#下载
[root@localhost opt]# ll | grep geth-linux-amd64-1.8.27-4bcc0a37.tar.gz
-rw-r--r--. 1 root root 14594041 Apr 17 21:18 geth-linux-amd64-1.8.27-4bcc0a37.tar.gz
# 解压安装
[root@localhost opt]# tar zxvf geth-linux-amd64-1.8.27-4bcc0a37.tar.gz
[root@localhost opt]# cd geth-linux-amd64-1.8.27-4bcc0a37
[root@localhost opt]# cp geth /usr/bin/geth
时间同步(时间错误导致无法同步节点) 同步网络时间
[root@localhost opt]# ntpdate cn.pool.ntp.org
16 Jul 09:59:56 ntpdate[28004]: step time server 119.28.183.184 offset 0.975532 sec
定时同步网络时间
[root@localhost opt]# echo '0 0 * * * root ntpdate cn.pool.ntp.org prefer' >> /etc/crontab
[root@localhost opt]# service crond restart
Redirecting to /bin/systemctl restart crond.service
配置Geth 配置启动
# 创建目录
[root@localhost opt]# mkdir ethdir
# 生成配置文件
[root@localhost opt]# geth --syncmode 'fast' --rpc --rpcaddr '0.0.0.0' --rpcport 8545 --datadir /opt/ethdir/data --port '30303' --rpcapi 'db,eth,net,web3,personal' --rpccorsdomain '*' --networkid 4 --cache 1024 dumpconfig > /opt/ethdir/config.toml
# 后台启动geth节点
[root@localhost opt]# nohup geth --config /opt/ethdir/config.toml >> /opt/ethdir/geth.log2>&1&
选项说明
选项 | 使用值 | 说明 |
---|---|---|
–syncmode | “fast” | Blockchain sync mode (“fast”, “full”, or “light”),同步模式,一般使用fast即可 |
–rpc | Enable the HTTP-RPC server | |
–rpcaddr | ‘0.0.0.0’ | HTTP-RPC server listening interface (default: “localhost”) |
–rpcport | 8545 | HTTP-RPC server listening port (default: 8545) |
–datadir | /opt/ethdir/data | Data directory for the databases and keystore |
–port | ‘30303’ | Network listening port (default: 30303) |
–rpcapi | ‘db,eth,net,web3,personal’ | API’s offered over the HTTP-RPC interface |
–rpccorsdomain | ‘*’ | Comma separated list of domains from which to accept cross origin requests (browser enforced) |
–networkid | 4 | Network identifier (integer, 1=Frontier(主网), 2=Morden (disused), 3=Ropsten, 4=Rinkeby) (default: 1) |
–cache | 1024 | Megabytes of memory allocated to internal caching (default: 1024) |
https://geth.ethereum.org/interface/Command-Line-Options
基本指令 登录控制台
[root@localhost rinkeby]# geth attach geth.ipc
Welcome to the Geth JavaScript console!
instance: Geth/v1.8.27-stable-4bcc0a37/linux-amd64/go1.11.9
coinbase: 0x08d589b4d5921b128cda9aad4ce82570186b5491
at block: 4741795 (Tue, 16 Jul 2019 13:59:26 CST)
datadir: /root/.ethereum/rinkeby
modules: admin:1.0 clique:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
>
创建账户
> personal.newAccount('password')
"0xf15f87cf98c847af5b1de0bb106854b6e40f6276"
>
查看账户余额
> eth.getBalance('0xf15f87cf98c847af5b1de0bb106854b6e40f6276')
0
>
其他指令 参见:https://geth.ethereum.org/interface/Management-APIs
查看日志 查看同步日志
[root@localhost opt]# more geth.log
INFO [07-03|21:17:49.633] Maximum peer countETH=25 LES=0 total=25
INFO [07-03|21:17:50.170] Starting peer-to-peer nodeinstance=Geth/v1.8.27-stable-4bcc0a3
7/linux-amd64/go1.11.9
INFO [07-03|21:17:50.170] Allocated cache and file handlesdatabase=/root/.ethereum/rinkeby/get
h/chaindata cache=512 handles=32768
INFO [07-03|21:17:56.473] Initialised chain configurationconfig="{ChainID: 4 Homestead: 1 DAO
: DAOSupport: true EIP150: 2 EIP155: 3 EIP158: 3 Byzantium: 1035301 Constantinople: 3660663Cons
tantinopleFix: 4321234 Engine: clique}"
INFO [07-03|21:17:56.474] Initialising Ethereum protocolversions="[63 62]" network=4
INFO [07-03|21:17:56.529] Loaded most recent local headernumber=4668667 hash=d18fbe…ab7758 td
=8547789 age=1m2s
INFO [07-03|21:17:56.529] Loaded most recent local full blocknumber=4668667 hash=d18fbe…ab7758 td
=8547789 age=1m2s
INFO [07-03|21:17:56.529] Loaded most recent local fast blocknumber=4668667 hash=d18fbe…ab7758 td
=8547789 age=1m2s
INFO [07-03|21:17:56.529] Loaded local transaction journaltransactions=0 dropped=0
INFO [07-03|21:17:56.530] Regenerated local transaction journaltransactions=0 accounts=0
WARN [07-03|21:17:56.530] Blockchain not empty, fast sync disabled
INFO [07-03|21:17:57.490] New local node recordseq=74 id=35056e59ec20edb9 ip=127.0.
0.1 udp=30303 tcp=30303
INFO [07-03|21:17:57.491] Started P2P networkingself=enode://d0e043a85000657cd8febdc
97678b946d5e20bd24bc0e7234962a17390a6abe2dd33eea67ff3df24634bef96807466c138256e7d65190ad9f360b7834f5163
5a@127.0.0.1:30303
INFO [07-03|21:17:57.494] IPC endpoint openedurl=/root/.ethereum/rinkeby/geth.ipc
INFO [07-03|21:17:57.495] HTTP endpoint openedurl=http://0.0.0.0:8545
cors=* vhosts=*
INFO [07-03|21:18:01.493] New local node recordseq=75 id=35056e59ec20edb9 ip=
udp=30303 tcp=30303
INFO [07-03|21:21:57.492] Block synchronisation started
WARN [07-03|21:22:04.382] Synchronisation failed, dropping peerpeer=d803dcc3febec864 err="no peers
available or all tried for download"
INFO [07-03|21:27:47.508] Imported new chain segmentblocks=2 txs=17 mgas=2.315 elapsed=5
41.329ms mgasps=4.276 number=4668669 hash=17d9b1…1baa1c age=10m23s cache=229.03kB
INFO [07-03|21:27:49.054] Imported new chain segmentblocks=9 txs=184 mgas=21.486 elapsed
=1.544smgasps=13.910 number=4668678 hash=c9d65b…f0e2d2 age=8m10scache=1.55mB
INFO [07-03|21:27:59.959] Imported new chain segmentblocks=28 txs=496 mgas=52.850 elapse
d=10.901smgasps=4.848number=4668706 hash=677f7f…86d5aa age=1m20scache=6.19mB
INFO [07-03|21:28:00.411] Imported new chain segmentblocks=4txs=74mgas=8.266elapse
d=451.917ms mgasps=18.290 number=4668710 hash=d10922…2ff143 cache=6.69mB
当出现Block synchronisation started字样时,开始同步节点,一般第一次要同步1-2天(fast模式)。
同步结束
> eth.blockNumber
4741984
>
当此命令返回的结果与链上的最新块一致时,同步完成。
附 【Centos7搭建Geth节点】rinkeby测试网浏览器
主网浏览器
推荐阅读
- 推动NFT走出监管困境,BSN推出支持NFT基础设施网络
- 腾讯|SaaS的收入模型有哪些(终于有人讲明白了)
- 就业方向上什么才是最重要的(--- 来自程序猿的迷茫。(C++?Java?or算法?))
- 区块链中加密货币的含义
- 波场万倍潜力币HYL23号21:09分 正式上线JustSwap
- 《瀚兰房地产开发区块链应用及案例分享》BSN培训精华回顾
- 对联盟链而言,跨链协议为什么重要()
- 区块链能够应用在哪些行业
- BSN区块链服务网络中密钥托管模式和公钥上传模式有啥区别()
- 币圈人物传|币圈大佬今何在 唯有一诺正当时