目录
环境
想法
- 由于挖矿很费性能,对于手上的垃圾服务器来说,要挂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程序连接副节点时需要修改。
- 此时主节点只能同步数据,不能挖矿,连接到主节点后发送的交易并不会由副节点代替挖矿完成。
Hi, I do believe this is an excellent site. I stumbledupon it 😉 I will come back once again since i have book marked it. Money and freedom is the best way to change, may you be rich and continue to guide other people.
Everything is very open with a clear clarification of the challenges. It was really informative. Your website is very useful. Thank you for sharing!
Веном 3 фильм https://bit.ly/venom-3-venom-2024
Веном 3 кино https://bit.ly/venom-3-venom-2024
I’m impressed, I must say. Seldom do I encounter a blog that’s both educative and engaging, and let me tell you, you have hit the nail on the head. The issue is something which too few folks are speaking intelligently about. Now i’m very happy that I found this during my search for something concerning this.
Howdy, I think your website might be having internet browser compatibility issues. Whenever I look at your website in Safari, it looks fine however when opening in IE, it has some overlapping issues. I simply wanted to give you a quick heads up! Other than that, wonderful blog.
There is certainly a great deal to learn about this subject. I like all the points you have made.
Веном 3 онлайн https://bit.ly/venom-3-venom-2024
Веном 3 онлайн https://bit.ly/venom-3-venom-2024
Hey! Someone in my Myspace group shared this website with us so I came to take a look.
I’m definitely enjoying the information. I’m book-marking and
will be tweeting this to my followers! Exceptional blog and brilliant design and style.
Feel free to surf to my blog – homepage
online ed medication no prescription
An interesting discussion is definitely worth comment. I do think that you need to publish more about this subject matter, it may not be a taboo subject but usually folks don’t speak about such subjects. To the next! All the best!
Spot on with this write-up, I actually feel this web site needs a great deal more attention. I’ll probably be returning to see more, thanks for the advice!
I enjoy reading through a post that will make people think. Also, thank you for allowing for me to comment.
Good blog you’ve got here.. It’s hard to find excellent writing like yours nowadays. I seriously appreciate individuals like you! Take care!!
After exploring a few of the blog articles on your web page, I really like your technique of writing a blog. I book-marked it to my bookmark webpage list and will be checking back soon. Take a look at my website as well and tell me how you feel.
Very good post. I’m facing a few of these issues as well..
Hi, I do think this is a great website. I stumbledupon it 😉 I am going to come back yet 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.
Hey there! I just want to offer you a big thumbs up for your great info you’ve got here on this post. I will be returning to your website for more soon.
Enhance your style with trendy shoes and clothing from ayouba.com.
Having read this I believed it was rather informative. I appreciate you finding the time and effort to put this information together. I once again find myself spending way too much time both reading and leaving comments. But so what, it was still worth it!
You made some decent points there. I checked on the internet for more information about the issue and found most individuals will go along with your views on this website.
https://artdaily.com/news/171650/Mp3Juice-Review–The-Pros-and-Cons-You-Need-to-Know
This is a good tip especially to those new to the blogosphere. Brief but very precise info… Many thanks for sharing this one. A must read post!
Точно важные новинки моды.
Все новости лучших подуимов.
Модные дома, бренды, высокая мода.
Свежее место для трендовых хайпбистов.
https://modastars.ru/
You’ve made some good points there. I looked on the internet to find out more about the issue and found most people will go along with your views on this site.
Spot on with this write-up, I actually think this amazing site needs much more attention. I’ll probably be returning to see more, thanks for the info.
Excellent post. I certainly love this site. Continue the good work!
Hello, I do think your blog could be having browser compatibility issues. When I take a look at your site in Safari, it looks fine however when opening in Internet Explorer, it’s got some overlapping issues. I merely wanted to provide you with a quick heads up! Apart from that, excellent website.
bookmarked!!, I love your web site!
Duplicity is a nice movie,i like the story and also the actors.
Some truly interesting information, well written and broadly user pleasant.
Greetings! Very useful advice within this post! It’s the little changes that will make the most significant changes. Thanks for sharing!
Thank you, I have recently been searching for info approximately this topic for ages and yours is the greatest I’ve came upon till now. But, what concerning the bottom line? Are you certain concerning the supply?
I conceive this website has very wonderful indited content material posts .
Oh my goodness! an amazing write-up dude. Thanks Nevertheless We are experiencing issue with ur rss . Do not know why Struggling to register for it. Possibly there is anyone obtaining identical rss difficulty? Anybody who knows kindly respond. Thnkx
News on why News became valuable to most of people.
We would also like to convey that most individuals that find themselves without the need of health insurance can be students, self-employed and people who are out of work. More than half in the uninsured are under the age of Thirty five. They do not experience they are wanting health insurance as they are young in addition to healthy. Their particular income is generally spent on housing, food, and entertainment. Many people that do go to work either entire or in their free time are not given insurance via their work so they proceed without because of the rising tariff of health insurance in america. Thanks for the concepts you reveal through this site.
An extremely fascinating go through, I may not concur entirely, however you do make some really legitimate factors.
Hello There. I found your blog using msn. This is a really well written article. I’ll be sure to bookmark it and return to read more of your useful information. Thanks for the post. I’ll certainly comeback.
dance schools that also offers free yoga classes would be very very nice’
The great intreguing web pages retain me coming here again and again. thank you a great deal.
there are dining sets come in wide variety and prices, i often get the lower priced ones,
Awesome post admin… May I ask what theme are you using on your blog? Where did you get it? Looks cool
You completed certain fine points there. I did a search on the matter and found most persons will have the same opinion with your blog.
As I web-site possessor I believe the content material here is rattling wonderful , appreciate it for your efforts. You should keep it up forever! Best of luck. Rent a car kosova
I was searching on the net for some info since yesterday night and I at last found this! This is a great webpage by the way, but it looks a little difficult to read from my android phone.
Right here is the perfect web site for anyone who wishes to understand this topic. You know a whole lot its almost tough to argue with you (not that I really would want to…HaHa). You definitely put a brand new spin on a topic that’s been discussed for many years. Wonderful stuff, just wonderful.
I’m more than happy to uncover this web site. I wanted to thank you for ones time for this particularly fantastic read!! I definitely loved every bit of it and I have you book-marked to see new stuff in your blog.
There is noticeably a lot of money to know about this. I assume you have made specific nice points in features also.