###1.安裝基礎工具javascript
yum update -y && yum install git bzip2 gcc-c++ ntp epel-release nodejs -y
###2.安裝cmakejava
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.配置環境變量node
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語言linux
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項目c++
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.開啓網絡時間同步git
systemctl enable ntpd systemctl start ntpd
###7.建立geth工做目錄github
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命令golang
[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中操做)web
> web3.eth.accounts []
建立賬戶的方式有兩種,第一種建立賬戶時直接初始化密碼json
> 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]