重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
[root@localhost ~]# yum -y install mariadb-server
[root@localhost ~]# vim /etc/my.cnf skip_name_resolve = ON innodb_file_per_table = ON server-id = 1 log-bin = master-log
[root@localhost ~]# systemctl start mariadb.service (启动mariadb server) [root@localhost ~]# mysql MariaDB [(none)]> grant replication slave,replication client on *.* to 'repluser'@'10.1.51.%' identified by 'replpasswd'; MariaDB [(none)]> flush privileges; MariaDB [(none)]> show master status\G (查看主服务器的状态信息,在从服务器中要用到) *************************** 1. row *************************** File: master-log.000003 (正在使用的二进制日志文件) Position: 245 (所处的位置) Binlog_Do_DB: Binlog_Ignore_DB:
[root@localhost ~]# mysql MariaDB [(none)]> install plugin rpl_semi_sync_master soname 'semisync_master.so'; MariaDB [(none)]> set global rpl_semi_sync_master_enabled = ON; 补充: MariaDB [(none)]> show plugins;(可查看插件是否激活) MariaDB [(none)]> show global variables like 'rpl_semi%';(可查看安装的插件是否启用) MariaDB [(none)]> show global status like '%semi%';(可查看从服务器的个数,此时是0个)
[root@localhost ~]# yum -y install mariadb-server
[root@localhost ~]# vim /etc/my.cnf 在[mysqld]段的最后添加以下内容 skip_name_resolve = ON innodb_file_per_table = ON server-id = 2 (id号不能跟主服务器相同) relay-log = slave-log (自定义二进制日志文件名)
[root@localhost ~]# systemctl start mariadb.service [root@localhost ~]# mysql MariaDB [(none)]> change master to master_host='10.1.51.60',master_user='repluser',master_password='replpasswd',master_log_file='master-log.000003',master_log_pos=245;
[root@localhost ~]# mysql MariaDB [(none)]> install plugin rpl_semi_sync_slave soname 'semisync_slave.so'; MariaDB [(none)]> set global rpl_semi_sync_slave_enabled = ON; MariaDB [(none)]> start slave;
完成上面配置后,可以在主服务器上查看半同步复制的相关信息,命令如下:
创新互联建站成都网站建设按需制作网站,是成都网站营销推广公司,为成都建筑动画提供网站建设服务,有成熟的网站定制合作流程,提供网站定制设计服务:原型图制作、网站创意设计、前端HTML5制作、后台程序开发等。成都网站营销推广热线:028-86922220MariaDB [(none)]> show global status like '%semi%'; Rpl_semi_sync_master_clients 1 (从服务器有一台)
测试以个人实际情况而定
MariaDB [hellodb]> source /root/hellodb.sql;
MariaDB [hellodb]> show master status; +-------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +-------------------+----------+--------------+------------------+ | master-log.000003 | 8102 | | | +-------------------+----------+--------------+------------------+ MariaDB [hellodb]> show global status like '%semi%'; +--------------------------------------------+-------+ | Variable_name | Value | +--------------------------------------------+-------+ | Rpl_semi_sync_master_clients | 1 | | Rpl_semi_sync_master_net_avg_wait_time | 1684 | | Rpl_semi_sync_master_net_wait_time | 60630 | | Rpl_semi_sync_master_net_waits | 36 | | Rpl_semi_sync_master_no_times | 1 | | Rpl_semi_sync_master_no_tx | 1 | | Rpl_semi_sync_master_status | ON | | Rpl_semi_sync_master_timefunc_failures | 0 | | Rpl_semi_sync_master_tx_avg_wait_time | 1884 | | Rpl_semi_sync_master_tx_wait_time | 65965 | | Rpl_semi_sync_master_tx_waits | 35 | | Rpl_semi_sync_master_wait_pos_backtraverse | 0 | | Rpl_semi_sync_master_wait_sessions | 0 | | Rpl_semi_sync_master_yes_tx | 35 | +--------------------------------------------+-------+
MariaDB [(none)]> show databases; MariaDB [(none)]> use hellodb; MariaDB [hellodb]> select * from students;
[root@localhost ~]# systemctl stop mariadb.service
[root@localhost ~]# vim /etc/my.cnf skip_name_resolve = ON innodb_file_per_table = ON server-id = 2 relay-log = slave-log replicate-do-db = mydb (只复制mydb数据库的内容) 补充:常用的过滤选项如下 Replicate_Do_DB= Replicate_Ignore_DB= Replicate_Do_Table= Replicate_Ignore_Table= Replicate_Wild_Do_Table= Replicate_Wild_Ignore_Table=
[root@localhost ~]# systemctl start mariadb.service
MariaDB [(none)]> show global variables like '%semi%'; +---------------------------------+-------+ | Variable_name | Value | +---------------------------------+-------+ | rpl_semi_sync_slave_enabled | OFF | | rpl_semi_sync_slave_trace_level | 32 | +---------------------------------+-------+ MariaDB [(none)]> set global rpl_semi_sync_slave_enabled = ON; MariaDB [(none)]> stop slave;(需先关闭从服务器复制功能再重启) MariaDB [(none)]> start slave;
MariaDB [hellodb]> create table semitable (id int);
MariaDB [(none)]> use hellodb MariaDB [hellodb]> show tables;(并没有) +-------------------+ | Tables_in_hellodb | +-------------------+ | classes | | coc | | courses | | scores | | students | | teachers | | toc | +-------------------+
MariaDB [hellodb]> create database mydb;
MariaDB [hellodb]> use mydb; MariaDB [mydb]> show tables; (可以查看到) +----------------+ | Tables_in_mydb | +----------------+ | tbl1 | +----------------+
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。