CentOS 7 部署以太坊私有鏈 go1.13.2 + go-ethereum1.9.12

###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
>

CentOS 7 部署以太坊私有鏈 go1.13.2 + go-ethereum1.9.12

###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] 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章