MYsql Master-slave replication:
Operating System: centOS6.6
Prepare the file: mariadb-5.5.40-linux-x86_64.tar.gz
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/59/12/wKiom1TGRPHB2RjkAACCTZqdx7Y120.jpg "title=" 111. PNG "alt=" wkiom1tgrphb2rjkaacctzqdx7y120.jpg "/>
(Installation MYSQL, performed in Node2 and node3 )
[[email protected] ~]# Yum install mysql–y (installing mysql client)
[Email protected] ~]# SCP mariadb-5.5.40-linux-x86_64.tar.gz node3:/root
[[email protected] ~]# useradd-r MySQL
[Email protected] ~]# Mkdir-pv/mydata/data
[Email protected] ~]# chown-r mysql.mysql/mydata/data/
[Email protected] ~]# tar-xfmariadb-5.5.40-linux-x86_64.tar.gz-c/usr/local/
[Email protected] ~]# cd/usr/local/
[[email protected] local]# lnmariadb-5.5.40-linux-x86_64/-sv MySQL
[Email protected] local]# CD mysql/
[Email protected] mysql]# chown-r root.mysql./*
[[email protected] MySQL] #scripts/mysql_install_db--user=mysql--datadir=/mydata/data/
[Email protected] mysql]# Mkdir/etc/mysql
[Email protected] mysql]# CPSUPPORT-FILES/MY-LARGE.CNF/ETC/MYSQL/MY.CNF
[Email protected] mysql]# VIM/ETC/MYSQL/MY.CNF
# Try number of CPU ' s*2 forthread_concurrency
Thread_concurrency = 8
DataDir =/mydata/data
Innodb_file_per_table =on
Skip_name_resolve = On
# Replication Master Server (default)
# Binary logging is required forreplication
Log-bin=mysql-bin (enable binary logging)
# Binary Logging format-mixed recommended
Binlog_format=mixed
# required Unique ID between 1 and 2^32-1
# defaults to 1 if master-host are not set
# but would not function as a master ifomitted
Server-id = 1
[email protected] mysql]# CP support-files/mysql.server/etc/init.d/mysqld
[Email protected] mysql]# chkconfig--add mysqld
[[email protected] mysql]# chkconfig--list mysqld (see if Add to Startup item)
[[Email protected] mysql]# service mysqld start
[Email protected] mysql]# cd/mydata/data/
[email protected] data]# LL
-RW-RW----1 mysqlmysql 245 Jan 10:13mysql-bin.000001
-RW-RW----1 Mysqlmysql 10:13mysql-bin.index
..... Toggle NODE2.......
[[email protected] data]#/usr/local/mysql/bin/mysql (connection to MySQL, you can also use the #mysql directly into )
MariaDB [(None)]> GRANT replicationclient,replication SLAVE on * * to ' repluser ' @ ' 172.16.%.% ' identified by ' Replpass ' ; (Create an account with copy permission)
MariaDB [(None)]> FLUSH privileges;
..... Toggle NODE3.......
Modifying a node-dependent configuration
[Email protected] mysql]# VIM/ETC/MYSQL/MY.CNF
# Replication Master Server (default)
# Binary logging is required forreplication
#log-bin=mysql-bin (binary logs are not enabled)
# required Unique ID between 1 and 2^32-1
# defaults to 1 if master-host are not set
# but would not function as a master ifomitted
Server-id = ( Server-id must be modified, not with Node2 same)
Relay-log = Relay-bin (add trunk log)
read-only = on (Open read-only, use on or 1 all Can)
[Email protected] mysql]# service mysqld restart
[[email protected] mysql]#/usr/local/mysql/bin/mysql (connect mysql)
MariaDB [(None)]> SHOW GLOBAL variableslike '%only% '; (see if read-only is turned on)
..... Toggle NODE2.......
[Email protected] data]#/usr/local/mysql/bin/mysql
MariaDB [(None)]> SHOW MASTER STATUS;
| File | Position
| mysql-bin.000001 | 496 | (binary file log and location)
..... Toggle NODE3.......
[Email protected] Mysql]#/usr/local/mysql/bin/mysql
MariaDB [(None)]> change MASTER to master_host= ' 172.16.18.20 ', master_user= ' repluser ', master_password= ' Replpass ', Master_log_file= ' mysql-bin.000001 ', master_log_pos=496, master_connect_retry=5, master_heartbeat_period=2;
( connect to master server )
| Master_host = ' host_name ' Primary server address
| Master_user = ' user_name ' user name with copy permission
| Master_password = ' PASSWORD ' user password
| Master_port = Port_num The port of the primary server
| Master_connect_retry = interval connection retry interval
| Master_heartbeat_period = Interval heartbeat detection interval
| Master_log_file = ' Master_log_name ' primary server binary log file
| Master_log_pos = location in master_log_pos binary log file
MariaDB [(None)]> show SLAVE status\g ( view from server status )
Slave_io_running:no
Slave_sql_running:no
[Email protected] ~]# cd/mydata/data/
[email protected] data]# LL
-RW-RW----1 MySQL mysql 245 Jan 11:21 relay-bin.000001
-RW-RW----1 Mysqlmysql 11:21relay-log.info
MariaDB [(None)]> START SLAVE; ( enable from server )
MariaDB [(None)]> show SLAVE status\g ( view from server status )
Slave_io_running:yes
Slave_sql_running:yes
..... Toggle NODE2.......
[Email protected] Data]#/usr/local/mysql/bin/mysql
mysql> Create databasemydb; (Create a database on the primary server)
..... Toggle NODE3.......
[Email protected] Mysql]#/usr/local/mysql/bin/mysql
Mysql> show Slave status\g; (View status)
Slave_io_state:waiting Formaster to send event
master_host:172.16.18.20
Master_user:repluser
master_port:3306
Connect_retry:60
master_log_file:mysql-bin.000001
read_master_log_pos:579 (position has changed)
mysql> show databases; (in NODE3 View, the data has been copied over)
MySQL compilation installation and master-slave replication