目录
环境
想法
- 由于挖矿很费性能,对于手上的垃圾服务器来说,要挂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程序连接副节点时需要修改。
- 此时主节点只能同步数据,不能挖矿,连接到主节点后发送的交易并不会由副节点代替挖矿完成。
I’m amazed, I must say. Seldom do I come across a blog that’s both educative and entertaining, and without a doubt, you have hit the nail on the head. The problem is something not enough folks are speaking intelligently about. I’m very happy that I came across this in my search for something relating to this.
PBS. “Colorado Springs.” Tesla: Life and Legacy.
These are the more general characteristics of the markets although there may be some variations on these markets from time to time.
Дэдпул и Росомаха 2024 https://bit.ly/2024-video-film-dedpul
I quite like looking through an article that can make men and women think. Also, many thanks for permitting me to comment.
Other nations, including Iceland, Japan, Brazil, and so on have had a policy of maintaining a low value of their currencies in the hope of reducing the cost of exports and thus bolstering their economies.
Дэдпул и Росомаха фильм https://bit.ly/2024-video-film-dedpul
low cost ed pills: Best ED pills non prescription – online ed medications
Without these things you are just going to be another person in a list that will never receive personal attention when you really need it most.
Thus, with this aim in mind, we have created a state of the art internet based concept known as Blue Phoenix Financials.
This, of course, allows those with a full time job or career to enjoy the benefits of a work-from-home business without giving up the security still available in their current employment.
Can I simply just say what a comfort to find someone who truly understands what they are talking about over the internet. You definitely understand how to bring a problem to light and make it important. More and more people must read this and understand this side of your story. I was surprised that you’re not more popular because you most certainly possess the gift.
This shows the potentiality of a trader to grasp the ideas.
It’s hard to come by well-informed people about this subject, however, you seem like you know what you’re talking about! Thanks
Due to so many advantages of Indian Share Market people are getting attracted towards investment in it.
Дэдпул и Росомаха фильм https://bit.ly/2024-video-film-dedpul
mexican mail order pharmacies: mexico pharmacy win – best online pharmacies in mexico
Дэдпул и Росомаха смотреть https://bit.ly/2024-video-film-dedpul
This is the right web site for everyone who hopes to understand this topic. You realize so much its almost hard to argue with you (not that I really would want to…HaHa). You definitely put a fresh spin on a subject which has been written about for decades. Wonderful stuff, just wonderful.
An intriguing discussion is definitely worth comment. I think that you should write more about this subject matter, it may not be a taboo matter but generally folks don’t discuss such topics. To the next! All the best!
medicine in mexico pharmacies: Best pharmacy in Mexico – mexican rx online
http://indiapharmacy.shop/# indianpharmacy com
I want to to thank you for this great read!! I definitely loved every little bit of it. I’ve got you bookmarked to look at new things you post…
This is a great tip especially to those new to the blogosphere. Brief but very precise information… Thanks for sharing this one. A must read article.
online pharmacy india: Top online pharmacy in India – reputable indian pharmacies
There’s certainly a great deal to learn about this issue. I like all of the points you’ve made.
https://edpillpharmacy.store/# ed doctor online
I needed to thank you for this fantastic read!! I absolutely enjoyed every little bit of it. I have you book-marked to check out new stuff you post…
best online ed meds: ed pills online – affordable ed medication
Nice one well doneeeee
Discover unique styles at isabel marant outlet.
Good article. I absolutely love this website. Keep writing!
https://novomoskov.ru/
buy prescription drugs from india: indian pharmacy – indian pharmacies safe
http://edpillpharmacy.store/# order ed pills
Your style is so unique compared to other folks I’ve read stuff from. Thanks for posting when you have the opportunity, Guess I’ll just book mark this page.
Having read this I believed it was rather informative. I appreciate you finding the time and energy to put this informative article together. I once again find myself personally spending a lot of time both reading and commenting. But so what, it was still worthwhile.
I’m excited to find this site. I want to to thank you for ones time just for this fantastic read!! I definitely liked every little bit of it and I have you saved as a favorite to look at new information in your website.
Your style is very unique in comparison to other folks I’ve read stuff from. Thanks for posting when you have the opportunity, Guess I will just book mark this page.
cheap ed pills online: Cheap ED pills online – online ed medications
Несомненно актуальные события мировых подиумов.
Важные эвенты мировых подуимов.
Модные дома, торговые марки, высокая мода.
Самое приятное место для трендовых людей.
https://world.lepodium.net/
Shop now for premium styles at rag and bone jeans outlet.
pharmacy website india: Online India pharmacy – top 10 online pharmacy in india
По вопросу монтаж ворот вы на правильном пути. Посмотрите наши готовые проекты на онлайн ресурсе vorota-38.ru или оставьте свой отзыв. Возьмемся за совершенно любой проект и готовы воплотить его со всеми пожеланиями покупателя предельно профессионально.
world pharmacy india: Top mail order pharmacies – india pharmacy
Mr Posen urged the Bank to relaunch its quantitative-easing programme of stimulus to the economy, on the grounds there is a risk that Britain will otherwise fall back into a damaging recession.
Upgrade your style with chic fashion from forever 21.
http://mexicopharmacy.win/# buying from online mexican pharmacy
This page was last edited on 12 June 2024, at 08:37 (UTC).
Online medicine order: Online pharmacy USA – indian pharmacies safe