MySQL master-slave and MySQL primary and semi-synchronous replication

Source: Internet
Author: User

First, preparation (master and slave need to configure):     yum -y install mysql mysql-server# installation mysql   yum -y install ntpdate# installation time Sync   echo  ' */1 * * * *  /usr/sbin/ntpdate ntp1.aliyun.com &>/dev/null '  >>/var/spool/cron/root# Configure Network time synchronization   service mysqld start# Start Service   chkconfig --add mysqld# Add as System service    chkconfig  mysqld on# turn on Default run level two, primary server configuration: The main profile defaults to:/etc/my.cnf    [mysqld ]  datadir=/var/lib/mysql  socket=/var/lib/mysql/mysql.sock  user=mysql   symbolic-links=0  log-bin=master-bin# Open Binary log file   server-id=1# set server ID to ensure global unique    sync-binlog=1             #全局唯一的server-id   innodb-flush-logs-at-trx-commit=1              innodb-support-xa=1  service mysqld restart# Restart Service   mysql> show global variables  like  '%server% ';       #数据库id   mysql> show  master logs;       #查看数据库二进制日志   mysql> show master  status;     #查看主服务器状态, remember the binary log name, configure the server to be used   mysql> grant  replication slave,replication client on *.* to   ' copy ' @ ' 192.168.0.50 '   identified by  ' 123.com ';       #授权192. Copy users on 168.0.50 host have replication permissions on all libraries    mysql> select Host,User,Password from mysql.user; #查看用户三, from server configuration:     [mysqld]    datadir=/var/lib/mysql    socket=/var/lib/mysql/ mysql.sock    user=mysql    symbolic-links=0     relay-log=slave-log# enable the relay log     server-id=10# server ID, globally unique     read-only=1# set the server to read-only mode (not valid for users with root privileges)      service mysqld restart# Restart Service     mysql> change  Master to master_host= ' 192.168.0.10 ', master_user= ' copy ',            master_password= ' 123.com ', master_log_file= ' master-bin.000001 ', master_log_pos=590; master_host                # Primary server address master_user                  #拥有复制权限的用户master_password             # Password master_log_file             #从哪个二进制日志开始复制master_ log_pos              #从二进制日志的什么位置开始复制      mysql> start&Nbsp;slave, #开启从服务器     mysql> show slave status\G; #查看从服务器状态四, verify master-slave:      Primary server:         mysql> create database  db_test; #创建数据库      Slave server: mysql> show databases;    # See if the server is synchronizing five, primary primary replication      server a:        [mysqld]# Add content log-bin=master-bin# enable binary log relay-log=slave-log# enable relay log server-id=1# server ID, globally unique auto-increment-offset=1# Self-increment column start auto-increment-increment=2# self-increment one step at a time (example: 1,3,5,7,9 ...)     mysql> grant replication slave,replication client on  *.* to   ' copy ' @ ' 192.168.0.50 '  identified by  ' 123.com ';     Mysql> change master to master_host= ' 192.168.0.50 ', master_user= ' copy ',           master_password= ' 123.com ', master_log_file= ' master-bin.000001 ',master_log_pos=106;        mysql> start  slave;    mysql> show slave status\g;     Server b:         [MYSQLD] #添加内容         log-bin =master-binrelay-log=slave-logserver-id=10auto-increment-offset=2# self-increment column starting auto-increment-increment=2# self-increment one step at a time (example: 2, 4,6,8,10 ...)         mysql> grant replication slave, replication client on *.* to   ' copy ' @ ' 192.168.0.10 '  identified by   ' 123.com '; mysql> change master to master_host= ' 192.168.0.10 ', master_user= ' copy ',     master_password= ' 123.com ', master_log_file= ' master-bin.000003 ', master_log_pos=106;mysql > start slave;mysql> show slave status\G; semi-synchronous replication      To use semi-synchronous replication, the following conditions must be met: &nbsp       1. mysql 5.5 and above version 2.  variable have_dynamic_loading is YES3.   Asynchronous replication already exists      primary:mysql> install plugin rpl_semi_sync_master  soname  ' semisync_master.so '; #安装插件mysql > show plugins; #查看插件是否安装成功mysql > SET  global rpl_semi_sync_master_enabled = 1; #启用半同步mysql > show status like  ' Rpl_semi_sync_master_status '; #查看是否在运行      from: Mysql> install plugin rpl_ semi_sync_slave soname  ' semisync_slave.so '; #安装插件mysql > show plugins;mysql> set  GLOBAL rpl_semi_sync_slave_enabled = 1; #启用半同步mysql > stop slave# off replication thread MySQL > START SLAVE  #开启复制线程mysql > show status like  ' rpl_semi_sync_slave_ Status '; #查看是否在运行mysql > show variables like  '%rpl% '; #查看和半同步相关的服务器变量rpl_semi_sync_master_ enabled# whether to enable the semi-synchronous rpl_semi_sync_master_timeout# Wait Timeout time rpl_semi_sync_master_wait_for_slave_count     #需要等待多少个slave应答, To return to the client mysql> show status like  '%rpl_semi% '; #半同步状态Rpl_semi_sync_master_clients # Current semi-synchronous replication from number seven, and copy related files      from node:         Master.info: Used to save slave connection to master (account number, password, server address, duplicate binaries, etc.) Relay-log.info: Saves the location of the binary files that have been copied to the current slave node, and the location of the Relay-log


This article is from the "Automated Operations" blog, please be sure to keep this source http://hongchen99.blog.51cto.com/12534281/1936473

MySQL master-slave and MySQL primary and semi-synchronous replication

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.