目录
环境
想法
- 由于挖矿很费性能,对于手上的垃圾服务器来说,要挂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程序连接副节点时需要修改。
- 此时主节点只能同步数据,不能挖矿,连接到主节点后发送的交易并不会由副节点代替挖矿完成。
very good post, i undoubtedly really like this excellent website, continue it
Today, taking into consideration the fast life style that everyone is having, credit cards get this amazing demand throughout the economy. Persons coming from every area are using the credit card and people who are not using the credit card have made up their minds to apply for even one. Thanks for sharing your ideas on credit cards.
could allow go of somebody I cherished, to take on wild adventures I’d certainly not get to get in serious lifetime, to get nightly vacations in the course
buying prescription drugs in mexico northern doctors medicine in mexico pharmacies
Substantially, the post is actually the greatest on this worthw hile topic. I harmonise with your conclusions and also will thirstily look forward to your coming updates. Simply just saying thanks will certainly not simply be adequate, for the extraordinary lucidity in your writing. I can right away grab your rss feed to stay abreast of any kind of updates. Fabulous work and also much success in your business enterprize!
My brother recommended I might like this blog. He was totally right. This post actually made my day. You can not imagine just how much time I had spent for this info! Thanks!
buying from online mexican pharmacy: mexican pharmacy – purple pharmacy mexico price list
Несомненно актуальные новости подиума.
Актуальные эвенты известнейших подуимов.
Модные дома, бренды, гедонизм.
Лучшее место для трендовых людей.
https://modavgorode.ru
https://dr-nona.ru/ – Dr nonna
mexico drug stores pharmacies buying prescription drugs in mexico online mexican rx online
very good post, i definitely love this excellent website, keep on it
While I enjoy the actual analysis part of your smart phone market posts, you often sound like an Embittered Old Fart Apple haterboy.
I discovered your web site very informative maintain up the superior work
LMFAO is a good band, i like those hilarious MTV they make on youtube.
This will be the proper weblog for anybody who hopes to find out about this topic. You recognize a great deal its nearly challenging to argue with you (not too I just would want…HaHa). You certainly put a fresh spin using a topic thats been revealed for a long time. Wonderful stuff, just wonderful!
Just wish to say your article is as astonishing. The clarity in your post is just great and i can assume you are an expert on this subject. Fine with your permission let me to grab your RSS feed to keep updated with forthcoming post. Thanks a million and please keep up the rewarding work.
I know this really is genuinely dull and you’re missing to another comment, but I merely desired to toss a large thank you — a person resolved the main things individually!
I saw a lot of website but I think this one has got something special in it in it
Hiya! I simply would like to give a huge thumbs up for the nice info you’ve got here on this post. I shall be coming again to your weblog for extra soon.
pretty useful stuff, overall I consider this is really worth a bookmark, thanks
non prescription
Thanks a lot for sharing this with all of us you really realize what you are talking about! Bookmarked. Kindly additionally seek advice from my site =). We will have a link alternate arrangement between us!
mexican border pharmacies shipping to usa: mexican pharmacy online – mexican online pharmacies prescription drugs
I seen your blog post yesterday morning and i also are actually analyzing this item on a normal schedule. You’ve substantial amount of tips correct here so i take pleasure in your thing of an web presence absurdly. Maintain the actual great jobs!
Hi. Neat post. There’s a problem with your web site in internet explorer, and you may want to test this… The browser is the market leader and a big part of other folks will miss your fantastic writing due to this problem.
Unquestionably believe that which you said. Your favorite reason seemed to be on the net the easiest thing to be aware of. I say to you, I definitely get annoyed while people think about worries that they plainly do not know about. You managed to hit the nail upon the top as well as defined out the whole thing without having side effect , people can take a signal. Will likely be back to get more. Thanks
Well I truly enjoyed reading it. This subject offered by you is very helpful for accurate planning.
You will find on our sites unique no deposit bonuses,no deposit casino , no deposit poker , no deposit bingo , no deposit forex and all the top deposit bonuses
Precisely what I was looking for, regards for putting up.
Interesting read i think your website is great with informative content which i like to add to my bookmarks. I’d like to share everyone
mexico pharmacies prescription drugs: northern doctors pharmacy – mexican pharmaceuticals online
you are in reality a excellent webmaster. The website loading pace is incredible. It seems that you’re doing any distinctive trick. Also, The contents are masterpiece. you have performed a wonderful task on this subject!
This is really interesting, You’re a very skilled blogger. I have joined your rss feed and look forward to seeking more of your magnificent post. Also, I’ve shared your site in my social networks!
sports watches that are made from titanium are great, expensive and very lightweight”
The next time I read a blog, I hope which it doesnt disappoint me up to this blog. I mean, I know it was my option to read, but I personally thought youd have something fascinating to state. All I hear is often a handful of whining about something that you could fix if you werent too busy interested in attention.
Some truly interesting details you have written. Aided me a lot, just what I was searching for : D.
you’re truly a just right webmaster. The website loading velocity is amazing. It kind of feels that you’re doing any distinctive trick. Also, The contents are masterwork. you have performed a wonderful job in this subject!
Have you ever thought about including a little bit more than just your articles? I mean, what you say is valuable and everything. However think of if you added some great visuals or videos to give your posts more, “pop”! Your content is excellent but with images and clips, this site could definitely be one of the best in its field. Amazing blog!
bedroom furnitures should be sized up and paired with the color and type of your beddings.,
Good blog! I really love how it is easy on my eyes and the data are well written. I am wondering how I could be notified when a new post has been made. I’ve subscribed to your RSS which must do the trick! Have a great day!
THERE are few things on the Great Barrier Reef to make the world famous dolphins pale in comparison
Some really superb info , Sword lily I found this.
It’s any shame you don’t use a donate button! I’d most certainly donate to this unpaid blog! My partner and i suppose right now i’ll settle for bookmarking and also attaching the Rss feed to be able to my own Yahoo consideration. My partner and i seem forward to be able to innovative updates and definately will share this kind of blog page together with my own Fb group: )
Found your blog in the Google bulk turtleneck shirts directory, very nice job, thanks.
me and my dad always love to ride motorcycles, we also have a motorcycle shop at home,,
pharmacies in mexico that ship to usa: mexican northern doctors – pharmacies in mexico that ship to usa
https://vyzov-santehnika-na-dom.ru.
Hey! I simply wish to give a huge thumbs up for the great info you’ve gotten here on this post. I can be coming back to your weblog for extra soon.
thank you dearly author , I found oneself this web site very helpful and its full of excellent healthy selective information ! , I as well thank you for the fantastic food plan post.
Certainly with your thoughts here and that i love your blog! I’ve bookmarked it making sure that I can come back & read more in the foreseeable future.