Centos7 mariadb 10.5主主复制
1.主数据库(1)
vim /etc/my.cnf
port=3306
server-id=129
log-bin=mysql-bin
auto_increment_increment=2
auto_increment_offset=1
binlog-ignore=mysql
binlog-ignore=information_schema
binlog-ignore=performance_schema
character_set_server=utf8
log-bin-trust-function-creators=1
skip-name-resolve
2.主数据库(2)
vim /etc/my.cnf
port=3306
server-id=130
log-bin=mysql-bin
auto_increment_increment=2
auto_increment_offset=2
binlog-ignore=mysql
binlog-ignore=information_schema
binlog-ignore=performance_schema
character_set_server=utf8
log-bin-trust-function-creators=1
skip-name-resolve
port=3305 将mysql启动端口设置成3305(默认为3306)
log-bin 启动mysql二进制日志,如果没有配置这个将无法远程链接
binlog-ignore 指定不同步的数据库,如果有多个数据库不需要同步可以多个分别声明
character_set_server=utf8 指定utf8为默认字符集
server-id 可以为任意自然数,必须保证两台mysql主机不重复
auto_increment_increment=2 步进值auto_imcrement。一般有n台主MySQL就填n
auto_increment_offset 设定数据库中自动增长的起点,两台mysql的起点必须不同,这样才能避免两台服务器同步时出现主键冲突
replicate-do-db 要同步的数据库,如果需要就填,指定数据库的名称即可,默认为所有库,声明了不同步就默认除了不同步数据库意外的所有库。这里我没写。
log-bin-trust-function-creators=1 在默认情况下mysql会阻止主从同步的数据库function的创建,这会导致我们在导入sql文件时如果有创建function或者使用function的语句将会报错。
skip-name-resolve 跳过DNS 解析
3. 进入数据库相互授权
flush privileges;
1相互授权:192.168.126.129
grant replication slave, replication client on *.* to 'slaveuser'@'192.168.126.130' identified by 'slaveuserPassword';
2相互授权:192.168.126.130
grant replication slave, replication client on *.* to 'slaveuser'@'192.168.126.129' identified by 'slaveuserPassword';
备注
(注意:推荐两个主机相互授权的账号密码相同,否则在接下来的操作中可能会比较乱
分别查看两台主机的日志节点:
show master status;
192.168.126.129
mysql-bin.000001 | 245 | | mysql,information_schema,performance_schema
192.168.126.130
mysql-bin.000001 | 245 | | mysql,information_schema,performance_schema
4.相互设置同步的日志节点
(master_log_file='mysql-bin.000002',master_log_pos=245;master_log_file为show master status的mysql-bin,master_log_pos为对应的点)
192.168.126.129:
change master to master_host='192.168.126.130',master_port=3306, master_user='slaveuser',master_password='slaveuserPassword',master_log_file='mysql-bin.000002',master_log_pos=245;
192.168.126.130:
change master to master_host='192.168.126.129', master_port=3306, master_user='slaveuser',master_password='slaveuserPassword',master_log_file='mysql-bin.000002',master_log_pos=245;
5.在两台主机上启动slave服务
start slave;
说明:
所有的内容都是另一台主机的内容,log_file和log_pos对于另一台主机的日志节点。
还有,必须要说明的是,每次“flush privileges”和“stop slave”后日志节点的内容会改变,
所以如果不确定,每次执行此操作前必须要查看日志节点
show master status。另外,执行此操作时slave必须没有启动,
如果之前执行了,那就先停止,指令:stop slave;
查看slave状态
show slave status\G
关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service 禁止防火墙
创建数据库测试
CREATE DATABASE test_db;
CREATE TABLE runoob_tbl(runoob_id INT NOT NULL AUTO_INCREMENT,runoob_title VARCHAR(100) NOT NULL,runoob_author VARCHAR(40) NOT NULL, submission_date DATE, PRIMARY KEY ( runoob_id ))ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO runoob_tbl (runoob_title, runoob_author, submission_date)VALUES ("学习 PHP", "菜鸟教程", NOW());
CREATE TABLE runoob_tbl(runoob_id INT NOT NULL AUTO_INCREMENT,runoob_title VARCHAR(100) NOT NULL,runoob_author VARCHAR(40) NOT NULL, submission_date DATE, PRIMARY KEY ( runoob_id ))ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE DATABASE test_db2;
https://blog.csdn.net/m0_37673753/article/details/81281444
https://blog.csdn.net/weixin_43063753/article/details/87638653
https://www.cnblogs.com/pangguoming/p/9640410.html
同步网络时间
yum install ntpdate -y
ntpdate ntp1.aliyun.com