Geth在Centos上安装

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cowfishy/article/details/80211116

注:建议在虚拟机上安装(作为Template VM,后续Copy为多节点组成私有链)

下载cmake3.x: (智能合约需要cmake3.x版本才可以编译):

wget https://cmake.org/files/v3.3/cmake-3.3.2.tar.gz
# 解压
tar zxvf cmake-3.3.2.tar.g
cd cmake-3.3.2
# 安装
./configure
make
make install

移动到/usr/local/cmake下:

mkdir /usr/local/cmake
mv -f cmake-3.3.2/* /usr/local/cmake/
# 编辑环境变量配置文件
vim /etc/profile
# 在末尾加上
PATH=/usr/local/cmake/bin:$PATH
export PATH

然后执行: 

# 重新加载系统配置文件
source /etc/profile
# 查看并确认cmake版本信息
cmake --version

安装Git, Nodejs, gcc-c++, ntp, epel 等辅助工具:

yum update -y && yum install git bzip2 gcc-c++ ntp epel-release nodejs -y

安装Golang (go-ethereum是golang编写的):

wget https://storage.googleapis.com/golang/go1.10.2.linux-amd64.tar.gz
tar zxvf go1.10.2.linux-amd64.tar.gz 
mv go /usr/local/
echo "export GOROOT=/usr/local/go" >> /etc/profile 
echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile
source /etc/profile

下载go-ethereum:
git clone https://github.com/ethereum/go-ethereum.git  
cd go-ethereum/
make all
echo "export PATH=$PATH:/root/go-ethereum/build/bin" >> /etc/profile
source /etc/profile

启动网络时间同步,开启防火墙,打开8087和30303端口(geth用到的端口):

systemctl enable ntpd 
systemctl start ntpd
systemctl start firewalld
firewall-cmd --zone=public --add-port=8087/tcp --permanent
firewall-cmd --zone=public --add-port=30303/tcp --permanent

编写genesiso.json文件:

cd ~
vim genesis.json

{  
  "nonce": "0x0000000000000042",  
  "timestamp": "0x00",  
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",  
  "extraData": "0x00",  
  "gasLimit": "0x80000000",  
  "difficulty": "0x400",  
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",  
  "coinbase": "0x2D356ee3F5b8718d8690AFCD31Fe2CB5E602677e",  
  "alloc": {},  
  "config": {  
    "chainId": 15,  
    "homesteadBlock": 0,  
    "eip155Block": 0,  
    "eip158Block": 0  
  }  
}  

# 创建区块文件夹
mkdir -p /root/ethbase/chain
cd root & geth --datadir "/root/ethbase/chain" init genesis.json
# 输出调试log
geth --dev console 2>> geth_dev_log

然后尝试:

> eth.accounts
"0x3341e796e5d43919287d49a86cb595d74ddea657"
一切ok, 后续就是针对geth的操作了

没有更多推荐了,返回首页