{"id":2300,"date":"2025-02-12T06:52:16","date_gmt":"2022-10-04T19:10:55","guid":{"rendered":""},"modified":"2025-02-02T00:46:18","modified_gmt":"2025-02-01T23:46:18","slug":"how-to-setup-mariadb-master-master-replication-on-debian-11","status":"publish","type":"post","link":"https:\/\/netcloud24.com\/knowledgebase\/how-to-setup-mariadb-master-master-replication-on-debian-11\/","title":{"rendered":"How to Setup MariaDB Master-Master Replication on Debian 11"},"content":{"rendered":"<p>\u00a0<\/p>\n<\/p>\n<header>\n<h1>\u00a0<\/h1>\n<\/header>\n<article>\n<p>Master-Master replication in MariaDB allows both database servers to act as a master and replicate data to each other. This setup is useful for load balancing, failover, and ensuring data consistency across servers. In this guide, we will walk through the steps to configure Master-Master replication on MariaDB using Debian 11. Whether you are setting this up on local machines or on a , this tutorial will help you get started.<\/p>\n<section>\n<h2>Prerequisites<\/h2>\n<p>Before you begin, ensure that you have the following:<\/p>\n<ul>\n<li>Two Debian 11 servers with MariaDB installed.<\/li>\n<li>Root or sudo access to both servers.<\/li>\n<li>Firewall rules that allow communication on port 3306 (MariaDB\u2019s default port).<\/li>\n<li>A basic understanding of MariaDB commands.<\/li>\n<\/ul>\n<\/section>\n<section>\n<h2>Step 1: Update Your System<\/h2>\n<p>On both servers, start by updating the system packages:<\/p>\n<pre><code>sudo apt update &amp;&amp; sudo apt upgrade -y<\/code><\/pre>\n<p>Keeping your system updated is important, especially if you are deploying it on a <a href=\"https:\/\/ie.netcloud24.com\">VPS Windows VPS Servers<\/a> platform.<\/p>\n<\/section>\n<section>\n<h2>Step 2: Install MariaDB on Both Servers<\/h2>\n<p>If MariaDB is not installed, install it on both servers by running:<\/p>\n<pre><code>sudo apt install mariadb-server -y<\/code><\/pre>\n<p>After installation, start and enable MariaDB on both servers:<\/p>\n<pre><code>sudo systemctl start mariadb\r\nsudo systemctl enable mariadb<\/code><\/pre>\n<\/section>\n<section>\n<h2>Step 3: Configure MariaDB on Server 1 (Master 1)<\/h2>\n<p>Log in to the MariaDB shell on the first server:<\/p>\n<pre><code>sudo mysql -u root -p<\/code><\/pre>\n<p>Create a replication user and grant replication privileges:<\/p>\n<pre><code>CREATE USER 'repl_user'@'%' IDENTIFIED BY 'strong_password';\r\nGRANT REPLICATION SLAVE ON *.* TO 'repl_user'@'%';\r\nFLUSH PRIVILEGES;<\/code><\/pre>\n<p>Exit the MariaDB shell, and then edit the MariaDB configuration file:<\/p>\n<pre><code>sudo nano \/etc\/mysql\/mariadb.conf.d\/50-server.cnf<\/code><\/pre>\n<p>Add or modify the following lines under the `[mysqld]` section:<\/p>\n<pre><code>[mysqld]\r\nserver-id=1\r\nlog_bin=\/var\/log\/mysql\/mariadb-bin\r\nbinlog_do_db=your_database_name\r\nbind-address=0.0.0.0<\/code><\/pre>\n<p>Save and exit the file. Restart MariaDB:<\/p>\n<pre><code>sudo systemctl restart mariadb<\/code><\/pre>\n<\/section>\n<section>\n<h2>Step 4: Configure MariaDB on Server 2 (Master 2)<\/h2>\n<p>Log in to the MariaDB shell on the second server:<\/p>\n<pre><code>sudo mysql -u root -p<\/code><\/pre>\n<p>Create the same replication user on this server:<\/p>\n<pre><code>CREATE USER 'repl_user'@'%' IDENTIFIED BY 'strong_password';\r\nGRANT REPLICATION SLAVE ON *.* TO 'repl_user'@'%';\r\nFLUSH PRIVILEGES;<\/code><\/pre>\n<p>Exit the MariaDB shell, and then edit the configuration file on the second server:<\/p>\n<pre><code>sudo nano \/etc\/mysql\/mariadb.conf.d\/50-server.cnf<\/code><\/pre>\n<p>Modify the configuration to reflect the second server:<\/p>\n<pre><code>[mysqld]\r\nserver-id=2\r\nlog_bin=\/var\/log\/mysql\/mariadb-bin\r\nbinlog_do_db=your_database_name\r\nbind-address=0.0.0.0<\/code><\/pre>\n<p>Save and exit the file. Restart MariaDB on the second server:<\/p>\n<pre><code>sudo systemctl restart mariadb<\/code><\/pre>\n<\/section>\n<section>\n<h2>Step 5: Set Up Master-Master Replication<\/h2>\n<p>On the first server, find the current log position:<\/p>\n<pre><code>sudo mysql -u root -p -e 'SHOW MASTER STATUS\\G'<\/code><\/pre>\n<p>Note the values of <code>File<\/code> and <code>Position<\/code>. You will need these when configuring the second server.<\/p>\n<p>Now, on the second server, configure the replication with the following command:<\/p>\n<pre><code>CHANGE MASTER TO\r\nMASTER_HOST='IP_of_first_server',\r\nMASTER_USER='repl_user',\r\nMASTER_PASSWORD='strong_password',\r\nMASTER_LOG_FILE='File_from_first_server',\r\nMASTER_LOG_POS=Position_from_first_server;<\/code><\/pre>\n<p>Start the replication:<\/p>\n<pre><code>START SLAVE;<\/code><\/pre>\n<p>Repeat the same steps on the first server, using the details from the second server.<\/p>\n<pre><code>CHANGE MASTER TO\r\nMASTER_HOST='IP_of_second_server',\r\nMASTER_USER='repl_user',\r\nMASTER_PASSWORD='strong_password',\r\nMASTER_LOG_FILE='File_from_second_server',\r\nMASTER_LOG_POS=Position_from_second_server;<\/code><\/pre>\n<p>Start the replication on the first server:<\/p>\n<pre><code>START SLAVE;<\/code><\/pre>\n<\/section>\n<section>\n<h2>Step 6: Verify Replication<\/h2>\n<p>To check the replication status on both servers, run:<\/p>\n<pre><code>SHOW SLAVE STATUS\\G;<\/code><\/pre>\n<p>Ensure that <code>Slave_IO_Running<\/code> and <code>Slave_SQL_Running<\/code> are both set to &#8220;Yes&#8221;.<\/p>\n<\/section>\n<footer>\n<p>You have successfully set up MariaDB Master-Master replication on Debian 11. This configuration helps improve availability, redundancy, and load balancing for your database setup. For reliable hosting solutions, consider using . They offer a range of hosting options, including <strong>windows virtual private servers<\/strong>, <strong>vps windows hosting<\/strong>, and <strong>windows virtual dedicated server hosting<\/strong>. Whether you&#8217;re looking for <strong>windows vps italy<\/strong> or <strong>uk vps windows<\/strong> solutions, their services provide the performance and flexibility you need for database replication and hosting.<\/p>\n<\/footer>\n<\/article>\n<div class=\"post-author-box\" style=\"border-top:1px solid #ddd;margin-top:20px;padding-top:15px;\">\n<p><strong>Author:<\/strong> \u0141ukasz Bodziony<\/p>\n<p><strong>Website:<\/strong> <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a><\/p>\n<p><em>\u0141ukasz Bodziony is the CEO and founder of <a href=\"https:\/\/netcloud24.com\" target=\"_blank\" rel=\"dofollow\">NETCLOUD24<\/a>, a global VPS hosting brand proudly originating from Poland. With extensive experience in cloud computing, virtualization, and server management, he delivers high-performance <strong>Windows VPS<\/strong> and <strong>Remote Desktop Services (RDS)<\/strong> solutions to clients across Europe, North America, and beyond.<\/em><\/p>\n<p><em>His expertise covers a wide range of technologies, including <strong>Microsoft Azure<\/strong>, <strong>Proxmox VE<\/strong>, <strong>Amazon Web Services (AWS)<\/strong>, and numerous other virtualization and cloud platforms.<\/em><\/p>\n<p><em>Beyond running his hosting business, \u0141ukasz also provides <strong>professional paid server configuration and optimization services<\/strong> for companies and individuals. Outside of work, he is dedicated to caring for his children and building a secure future for them.<\/em><\/p>\n<p><em>If you are interested in working with him or need expert assistance with your hosting, cloud environment, or server setup, feel free to reach out via <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a>.<\/em><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 \u00a0 Master-Master replication in MariaDB allows both database servers to act as a master and replicate data to each other. This setup is useful for load balancing,\u2026<\/p>\n","protected":false},"author":1,"featured_media":3421,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[],"tags":[14,12,11,23,20,21,22,17,7,8,6,10,18,19,15,24,16,5,13,9],"class_list":["post-2300","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","tag-cheapvps","tag-cloudvps","tag-hostingvps","tag-rds","tag-rdscal","tag-remotedesktop","tag-remotedesktopvps","tag-servervps","tag-ukvps","tag-virtualserver","tag-vpshosting","tag-vpsserver","tag-vpssolutions","tag-vpswindows","tag-vpswithwindows","tag-windowsrds","tag-windowsserver","tag-windowsvps","tag-windowsvpshosting","tag-windowsvpsuk"],"jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/2300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=2300"}],"version-history":[{"count":0,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/2300\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media\/3421"}],"wp:attachment":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=2300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=2300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=2300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}