Pitfalls in modifying virtual machine static IP (related to docker)
Since I changed to a mobile wifi, I wanted to change the static IP of the virtual machine on my computer. However, after changing the static IP, I found that I could ping my virtual machine IP, but I used the telnet command to access my IP. Port 3306 is blocked, so I can't connect to my mysql.
1. Problem troubleshooting ideas
First of all, since the software in my virtual machine is all installed using docker, I use
docker ps
ComeView my running containers
Then I discovered that my containers started normally, but I couldn’t connect to mysql in my virtual machine through my own host, so I wondered if it was because of the firewall Reason
systemctl status firewalld.service
Through the above command, I found that my firewall was not turned on at all.
I used the following command on the external network to test the connection between the virtual machine and mysql in the virtual machine.
ping 虚拟机的ip 这里是可以ping的通的
telnet 虚拟机ip 3306 发现还是访问不通我的mysql
No way, try the kibana container I installed using the browser link again.
I found that kibana cannot be used. At this time, I pointed the finger of the problem at my docker, wondering whether I should restart docker after reconfiguring the static IP of the virtual machine, because docker should have a proxy container IP and The process of host IP. So I restarted my docker using the following command.
sudo systemctl restart docker
Sure enough, after restarting docker, I can connect to mysql in my virtual machine through my host.
But I still can't connect to kibana, and I'm still confused. And I can access kibana through telnet on my host, but I still can't access it through the browser.
There is no other way but to take a look at kibana’s startup log.
docker logs kibana的容器id
Found the following situation
{
"type":"log","@timestamp":"2023-10-31T06:29:53Z","tags":["warning","elasticsearch","admin"],"pid":7,"message":"Unable to revive connection: http://172.20.10.11:9200/"}
{
"type":"log","@timestamp":"2023-10-31T06:29:53Z","tags":["warning","elasticsearch","admin"],"pid":7,"message":"No living connections"}
It suddenly dawned on me that kibana wanted to connect to my elasticsearch, but the connection was still the same IP as before, so I needed to modify kibana's configuration.
docker run --name kibana -e ELASTICSEARCH_HOSTS=http://172.20.10.11:9200 -p 5601:5601 \
-d kibana:7.4.2
172.20.10.11为自己的虚拟机ip ifconfig命令查看
This is the command that was previously used to start the kibana container and elasticsearch, so the container must be modified. I asked chatgpt and got the following conclusion.
When using Docker to run a container, you can use the docker update
command to change the configuration of the container. However, this command does not support changing the container's host port mapping.
If you need to change the container port mapping, you need to delete the original container and create a new one to implement the changes. Here are the rough steps:
-
Stop and delete the existing Kibana container:
docker stop kibana docker rm kibana
-
Rerun the Kibana container using the new command and update the Elasticsearch address:
docker run --name kibana -e ELASTICSEARCH_HOSTS=http://NEW IPADDR -p 5601:5601 \ -d kibana:7.4.2
You're done.
2. Summary
Through the above situation and questions, I summarized several of my conclusions:
- After reconfiguring the static IP of the virtual machine, if the mysql and other containers were installed using docker, you need to restart docker and the container. dkcoer should have an IP between the proxy host and the container.
- When the kibana container is started, it is usually based on the installed elasticsearch. After the static IP is modified, kibana naturally has to be re-bound. Here is a reference to gpt. After deleting the container, re-bind and start a new kibana
When a container is started, it is usually based on Install elasticsearch. After the static IP is modified, kibana naturally has to be re-bound. Here is a reference to gpt. After deleting the container, re-bind and start a new kibana - The steps to solve the problem are to first check whether the container is started, then check whether the firewall has set port permissions, then restart the container and check the startup log, and finally locate the problem.