目录
环境
想法
- 由于挖矿很费性能,对于手上的垃圾服务器来说,要挂nginx和tomcat还要挖矿实在是难为它了。
- 因此想把挖矿的任务分给另一台服务器。
- 目标效果即为:
- 副节点连上主节点,两者的数据同步。
- 主节点关闭挖矿,节省性能,由副节点挖矿。
开搞
让副节点连上主节点
- 注意:
- 不要在副节点上直接打开geth执行
- $ geth attach http://your_ip:8545
- 这样相当于远程连接控制主节点了,就像我们在windows上用ssh远程连接linux去控制geth挖矿的开启和关闭一样,链上仍然只有主节点一个,只不过有主节点本机和另一台机可以去控制主节点。
- 不要在副节点上直接打开geth执行
- 副节点需要和主节点用一样的创世块文件
- 这里就用和之前的文章(以太坊私链搭建)所用的创世块一致
- genesis.json
{
"config":{
"chainId":7,
"homesteadBlock":0,
"eip150Block":0,
"eip155Block":0,
"eip158Block":0,
"byzantiumBlock":0,
"constantinopleBlock":0,
"petersburgBlock":0,
"istanbulBlock":0,
"ethhash":{}
},
"alloc":{},
"coinbase":"0x0000000000000000000000000000000000000000",
"difficulty":"0x2",
"extraData":"",
"gasLimit":"0xffffffff",
"nonce":"0x0000000000000042",
"mixhash":"0x0000000000000000000000000000000000000000000000000000000000000000", "parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp":"0x00"
}
- 还要准备启动脚本,这里也保持和主节点一致
- rungeth.sh
geth --datadir ./data --networkid 7 --http --http.addr 0.0.0.0 --http.vhosts "*" --http.api "admin,debug,web3,eth,txpool,personal,ethash,miner,net" --http.corsdomain "*" --snapshot --mine --miner.threads 1 --allow-insecure-unlock console 2> 1.log
- 在副节点所在机新建一个用户
- $ geth --datadir ./data account new
- 然后在副节点所在机初始化创世块
- $ sudo geth --datadir ./data init ./genesis.json
- 启动geth
- $ sudo ./rungeth.sh
- 如果是在一台机子上搞两个节点,则要修改他们的运行端口,使之不要重复,不然其中一个会启动不起来。
- 至此,副节点就部署完成了,接下来要在主节点中添加副节点。
- 首先查看一下副节点的enode
- > admin.nodeInfo.enode
- 首先查看一下副节点的enode
- -
- 在主节点添加副节点的enode
- >admin.addPeer("encode")
- 在主节点添加副节点的enode
- 查看是否添加成功
- 方法1:
- 直接对比两者的块高度看看是否相等,如果块比较多,可能需要等待一下同步。
- > eth.blockNumber
- 方法2:
- net.peerCount
- admin.peers
- 方法1:
- 让副节点代替主节点挖矿
- 把主节点挖矿停掉,在主节点所在机执行:
- > miner.stop()
- 让副节点挖矿,在副节点所在机执行:
- > miner.start()
- 把主节点挖矿停掉,在主节点所在机执行:
修改java程序连接副节点
- 上一篇的文章:java使用web3j调用以太坊私链上的智能合约
- 上文中讲到,java程序连接单节点(主节点)的私链去调用智能合约。
- 注意:
- 如果不修改的话,此时主节点虽然开着geth,但关闭了挖矿,只能和副节点进行数据同步,而连接主节点发送的请求都是不能执行的。
- 而且主节点的geth不能关闭,否则副节点也会出问题。
- 不要在开着geth的时候直接关闭ssh窗口,否则会导致链的数据丢失,要在geth里执行> exit 退出。
- 复制副节点的用户私钥文件到java程序执行的机子上,
- 修改java程序使用这个私钥文件,并把用户地址也改成这个私钥文件的用户。
- 修改java程序连接副节点所在的服务器ip地址。
- 到这里就可以了,如此就实现了让副节点代替主节点挖矿的任务了。
存在的问题
- 主节点的账号是不能在连接副节点后使用的,也就是说,两个节点实际上只有链上的数据是互通的,账号是不互通的。因此java程序连接副节点时需要修改。
- 此时主节点只能同步数据,不能挖矿,连接到主节点后发送的交易并不会由副节点代替挖矿完成。
ремонт телефонов айфон рядом
ремонт iphone центр
buying prescription drugs in mexico online: mexican online pharmacies prescription drugs – purple pharmacy mexico price list
canadian online pharmacy northwest pharmacy canada 77 canadian pharmacy
сервис центр apple
сервисный центр по ремонту apple
This is a very good tip especially to those fresh to the blogosphere. Simple but very precise info… Many thanks for sharing this one. A must read post!
Pretty! This was an incredibly wonderful article. Thank you for providing these details.
You’re so awesome! I do not believe I’ve read through anything like that before. So good to discover somebody with genuine thoughts on this subject matter. Really.. many thanks for starting this up. This web site is one thing that’s needed on the internet, someone with some originality.
Great article. I’m experiencing a few of these issues as well..
ремонт смартфонов в москве сервисные центры
One of the major features of boomerang casino bet is its generous welcome bonuses, which offer new players an great head start. With up to 500€ in bonuses and regular promotions, there’s always something to anticipate. The casino is committed to ensuring a protected and secure environment, utilizing advanced encryption technologies to safeguard your data and transactions.
Hi, I do think this is a great blog. I stumbledupon it 😉 I may return once again since i have saved as a favorite it. Money and freedom is the best way to change, may you be rich and continue to help others.
Excellent article. I’m going through many of these issues as well..
Having read this I believed it was extremely informative. I appreciate you spending some time and effort to put this short article together. I once again find myself personally spending way too much time both reading and leaving comments. But so what, it was still worthwhile!
You need to take part in a contest for one of the highest quality websites on the web. I am going to recommend this site!
где можно отремонтировать телефон
ближайшая мастерская по ремонту телефонов
Срочные микрокредиты стали незаменимым инструментом для тех, кто ценит свое время и нуждается в деньгах здесь и сейчас. В отличие от банковских кредитов, Займы без отказа в новых МФО готовы предоставить микрокредит даже тем, чья кредитная история далека от идеальной. Заполнение заявки занимает всего несколько минут, а деньги поступают на карту практически мгновенно. Это надежное решение для всех, кто столкнулся с непредвиденными расходами.
This blog was… how do you say it? Relevant!! Finally I’ve found something that helped me. Thanks a lot.
Upgrade your wardrobe with elegant pieces from pistola jeans sale.
A fascinating discussion is worth comment. I believe that you should publish more about this subject matter, it may not be a taboo subject but typically people don’t talk about such topics. To the next! Kind regards!
I was very happy to uncover this page. I want to to thank you for ones time just for this wonderful read!! I definitely really liked every part of it and i also have you book marked to see new stuff in your website.
This website was… how do I say it? Relevant!! Finally I have found something that helped me. Thank you.
срочный ремонт телефонов рядом
ремонт телефонов
ремонт телефонов москва
ремонт iphone сервисный центр
ремонт смартфонов рядом
Thank you great posting about essential oil. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
мастерская по ремонту сотовых телефонов
Next time I read a blog, Hopefully it does not fail me just as much as this one. I mean, I know it was my choice to read through, nonetheless I really believed you would probably have something useful to talk about. All I hear is a bunch of moaning about something that you could possibly fix if you were not too busy seeking attention.
Good post. I learn something new and challenging on blogs I stumbleupon on a daily basis. It will always be exciting to read through articles from other authors and use a little something from other web sites.
lasix furosemide: lasix for sale – buy lasix online
п»їcytotec pills online http://furosemide.win/# lasix dosage
lasix medication
Pretty! This was an incredibly wonderful post. Thank you for providing these details.
A motivating discussion is worth comment. I do believe that you ought to publish more about this subject matter, it may not be a taboo subject but generally folks don’t talk about these subjects. To the next! Best wishes.
I wanted to thank you for this excellent read!! I certainly enjoyed every bit of it. I’ve got you bookmarked to check out new stuff you post…
You’ve articulated this issue perfectly.프라그마틱
сервисный ремонт apple
lasix 40mg: cheap lasix – lasix for sale
Good day! I could have sworn I’ve been to this website before but after browsing through some of the articles I realized it’s new to me. Anyhow, I’m certainly happy I stumbled upon it and I’ll be book-marking it and checking back regularly!
ремонт смартфонов москва
ремонт смартфонов
lisinopril 250mg: Lisinopril refill online – lisinopril without rx
This page truly has all the information and facts I wanted about this subject and didn’t know who to ask.
I was very happy to uncover this great site. I wanted to thank you for your time for this wonderful read!! I definitely enjoyed every part of it and i also have you book marked to see new information on your site.
buy cytotec over the counter http://tamoxifen.bid/# tamoxifen warning
lasix 40mg
центры ремонта iphone
мастер iphone москва