休言女子非英物,夜夜龙泉壁上鸣。这篇文章主要讲述Linux第十二周(数据库主从复制,主主复制,xtrabackup实现备份,Mycat读写分离,ansible常用模块)相关的知识,希望能为你提供帮助。
1、主从复制及主主复制的实现
#主从复制
#8-2为主节点,8为从节点
#都是用MY_SQL 8.0
[root@centos8-2 ~]# yum -y install mysql-server
[root@centos8 ~]# yum -y install mysql-server
[root@centos8-2 ~]# systemctl enable --now mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@centos8 ~]#systemctl enable --now mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
#主节点的配置
[root@centos8-2 ~]# vim /etc/my.cnf
[mysqld]
server-id=151
#更改二进制日志位置,部分数据库默认没有打开log-bin,使用‘log-bin’后续不加地址则只表示打开
log-bin=/data/sql_logs/mysql-bin
#二进制日志文件夹赋权
[root@centos8-2 ~]# chown -R mysql.mysql /data/sql_logs
#重启数据库让配置生效
[root@centos8-2 ~]# systemctl restart mysqld
#输入数据库
[root@centos8-2 ~]# mysql
#查看从二进制日志的文件和位置开始进行复制
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File| Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 |156 ||||
+------------------+----------+--------------+------------------+-------------------+
创建有复制权限的用户账号
mysql> create user repluser@10.0.0.% identified by 123456;
mysql> grant replication slave on *.* to repluser@10.0.0.%;
#从节点的配置
[mysqld]
server_id=150 #为当前节点设置一个全局惟的ID号
read_only=ON #设置数据库只读,针对supper user无效
[mysqld]
mysql> CHANGE MASTER TO MASTER_HOST=10.0.0.151,
-> MASTER_USER=repluser,
-> MASTER_PASSWORD=123456,
-> MASTER_LOG_FILE=mysql-bin.000003,
-> MASTER_LOG_POS=156;
Query OK, 0 rows affected, 8 warnings (0.01 sec)
mysql> start slave;
mysql> show slave status\\G
Slave_IO_State: Waiting for source to send event
Master_Host: 10.0.0.151
Master_User: repluser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 681
Relay_Log_File: centos8-relay-bin.000002
Relay_Log_Pos: 849
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 681
Relay_Log_Space: 1060
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
..........
#检验
#主节点创建库
mysql> create database testdb;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database|
+--------------------+
| information_schema |
| mysql|
| performance_schema |
| sys|
| testdb|
+--------------------+
5 rows in set (0.00 sec)
从节点查看是否同步
mysql> show databases;
+--------------------+
| Database|
+--------------------+
| information_schema |
| mysql|
| performance_schema |
| sys|
| testdb|
+--------------------+
5 rows in set (0.00 sec)
?#主主复制:两个节点,都可以更新数据,并且互为主从?
【Linux第十二周(数据库主从复制,主主复制,xtrabackup实现备份,Mycat读写分离,ansible常用模块)】?#容易产生的问题:数据不一致,同时写入相同数据会导致同步失败,因此慎用.?
#主主复制
#master1配置
[root@localhost ~]# cat /etc//my.cnf
...
[mysqld]
server-id=128
auto_increment_offset=1
auto_increment_increment=2
[root@localhost ~]# systemctl restart mysqld
[root@localhost ~]# mysql
mysql> show master logs;
+---------------+-----------+-----------+
| Log_name| File_size | Encrypted |
+------------推荐阅读
- #yyds干货盘点#K8S 之节点资源
- Docker-可视化管理工具总结-推荐使用Portainer
- 在Power Apps中使用环境变量
- BBoss-ES操作数据及抽ES数据存到List数组
- #导入Word文档图片# Linux下线程编程
- Docker容器实战八(镜像管理命令)
- 解决方案架构师技巧-5种架构图
- 编程为什么有趣(浅谈编程的快乐。)
- 详解文件IO系列讲讲 MQ 消息中间件 (Kafka,RocketMQ等)与MMAPPageCache 的故事...