目录
环境
想法
- 由于挖矿很费性能,对于手上的垃圾服务器来说,要挂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程序连接副节点时需要修改。
- 此时主节点只能同步数据,不能挖矿,连接到主节点后发送的交易并不会由副节点代替挖矿完成。
Thank you for great information. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
best price for cialis 20 mg: Generic Tadalafil 20mg price – cialis paypall
I’m amazed, I have to admit. Rarely do I come across a blog that’s both educative and entertaining, and let me tell you, you have hit the nail on the head. The problem is something not enough people are speaking intelligently about. I am very happy that I found this in my hunt for something concerning this.
how to get cialis prescription: canadian pharmacy cialis – viagra cialis melbourne site:au
I love it when people get together and share ideas. Great website, stick with it.
http://sildenafil.llc/# buy viagra generic
Hi, I do believe this is an excellent site. I stumbledupon it 😉 I will revisit yet again since i have bookmarked it. Money and freedom is the greatest way to change, may you be rich and continue to help other people.
Thank you for great content. Hello Administ. Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Good article. I’m going through some of these issues as well..
Hi, I do believe this is a great web site. I stumbledupon it 😉 I am going to come back once again since I bookmarked it. Money and freedom is the best way to change, may you be rich and continue to help other people.
Everything is very open and very clear explanation of issues. was truly information.Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Thank you for great article. Hello Administ .Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me.Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Thank you for content. Area rugs and online home decor store. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Nice article inspiring thanks. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Thank you great posting about essential oil. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me.Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Good info. Lucky me I reach on your website by accident, I bookmarked it. Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Thank you for content. Area rugs and online home decor store. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Thank you for great article. Hello Administ .Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Thank you for great article. Hello Administ .Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
lowest price generic cialis: cheapest tadalafil – can i take cialis and viagra together
Стоимость разработки дизайн проекта mudryakova.ru
По теме дизайн ванной комнаты Вы на правильном пути. Чтобы начать с нами работать, достаточно оформить заявку на онлайн портале mudryakova.ru или позвонить по телефону +7(812)408-00-07. Главный офис находится по адресу: г. Санкт-Петербург, ул. Мебельная, д. 49/92. График работы с пн по пт с 9:00 до 19:00. Фотографии выполненных нами дизайн-проектов можно увидеть на отмеченном сайте, также территориально. Работаем как под ключ, также оказываем отдельные виды услуг.
Pretty! This has been a really wonderful post. Many thanks for supplying these details.
https://cpaday.com.ua/yak-vibrati-naykrashchiy-lentochniy-germetik-dlya-far-poradi-i-rekomendatsiyi
Howdy! This article couldn’t be written much better! Looking through this article reminds me of my previous roommate! He always kept preaching about this. I’ll forward this information to him. Pretty sure he’s going to have a great read. Thanks for sharing!
Everything is very open with a clear explanation of the issues. It was truly informative. Your site is very useful. Thanks for sharing!
order generic cialis by phone: Generic Tadalafil 20mg price – cialisblack
Greetings! Very useful advice within this post! It’s the little changes that make the most important changes. Many thanks for sharing!
Everything is very open with a precise explanation of the issues. It was really informative. Your site is very useful. Thank you for sharing!
Авария — это всегда стресс и удар по эмоциональному состоянию. Но когда все утихает, остаётся битый автомобиль, который напоминает о неприятном событии. Не позволяйте прошлому тянуть вас назад! На tvoy-auto.ru мы предлагаем услугу выкупа аварийных битых автомобилей, чтобы вы могли быстро и без лишних забот избавиться от этого груза.
Мы понимаем, что ваше главное желание сейчас — закрыть эту страницу жизни и начать новую. Именно поэтому мы готовы взять на себя все заботы, связанные с выкупом аварийного автомобиля. Мы предложим вам достойную цену и обеспечим оперативный процесс, чтобы вы могли как можно скорее оставить неприятные моменты позади.
Пусть ваш битый автомобиль перестанет быть проблемой — доверьте его нам, и мы позаботимся обо всем. С tvoy-auto.ru вы сможете с легкостью расстаться с прошлым и сделать шаг навстречу новым возможностям и новым дорогам в вашей жизни.
cialis professional: cialis pills for sale – cialis ontario no prescription
https://tadalafil.auction/# cialis цена
cialis quebec dollars canadien: Generic Tadalafil 20mg price – cialis grapefruit interaction
acquisto farmaci con ricetta: Avanafil prezzo – comprare farmaci online con ricetta
http://avanafil.pro/# farmacia online piГ№ conveniente
dove acquistare viagra in modo sicuro: viagra online siti sicuri – viagra 100 mg prezzo in farmacia
Farmacia online miglior prezzo: kamagra oral jelly consegna 24 ore – farmaci senza ricetta elenco
Farmacia online piГ№ conveniente: Farmacie on line spedizione gratuita – Farmacie on line spedizione gratuita
Greetings! Very useful advice in this particular article! It is the little changes that produce the biggest changes. Thanks a lot for sharing!
Hello! I simply wish to give you a big thumbs up for your excellent information you have right here on this post. I’ll be returning to your web site for more soon.
Несомненно актуальные новости индустрии.
Абсолютно все новости всемирных подуимов.
Модные дома, бренды, haute couture.
Приятное место для трендовых людей.
https://stylecross.ru/read/2024-06-19-lacoste-kachestvennyy-premium-po-tsene-mass-marketa/
farmacia online senza ricetta: Farmacia online migliore – farmacia online piГ№ conveniente
http://kamagrait.pro/# п»їFarmacia online migliore
Farmacia online miglior prezzo: kamagra gold – top farmacia online
I’m always excited to see The posts in my feed. Another excellent article!