background
In the process of learning to deploy the elasticsearch cluster, the docker deployment method is adopted. Containers in a single docker host can communicate with each other, but elasticsearch requires more resources, generally one host and one node. So I cloned two virtual machines to simulate multi-host docker deployment in the production environment.
accident scene
completed handshake with [{es01}{UnmdQLEwT-SK16zE4VTUpw}{ywZQUGfpSw6Rg73ox4dmsQ}{es01}{172.19.0.2}{172.19.0.2:9301}{cdfhilmrstw}] at [192.168.0.226:9301] but followup connection to [172.19.0.2:9301] failed
solution one
In the host, add the network segment of the docker container on the other host to the routing table.
Existing host A 192.168.0.226, host B 192.168.0.227
Modify the network segment used by the docker container on host A to 10.19.0.0/24, and host B remains the default network segment 172.19.0.0/24
temporary plan
Add routing table to host A
sudo route add -net 172.19.0.0 netmask 255.255.0.0 gw 192.168.0.227
Add routing table to host B
sudo route add -net 10.19.0.0 netmask 255.255.0.0 gw 192.168.0.226
The route added in this way will be lost after the network card is restarted.
permanent program
In /etc/init.d/network, there are the following scripts
# Add non interface-specific static-routes.
if [ -f /etc/sysconfig/static-routes ]; then
if [ -x /sbin/route ]; then
grep "^any" /etc/sysconfig/static-routes | while read ignore args ; do
/sbin/route add -$args
done
else
net_log $"Legacy static-route support not available: /sbin/route not found"
fi
fi
It means that if there is /etc/sysconfig/static-routes, it will filter out the execution route add at the beginning of any, which is equivalent to manually adding routes in the temporary solution. Special attention: the script will have its own - after the
route add, and the net after any Or there is no need to add -
A host in front of the host
sudo vim /etc/sysconfig/static-routes
Add the following
any net 172.19.0.0 netmask 255.255.0.0 gw 192.168.0.227
B host
sudo vim /etc/sysconfig/static-routes
Add the following
any net 10.19.0.0 netmask 255.255.0.0 gw 192.168.0.226
Then restart the host
sudo reboot
or restart the network card
sudo systemctl restart network
At this point, the containers in hosts A and B can access each other.
solution two
Use Docker's overlay network to solve cross-host communication. If you only start with a container, you need to add –attachable to create an overlay network. Detailed explanation about the use of overlay network