Environment
Centos
Mysql 5.1
Premise
Installation of Epel, detailed installation steps please take the photo
http://blog.csdn.net/robinsonmhj/article/details/36184863
List of machines
Machine IP |
Machine name |
192.168.0.135 |
Db1 |
192.168.0.136 |
Monitor |
192.168.0.137 |
Db2 |
Virtual IP |
Role |
192.168.0.138 |
Writter |
192.168.0.139 |
Reader |
192.168.0.140 |
Reader |
Installation steps
1. Install MySQL on DB1 and DB2
Yum Install Mysql-server
2. Change the configuration file
Configuration file for DB1
[Mysqld]datadir =/data/mysqlsocket=/data/mysql/mysql.sockuser=mysql<span style= "FONT-SIZE:18PX;" ><strong>server-id=1</strong></span>table_cache = 512sort_buffer_size = 2Mread_buffer_size = 2mread_rnd_buffer_size = 8mmyisam_sort_buffer_size = 64mthread_cache_size = 8query_cache_size = 64Mthread_concurrency = 8log-bin=mysql-binbinlog_format = mixedmax_connections=2048character_set_server=utf8wait_timeout=1800interactive _timeout=1800skip-show-databaseskip-name-resolvetmp_table_size = 512mmax_heap_table_size = 512Mbinlog-ignore-db = mysqlreplicate-ignore-db = mysqlbinlog-ignore-db = Information_schemareplicate-ignore-db = Information_ schemabinlog-ignore-db = Performance_schemareplicate-ignore-db = Performance_schemabinlog-ignore-db = Testreplicate-ignore-db = Testinnodb_data_home_dir=/data/mysql/innodbinnodb_data_file_path=ibdata1:2000m;ibdata2 : 10m:autoextendinnodb_log_group_home_dir=/data/mysql/innodb/loginnodb_file_per_table=1innodb_buffer_pool_size = 1000Minnodb_additional_mem_pool_size = 20minnodb_log_file_size = 100minnodb_log_buffer_size = 8minnodb_flush_log_at_trx_commit = 2innodb_lock_wait_timeout = 50default-storage-engine = Myisam#default-storage-engine = INNODB[mysqld_safe]log-error= /var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid[mysqldump]quickmax_allowed_packet = 16Msocket=/data/mysql /mysql.sock[mysql]no-auto-rehashsocket=/data/mysql/mysql.sock
Configuration file for DB2
[Mysqld]datadir =/data/mysqlsocket=/data/mysql/mysql.sockuser=mysql<span style= "FONT-SIZE:18PX;" ><strong>server-id=2</strong></span>table_cache = 512sort_buffer_size = 2Mread_buffer_size = 2mread_rnd_buffer_size = 8mmyisam_sort_buffer_size = 64mthread_cache_size = 8query_cache_size = 64Mthread_concurrency = 8log-bin=mysql-binbinlog_format = mixedmax_connections=2048character_set_server=utf8wait_timeout=1800interactive _timeout=1800skip-show-databaseskip-name-resolvetmp_table_size = 512mmax_heap_table_size = 512Mbinlog-ignore-db = mysqlreplicate-ignore-db = mysqlbinlog-ignore-db = Information_schemareplicate-ignore-db = Information_ schemabinlog-ignore-db = Performance_schemareplicate-ignore-db = Performance_schemabinlog-ignore-db = Testreplicate-ignore-db = Testinnodb_data_home_dir=/data/mysql/innodbinnodb_data_file_path=ibdata1:2000m;ibdata2 : 10m:autoextendinnodb_log_group_home_dir=/data/mysql/innodb/loginnodb_file_per_table=1innodb_buffer_pool_size = 1000Minnodb_additional_mem_pool_size = 20minnodb_log_file_size = 100minnodb_log_buffer_size = 8minnodb_flush_log_at_trx_commit = 2innodb_lock_wait_timeout = 50default-storage-engine = Myisam#default-storage-engine = INNODB[mysqld_safe]log-error= /var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid[mysqldump]quickmax_allowed_packet = 16Msocket=/data/mysql /mysql.sock[mysql]no-auto-rehashsocket=/data/mysql/mysql.sock
3. Establish replication on DB1 and DB2 to monitor users
GRANT REPLICATION CLIENT on * * to ' mmm_monitor ' @ ' 192.168.0.136 ' identified by ' monitor '; GRANT SUPER, REPLICATION CLIENT, PROCESS on * * to ' mmm_agent ' @ ' 192.168.0.% ' identified by ' agent '; GRANT REPLICATION SLAVE on * * to ' REPLICATION ' @ ' 192.168.0.% ' identified by ' REPLICATION ';
4. Set DB1 and DB2 to each other as master and slave
4.1 Run on the DB1. MySQL command
Change MASTER to master_host= ' 192.168.0.137 ', master_port=3306, master_user= ' replication ', master_password= ' Replication ', master_log_file= ' mysql-bin.000006 ', master_log_pos=106; Note: <span></span><pre name= " The values for code "class=" HTML ">master_log_file and Master_log_pos are viewed on the DB2 by example the following command to run the MySQL command show master status
4.2 Running on DB2, MySQL command
Change MASTER to master_host= ' 192.168.0.135 ', master_port=3306, master_user= ' replication ', master_password= ' Replication ', master_log_file= ' mysql-bin.000006 ', master_log_pos=106; Note: <span></span><pre name= " The values for code "class=" HTML ">master_log_file and Master_log_pos are viewed on the DB1 by example the following command to run the MySQL command show master status
5. Install the mysql-mmm-agent on DB1 and DB2
Yum Install mysql-mmm-agent*
6. Install the Mysql-mmm-monitor on monitor
Yum Install mysql-mmm-monitor*
7. Change the configuration file
Change on DB1,DB2 and monitor
/etc/mysql-mmm/mmm_common.conf. Changes to the content such as the following
Active_master_role writer
Change configuration file/etc/mysql-mmm/mmm_agent.conf
The content on DB1 such as the following
Include mmm_common.conf# the ' this ' variable refers to this server. Proper operation requires # that's ' this ' server (db1 by default), as-well as all other servers, with the # Proper IP addres SES set in Mmm_common.conf.<span style= "FONT-SIZE:18PX;" ><strong>this db1</strong></span>
The content on DB2 such as the followingInclude mmm_common.conf# the ' this ' variable refers to this server. Proper operation requires # that's ' this ' server (db1 by default), as-well as all other servers, with the # Proper IP addres SES set in Mmm_common.conf.<span style= "FONT-SIZE:18PX;" ><strong>this db2</strong></span>
Change Configuration Monitor File
/etc/mysql-mmm/mmm_mon.conf, content such as the following
Include mmm_common.conf<monitor> IP <span style= "FONT-SIZE:18PX;" ><strong>192.168.0.136</strong></span> Pid_path /var/run/mysql-mmm/mmm_mond.pid bin_path /usr/libexec/mysql-mmm status_path /var/lib/mysql-mmm/mmm_mond.status ping_ips <span style= "FONT-SIZE:18PX;" ><strong>192.168.0.135,192.168.0.137</strong></span> auto_set_online The kill_host_bin does not exist by default, though the monitor would # throw a warning about it missing. See the sections 5.10 "Kill Host # functionality" in the PDF documentation. # # kill_host_bin /usr/libexec/mysql-mmm/monitor/kill_host #</monitor>
8. In DB1. Start Agent on DB2
# cd/etc/init.d/ # chkconfig mysql-mmm-agent on # service mysql-mmm-agent start
9. Start Monitor on monitor # cd/etc/init.d/ # chkconfig Mysql-mmm-monitor on # service Mysql-mmm-monitor start
10. View on Monitor
Mmm_control-show status
10.2 Put a machine on the line
Mmm_control Set_online DB1
10.3 Test
Stop MySQL on the DB1 service mysqld stop
Look at the state mmm_control-show status. The write IP on the DB1 should float to the DB2.
References
http://blog.csdn.net/mydeman/article/details/6845567
http://hi.baidu.com/viewehsoitfmyzr/item/5024bec2ef02ccd196445280
CentOS build Mysql MMM high-availability architecture