【仿RabbitMQ消息隊列項目day2】使用muduo庫中基于protobuf的應用層協議進行通信

一.什么是muduo?

muduo庫是?個基于非阻塞IO和事件驅動的C++高并發TCP網絡編程庫。

簡單來理解,它就是對原生的TCP套接字的封裝,是一個比socket編程接口更好用的編程庫。?

二.使用muduo庫完成一個英譯漢翻譯服務

TranslateServer.hpp:

#pragma once
#include <iostream>
#include <functional>
#include <unordered_map>
#include <string>
#include "muduo/net/TcpConnection.h"
#include "muduo/net/TcpServer.h"
#include "muduo/net/EventLoop.h"using std::cout;
using std::endl;
class TranslateServer
{
private:muduo::net::EventLoop _baseloop;muduo::net::TcpServer _server;
public:TranslateServer(int port):_server(&_baseloop, muduo::net::InetAddress("0.0.0.0", port), \"TranslateServer", muduo::net::TcpServer::kReusePort){//bind是一個函數適配器_server.setConnectionCallback(std::bind(&TranslateServer::_onConnection, this, std::placeholders::_1));_server.setMessageCallback(std::bind(&TranslateServer::_onMessage, this, std::placeholders::_1, \std::placeholders::_2, std::placeholders::_3));}void start(){_server.start(); //開始事件監聽_baseloop.loop(); //開始事件監控,這是一個死循環阻塞接口}// typedef std::function<void (const TcpConnectionPtr&)> ConnectionCallback;
// typedef std::function<void (const TcpConnectionPtr&,
//                             Buffer*,
//                             Timestamp)> MessageCallback;//連接建立成功或者關閉時侯的回調函數void _onConnection(const muduo::net::TcpConnectionPtr& conn){if (conn->connected()){cout << "新連接建立成功\n";}else{cout << "連接關閉\n";}}//通信連接收到請求時的回調函數void _onMessage(const muduo::net::TcpConnectionPtr& conn, muduo::net::Buffer* buffer, muduo::Timestamp time){std::string str = buffer->retrieveAllAsString();std::string resp = translate(str);conn->send(resp);}std::string translate(const std::string& str){static std::unordered_map<std::string, std::string> _dict = {{"hello", "你好"},{"white", "白色"}};if (_dict.count(str)){return _dict[str];}return "沒找到";}};

TranslateClient.hpp:

#pragma once
#include <functional>
#include <iostream>
#include "muduo/net/TcpClient.h"
#include "muduo/net/TcpConnection.h"
#include "muduo/net/EventLoopThread.h"class TranslateClient
{
private:muduo::net::EventLoopThread _loopThread; //EventLoop是阻塞式死循環,必須另起一個線程,否則用戶無法在主線程輸入。//_loopThread一建立就立馬啟動muduo::net::TcpClient _client;muduo::net::TcpConnectionPtr _conn;//TcpClient的connect是非阻塞接口,調用立馬返回,這有可能導致用戶send時尚未建立連接,而解引用空指針muduo::CountDownLatch _latch; //保證建立連接和send之間的同步關系
public:TranslateClient(const std::string& serverIp, int serverPort):_client(_loopThread.startLoop(), muduo::net::InetAddress(serverIp, serverPort), "TranslateClient"),_latch(1){_client.setConnectionCallback(std::bind(&TranslateClient::_onConnection, this, std::placeholders::_1));_client.setMessageCallback(std::bind(&TranslateClient::_onMessage, this, std::placeholders::_1, \std::placeholders::_2,std::placeholders::_3));}void connect(){_client.connect();_latch.wait();}bool send(std::string& msg){if (_conn->connected()){_conn->send(msg);return true;}else{return false;}}private:/*************** 連接建立或者斷開時的回調函數* **************/void _onConnection(const muduo::net::TcpConnectionPtr &conn){if (conn->connected()){_latch.countDown();_conn = conn;}else{_conn.reset();}}void _onMessage(const muduo::net::TcpConnectionPtr& conn, muduo::net::Buffer* buffer, muduo::Timestamp time){std::cout << "翻譯結果:" << buffer->retrieveAllAsString() << std::endl;}
};

muduo的精髓在于大量的回調函數,建立或斷開連接,收到消息時,都會調用我們傳入的回調函數,回調函數就是我們處理業務的地方。

三.muduo中基于protobuf的自定義協議

像上述的英譯漢服務,雙方肯定是能正常通信,但這絕不是一個成熟的方案。TCP通信時面向字節流的,存在數據粘包問題,要想解決必須使用用戶層協議。

用戶層協議主要就是解決數據粘包問題,另外序列化和反序列化也是其中的重要環節。muduo庫是由陳碩大佬編寫的,在安裝好的muduo庫中,他提供了一些編程樣例,其中有一個就是基于protobuf,定制了一個用戶層協議,用于網絡通信。所以嚴格來說,該自定義協議并不是muduo庫中的一部分。

class ProtobufCodec : muduo::noncopyable
{public:enum ErrorCode{kNoError = 0,kInvalidLength,kCheckSumError,kInvalidNameLen,kUnknownMessageType,kParseError,};typedef std::function<void (const muduo::net::TcpConnectionPtr&,const MessagePtr&,muduo::Timestamp)> ProtobufMessageCallback;typedef std::function<void (const muduo::net::TcpConnectionPtr&,muduo::net::Buffer*,muduo::Timestamp,ErrorCode)> ErrorCallback;explicit ProtobufCodec(const ProtobufMessageCallback& messageCb): messageCallback_(messageCb),errorCallback_(defaultErrorCallback){}ProtobufCodec(const ProtobufMessageCallback& messageCb, const ErrorCallback& errorCb): messageCallback_(messageCb),errorCallback_(errorCb){}void onMessage(const muduo::net::TcpConnectionPtr& conn,muduo::net::Buffer* buf,muduo::Timestamp receiveTime);void send(const muduo::net::TcpConnectionPtr& conn,const google::protobuf::Message& message){// FIXME: serialize to TcpConnection::outputBuffer()muduo::net::Buffer buf;fillEmptyBuffer(&buf, message);conn->send(&buf);}static const muduo::string& errorCodeToString(ErrorCode errorCode);static void fillEmptyBuffer(muduo::net::Buffer* buf, const google::protobuf::Message& message);static google::protobuf::Message* createMessage(const std::string& type_name);static MessagePtr parse(const char* buf, int len, ErrorCode* errorCode);private:static void defaultErrorCallback(const muduo::net::TcpConnectionPtr&,muduo::net::Buffer*,muduo::Timestamp,ErrorCode);ProtobufMessageCallback messageCallback_;ErrorCallback errorCallback_;const static int kHeaderLen = sizeof(int32_t);const static int kMinMessageLen = 2*kHeaderLen + 2; // nameLen + typeName + checkSumconst static int kMaxMessageLen = 64*1024*1024; // same as codec_stream.h kDefaultTotalBytesLimit
};

ProtobufCodec類就是基于protobuf定義的結構化數據的應用層協議,協議格式如下:

onMessage的實現如下:?

void ProtobufCodec::onMessage(const TcpConnectionPtr& conn,Buffer* buf,Timestamp receiveTime)
{while (buf->readableBytes() >= kMinMessageLen + kHeaderLen){const int32_t len = buf->peekInt32();if (len > kMaxMessageLen || len < kMinMessageLen){errorCallback_(conn, buf, receiveTime, kInvalidLength);break;}else if (buf->readableBytes() >= implicit_cast<size_t>(len + kHeaderLen)){ErrorCode errorCode = kNoError;MessagePtr message = parse(buf->peek()+kHeaderLen, len, &errorCode);if (errorCode == kNoError && message){messageCallback_(conn, message, receiveTime);buf->retrieve(kHeaderLen+len);}else{errorCallback_(conn, buf, receiveTime, errorCode);break;}}else{break;}}
}

onMessage函數解決了TCP粘包的問題,從緩沖區中解析出一個完整的protobuf結構化數據(一個message)后,再調用messageCallback_處理。messageCallback_是構造ProtobufCodec時傳入的回調函數。

如果我們的業務場景很單一,例如上面的英譯漢服務器,直接把我們寫的業務邏輯作為回調傳給messageCallback_就OK了。但如果我們有多種業務,例如翻譯和計算業務,則還可以在此基礎上引入任務分發器ProtobufDispatcher,回調它的ProtobufDispatcher函數。

class ProtobufDispatcher
{public:typedef std::function<void (const muduo::net::TcpConnectionPtr&,const MessagePtr& message,muduo::Timestamp)> ProtobufMessageCallback;explicit ProtobufDispatcher(const ProtobufMessageCallback& defaultCb): defaultCallback_(defaultCb){}void onProtobufMessage(const muduo::net::TcpConnectionPtr& conn,const MessagePtr& message,muduo::Timestamp receiveTime) const{CallbackMap::const_iterator it = callbacks_.find(message->GetDescriptor());if (it != callbacks_.end()){it->second->onMessage(conn, message, receiveTime);}else{defaultCallback_(conn, message, receiveTime);}}template<typename T>void registerMessageCallback(const typename CallbackT<T>::ProtobufMessageTCallback& callback){std::shared_ptr<CallbackT<T> > pd(new CallbackT<T>(callback));callbacks_[T::descriptor()] = pd;}private:typedef std::map<const google::protobuf::Descriptor*, std::shared_ptr<Callback> > CallbackMap;CallbackMap callbacks_;ProtobufMessageCallback defaultCallback_;
};

onProtobufMessage會根據你傳入的結構化數據類型(message),調用不同的回調函數,這些回調函數就是我們注冊的業務處理方法。

四.編寫一個翻譯+加法服務

  1. 編寫.并翻譯proto文件,構建翻譯的請求和響應,加法的請求和響應的類
  2. 編寫服務端
  3. 編寫客戶端

Server.cc:

#include <memory>
#include "muduo/protobuf/codec.h"
#include "muduo/protobuf/dispatcher.h"
#include "muduo/base/Logging.h"#include "muduo/net/TcpServer.h"
#include "muduo/net/TcpConnection.h"
#include "muduo/net/EventLoop.h"#include "business.pb.h"using std::placeholders::_1;
using std::placeholders::_2;
using std::placeholders::_3;
class Server
{
public:typedef std::shared_ptr<google::protobuf::Message> MessagePtr;typedef std::shared_ptr<business::TranslateRequest> TranslateRequestPtr;typedef std::shared_ptr<business::AddRequest> AddRequestPtr;private:muduo::net::EventLoop _baseLoop;muduo::net::TcpServer _server;ProtobufDispatcher _dispatcher; // 請求分發器ProtobufCodec _codec;           // protobuf處理器--解析出結構化數據,發送結構化數據(序列化和發序列化內部會做)
public:Server(int port): _server(&_baseLoop, muduo::net::InetAddress("0.0.0.0", port), "Server",muduo::net::TcpServer::kReusePort),_dispatcher(std::bind(&Server::_onUnknownMessage, this,\std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)),_codec(std::bind(&ProtobufDispatcher::onProtobufMessage, &_dispatcher,std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)){// 注冊業務處理函數_dispatcher.registerMessageCallback<business::AddRequest>(bind(&Server::_onAdd, this, _1, _2, _3));_dispatcher.registerMessageCallback<business::TranslateRequest>(bind(&Server::_onTranslate, this, _1, _2, _3));//注冊_server的回調函數_server.setMessageCallback(std::bind(&ProtobufCodec::onMessage, &_codec,std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));_server.setConnectionCallback(std::bind(&Server::_onConnection, this, std::placeholders::_1));}void start(){_server.start();_baseLoop.loop();}private:void _onUnknownMessage(const muduo::net::TcpConnectionPtr &conn, const MessagePtr &message, muduo::Timestamp){LOG_INFO << "onUnknownMessage: " << message->GetTypeName();conn->shutdown();}void _onAdd(const muduo::net::TcpConnectionPtr& conn, const AddRequestPtr &messagePtr, muduo::Timestamp time){int x = messagePtr->num1();int y = messagePtr->num2();business::AddResponse resp;resp.set_result(x + y);_codec.send(conn, resp); //讓protobuf處理器幫我們序列化并用conn發送}void _onTranslate(const muduo::net::TcpConnectionPtr& conn, const TranslateRequestPtr &messagePtr, muduo::Timestamp time){const std::string& ret = translate(messagePtr->msg());business::TranslateResponse resp;resp.set_msg(ret);_codec.send(conn, resp);}void _onConnection(const muduo::net::TcpConnectionPtr &conn){if (conn->connected()){LOG_INFO << "新連接建立成功!";}else{LOG_INFO << "連接即將關閉!";}}std::string translate(const std::string& str){static std::unordered_map<std::string, std::string> dict_map = {{"hello", "你好"},{"Hello", "你好"},{"你好", "Hello"},{"吃了嗎", "油潑面"}};auto it = dict_map.find(str);if (it == dict_map.end()) {return "沒聽懂!!";}return it->second;}
};int main()
{Server server(8085);server.start();return 0;
}

Client.cc:?


#include "muduo/protobuf/codec.h"
#include "muduo/protobuf/dispatcher.h"
#include "muduo/base/Logging.h"
#include "muduo/base/Mutex.h"
#include "muduo/net/EventLoop.h"
#include "muduo/net/TcpClient.h"
#include "muduo/net/EventLoopThread.h"
#include "muduo/base/CountDownLatch.h"#include "business.pb.h"
#include <iostream>
#include <functional>class Client {public:typedef std::shared_ptr<google::protobuf::Message> MessagePtr; //這是Protobuf庫的頭文件typedef std::shared_ptr<business::AddResponse> AddResponsePtr;typedef std::shared_ptr<business::TranslateResponse> TranslateResponsePtr;Client(const std::string &sip, int sport):_latch(1), _client(_loopthread.startLoop(), muduo::net::InetAddress(sip, sport), "Client"),_dispatcher(std::bind(&Client::onUnknownMessage, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)),_codec(std::bind(&ProtobufDispatcher::onProtobufMessage, &_dispatcher, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)){_dispatcher.registerMessageCallback<business::TranslateResponse>(std::bind(&Client::onTranslate, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));_dispatcher.registerMessageCallback<business::AddResponse>(std::bind(&Client::onAdd, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));_client.setMessageCallback(std::bind(&ProtobufCodec::onMessage, &_codec,std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));_client.setConnectionCallback(std::bind(&Client::onConnection, this, std::placeholders::_1));      }void connect() {_client.connect();_latch.wait();//阻塞等待,直到連接建立成功}void Translate(const std::string &msg){business::TranslateRequest req;req.set_msg(msg);send(&req);}void Add(int num1, int num2) {business::AddRequest req;req.set_num1(num1);req.set_num2(num2);send(&req);}private:bool send(const google::protobuf::Message *message) {if (_conn->connected()) {//連接狀態正常,再發送,否則就返回false_codec.send(_conn, *message);return true;}return false;}  void onTranslate(const muduo::net::TcpConnectionPtr& conn, const TranslateResponsePtr& message, muduo::Timestamp) {std::cout << "翻譯結果:" << message->msg() << std::endl;}void onAdd(const muduo::net::TcpConnectionPtr& conn, const AddResponsePtr& message, muduo::Timestamp) {std::cout << "加法結果:" << message->result() << std::endl;}void onUnknownMessage(const muduo::net::TcpConnectionPtr& conn, const MessagePtr& message, muduo::Timestamp) {LOG_INFO << "onUnknownMessage: " << message->GetTypeName();conn->shutdown();}void onConnection(const muduo::net::TcpConnectionPtr&conn){if (conn->connected()) {_latch.countDown();//喚醒主線程中的阻塞_conn = conn;}else {//連接關閉時的操作_conn.reset();}}private:muduo::CountDownLatch _latch;//實現同步的muduo::net::EventLoopThread _loopthread;//異步循環處理線程muduo::net::TcpConnectionPtr _conn;//客戶端對應的連接muduo::net::TcpClient _client;//客戶端ProtobufDispatcher _dispatcher;//請求分發器ProtobufCodec _codec; //Protobuf處理器
};int main() 
{Client client("127.0.0.1", 8085);client.connect();client.Translate("hello");client.Add(11, 22);sleep(1);return 0;
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/14280.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/14280.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/14280.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

MyBatis中Where標簽:揭秘高效SQL構建的秘密

哈嘍&#xff0c;大家好&#xff0c;我是木頭左&#xff01; 理解Where標簽的基礎概念 在MyBatis中&#xff0c;<where>標簽是用于構建SQL查詢語句中的一個非常重要的元素。它允許你在一個動態的SQL語句中添加WHERE子句&#xff0c;而不需要擔心SQL語法錯誤或額外的逗號…

如何利用51建模網,實現3D模型線上展示和應用?

按照下面的步驟&#xff0c;在51建模網上傳3D模型&#xff0c;并編輯完成后&#xff0c;接下來就是如何讓這些3D模型得到更好的展示、傳播和應用。 一、3D內容快速分享與傳播 3D模型在51建模網上傳發布后&#xff0c;即可獲得一個可分享的鏈接和二維碼&#xff0c;直接分享給客…

20240520解決在Ubuntu20.04下編譯RK3588的Android12的SDK出現C2_GIT_BUILD_VERSION未定義的問題

20240520解決在Ubuntu20.04下編譯RK3588的Android12的SDK出現C2_GIT_BUILD_VERSION未定義的問題 2024/5/20 20:19 緣起&#xff1a;通過./repo/repo/repo sync -l得到的SDK正常&#xff0c;但是解壓縮之后的SDK卻出錯了&#xff01; 通過grep很容易發現有三個地方有&#xff0c…

深入分析 Android Activity (一)

深入分析 Android Activity (一) 接下來我們會深入分析 Activity 的一些高級特性和內部實現&#xff0c;包括窗口管理、生命周期管理、以及與 Fragment 的交互。 1. Activity 的窗口管理 在 Android 中&#xff0c;每個 Activity 都與一個 Window 相關聯。Window 是一個抽象…

如何選購尼龍輸送帶

尼龍輸送帶選購攻略&#xff1a;從入門到精通&#xff0c;一篇文章全搞定&#xff01; 在工業生產中&#xff0c;尼龍輸送帶作為關鍵的物流傳輸設備&#xff0c;其選擇和使用直接關系到生產效率和成本控制。面對市面上琳瑯滿目的尼龍輸送帶產品&#xff0c;如何選購到性價比高…

PointCloudLib 點云投影到XOY平面功能實現 C++版本

0.實現效果 左圖為原始點云,右圖為投影到XOY平面上的點云 將三維的點云投影到二維平面,方便處理一些二維輪廓方面的計算。 可以投影到空間中任意平面上。 1.算法原理 原理 點云投影是將三維空間中的點云數據映射到一個二維平面上的過程。這通常通過以下步驟實現: 確定投…

使用Golang開發一個HTTP客戶端請求命令行工具

什么是Golang Golang&#xff0c;也被稱為Go語言&#xff0c;是由Google開發的一種開源的編程語言。它于2007年開始設計&#xff0c;于2009年首次公開發布。Golang被設計成一種通用的編程語言&#xff0c;旨在提供簡單、高效和可靠的軟件開發方式。Golang具有靜態類型、垃圾回…

微服務實踐k8sdapr開發部署調用

前置條件 安裝docker與dapr: 手把手教你學Dapr - 3. 使用Dapr運行第一個.Net程序安裝k8s dapr 自托管模式運行 新建一個webapi無權限項目 launchSettings.json中applicationUrl端口改成5001,如下: "applicationUrl": "http://localhost:5001" //Wea…

c#實現視頻播放

在winform上實現視頻播放常用的控件時media player&#xff0c;vs工具欄初始狀態下沒有&#xff0c;需要我們到com組件中添加。添加完成后&#xff0c;把media player控件拖拽到一個Form窗口中。 在此實現遍歷某個文件夾下是否有mp4視頻&#xff0c;如果有則播放視頻。&#x…

BeautifulSoup4通過lxml使用Xpath,以及獲取(定位)元素和其文本或者屬性

環境&#xff1a;win10&#xff0c;python3.8.10 首先需要安裝&#xff1a;beautifulsoup4&#xff0c;lxml 使用命令&#xff1a; pip38 install beautifulsoup4 pip38 install lxml 安裝完畢后查看一下&#xff1a; 寫代碼&#xff1a; from bs4 import BeautifulSoup …

Go 圖像處理

Golang中的image包提供了基本的圖像類型、顏色模型、以及用于處理圖像的各種函數和接口。 常用類型與接口 image.Image 接口 這是Go語言中處理圖像的核心接口&#xff0c;定義了所有圖像必須實現的方法&#xff1a; type Image interface {// Bounds returns the domain for…

rocketmq 學習二 基本概念

教程&#xff1a;基本概念 | RocketMQ 視頻教程 https://www.bilibili.com/video/BV1d5411y7UW?vd_sourcef1bd3b5218c30adf0a002c8c937e0a27 版本&#xff1a;5.0 一 基本概念 1.1 生產者/Producer 1.1.1 定義 消息發布者。是構建并傳輸消息到服務端的運行實體。…

異眾比率(variation ratio)

異眾比率&#xff08;variation ratio&#xff09;是指非眾數組的頻數占總頻數的比率&#xff0c;其計算公式為: 其中&#xff0c;為眾數組的頻數。 異眾比率主要用于衡量眾數對一組數據的代表程度。異眾比率越大&#xff0c;說明非眾數組的頻數占總頻數的比重越大&#xff0…

harbor 認證

Harbor 認證過程 Harbor以 Docker Registry v2認證為基礎&#xff0c;添加上一層權限保護。1.v2 集成了一個安全認證的功能&#xff0c;將安全認證暴露給外部服務&#xff0c;讓外部服務去實現2.強制用戶每次Docker pull/push請求都要帶一個合法的Token&#xff0c;Registry會…

python的requests爬蟲模塊使用代理ip方法---集合

形式一 import requests proxies {http:128.3.74.224:2890,https:128.3.74.224:2890} ip requests.get(http://httpbin.org/ip,proxiesproxies) print(ip.text)形式二 形式一不行的情況下&#xff0c;試試形式二 import requests proxies {http:http://127.0.0.1:7890,http…

【AHK V2】設計模式之命令模式

目錄 情景劇場什么是命令模式優缺點優點缺點 使用命令模式的步驟命令模式代碼示例合理使用AI工具自動生成代碼 情景劇場 我們來設想一個場景&#xff1a; 你進入一家餐館&#xff0c;餐館只有老板一個人&#xff08;老板即廚師&#xff09;。 “老板&#xff0c;一份小炒肉&am…

Vue插槽solt如何傳遞具名插槽的數據給子組件?

在Vue中&#xff0c;你可以通過作用域插槽&#xff08;scoped slots&#xff09;來傳遞數據給子組件。這同樣適用于具名插槽。首先&#xff0c;你需要在子組件中定義一個具名插槽&#xff0c;并通過v-slot指令傳遞數據。例如&#xff1a; 子組件&#xff08;ChildComponent.vu…

自用RedisConfig的配置,更改key為string和value json的序列化,避免set亂的key

自用RedisConfig的配置&#xff0c;更改key為string和value json的序列化&#xff0c;避免set亂的key&#xff0c;使用StringRedisTemplate也可以解決&#xff0c;保證了redis set的值是正確的 Configuration public class RedisConfig {//更改key為string和value json的序列化…

吃透1850道真題和解析備考AMC8和AMC(1020240524持續發布)

多做真題&#xff0c;吃透真題和背后的知識點是備考AMC8、AMC10有效的方法之一&#xff0c;通過做真題&#xff0c;可以幫助孩子找到真實競賽的感覺&#xff0c;而且更加貼近比賽的內容&#xff0c;可以通過真題查漏補缺&#xff0c;更有針對性的補齊知識的短板。 今天我們繼續…

在新cloud上啟動備份數據庫

情況介紹&#xff1a;在云上劃拉一塊地方建立本地數據庫測試環境&#xff0c;通過數據庫備份包恢復數據并啟動。 1.在云上或者你自己的server上安裝Percona Server for MySQL&#xff0c;步驟如下 Use APT repositories - Percona Server for MySQL How to Install or Upgra…