First, the environment
System CentOS 6.4×64 minimal installation
manager 192.168.3.51
master 192.168.3.52 (backup master)
slave1 192.168.3.53
slave2 192.168.3.54
Second, configure hosts resolved locally
4 sets of machines are configured with the same resolve hosts, as follows
[Root @ manager ~] # cat / etc / hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.3.51 manager
192.168.3.52 master
192.168.3.53 slave1
192.168.3.54 slave2
Third, is arranged between the four hosts ssh Free secret key landing
manager:
[Root @ manager ~] # ssh-keygen
[Root @ manager ~] # ssh-copy-id -i ~ / .ssh / id_rsa.pub root @ master
[Root @ manager ~] # ssh-copy-id -i ~ / .ssh / id_rsa.pub root @ slave1
[Root @ manager ~] # ssh-copy-id -i ~ / .ssh / id_rsa.pub root @ slave2
master:
[Root @ master ~] # ssh-keygen
[Root @ master ~] # ssh-copy-id -i ~ / .ssh / id_rsa.pub root @ manager
[Root @ master ~] # ssh-copy-id -i ~ / .ssh / id_rsa.pub root @ slave1
[Root @ master ~] # ssh-copy-id -i ~ / .ssh / id_rsa.pub root @ slave2
slave1:
[Root @ slave1 ~] # ssh-keygen
[Root @ slave1 ~] # ssh-copy-id -i ~ / .ssh / id_rsa.pub root @ manager
[Root @ slave1 ~] # ssh-copy-id -i ~ / .ssh / id_rsa.pub root @ master
[Root @ slave1 ~] # ssh-copy-id -i ~ / .ssh / id_rsa.pub root @ slave2
slave2:
[Root @ slave2 ~] # ssh-keygen
[Root @ slave2 ~] # ssh-copy-id -i ~ / .ssh / id_rsa.pub root @ manager
[Root @ slave2 ~] # ssh-copy-id -i ~ / .ssh / id_rsa.pub root @ master
[Root @ slave2 ~] # ssh-copy-id -i ~ / .ssh / id_rsa.pub root @ slave1
Fourth, install mysql
Install mysql service on the master, slave1, slave2. Here installed mysql-5.5.37.tar.gz, use a script to install
Script reads as follows
[Root @ master ~] # 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.X
install_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 is complete ——– +”
echo “+ ————————— +”
fi
# / Etc / init.d / mysqld stop
}
install_mysql
Establish the main master, slave1, slave2 from replication between
Amendment 3 station set server-id, guaranteed to be unique
#master of server-id
[Root @ master ~] # grep server-id /etc/my.cnf
server-id = 1
# Slave1 of server-id
[Root @ slave1 ~] # grep server-id /etc/my.cnf
server-id = 53
# Slave2 of server-id
[Root @ slave2 ~] # grep server-id /etc/my.cnf
server-id = 53
Configure the master-slave synchronization with the account on master, slave1. slave1 is a backup master, this also needs to be authorized.
# Create a master-slave synchronization account
Leave a Reply