First, the environment
System CentOS 6.4x64 Minimized installation
Manager 192.168.3.51
Master 192.168.3.52 (Standby Master)
Slave1 192.168.3.53
Slave2 192.168.3.54
Second, configure the hosts local parsing
4 units are configured with the same hosts resolution, the content is as follows
[Email protected] ~]# cat/etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost Localhost.localdomain localhost6 Localhost6.localdomain6192.168.3.51manager192.168.3.52master192.168.3.53slave1192.168.3.54slave2
Three, configure four host SSH secret key login
Manager
[Email protected] ~]# ssh-keygen[[email protected] ~]# ssh-copy-id-i ~/.ssh/id_rsa.pub [email protected][[email Protect Ed] ~]# ssh-copy-id-i ~/.ssh/id_rsa.pub [email protected][[email protected] ~]# ssh-copy-id-i ~/.ssh/id_rsa.pub [email p Rotected]
Master
[Email protected] ~]# ssh-keygen[[email protected] ~]# ssh-copy-id-i ~/.ssh/id_rsa.pub [email protected][[email Protect Ed] ~]# ssh-copy-id-i ~/.ssh/id_rsa.pub [email protected][[email protected] ~]# ssh-copy-id-i ~/.ssh/id_rsa.pub [email p Rotected]
SLAVE1:
[Email protected] ~]# ssh-keygen[[email protected] ~]# ssh-copy-id-i ~/.ssh/id_rsa.pub [email protected][[email Protect Ed] ~]# ssh-copy-id-i ~/.ssh/id_rsa.pub [email protected][[email protected] ~]# ssh-copy-id-i ~/.ssh/id_rsa.pub [email p Rotected]
Slave2:
[Email protected] ~]# ssh-keygen[[email protected] ~]# ssh-copy-id-i ~/.ssh/id_rsa.pub [email protected][[email Protect Ed] ~]# ssh-copy-id-i ~/.ssh/id_rsa.pub [email protected][[email protected] ~]# ssh-copy-id-i ~/.ssh/id_rsa.pub [email p Rotected]
Iv. installation of MySQL
Install the MySQL service on the master,slave1,slave2. Installed here is mysql-5.5.37.tar.gz, using a script to install
The script content is as follows
[[email protected] ~]# cat mysql_install.sh #!/bin/bash datadir= '/data/mysql/ Data ' version= ' mysql-5.5.37 ' EXPORT LANG=ZH_CN. utf-8 #Source function library. /etc/init.d/functions #camke install mysql5.5.xinstall_mysql () { read -p "please input a password for root: " PASSWD if [ ! -d $DATADIR ];then mkdir -p $DATADIR fi yum install cmake make gcc-c++ bison-devel ncurses-devel -y id mysql &>/dev/null if [ $? -ne 0 ];then useradd mysql -s /sbin/nologin -M fi #useradd mysql -s /sbin/nologin -m #change datadir owner to mysql chown -R mysql.mysql $DATADIR cd #wget http://mirrors.sohu.com/mysql/ mysql-5.5/mysql-5.5.38.tar.gz tar xf $VERSION. tar.gz cd $VERSION cmake . -dcmake_install_prefix=/usr/local/$VERSION -dmysql_datadir= $DATADIR -dmysql_unix_addr= $DATADIR/mysql.sock -DDEFAULT_CHARSET=utf8 -ddefault_collation=utf8_general_ci - Denabled_local_infile=on -dwith_innobase_storage_engine=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -dwithout_example_storage_engine=1 - dwithout_partition_storage_engine=1 make && Make install if [ $? -ne 0 ];then action "install mysql is failed! " /bin/false exit $? fi sleep 2 #link ln -s /usr/local/$VERSION/ /usr/local/mysql ln -s /usr/local/mysql/bin/* /usr/bin/ #copy config and start file / bin/cp /usr/local/mysql/support-files/my-small.cnf /etc/my.cnf cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld chmod 700 /etc/init.d/mysqld #init mysql /usr/local/mysql/scripts/mysql_install_db --basedir =/usr/local/mysql --datadir= $DATADIR --user=mysql if [ $? -ne 0 ];then action "install mysql is failed!" /bin/false exit $? fi #check mysql /etc/init.d/mysqld start if [ $? -ne 0 ];then action "mysql start is failed!" /bin/false exit $? fi chkconfig --add mysqld chkconfig mysqld on /usr/local/mysql/bin/mysql -e "Update mysql.user set password=password (' $PASSWD ') where host= ' localhost ' and user= ' root '; /usr/local/mysql/bin/mysql -e "update Mysql.user set password=password (' $PASSWD ') where host= ' 127.0.0.1 ' and user= ' Root '; ' /usr/local/mysql/bin/mysql -e "Delete from mysql.user where password= "; /usr/local/mysql/bin/mysql -e "flush privileges;" #/usr/local/mysql/bin/mysql -e "Select version ( );" >/dev/null 2>&1 if [ $? -eq 0 ];then echo "+---------------------------+" echo "+------MySQL Installation complete--------+" echo "+---------------------------+" fi #/etc/init.d/ Mysqld stop} install_mysql
Establish master-slave replication between master,slave1,slave2
Modify the Server-id of the 3 machine to ensure that it is the only one
#master的server-id[[email protected] ~]# grep server-id/etc/my.cnf server-id= 1#slave1 server-id[[email protected] ~]# grep server-id/etc/my.cnf server-id= 53#slave2 server-id[[email protected] ~]# grep server-id/etc/my.cnf server-id= 53
Configure the master-slave sync account on the master,slave1. SLAVE1 is the backup master, which also requires authorization.
#创建主从同步用的账号
This article is from the "ly36843" blog, please be sure to keep this source http://ly36843.blog.51cto.com/3120113/1671718
CentOS6.4 build MySQL high-availability architecture MHA