目录
环境
想法
- 由于挖矿很费性能,对于手上的垃圾服务器来说,要挂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程序连接副节点时需要修改。
- 此时主节点只能同步数据,不能挖矿,连接到主节点后发送的交易并不会由副节点代替挖矿完成。
Hello there! This blog post couldn’t be written much better! Looking at this post reminds me of my previous roommate! He always kept talking about this. I will forward this post to him. Fairly certain he’ll have a great read. Thanks for sharing!
Having read this I thought it was extremely enlightening. I appreciate you finding the time and energy to put this short article together. I once again find myself personally spending way too much time both reading and posting comments. But so what, it was still worthwhile!
This is a very good tip especially to those fresh to the blogosphere. Short but very accurate information… Thanks for sharing this one. A must read post.
buy cytotec in usa http://lisinopril.guru/# lisinopril 10mg
furosemida 40 mg
Discover unique fashion pieces at citizens of humanity.
buy lipitor with mastercard: Lipitor 10 mg price – how much is lipitor discount
Good info. Lucky me I reach on your website by accident, I bookmarked it. Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Наиболее актуальные события модного мира.
Абсолютно все эвенты известнейших подуимов.
Модные дома, бренды, высокая мода.
Приятное место для стильныех людей.
https://irkutsk.rftimes.ru/news/2024-06-05-v-irkutskoy-oblasti-proizoshlo-zemletryasenie-magnitudoy-4-8
You ought to be a part of a contest for one of the finest sites on the web. I will recommend this web site!
buy lipitor 10mg: buy lipitor 20mg – order lipitor
There is definately a great deal to know about this subject. I love all the points you have made.
purchase cytotec https://furosemide.win/# lasix furosemide 40 mg
furosemide 100 mg
https://tamoxifen.bid/# tamoxifen alternatives
I was excited to uncover this page. I wanted to thank you for your time just for this wonderful read!! I definitely really liked every part of it and I have you bookmarked to look at new things on your website.
You are so awesome! I don’t suppose I’ve truly read through anything like this before. So nice to find somebody with a few original thoughts on this topic. Seriously.. many thanks for starting this up. This site is one thing that’s needed on the web, someone with a little originality.
tamoxifen: effexor and tamoxifen – aromatase inhibitors tamoxifen
Ford Rhodes Parks & Co., ITC Classic Finance Ltd., and Abu Dhabi Commercial Bank, where he was a team leader of NRI Portfolio Management and Depository Services.
purchase cytotec https://lipitor.guru/# lipitor 10mg price singapore
lasix 100 mg tablet
Greetings! Very helpful advice in this particular article! It is the little changes which will make the biggest changes. Thanks a lot for sharing!
Good post. I learn something totally new and challenging on websites I stumbleupon everyday. It’s always useful to read content from other authors and practice something from other websites.
buy furosemide online: buy furosemide – furosemide
It also handles citizens’ settlement claims for personal and property damage caused by the military exercises of foreign military forces stationed in Germany.
Ostrava’s asset management and superannuation services can help you set up, administer and execute investment strategies for your funds, including estate planning for your Self Managed Superannuation Fund (SMSF).
сервисный ремонт айфонов в москве
39/2008 on State Ministries mandated that a ministry must have specific function and responsibilities and also must have minimum number of directorates and other ministerial apparatuses, thus formation of minister without portfolio is currently unlikely in post-Reformation Indonesia.
The software makes it a simple task to determine who needs access to what aspects of the brand and when access may be gained.
lipitor 40: Atorvastatin 20 mg buy online – generic cost of lipitor
furosemide lasix generic name lasix furosemide
ремонт телефонов айфон в москве адреса
bookmarked!!, I really like your web site.
buy cytotec pills https://cytotec.pro/# cytotec buy online usa
lasix medication
Hey there! I just wish to give you a huge thumbs up for your great information you’ve got here on this post. I’ll be coming back to your web site for more soon.
The current yield refers only to the yield of the bond at the current moment.
generic lipitor cost: Lipitor 10 mg price – lipitor generic
сервисный центр iphone в москве адреса
You’re so cool! I don’t suppose I’ve truly read a single thing like that before. So wonderful to discover somebody with a few genuine thoughts on this issue. Really.. many thanks for starting this up. This web site is something that is needed on the internet, someone with a bit of originality.
I’m amazed, I have to admit. Rarely do I come across a blog that’s both educative and interesting, and let me tell you, you have hit the nail on the head. The problem is something too few people are speaking intelligently about. I’m very happy that I stumbled across this during my hunt for something relating to this.
Bucketing can take place in a couple of different ways.
Hi, I do believe this is a great website. I stumbledupon it 😉 I will come back 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 other people.
Handbook of Digital Currency: Bitcoin, Innovation, Financial Instruments, and Big Data.
Very good blog post. I definitely love this site. Thanks!
Brunei investors bought The Dorchester on Park Lane in London in 1985 for US$50 million and in 1996 BIA formed the Dorchester Collection, a conglomerate of luxury hotels in UK, United States, France and Italy.
It suggests that it is the perfect time to gather with your loved ones and celebrate special occasions or simply enjoy each other’s company.
сервисный центр по ремонту айфонов в москве
Discover exclusive collections at stussy jeans.
You are so cool! I do not think I’ve read through a single thing like this before. So good to find someone with genuine thoughts on this subject matter. Really.. many thanks for starting this up. This site is one thing that’s needed on the web, someone with a bit of originality.
alternatives to tamoxifen: buy tamoxifen citrate – tamoxifen estrogen
buy cytotec in usa https://tamoxifen.bid/# how to get nolvadex
lasix 40mg
I love it when people get together and share views. Great blog, keep it up.
When I originally commented I seem to have clicked the -Notify me when new comments are added- checkbox and now every time a comment is added I receive four emails with the exact same comment. Is there a way you are able to remove me from that service? Appreciate it.