Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to gracefully restore the running mysql container application

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to gracefully restore the running mysql container application". In the daily operation, I believe that many people have doubts about how to gracefully restore the running mysql container application. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "how to gracefully restore the running mysql container application". Next, please follow the editor to study!

Longhorn is a lightweight Kubernetes-based distributed block storage system that is completely open source and has been donated to CNCF. With the popularity of cloud native applications, when more and more services are running in containers, the problem of persistent storage of data gradually emerges. What we need to do is not only to persist the data, but also to consider the accuracy of backup and the complexity of migration.

The distributed block storage provided by Longhorn can directly use persistent storage in Kubernetes. It can provide multiple copies of data volumes on different hosts to ensure the reliability of data. It provides a simple UI that can directly manage storage nodes and data volumes, and easily achieve backup / scheduled backup of data volumes. You can also use the disaster recovery backup function to create disaster recovery backup volumes in different clusters. And fail over in time in case of emergency.

In this article, we will deploy MySQL as Pod in cluster A, and use Longhorn as persistent storage volume. Then, relying on the multi-cluster management features of Rancher and the disaster recovery backup function of Longhorn, we will demonstrate how to gracefully migrate MySQL applications and data from cluster A to cluster B.

Environmental preparation

Rancher (HA deployment)-v2.4.8

Longhorn (deployed via Rancher UI Catalog)-v1.0.2

MySQL-8

Private S3-minio deployment

Business clusters An and B

Deploy longhorn

In Rancher, enter the system project in Cluster An and start Longhorn with one click in the App Store.

After waiting for the App Store to be deployed successfully, you can follow the App Store link to Longhorn UI.

Next, we start Longhorn in cluster B in the same way and wait for Longhorn to run properly.

Create a secret accessed by S3 (for longhorn backup)

Access Rancher, enter the system project of cluster A, select Resources > ciphertext menu, and create a secret to access S3 in the longhorn-system namespace. The parameters to be added include:

Visit Rancher, enter the system project in cluster B, select Resources > ciphertext menu, and create the same secret content in the longhorn-system namespace as above.

Configure longhorn backup target

Next we need to configure the same backup target in the Longhorn of both An and B clusters.

Jump from the link to the App Store to longhorn UI, click the Setting > General menu, find the Backup category, and configure the backup target.

Currently, Longhorn supports two backup methods of NFS/S3. In this example, we use minio to build a private S3 service. Here we configure it in S3 mode.

PS: if you use NFS, you need to make sure that NFS server supports NFSv4

Deploy MySQL applications

Deploy a MySQL application in cluster A, create a test table article in MySQL and insert a piece of data.

Back up this volume in the Longhorn of cluster A.

After the backup is successful, you can see the backup information in the Longhorn of cluster B (because the Longhorn of both clusters is configured with the same backup target, the backup information is shared).

Create a disaster recovery backup volume

Access the Longhorn UI of cluster B, use the backup of the Volume of cluster A, and create a disaster recovery backup volume in cluster B.

Here, the name of Volume is automatically populated based on the backup volume, and manual modification is not recommended.

After saving, visit the Volume page to see our newly created disaster recovery backup volume.

Insert several pieces of data again in the MySQL application of cluster A.

Access the Longhorn UI of cluster An and back up the volume again. At this time, you can see that the disaster recovery backup volume icon in cluster B turns gray, indicating that the volume is synchronizing the latest backup data of Volume in cluster A, and the disaster recovery backup volume cannot be activated and used at this time.

After a while, the icon turns blue, indicating that you have successfully synchronized with the latest backup of Volume in cluster A. Then we can use this volume.

If automatic backup is set for MySQL volumes in cluster A, Longhorn in cluster B will regularly poll for the latest backup and automatically synchronize incremental data information to the disaster recovery backup volume to keep the data consistent with the Volume data in cluster A.

Restore mysql applications in a new cluster

Assuming that our cluster An is no longer available, we can quickly restore the MySQL application in cluster B using the latest backup volumes.

First of all, we activate the disaster recovery backup volume of cluster B.

After waiting for the volume state to change to Detached, select create PV/PVC.

It is not recommended to change the names of PV and PVC. Namespace can be filled in according to the name of namespace in actual cluster B. Save the session, and the PVC is created in the specified namespace of cluster B.

Visit Rancher to see that the PVC has been created successfully.

Use the recovered PVC to create a MySQL application, and then query the data, you can see that the data has also been restored! The great task has been completed!

At this point, the study on "how to gracefully restore the running mysql container application" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report