###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
>
###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]
有疑问加站长微信联系(非本文作者)