Set Up MySQL 8 Replication with Linux Nodes

树莓派搭建高可靠NAS数据库服务器实战 NAS(网络附加存储)与数据库服务的融合是边缘计算和家庭数据中心的核心能力。其本质在于通过分层架构实现存储可靠性与数据服务性能的协同优化:底层依托ZFS等具备校验和、快照与写时复制能力的现代文件系统保障数据一致性;中层借助Docker容器化技术隔离数据库实例(如PostgreSQL、InfluxDB),解决依赖冲突与升级风险;上层采用Nginx反向代理统一HTTPS访问入口,兼顾安全与易用。该方案特别适配低功耗、7×24运行的嵌入式场景,显著区别于传统x86服务器设计逻辑。树莓派并非性能缩水版,而是为高可靠 阅读详情

https://arctype.com/blog/mysql-8-create-master-slave-replication/

MySQL is an open-source and one of the most widely used relational database management systems. Setting up a separate MySQL backup server is essential in the event of failure, as the backup server contains everything necessary for a successful recovery.

Replication features in MySQL allow you to maintain multiple copies of MySQL data. All data in the master server will be synced to the slave server automatically. If your master server fails, you can promote a Slave to a Master for commit operations.

Prerequisites

• Two servers running Ubuntu 20.04.

• A root password is configured on both servers.

For this tutorial, we will use the following configuration:

ServerIP Address
master45.58.41.25
slave45.58.40.60

Install MySQL 8

First, you will need to install the MySQL 8 server on both servers.

Run the following command to install the MySQL 8 server on both servers.

apt install mysql-server -y

After installing the MySQL server, you will need to set a MySQL root password on both servers.

Run the following command to set a root password:

mysql_secure_installation

You will be asked the following:

Press y|Y for Yes, any other key for No:

Just press Enter to set a root password:

Please set the password for root here.
New password: 
Re-enter new password:

Set your MySQL root password and answer the remaining questions as shown below:

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y

Configure Master Server

First, you will need to edit the MySQL default configuration file on the Master server to allow remote access and enable the binary log.

nano /etc/mysql/mysql.conf.d/mysqld.cnf

Add or modify the following lines:

[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
bind-address            = 0.0.0.0  
log_error = /var/log/mysql/error.log
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
max_binlog_size = 500M
slow_query_log = 1

Save and close the file, then restart the MySQL service to apply the changes.

systemctl restart mysql

Create a Replication User on Master Server

Next, you will need to create a replication user on the Master server to manage the replication.

To do so, connect to the MySQL shell with the following command:

mysql -u root -p

Provide your MySQL root password, then run the following command to create a replication user:

mysql> CREATE USER slaveuser@45.58.40.60 IDENTIFIED WITH mysql_native_password BY 'password';

Next, grant REPLICATION SLAVE privileges to replication user:

mysql> grant replication slave on *.* to slaveuser@45.58.40.60;

Next, flush the privileges to apply the changes:

mysql> flush privileges;

Next, check the privileges using the following command:

mysql> show grants for slaveuser@45.58.40.60;

Sample output:

+-------------------------------------------------------------+
| Grants for slaveuser@45.58.40.60                            |
+-------------------------------------------------------------+
| GRANT REPLICATION SLAVE ON *.* TO `slaveuser`@`45.58.40.60` |
+-------------------------------------------------------------+

Next, exit from the MySQL shell with the following command:

mysql> exit;

Note: Replace the 45.58.40.60 with the IP address of the Slave server.

Configure Slave Server

Next, you will need to edit the MySQL main configuration file and make some changes:

nano /etc/mysql/mysql.conf.d/mysqld.cnf

Add or modify the following lines:

pid-file        = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
bind-address            = 0.0.0.0  
datadir = /var/lib/mysql
log_bin = /var/log/mysql/mysql-bin.log
server-id = 2
read_only = 1
max_binlog_size = 500M
slow_query_log   = 1

Save and close the file, then restart the MySQL service to apply the changes:

systemctl restart mysql

Initialize Replication on Slave Server

Next, you will need to start the Replication process on the slave server.

First, connect to the MySQL shell on the Master server with the following command:

mysql -u root -p

Next, check the Master status with the following command:

mysql> show master status\G

Sample output:

*************************** 1. row ***************************
             File: mysql-bin.000002
         Position: 1047
     Binlog_Do_DB: 
 Binlog_Ignore_DB: 
Executed_Gtid_Set: 
1 row in set (0.00 sec)

From the above output, note down the master log file and position number

Next, go to the Slave server and connect to the MySQL shell:

mysql -u root -p

Next, use the information obtained from the Master server and configure the Slave server with the following command:

mysql> CHANGE MASTER TO MASTER_HOST='45.58.41.25', MASTER_USER='slaveuser', MASTER_PASSWORD='password', MASTER_LOG_FILE='mysql-bin.000002', MASTER_LOG_POS=1047;

Next, start the Slave using the following command:

Note: replace IP 45.58.41.25 with the IP address of the Master server.

mysql> start slave;

Next, verify the Slave status with the following command:

mysql> show slave status\G

You should get the following output:

*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 45.58.41.25
                  Master_User: slaveuser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000002
          Read_Master_Log_Pos: 1047
               Relay_Log_File: slave-relay-bin.000002
                Relay_Log_Pos: 324
        Relay_Master_Log_File: mysql-bin.000002
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

Verify Master-Slave Replication

At this point, MySQL Master-Slave replication is configured. Now, it's time to test whether the replication is working or not.

First, go to the Master server and create a database with the following command:

mysql -u root -p
mysql> create database replicadb;

Next, verify all databases using the following command:

mysql> show databases;

Sample output:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| replicadb          |
| sys                |
+--------------------+

Next, exit from the MySQL shell:

mysql> exit;

Next, go to the Slave server and connect to the MySQL

mysql -u root -p

Next, list all databases using the following command:

mysql> show databases;

Sample output:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| replicadb          |
| sys                |
+--------------------+

The above output indicates that MySQL Master-Slave replication is working as expected because the database 'replicadb' was replicated on server 2.

Conclusion

In the above guide, you learned how to set up a two-node MySQL 8 Master-Slave replication on Ubuntu 20.04. You can now implement this setup in the production environment to perform live copies of your databases.

【信息科学与工程学】计算机科学与自动化——第一百五十五篇 缓存系统设计01 基础知识 CPU:拥有 L1/L2/L3 多级缓存,用于暂存即将执行的指令和频繁访问的数据。GPU:包含显存、纹理缓存、常量缓存、指令缓存等,加速图形渲染和通用计算。RAID 卡 / 存储控制器:自带缓存(通常带电池保护),用于合并写操作、加速读写。打印机:内置内存缓存,用于暂存待打印的页面数据,避免反复从电脑传输。光驱 / 蓝光播放器:内部缓存用于平滑读取光盘数据,防止因寻道延迟导致卡顿。操作系统:页缓存(Page Cache):缓存文件系统数据,减少磁盘 I/O。目录缓存(dentry cache):加速路径查找 阅读详情

相关推荐

【信息科学与工程学】计算机科学与技术——第七十七篇 系统架构设计02

编号类型模型配方企业资本运作的方法/规则/条件/依据及所有的步骤(​风险处理/异常处理/危机应对关联知识法律法规和裁决依据​​由发起人(通常是知名投资人、投行或产业资本)先设立一个只有现金、无实际业务的特殊目的收购公司(SPAC),通过IPO募集资金并在交易所上市。然后在规定时间内(通常24个月)寻找一家非上市公司进行合并(De-SPAC),使目标公司迅速实现上市,规避传统IPO的复杂流程和不确定性。1.:在开曼或特拉华注册空壳公司,注入少量种子资金。2.

weixin_49199313的博客 198

MGR/GTID/MHA 数据库集群与 Redis/Codis 缓存全套实战教程

本文基于多台 CentOS 虚拟机,完整实操 MySQL MGR 多主、GTID 一主两从、MHA 自动故障切换三类数据库高可用架构,搭配 MySQL Router、LVS+Keepalived 实现三层负载均衡;同时覆盖 Redis 主从、哨兵、Cluster 分片集群,以及 Codis 分布式缓存完整部署,包含源码编译、集群初始化、故障切换、在线扩容全套命令实操,适合数据库与中间件运维进阶实训。

2401_84291419的博客 288

【信息科学与工程学】【数据中心】第三十五篇 云计算数据中心的学科知识04

编号学科(课程)核心知识点在云计算/云存储/云网络/云安全/云MaaS中的作用代表教材/资料/论文 + 数学方程式列表工业界应用D1421​云原生数据库:TiDB​HTAP(混合事务/分析处理)、分布式SQL、水平扩展、强一致(Raft)、自动故障恢复、与MySQL兼容、TiFlash列式引擎提供弹性扩展的分布式数据库;支撑高并发在线交易与实时分析教材:《TiDB in Action》PingCAP(2020) 论文:《TiDB: A Raft-based HTAP Database》(2017)

weixin_49199313的博客 153

liunx版本的

services:ports:volumes:network_mode: "host" # 添加此行(必须)kibana:ports:ELASTICSEARCH_HOSTS: http://192.168.1.145:9200 # 具体ip(必须)network_mode: "host" # # 添加此行(必须)

m0_45209551的博客 1151

使用 TiUP 部署 tidb 三节点集群

最近 TiDB 认证免费考证活动火热报名中!于是在官网下载了一个安装包,在本地环境创建了三台 Centos7.9 的虚拟机,通过 tiup 部署 三节点集群,数据库版本 v7.1.9-0.0TiUP 是在 TiDB v4.0 中引入的集群运维工具,提供了使用 Golang 编写的集群管理组件。通过使用 TiUP cluster 组件,可以轻松执行日常的数据库运维操作,包括部署、启动、关闭、销毁、弹性扩缩容、升级 TiDB 集群,以及管理 TiDB 集群参数。

fangmiao_haha的博客 181

DevOps记录

目录 CI/CD Docker & Kubernetes Docker开发 + 阿里云容器镜像服务 Kubernetes Kubernetes Dashboard Ansible Ansible Tower Terraform

保持初心 保持好奇 1735

Nextcloud容器化迁移:企业级部署架构深度解析

在数字化转型浪潮中,企业自托管解决方案正经历从传统部署模式向云原生架构的演进。Nextcloud作为领先的开源文件同步与共享平台,其容器化部署不仅简化了运维复杂度,更在可扩展性、资源隔离和持续交付方面带来了革命性改进。本文深入探讨Nextcloud Docker化迁移的技术挑战、架构设计原则以及生产环境最佳实践。 ## 1. 架构演进分析:从单体到微服务的范式转变 传统Nextcloud部署通

gitblog_00225的博客 319

企业级GB28181视频监控平台实战:从零构建标准化安防系统

### 真实场景下的安防挑战 在智慧城市、智慧园区、智慧交通等现代化安防项目中,系统集成商常常面临三大核心痛点: **痛点一:设备品牌碎片化** - 一个中型园区可能同时部署海康、大华、宇视等多个品牌的监控设备,每个厂商都有不同的私有协议和管理平台,导致系统集成困难,维护成本高昂。 **痛点二:跨网络传输瓶颈** - 传统视频监控系统难以实现跨公网、跨专网的实时视频传输,特别是在多级联网、上

gitblog_00528的博客 366

主神空间平台:基于无限流架构的分布式规则引擎实践

规则引擎是分布式系统中的核心技术组件,通过声明式的方式定义和执行业务逻辑。其工作原理基于条件评估和动作触发机制,能够实现业务规则的动态管理和热更新。在技术价值层面,规则引擎解决了传统架构中业务规则频繁变更、服务耦合度高的问题,显著提升了系统的灵活性和可维护性。典型的应用场景包括电商促销、多租户系统、游戏服务器等需要复杂业务逻辑处理的领域。本文介绍的主神空间平台正是基于无限流架构思想,将每个业务场景抽象为独立的'任务世界',通过FX规则引擎实现高并发、多租户场景下的规则管理,为分布式系统开发提供了创新的解决方

weixin_30596343的博客 432

【信息科学与工程学】计算机科学与自动化——第三百零五篇 计算机系统中的各类运算操作01

编号类型领域运算操作运算类型算法算法的详细设计及数学分析参数列表及参数的数值设计应用场景 (100+条)集合运算​1集合运算关系代数并集 (Union)集合运算归并排序去重合并两个集合,去除重复元素。时间复杂度 O(n+m),n,m为两集合大小。输入:集合A, B。输出:A∪B。数据集成、多表结果合并、去重后的全量数据提取。2集合运算关系代数交集 (Intersection)集合运算哈希交集找出同时属于两个集合的元素。平均时间复杂度 O(min(n,m)),最坏 O(n*m)。输入:集合A, B。输出:A∩

weixin_49199313的博客 989

【信息科学与工程学】【数据中心】 第七篇 智算中心CLOS组网整体设计

区域主要功能网络要求技术选型安全等级可用性要求训练区​大规模AI模型训练,分布式计算超高带宽(100G+),超低延迟(<1ms),无损网络RoCEv2,PFC,DCQCN,多路径P4(最高)99.99%推理区​实时AI推理,模型服务低延迟(<10ms),高可用,弹性扩展智能负载均衡,服务网格,容器网络P3(高)99.999%公共服务区​统一认证,API网关,数据服务多租户隔离,安全防护,弹性带宽VXLAN,EVPN,微隔离P3(高)99.99%存储区​高性能存储,数据湖超高带宽,低延迟,高IOPSNVMe-

weixin_49199313的博客 1299

【信息科学与工程学】计算机科学与自动化——第八十一篇 Java分布式软件高并发/高可用算法01

4. 消息队列(如Kafka的Topic分区,本质是范围)。3. 若是ACCEPT事件,bossGroup线程接受连接,创建SocketChannel,并将其注册到workerGroup的一个EventLoop的Selector上,关注READ事件。1. 分布式缓存分片(如Redis Cluster)。4. 分布式文件存储(如Ceph CRUSH)。6. 调用栈的模拟(如协程)。3. 服务网格(如Istio)的基础。2. 本地缓存与集中式缓存(如Redis)的一致性维护。3. 静态数据(如配置)缓存。

weixin_49199313的博客 1141

【信息科学与工程学】计算机科学与自动化——第八十四篇 C++分布式软件高并发/高可用算法01

4. 提交:协调者选择提交时间戳(>所有读时间戳),两阶段提交:a) 写意图预提交到所有参与者,b) 参与者持久化后确认,c) 协调者决定提交,异步清理意图。:客户端请求发送到协调节点,协调节点根据路由转发到主分片所在节点。Span有父子关系。1. 索引文档:客户端发送PUT请求到协调节点,协调节点路由到主分片节点,主分片写入本地,然后并行复制到副本分片,等待确认后响应客户端。3. 搜索:客户端发送搜索请求到协调节点,协调节点广播到所有相关分片,每个分片执行查询,返回结果,协调节点合并、排序、分页后返回。

weixin_49199313的博客 1014

【信息科学与工程学】计算机科学与自动化-——第十五篇云计算 12 公有云里的“多Region + 多AZ“ 02 运营算法01

算法逐步思考推理思考(含数学方程式、对象、资源、任务、进程/协程/线程及对应的代数、约束、目标函数/传递函数/依赖函数、参数及参数的数值范围及边界条件、逐步推理的数学方程式列表、上下文切换、并发/串行/随机/乱序/顺序)算法逐步思考推理思考(含数学方程式、对象、资源、任务、进程/协程/线程及对应的代数、约束、目标函数/传递函数/依赖函数、参数及参数的数值范围及边界条件、逐步推理的数学方程式列表、上下文切换、并发/串行/随机/乱序/顺序)云厂商提高闲置资源利用率。算法复杂度为O(N),N为实例数量。

weixin_49199313的博客 200

【信息科学与工程学】【云计算】计算机科学与自动化——第十五篇 云计算10 云计算领域架构

​:作为前端请求的统一入口,负载均衡器基于预设算法(如轮询、最小连接数)动态分配流量至后端服务器集群。​:通过IP哈希或Cookie绑定,保障同一用户请求由同一服务器处理(如电商购物车场景)。​:Nginx(HTTP/HTTPS反向代理)、HAProxy(TCP层负载均衡)。​:实时监控服务器状态(如响应时间、连接数),自动剔除故障节点,确保服务连续性。​:本地资源满载时,将流量分流至公有云(如AWS + 私有云混合架构)。​:LSTM预测流量峰值,强化学习动态调整权重(如阿里云智能负载均衡)。

weixin_49199313的博客 1822

【信息科学与工程学】计算机科学与自动化——第一百五十九篇 系统架构分析与设计01

根据提供的《系统可靠性分析与设计》《软件工程》《软件架构设计》《信息系统安全统一监管平台设计》四份资料,"系统架构设计"语境下的"算法"主要包括可靠性指标与系统计算算法、可靠性预测模型、架构评估算法、容错与恢复算法、以数据为中心的关联分析算法等。下面按你要求的表格格式整理。编号类型领域算法算法的数学分析及代码分析及参数列表关联知识1可靠性指标计算系统可靠性MTTF / MTTR / MTBF / 可用性计算​数学: MTTF = 1/λ;MTTR = 1/μ;MTBF = MTTR + MTTF;系统可用性

weixin_49199313的博客 117

【信息科学与工程学】计算机科学与自动化——第一百五十九篇 系统架构分析与设计02

4. 同步链路预算:T_sync ≤ 10ms,分解:T_validate(1ms) + T_route(0.5ms) + T_frozen_try(2ms) + T_acct_try(2ms) + T_confirm_parallel(3ms) + T_notify(1ms) ≈ 9.5ms。2. 多目标评分:Score(channel) = w₁×(1 - cost_i/cost_max) + w₂×(1 - latency_i/latency_max) + w₃×availability_i。

weixin_49199313的博客 5

MySQL 事务、四大隔离级别、MVCC完整原理笔记|案例+问题演示

本文完整讲解MySQL InnoDB事务全套核心知识点,从并发数据错乱问题引出事务概念,详解事务四大特性ACID底层实现原理:原子性依靠undo log、持久性依靠redo log、隔离性由锁+MVCC保障,一致性为最终状态由技术与业务代码共同实现。通过4组客户端宕机实操实验区分自动提交、显式/隐式事务提交与回滚机制。依次介绍四大隔离级别,脏读、不可重复读、幻读三类并发问题,深入拆解MVCC多版本并发控制、隐藏列、undo版本链、ReadView快照可见性规则,对比RC与RR隔离级别快照生成差异。

m0_68447088的博客 289
下一篇: MySQL复制跳过错误--slave_skip_errors、sql_slave_skip_counter、slave_exec_mode
yangfree990
博客等级 码龄24年 0粉丝 · 2原创
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值