Configuring bitsCN.com for mysql master-slave synchronization
Master host: www IP: 192.168.9.124
From host: www1 IP: 192.168.9.123
# Download mysql
Wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.58-linux-i686-glibc23.tar.gz/from/ftp://mirror.anl.gov/pub/mysql/
# Install mysql
Tar xzf mysql-5.1.58-linux-i686-glibc23.tar.gz
Useradd mysql
Music mysql-5.1.58-linux-i686-glibc23/usr/local/mysql
Chown-R root.
Chown-R mysql data
Cp support-files/my-medium.cnf/etc/my. cnf
Bin/mysqld_safe -- user = mysql &
Cp support-files/mysql. server/etc/init. d/mysql. server
Cd
Export PATH = $ PATH:/usr/local/mysql/bin/# add the environment variable
Change master/slave root passwords respectively
# Mysql
Mysql> update mysql. user set password = password ('000000') where user = "root" and host = "localhost ";
Www:
Mysql> grant all privileges on *. * to root@192.168.9.123 identified by '000000'; # authorize 192.168.9.123 to log on to mysql
Mysql> flush privileges; # refresh the permission table
Mysql> exit;
Test on slave server
Www1
# Mysql-u root-h 192.168.9.124-p
Www
Mysql> flush tables with read lock; (LOCK the master database)
Log and offset
Mysql> show master status;
Mysqldump-p -- all-database -- lock-all-tables> db. SQL
Www1
Scp-P root@192.168.9.124:/root/db. SQL.
######## Modify from my. cnf ############
Server-id = 2
Master-host = 192.168.9.124
Master-user = slave
Masters-password = 123456
Master-port = 3306
Log-bin = mysql-bin
-----------------------------------
Restart mysql
Lsof-I: 3306 | xargs kill-9
/Usr/local/mysql/bin/mysqld_safe -- user = mysql &
Mysql-p <db. SQL # import db. mysql
Www
Mysql> unlock tables; (unlock the master database)
Mysql> show master status;
Www1
Mysql> slave stop;
Mysql> change master to MASTER_HOST = '192. 168.9.124 ', MASTER_USER = 'root ',
MASTER_PASSWORD = '000000', MASTER_LOG_FILE = 'MySQL-bin.000001 ', MASTER_LOG_POS = 123456; (later log_file log_pos refers to the log name and offset of the master database)
Mysql> slave start;
Check status
Mysql> show master status;
Mysql> show slave status;
Mysql> show processlist;
Www
-A input-s 192.168.9.123-p tcp -- dport 3306-j ACCEPT allow 192.168.9.123 to connect to Port 3306
-A input-p tcp -- dport 22-j ACCEPT # Allow ssh
-A input-j DROP # reject all
Author "xavier"
BitsCN.com