CENTOS 部署ETH 以太坊

aside section._1OhGeD · · 1264 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

2.解压go安装包

[root@hadoop111~]# tar -C /usr/local -xzf go1.10.linux-amd64.tar.gz

3.添加go环境变量

[root@hadoop111~]# echo 'export GOROOT=/usr/local/go' >> /etc/profile

[root@hadoop111 ~]# echo 'export PATH=$PATH:$GOROOT/bin'>> /etc/profile

[root@hadoop111 ~]# echo 'export GOPATH=/home/go' >>/etc/profile

[root@hadoop111 ~]# echo 'export PATH=$PATH:$GOPATH/bin'>> /etc/profile

4.刷新环境变量

[root@hadoop111 ~]# source /etc/profile

5.验证go语言是否安装成功

[root@hadoop111 ~]# go version

goversion go1.10 linux/amd64

三、安装其它安装以太坊需要的环境组件

安装curlgit nodejsgcc-c++

[root@hadoop111 ~]# yum install-y curl gitnodejs gcc-c++

四、编译安装以太坊(这里采用的是源码安装方式)

1. 下载以太坊源码

[root@hadoop111 ~]# cd/usr/local #创建目录

[root@hadoop111 ~]# git clone https://github.com/ethereum/go-ethereum.git#通过git下载以太坊源码

正克隆到 'go-ethereum'...

remote: Counting objects: 70885,done.

remote: Total 70885 (delta 0),reused 0 (delta 0), pack-reused 70885

接收对象中: 100% (70885/70885),96.27 MiB | 174.00 KiB/s, done.

处理 delta 中: 100% (47083/47083), done.

2. 编译

[root@hadoop111 ~]# cdgo-ethereum

[root@hadoop111 ~]# make all

[root@hadoop111 ~]# ln -sv/usr/local/go-ethereum/build/bin/geth /usr/bin #添加软连接

3. 安装cmake,智能合约需要使用

[root@hadoop111 ~]# cd ~

[root@hadoop111 ~]# wget https://cmake.org/files/v3.9/cmake-3.9.2.tar.gz #下载cmake安装包

[root@hadoop111 ~]# tar xvfcmake-3.9.2.tar.gz #解压

[root@hadoop111 ~]# cdcmake-3.9.2

[root@hadoop111 ~]# ./configure&& make && make install #编译安装

4. 检查安装结果

[root@hadoop111 ~]# systemctlis-enabled chronyd #时间同步服务

[root@hadoop111 ~]# cmake --version

cmake version 3.9.2

CMake suite maintained andsupported by Kitware (kitware.com/cmake).

[root@hadoop111 ~]# geth version

WARN [06-14|14:18:56] Sanitizingcache to Go's GC limits  provided=1024 updated=607

Geth

Version: 1.8.12-unstable

Git Commit:ea89f40f0dab7957aa1825b56be80e84d3b04b5c

Architecture: amd64

Protocol Versions: [63 62]

Network Id: 1

Go Version: go1.10

Operating System: linux

GOPATH=/home/go

GOROOT=/usr/local/go

五、使用以太坊私有链

1.初始化创世区块

创建一个genesis.json文件

[root@hadoop111 ~]# cd /root

[root@hadoop111 ~]# mkdireth-test

[root@hadoop111 ~]# cd eth-test

[root@hadoop111 ~]# vigenesis.json

添加如下内容

{

"config":{

"chainId":20,

"homesteadBlock":0,

"eip155Block":0,

"eip158Block":0

},

"alloc":{},

"coinbase":"0x0000000000000000000000000000000000000000",

"difficulty":"0x200",

"extraData":"",

"gasLimit":"0x2fefd8",

"nonce":"0x0000000000000042",

"mixhash":"0x0000000000000000000000000000000000000000000000000000000000000000",

"parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000",

"timestamp":"0x00"

}

2. 初始化节点

[root@hadoop111 ~]# geth--datadir "/root/eth-test/" init genesis.json#初始化创世区块

执行完成后,将会出现类似以下信息,表示创世区块初始化完成

file:///C:/Users/pc/AppData/Local/Temp/msohtmlclip1/01/clip_image002.jpg

启动以太坊

[root@hadoop111 ~]# cd /usr/bin

[root@hadoop111 ~]# ./geth --rpc--rpccorsdomain "*" --datadir "/root/eth-test/" --rpcapi"db,net,eth,web3,personal,miner,debug,admin" --networkid 100000console 2>>eth_output.log

注意:上面命令中–datadir后的”/root/eth-test/”要跟我们上一步的–datadir参数一致。命令执行完,自动进入geth的命令行则说明以太坊私有链安装成功了。

file:///C:/Users/pc/AppData/Local/Temp/msohtmlclip1/01/clip_image004.jpg

3. 创建账户,挖矿

查看帐户,可以看到当前帐户是空的

[root@hadoop111 ~]#eth.accounts

创建两个帐户,并初始化密码。注意密码是用户自定义的。

>personal.newAccount('123456')

"0x3e5b345a8b88fe181f75d6956c40c104de7b61ee"

>personal.newAccount('123456')

"0xc6b5ec8fff2696375c16c930a9fb7aec4a106b11"

再次查询账户,发现有两个了

> eth.accounts

["0x3e5b345a8b88fe181f75d6956c40c104de7b61ee","0xc6b5ec8fff2696375c16c930a9fb7aec4a106b11"]

为了操作方便,给账户起一个名字

> test1 = eth.accounts[0]

"0x3e5b345a8b88fe181f75d6956c40c104de7b61ee"

> test2 = eth.accounts[1]

"0xc6b5ec8fff2696375c16c930a9fb7aec4a106b11"

设置操作账号

> miner.setEtherbase(test1) #如果不设置挖矿会默认保存到创建的第一个帐户

true

开始挖矿

> miner.start() #执行挖矿一段时间,然账户中有余额,第一次最好时间长一点,约3分钟,避免挖不到

停止挖矿

> miner.stop()

true

查看账户

> eth.getBalance(test1)

65000000000000000000

4. 账户转账

转账前需要先解锁账户,否则,会报错Error: authentication needed:password or unlock

>personal.unlockAccount(test1,'123456')

true

转账时要注意,超过余额会报错

> eth.sendTransaction({from:test1, to: test2, value: web3.toWei(1, 'ether')})

"0xe85d7e65919ce73c64958d07f29decece7cf7f6c1289d77c12e7c7eb5f631553"

查看账户,发现转出账户余额并未减少,转入账户也没有增加,因为我们的交易还未成功写进区块,写进区块的方式是挖矿,我们再次开启挖矿,挖矿成功后,再次查看余额,发现到账:

>eth.getBalance(test2)

0

> miner.start(1)#执行挖矿让交易执行,1表示使用一个cpuminer.stop()

null

过一会发现,已到账

> eth.getBalance(test2)

1000000000000000000

此时,可以看出转入账户,增加了1个以太币。而转出账户,由于再次挖矿而获得奖励,从而余额增加,所以,从转出账户,不好判断交易的真实数额。

到此为止,本节的内容就完成了。可见以太坊的环境和操作还是比较简单的。






简单步骤


安装GO

wget https://studygolang.com/dl/golang/go1.13.3.linux-amd64.tar.gz

tar -xvf go1.13.3.linux-amd64.tar.gz -C /usr/local

echo 'export GOROOT=/usr/local/go' >> /etc/profile

echo 'export PATH=$PATH:$GOROOT/bin'>> /etc/profile

echo 'export GOPATH=/home/go' >>/etc/profile

echo 'export PATH=$PATH:$GOPATH/bin'>> /etc/profile

source /etc/profile 更新

重启


安装ETH源码

git clone https://github.com/ethereum/go-ethereum.git

cd build/bin

echo "export PATH=$PATH:/root/go-ethereum/build/bin" >> /etc/profile

source /etc/profile 更新


有疑问加站长微信联系(非本文作者)

本文来自:简书

感谢作者:aside section._1OhGeD

查看原文:CENTOS 部署ETH 以太坊

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1264 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传