目录
环境
想法
- 由于挖矿很费性能,对于手上的垃圾服务器来说,要挂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
![](https://blog.coolight.cool/wp-content/uploads/2022/02/image.png)
- -
- 在主节点添加副节点的enode
- >admin.addPeer("encode")
- 在主节点添加副节点的enode
![](https://blog.coolight.cool/wp-content/uploads/2022/02/image-1.png)
- 查看是否添加成功
- 方法1:
- 直接对比两者的块高度看看是否相等,如果块比较多,可能需要等待一下同步。
- > eth.blockNumber
- 方法2:
- net.peerCount
- admin.peers
- 方法1:
- 让副节点代替主节点挖矿
- 把主节点挖矿停掉,在主节点所在机执行:
- > miner.stop()
- 让副节点挖矿,在副节点所在机执行:
- > miner.start()
- 把主节点挖矿停掉,在主节点所在机执行:
修改java程序连接副节点
- 上一篇的文章:java使用web3j调用以太坊私链上的智能合约
- 上文中讲到,java程序连接单节点(主节点)的私链去调用智能合约。
- 注意:
- 如果不修改的话,此时主节点虽然开着geth,但关闭了挖矿,只能和副节点进行数据同步,而连接主节点发送的请求都是不能执行的。
- 而且主节点的geth不能关闭,否则副节点也会出问题。
- 不要在开着geth的时候直接关闭ssh窗口,否则会导致链的数据丢失,要在geth里执行> exit 退出。
- 复制副节点的用户私钥文件到java程序执行的机子上,
![](https://blog.coolight.cool/wp-content/uploads/2022/02/image-2.png)
- 修改java程序使用这个私钥文件,并把用户地址也改成这个私钥文件的用户。
- 修改java程序连接副节点所在的服务器ip地址。
- 到这里就可以了,如此就实现了让副节点代替主节点挖矿的任务了。
存在的问题
- 主节点的账号是不能在连接副节点后使用的,也就是说,两个节点实际上只有链上的数据是互通的,账号是不互通的。因此java程序连接副节点时需要修改。
- 此时主节点只能同步数据,不能挖矿,连接到主节点后发送的交易并不会由副节点代替挖矿完成。
The next time I read a blog, Hopefully it doesn’t disappoint me as much as this one. After all, Yes, it was my choice to read through, but I actually thought you’d have something interesting to say. All I hear is a bunch of complaining about something you could possibly fix if you weren’t too busy searching for attention.
http://ciprodelivery.pro/# ciprofloxacin over the counter
cipro: cipro 500mg best prices – buy cipro online without prescription
After checking out a few of the blog articles on your site, I truly like your technique of blogging. I book marked it to my bookmark site list and will be checking back in the near future. Take a look at my website too and let me know how you feel.
Hi, There’s no doubt that your website might be having web browser compatibility problems. When I take a look at your web site in Safari, it looks fine however, if opening in Internet Explorer, it has some overlapping issues. I simply wanted to provide you with a quick heads up! Apart from that, excellent website!
Hello there! I just would like to give you a huge thumbs up for the great information you’ve got right here on this post. I’ll be coming back to your blog for more soon.
http://paxloviddelivery.pro/# Paxlovid buy online
When I originally commented I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on every time a comment is added I receive 4 emails with the exact same comment. Is there a way you can remove me from that service? Cheers.
http://paxloviddelivery.pro/# Paxlovid over the counter
Hi! I simply wish to offer you a big thumbs up for the excellent info you have got right here on this post. I will be coming back to your site for more soon.
Aw, this was a really good post. Spending some time and actual effort to generate a superb article… but what can I say… I procrastinate a lot and never manage to get anything done.
where can i buy generic clomid without prescription: can you buy clomid without prescription – can i get clomid pill
https://ciprodelivery.pro/# where can i buy cipro online
After looking into a few of the blog posts on your web page, I really appreciate your way of blogging. I bookmarked it to my bookmark website list and will be checking back in the near future. Please visit my web site too and tell me your opinion.
I was able to find good info from your blog posts.
paxlovid india: paxlovid india – paxlovid price
Hi! I just would like to offer you a big thumbs up for the excellent info you have got here on this post. I will be returning to your blog for more soon.
Good article. I definitely love this website. Continue the good work!
https://clomiddelivery.pro/# cost of generic clomid tablets
That is a good tip particularly to those fresh to the blogosphere. Short but very precise information… Many thanks for sharing this one. A must read post.
Hi there! This article could not be written any better! Reading through this article reminds me of my previous roommate! He continually kept preaching about this. I most certainly will send this post to him. Pretty sure he’ll have a very good read. Many thanks for sharing!
buy generic ciprofloxacin: cipro for sale – buy cipro without rx
It’s hard to find knowledgeable people about this subject, however, you seem like you know what you’re talking about! Thanks
Howdy! This article couldn’t be written any better! Looking through this article reminds me of my previous roommate! He always kept talking about this. I’ll send this post to him. Fairly certain he’ll have a good read. Many thanks for sharing!
http://amoxildelivery.pro/# amoxicillin generic brand
can you get cheap clomid without prescription: cost of clomid without prescription – cost of generic clomid without dr prescription
Полностью важные события модного мира.
Все новости самых влиятельных подуимов.
Модные дома, торговые марки, haute couture.
Лучшее место для трендовых людей.
https://mvmedia.ru/novosti/282-vybiraem-puhovik-herno-podrobnyy-gayd/
I’d like to thank you for the efforts you’ve put in penning this blog. I’m hoping to view the same high-grade content from you in the future as well. In truth, your creative writing abilities has motivated me to get my own blog now 😉
When I originally commented I seem to have clicked on the -Notify me when new comments are added- checkbox and now every time a comment is added I get 4 emails with the exact same comment. Is there an easy method you are able to remove me from that service? Appreciate it.
doxycycline 1000 mg best buy: doxycycline 75 mg tab – buy doxycycline in india
https://ciprodelivery.pro/# ciprofloxacin 500 mg tablet price
Good day! I just wish to give you a big thumbs up for the great information you have here on this post. I’ll be returning to your web site for more soon.
I really love your site.. Great colors & theme. Did you build this website yourself? Please reply back as I’m planning to create my own blog and would like to know where you got this from or what the theme is called. Kudos!
I really like reading an article that will make people think. Also, thank you for allowing for me to comment.
ciprofloxacin generic price: buy cipro online without prescription – buy generic ciprofloxacin
https://clomiddelivery.pro/# how to get cheap clomid prices
You made some decent points there. I looked on the net for additional information about the issue and found most people will go along with your views on this website.
After going over a few of the articles on your blog, I truly like your way of writing a blog. I book marked it to my bookmark website list and will be checking back in the near future. Please visit my web site as well and let me know what you think.
Greetings! Very useful advice within this article! It is the little changes which will make the largest changes. Many thanks for sharing!
You have made some good points there. I looked on the net for additional information about the issue and found most people will go along with your views on this website.
ciprofloxacin over the counter: cipro online no prescription in the usa – buy generic ciprofloxacin
http://amoxildelivery.pro/# amoxicillin 500 mg
Your style is really unique in comparison to other folks I’ve read stuff from. I appreciate you for posting when you have the opportunity, Guess I’ll just book mark this blog.
Good article! We will be linking to this particularly great article on our site. Keep up the good writing.
india online pharmacy: п»їlegitimate online pharmacies india – best india pharmacy
https://foruspharma.com/# mexico pharmacies prescription drugs
It’s nearly impossible to find educated people on this topic, however, you sound like you know what you’re talking about! Thanks
Online medicine home delivery: top online pharmacy india – cheapest online pharmacy india
Oh my goodness! Awesome article dude! Thank you, However I am going through problems with your RSS. I don’t know the reason why I am unable to subscribe to it. Is there anybody else getting similar RSS issues? Anyone that knows the solution can you kindly respond? Thanks.
indian pharmacy online: buy prescription drugs from india – top 10 online pharmacy in india