目录
环境
想法
- 由于挖矿很费性能,对于手上的垃圾服务器来说,要挂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程序连接副节点时需要修改。
- 此时主节点只能同步数据,不能挖矿,连接到主节点后发送的交易并不会由副节点代替挖矿完成。
Профессиональный сервисный центр по ремонту квадрокоптеров и радиоуправляемых дронов.
Мы предлагаем:ремонт дронов москва
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
canada discount pharmacy: my canadian pharmacy review – canadian mail order pharmacy
Профессиональный сервисный центр по ремонту сотовых телефонов, смартфонов и мобильных устройств.
Мы предлагаем: ремонт телефонов москва рядом
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
https://mexstarpharma.com/# mexican mail order pharmacies
Automation started to take hold in the 1970s and 1980s, and the nineteen nineties noticed the arrival of digital sound and the growth of LCD technology.
Профессиональный сервисный центр по ремонту сотовых телефонов, смартфонов и мобильных устройств.
Мы предлагаем: ближайший ремонт смартфонов
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
Although, the average selling price of 2008 was 9 higher from 2009.
Anyone can take advantage of the centralized or decentralized platforms lending leverage, and make the process simpler.
https://mexstarpharma.online/# buying from online mexican pharmacy
At the 2011 Consumer Electronics Show, for instance, Lady Gaga told the press that she carries around a Polaroid 3-inch by 4-inch GL10 instant mobile printer in her purse.
Good post. I learn something new and challenging on sites I stumbleupon every day. It’s always exciting to read through articles from other writers and practice a little something from their web sites.
safe canadian pharmacies: pharmacy com canada – canadian world pharmacy
Way cool! Some very valid points! I appreciate you penning this write-up and the rest of the website is also very good.
Most online sites have the transaction costs per transaction are not many reasonable cost; the price of course, should not be a deciding factor.
ремонт телевизора на дому в москве
best canadian pharmacy online rate canadian pharmacies my canadian pharmacy
When I initially left a comment I seem to have clicked on the -Notify me when new comments are added- checkbox and from now on whenever a comment is added I receive four emails with the exact same comment. Is there a means you are able to remove me from that service? Thank you.
Thank you for content. Area rugs and online home decor store. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
pharmacies in mexico that ship to usa: mexican pharmacy – mexican online pharmacies prescription drugs
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 information. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Thank you for great content. Hello Administ. Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Thank you for great information. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
https://easyrxcanada.online/# canadian family pharmacy
medicine in mexico pharmacies: mexican rx online – mexican drugstore online
An intriguing discussion is definitely worth comment. There’s no doubt that that you need to write more about this topic, it might not be a taboo matter but usually folks don’t speak about these topics. To the next! All the best!
bookmarked!!, I really like your blog.
1xbet – лучший выбор для ставок на спорт, бонусы и акции 1xbet: уникальные предложения для игроков, 1xbet: ваш путь к успешным ставкам, 1xbet – ваша уверенность в каждой ставке, 1xbet предлагает широкий выбор видов ставок на спорт, 1xbet – ваш гид в мире спортивных ставок, 1xbet: профессиональное обслуживание и круглосуточная поддержка, 1xbet: лучшие коэффициенты и высокие шансы на победу, 1xbet: попробуй свою удачу и выиграй крупный джекпот, 1xbet: надежный партнер для ставок на спорт, 1xbet: удобный интерфейс и простая навигация, 1xbet: любимый букмекер миллионов, 1xbet: лучший выбор для ставок на любимые команды, 1xbet обеспечивает полную конфиденциальность и безопасность ваших данных, 1xbet предлагает актуальные ставки на спорт и киберспорт, 1xbet признан мировым лидером в сфере онлайн-ставок, 1xbet использует передовые технологии и инновации для лучшего игрового опыта, 1xbet гарантирует высокий уровень сервиса и профессионализм в каждой ставке.
Download the 1xbet program https://1xbetappdownloadegypt.com/ .
Профессиональный сервисный центр по ремонту ноутбуков, макбуков и другой компьютерной техники.
Мы предлагаем:ремонт macbook
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
canadian family pharmacy: canadian pharmacy price checker – canadian pharmacy
An outstanding share! I’ve just forwarded this onto a coworker who has been doing a little homework on this. And he actually bought me lunch due to the fact that I found it for him… lol. So let me reword this…. Thank YOU for the meal!! But yeah, thanx for spending some time to discuss this topic here on your website.
canadian pharmacy tampa pharmacy canadian superstore canadian mail order pharmacy
After looking into a handful of the articles on your web site, I truly like your technique of writing a blog. I added it to my bookmark website list and will be checking back in the near future. Please visit my website too and tell me how you feel.
https://mexstarpharma.online/# п»їbest mexican online pharmacies
https://easyrxcanada.com/# canada drugs
I love it when individuals come together and share views. Great website, keep it up.
I used to be able to find good advice from your blog articles.
mexico drug stores pharmacies purple pharmacy mexico price list mexico drug stores pharmacies
mexican drugstore online: mexican mail order pharmacies – п»їbest mexican online pharmacies
https://easyrxindia.com/# pharmacy website india
reddit canadian pharmacy best canadian pharmacy online canadian medications
It’s hard to find knowledgeable people on this topic, however, you seem like you know what you’re talking about! Thanks
You need to take part in a contest for one of the greatest sites on the net. I most certainly will highly recommend this blog!
https://easyrxcanada.online/# canadian pharmacy 1 internet online drugstore
Another positive element of boomerang online casino is its focus to responsible gambling. The casino provides players with resources and support to manage their gambling behavior responsibly, promoting a sustainable practice between enjoyment and responsible gaming. The assistance team is also on hand to support with any problems or queries, delivering fast and professional service to boost the overall user experience.
online canadian pharmacy: canadian pharmacy ratings – canadian pharmacy store
mexican online pharmacies prescription drugs mexico drug stores pharmacies medicine in mexico pharmacies
This website was… how do you say it? Relevant!! Finally I’ve found something that helped me. Thanks a lot!
I love it when folks get together and share opinions. Great website, stick with it.
https://mexstarpharma.com/# mexico drug stores pharmacies