Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構 | 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者”

第 10 章 以太坊私鏈入門

目錄

10.1. 軟件安裝與配置
10.1.1. Ubuntu
10.1.1.1. 安裝 geth
10.1.1.2. 安裝 solc
10.1.1.3. Node.js
10.1.2. CentOS 7
10.1.3. Windows
10.1.4. Mac OS
10.1.4.1. 安裝 Node
10.1.4.2. Ethereum Wallet
10.1.5. 編譯安裝
10.1.6. Netkiller OSCM 一鍵安裝
10.1.6.1. 1.8.10
10.1.6.2. 1.8.1
10.1.6.3. 1.8.10
10.1.7. 防止 geth 異常退出
10.2. 創世區塊
10.2.1. 初始化創世區塊
10.2.2. 創建主賬號
10.2.3. 啟動節點
10.2.4. 使用節點進行挖礦
10.2.4.1. 啟動礦工開始挖礦
10.2.4.2. 停止挖礦
10.2.4.3. 查看所挖金額
10.2.5. 在創世鏈中制定礦工賬號併為它充值
10.3. Blockchain explorer (區塊鏈瀏覽器)
10.4. 單機多實例演示
10.4.1. 實例一
10.4.2. 實例二
10.4.3. 添加節點
10.4.4. 節點測試
10.5. 使用 pm2 啟動以太坊

本文所用軟件版本

10.1. 軟件安裝與配置

10.1.1. Ubuntu

10.1.1.1. 安裝 geth

安裝環境



Ubuntu 17.10

				
sudo apt upgrade -y
sudo apt install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt update
sudo apt install ethereum			
				
				
				
neo@netkiller ~ % geth version
Geth
Version: 1.8.10-stable
Git Commit: 4bb3c89d44e372e6a9ab85a8be0c9345265c763a
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.9.5
Operating System: linux
GOPATH=
GOROOT=/usr/lib/go-1.9
				
				

10.1.1.2. 安裝 solc

				
sudo apt install solc -y
				
				
				
neo@netkiller ~ % solc --version
solc, the solidity compiler commandline interface
Version: 0.4.19+commit.c4cbbb05.Linux.g++				
				
				

10.1.1.3. Node.js

				
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs				
				
				

10.1.2. CentOS 7

			
yum update -y
yum install git wget bzip2 -y	
yum install golang -y

cd /usr/local/src
git clone https://github.com/ethereum/go-ethereum.git
cd go-ethereum/
gmake all
mv build /srv/go-ethereum

echo "export PATH=$PATH:$PWD/build/bin" >> /etc/profile
source /etc/profile		
			
			

上面安裝版本是 unstable 版本,如果是生產環境請使用 Release 版本 https://github.com/ethereum/go-ethereum/tags

			
wget https://github.com/ethereum/go-ethereum/archive/v1.8.10.tar.gz
tar zxvf v1.8.10.tar.gz
cd go-ethereum-1.8.10/
gmake all

mv build /srv/go-ethereum-1.8.10
			
			

10.1.3. Windows

				
訪問 https://geth.ethereum.org/downloads/
下載並安裝 Geth for Windows				
				
			

10.1.4. Mac OS

				
brew update
brew upgrade				
brew tap ethereum/ethereum
brew install ethereum
brew install solidity
				
			

10.1.4.1. 安裝 Node

				
brew install node
brew install npm
npm config set registry https://registry.npm.taobao.org
				
				

10.1.4.2. Ethereum Wallet

下載安裝以太坊錢包(大陸網絡可能下載有問題,需要翻牆)

https://github.com/ethereum/mist/releases/download/v0.9.3/Ethereum-Wallet-macosx-0-9-3.dmg

10.1.5. 編譯安裝

				
git clone https://github.com/ethereum/go-ethereum
sudo apt-get install -y build-essential golang
cd go-ethereum
make geth
				
			

10.1.6. Netkiller OSCM 一鍵安裝

Netkiller OSCM 是由 Netkiller 製作的一套自動化安裝腳本。

適用於 CentOS 7

10.1.6.1. 1.8.10

			
curl -s https://raw.githubusercontent.com/oscm/shell/master/blockchain/ethereum/centos/go-ethereum-1.8.10.sh | bash			
			
				

安裝完成後使用下面命令進入控制台

			
[root@localhost ~]# su - ethereum
Last login: Sat Feb  3 00:23:52 EST 2018 on pts/0
			
[ethereum@localhost ~]$ geth attach
Welcome to the Geth JavaScript console!

instance: Geth/v1.8.10-stable/linux-amd64/go1.8.10
 modules: admin: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

> 
			
				

10.1.6.2. 1.8.1

				
curl -s https://raw.githubusercontent.com/oscm/shell/master/blockchain/ethereum/centos/go-ethereum-1.8.1.sh | bash
				
				

10.1.6.3. 1.8.10

				
curl -s https://raw.githubusercontent.com/oscm/shell/master/lang/gcc/gcc.sh | bash
curl -s https://raw.githubusercontent.com/oscm/shell/master/lang/golang/golang-1.10.2.sh | bash
curl -s https://raw.githubusercontent.com/oscm/shell/master/blockchain/ethereum/centos/go-ethereum-1.8.10.sh | bash
curl -s https://raw.githubusercontent.com/oscm/shell/master/blockchain/ethereum/systemd/private.sh | bash

curl -s https://raw.githubusercontent.com/oscm/shell/master/lang/node.js/binrary/node-v10.1.0.sh | bash
curl -s https://raw.githubusercontent.com/oscm/shell/master/lang/node.js/binrary/profile.d.sh | bash
curl -s https://raw.githubusercontent.com/oscm/shell/master/blockchain/ethereum/truffle/truffle.sh | bash
				
				

10.1.7. 防止 geth 異常退出

在同步主網的過程中,我們發現經常出現geth崩潰退出,為了防止異常退出,我們寫了這個腳本。

		
[ethereum@netkiller ~]$ cat run.sh 
#!/bin/bash
for (( ; ; ))
do
	#geth --syncmode light --cache 2048 --maxpeers 200
	# geth --syncmode light --cache 2048 --maxpeers 200 --rpc --rpcaddr 0.0.0.0 --rpcport 7545 --rpcapi web3,admin,eth,personal --port 30303 2> /tmp/geth.log
	geth --datadir private --networkid 44444 --port 30302 --mine --rpc
	#geth --testnet --syncmode light --cache 2048 --maxpeers 200 --rpc 2> /tmp/geth.log
	sleep 10

done &