https://github.com/ethereum/go-ethereum/wiki

http://book.8btc.com/books/6/ethereum/_book/public-chain-chain.html

https://www.cnblogs.com/zl03jsj/p/6876064.html

安装客户端

yum -y install golang
go version
> go version go1.8.3 linux/amd64 wget https://gethstore.blob.core.windows.net/builds/geth-alltools-linux-amd64-1.7.3-4bb3c89d.tar.gz
tar xvfz geth-alltools-linux-amd64-1.7.3-4bb3c89d.tar.gz
export PATH=$PATH:/root/geth-alltools-linux-amd64-1.7.3-4bb3c89d

创始块初始化文件genesis.json

{
"config": {
"chainId": 123,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"nonce": "0x0000000000000033",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x8000000",
"difficulty": "0x100",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x3333333333333333333333333333333333333333",
"alloc": {}
} #参数名称 参数描述
#mixhash 与nonce配合用于挖矿,由上一个区块的一部分生成的hash。注意他和nonce的设置需要满足以太坊的Yellow paper, 4.3.4. Block Header Validity, (44)章节所描述的条件。
#nonce nonce就是一个64位随机数,用于挖矿,注意他和mixhash的设置需要满足以太坊的Yellow paper, 4.3.4. Block Header Validity, (44)章节所描述的条件。
#difficulty 设置当前区块的难度,如果难度过大,cpu挖矿就很难,这里设置较小难度
#alloc 用来预置账号以及账号的以太币数量,因为私有链挖矿比较容易,所以我们不需要预置有币的账号,需要的时候自己创建即可以。
#coinbase 矿工的账号,随便填
#timestamp 设置创世块的时间戳
#parentHash 上一个区块的hash值,因为是创世块,所以这个值是0
#extraData 附加信息,随便填,可以填你的个性信息
#gasLimit 该值设置对GAS的消耗总量限制,用来限制区块能包含的交易信息总和,因为我们是私有链,所以填最大。

私有链节点初始化

mkdir /opt/blockchain
geth --datadir /opt/blockchain init genesis.json

控制台方式连接私有链

geth --networkid 123 --datadir /opt/blockchain console

建立矿工帐号

# 第1个建立的帐号默认为矿工帐号
> personal.newAccount("me")
"0xdd3381d3d81593bcc4440a634fdf964e19744ed9"

节点默认矿工帐号

> eth.coinbase
Error: etherbase address must be explicitly specified
at web3.js:3143:20
at web3.js:6347:15
at get (web3.js:6247:38)
at <unknown> 建立以后就有了
> eth.coinbase
"0xdd3381d3d81593bcc4440a634fdf964e19744ed9"

后台启动

nohup geth --networkid 123 --datadir /opt/blockchain --mine --nodiscover --rpc --rpcaddr 0.0.0.0 --rpcapi "db,eth,net,web3,admin,personal" --ipcpath /opt/blockchain/geth.ipc &

以太坊钱包连接

/opt/Ethereum Wallet/ethereumwallet --rpc  /opt/blockchain/geth.ipc

连接到以太坊私链

geth attach /opt/blockchain/geth.ipc
geth attach http://127.0.0.1:8545

挖矿

miner.start(1)

矿工的以太WEI

> eth.getBalance(eth.coinbase)
2.031e+22 > web3.fromWei(eth.getBalance(eth.coinbase)) # 转成以太币

当前节点值

> admin.nodeInfo.enode
"enode://7ea7808369eef9718e4490b3913bbacc0176f88fe0d8ad6085ca3e614b30eb244a70aa226015aa8cfad58938915946dcefc78ef960f0447c526e221ac62077b2@[::]:30303?discport=0"

当前块号

> eth.blockNumber
255

当前块内容

> eth.getBlock(255)

多节点配置(开发环境的话,1个节点上建立多个帐户即可)

必须使用同样创始块初始化文件genesis.json创建节点,参考前面的操作。

节点1 192.168.48.111
节点2 192.168.48.112
节点3 192.168.48.113
节点4 192.168.48.114 # 查询节点1信息
> admin.nodeInfo.enode or admin.nodeInfo
"enode://9d12900c5b7105d6db5769bacbf16e02574e19f8a8db4d16c8fad2b10a17c566f09e81619c298e3d4bbca0f0f5476ee3ef60e16a2f8cd3fe323ea884025d3fe8@[::]:30303?discport=0" # 节点2, 3, 4分别添加节点1
# 节点1信息中的 [::] 需要替换为 ip地址 , 使用同一个 networkid
> personal.newAccount("he") > personal.newAccount("she") > personal.newAccount("it") > admin.addPeer("enode://9d12900c5b7105d6db5769bacbf16e02574e19f8a8db4d16c8fad2b10a17c566f09e81619c298e3d4bbca0f0f5476ee3ef60e16a2f8cd3fe323ea884025d3fe8@192.168.48.111:30303?discport=0")
true #随后自动同步区位块
> INFO [02-09|10:55:42] Block synchronisation started
INFO [02-09|10:55:42] Imported new state entries count=1 elapsed=117.431µs processed=1 pending=0 retry=0 duplicate=0 unexpected=0
INFO [02-09|10:55:45] Imported new block headers count=192 elapsed=2.803s number=192 hash=0a09dc…8adbb1 ignored=0
INFO [02-09|10:55:45] Imported new block receipts count=192 elapsed=3.552ms bytes=768 number=192 hash=0a09dc…8adbb1 ignored=0
INFO [02-09|10:55:45] Imported new block headers count=192 elapsed=106.312ms number=384 hash=a976d1…9df3ae ignored=0
INFO [02-09|10:55:45] Imported new block receipts count=192 elapsed=3.790ms bytes=768 number=384 hash=a976d1…9df3ae ignored=0
INFO [02-09|10:55:46] Imported new block headers count=2048 elapsed=1.262s number=2432 hash=cc5639…98edb1 ignored=0
INFO [02-09|10:55:47] Imported new block receipts count=2048 elapsed=96.143ms bytes=8192 number=2432 hash=cc5639…98edb1 ignored=0
INFO [02-09|10:55:48] Generating ethash verification cache epoch=1 percentage=67 elapsed=3.080s
INFO [02-09|10:55:49] Generated ethash verification cache epoch=1 elapsed=4.515s
INFO [02-09|10:55:59] Imported new block headers count=1792 elapsed=12.194s number=4224 hash=34b889…a9ffca ignored=0
INFO [02-09|10:55:59] Imported new block receipts count=1514 elapsed=79.429ms bytes=6056 number=3946 hash=37d0fc…7484d9 ignored=0
INFO [02-09|10:55:59] Imported new state entries count=1 elapsed=69.436µs processed=2 pending=0 retry=0 duplicate=0 unexpected=0
INFO [02-09|10:55:59] Imported new block receipts count=1 elapsed=102.927µs bytes=4 number=3947 hash=96d4bd…b936ca ignored=0
INFO [02-09|10:55:59] Committed new head block number=3947 hash=96d4bd…b936ca
INFO [02-09|10:55:59] Imported new chain segment blocks=277 txs=0 mgas=0.000 elapsed=239.845ms mgasps=0.000 number=4224 hash=34b889…a9ffca
INFO [02-09|10:55:59] Imported new block headers count=39 elapsed=544.628ms number=4263 hash=df5c71…ee6138 ignored=0
WARN [02-09|10:55:59] Skipping deep transaction reorg depth=4224
INFO [02-09|10:55:59] Imported new chain segment blocks=39 txs=0 mgas=0.000 elapsed=15.711ms mgasps=0.000 number=4263 hash=df5c71…ee6138
INFO [02-09|10:55:59] Fast sync complete, auto disabling
INFO [02-09|10:56:00] Imported new chain segment blocks=3 txs=0 mgas=0.000 elapsed=20.714ms mgasps=0.000 number=4266 hash=327227…dad296
INFO [02-09|10:56:04] Imported new chain segment blocks=1 txs=0 mgas=0.000 elapsed=7.450ms mgasps=0.000 number=4267 hash=759130…d8d811 # 登录节点1查看
> admin.peers
[{
caps: ["eth/63"],
id: "60823ad532b30cebf94013295d08010b657fb4a3c226fd6a3a96578bb85292f9987a4d0b3f24d92cd448dba3d083418dde368f811797c3bc966c3a9775e19553",
name: "Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9.2",
network: {
localAddress: "192.168.48.111:30303",
remoteAddress: "192.168.48.113:37136"
},
protocols: {
eth: {
difficulty: 2097152,
head: "0xb059eea745254c042c4736749d8cbd10d67ea4276b9e312a669e60d56992d967",
version: 63
}
}
}, {
caps: ["eth/63"],
id: "693ea792c9d1ce90c1242e0650cefcaf931de9f4f21ef5cd551047b409a45ee0654bfd769a4b8aa85e57da5aa35fdf86f950979d0e4e9b699857f86152e9d28c",
name: "Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9.2",
network: {
localAddress: "192.168.48.111:30303",
remoteAddress: "192.168.48.112:52756"
},
protocols: {
eth: {
difficulty: 2097152,
head: "0xb059eea745254c042c4736749d8cbd10d67ea4276b9e312a669e60d56992d967",
version: 63
}
}
}, {
caps: ["eth/63"],
id: "b8419370552fb2089d140b78be5c552a69c026b03d76ef88d443e9d5e5b48d27c07726a4e7ad18820426a7d881c82ac94f3d752329b7942d728d87b7c666ddbc",
name: "Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9.2",
network: {
localAddress: "192.168.48.111:30303",
remoteAddress: "192.168.48.114:44970"
},
protocols: {
eth: {
difficulty: 2097152,
head: "0xb059eea745254c042c4736749d8cbd10d67ea4276b9e312a669e60d56992d967",
version: 63
}
}
}] # 这种控制台添加节点方式,一旦退出控制台就失效,所以使用命令方式添加
nohup geth --networkid 123 --datadir /opt/blockchain --identity "TestChain_112" --mine --port 30303 --nodiscover --rpc --rpcaddr 0.0.0.0 --rpcport 8545 --rpcapi "db,eth,net,web3" --bootnodes "enode://9d12900c5b7105d6db5769bacbf16e02574e19f8a8db4d16c8fad2b10a17c566f09e81619c298e3d4bbca0f0f5476ee3ef60e16a2f8cd3fe323ea884025d3fe8@192.168.48.111:30303" & nohup geth --networkid 123 --datadir /opt/blockchain --identity "TestChain_113" --mine --port 30303 --nodiscover --rpc --rpcaddr 0.0.0.0 --rpcport 8545 --rpcapi "db,eth,net,web3" --bootnodes "enode://9d12900c5b7105d6db5769bacbf16e02574e19f8a8db4d16c8fad2b10a17c566f09e81619c298e3d4bbca0f0f5476ee3ef60e16a2f8cd3fe323ea884025d3fe8@192.168.48.111:30303" & nohup geth --networkid 123 --datadir /opt/blockchain --identity "TestChain_114" --mine --port 30303 --nodiscover --rpc --rpcaddr 0.0.0.0 --rpcport 8545 --rpcapi "db,eth,net,web3" --bootnodes "enode://9d12900c5b7105d6db5769bacbf16e02574e19f8a8db4d16c8fad2b10a17c566f09e81619c298e3d4bbca0f0f5476ee3ef60e16a2f8cd3fe323ea884025d3fe8@192.168.48.111:30303" &

centos7部署ethereum私有链的更多相关文章

  1. 区块链学习(四)truffle部署编译智能合约以太坊私有链

    前面我们介绍了以太坊私有链的搭建以及多节点私有链网络,这次我们介绍如何使用truffle框架来部署编译智能合约到我们之前搭建的私有链网络中. 搭建环境及需使用的工具:ubuntu18.04  Truf ...

  2. 从零构建以太坊(Ethereum)智能合约到项目实战——第20章 搭建自己的私有链网络

    P75 .1-以太坊私网建立 .合约编译.部署完全教程(1) 使用此博文进行安装配置:https://blog.csdn.net/w88193363/article/details/79402074 ...

  3. 区块链开发学习第三章:私有链上部署helloBlockchain简单合约

    前面讲了部署私有链以及新增账户,现在进行到了部署合约了,此操作真是踩了无数无数无数的坑,到写文章为止确实是已经部署好了,但是还有些坑是还没有解决的! 一.Solidity编译器 开始的时候用的http ...

  4. CentOS7搭建以太坊私有链

    1. 环境准备:Win10 64位安装 VM VirtualBox,操作系统版本: CentOS-7-x86_64-Everything-1611.iso(7.71G). 切换root账号,方便安装程 ...

  5. AntShares区块链的节点部署与搭建私有链

    近期陆续体验常见的区块链开源项目,比如小蚁OnChain出的AntShares.AntShares跟其它开源区块链项目不一样,他们家是使用C#开发,基于.NET Core执行在Linux,期待未来出G ...

  6. Truffle 4.0、Geth 1.7.2、TestRPC在私有链上搭建智能合约

    目录 目录 1.什么是 Truffle? 2.适合 Truffle 开发的客户端 3.Truffle的源代码地址 4.如何安装? 4.1.安装 Go-Ethereum 1.7.2 4.2.安装 Tru ...

  7. 区块链--Ubuntu上搭建以太坊私有链

    1.搭建私链所需环境 操作系统:ubuntu16.04,开虚拟机的话要至少4G,否则会影响测试挖矿时的速度 软件: geth客户端 Mist和Ethereum Wallet:https://githu ...

  8. 转:区块链开发(一)搭建基于以太坊go-ethereum的私有链环境

    区块链开发(一)搭建基于以太坊go-ethereum的私有链环境 wo541075754 · 2016-11-07 13:00:03 · 3730 次点击 · 预计阅读时间 3 分钟 · 约1小时前  ...

  9. 以太坊开发(二)使用Ganache CLI在私有链上搭建智能合约

    以太坊开发(二)使用Ganache CLI在私有链上搭建智能合约 在上一篇文章中,我们使用Truffle自带的客户端Truffle Develop,在私有链上搭建并运行了官方提供的WebPack智能合 ...

随机推荐

  1. python学习,day2:列表的使用,增删改合并等

    # coding=utf-8 # Author: RyAn Bi names = ['A','B','C','D'] print(names) print(names[0]) #从0开始记录 prin ...

  2. C++_异常4-将对象用作异常类型

    通常,引发异常的函数将传递一个对象.这样做的重要优点之一就是,可以利用不同的异常类型来区分不同的函数在不同的情况下引发的异常. 对象可以携带信息,程序员可以根据这些信息来确定异常的原因. 同时,cat ...

  3. POJ_1456 Supermarket 【并查集/贪心】

    一.题面 POJ1456 二.分析 1.贪心策略:先保证从利润最大的开始判断,然后开一个标记时间是否能访问的数组,时间尽量从最大的时间开始选择,这样能够保证后面时间小的还能够卖. 2.并查集:并查集直 ...

  4. 【KMP】洛谷P2375 [NOI2014]动物园 题解

        一开始的方向应该对了,但是没有想到合理的优化还是没写出来…… 题目描述 近日,园长发现动物园中好吃懒做的动物越来越多了.例如企鹅,只会卖萌向游客要吃的.为了整治动物园的不良风气,让动物们凭自己 ...

  5. Linux中断分层--软中断和tasklet

    1. Linux中断分层 (1)上半部:当中断发生时,它进行相应的硬件读写,并“登记”该中断.通常由中断处理程序充当上半部.(一般情况下,上半部不可被打断) (2)下半部:在系统空闲的时候,对上半部“ ...

  6. 今日工作总结:jquery轮转效果的集成与前台页面banner的设计思路总结

    今日做了两个项目中的两个问题,现在特来总结一下,以便分享给更多的朋友们. 1.jquery轮转效果的集成 涉及到jquery的不同版本问题,解决办法是在后缀用jQuery代替$.项目地址在:121.4 ...

  7. Qt客户端阿里云服上传文件

    整体原理: 阿里云提供了c程序上传文件到阿里云服务器的sdk工具包,将这个工具包继承在自己的客户端,调用接口即可实现上传文件. 前期准备: 1.阿里云c程序客户端的sdk,下载地址:https://h ...

  8. 设计模式学习总结(六)原型模式(Prototype)

    原型模式即通过对象拷贝的方式来实现对同类对象的生成的一种设计模式! 浅复制:对于值类型,则直接复制该值,对于引用类型的字段则是对其引用的复制,如果原引用与现引用只要有一个的值发生变化,则都会造成两者值 ...

  9. jenkins 部署应用

    一,安装rpm包 安装jdk 安装jenkins 查看jdk是否安装成功 启动jenkins systemctl start jenkins 开机自启 systemctl enable jenkins ...

  10. nfs 问题总结

    1. [root@backup read]# touch r01.txt   touch: cannot touch `r01.txt': Stale file handle   使用共享目录创建文件 ...