MySQL MHA configuration details
MySQL environment:
Master: 192.168.202.129: 3306
Slave: 192.168.202.129: 3307,192.168 .202.129: 3307,192.168 .202.130: 3306,192.168 .202.130: 3307,192.168 .202.130: 3308
MariaDB-10.0.13
MHA environment:
Manager: 192.168.202.129
Node: 192.168.202.130 (the instance listening on port 3306 serves as the standby master database), 192.168.202.129
: Http://code.google.com/p/mysql-master-ha/ (this requires FQ ),
You can also download it from the Resource Station of the customer's house:
------------------------------------------ Split line ------------------------------------------
Free in http://linux.bkjia.com/
The username and password are both www.bkjia.com
The specific download directory is in/July 6,/July 10/MySQL MHA configuration details/
For the download method, see
------------------------------------------ Split line ------------------------------------------
I. MySQL installation preparation:
1. Create the MySQL installation directory: mkdir-p/usr/local/mysql
2. Create a mysql user:
Groupadd mysql
Useradd-g mysql
3. Download the dependency package:
Yum install make apr * autoconf automake curl-devel gcc-c ++ gtk +-devel zlib-devel openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat * cpp glibc libgomp libstdc ++-devel keyutils-libs-devel libsepol-devel license-devel krb5-devel libXpm * freetype-devel freetype * fontconfig-devel lib* libpng * php-common php-gd gettext-devel ncurses * libtool * libxml2 libxml2-devel patch policycoreutils bison
4. Download cmake: yum install cmake-y.
5. Start Compilation:
Cmake.-DCMAKE_INSTALL_PREFIX =/usr/local/mysql-example =/home/mysql/data-DDEFAULT_CHARSET = utf8-DDEFAULT_COLLATION = utf8_general_ci-dextra_sets char= all-items = 1
6. Enter the following command: make & make install
After the above process is completed, MySQL is installed. The configuration process is as follows:
2. Compile and install MySQL:
1. Modify the environment variable vi/etc/profile and add the following statement:
Export PATH = $ PATH:/usr/local/mysql/bin
2 source/etc/profile load Environment Variables
3 copy the my-default.cnf under/usr/local/mysql/support_files to/etc: cp/usr/local/mysql/support_files/my-default.cnf/etc/my. cnf: Modify the file and add the following content:
[Mysqld_multi]
Mysqld =/usr/local/mysql/bin/mysqld_safe
Mysqladmin =/usr/local/mysql/bin/mysqladmin
Log =/home/mysql/mydata/log/mysqld_multi.log
[Mysqld1]
Socket =/home/mysql/mydata/data1/socket/mysqld. sock
Port = 3306
Pid-file =/home/mysql/mydata/data1/mysqld. pid
Datadir =/home/mysql/mydata/data1
Log_bin =/home/mysql/mydata/data1/binlog/mysql-bin
Server-id = 1
[Mysqld2]
Socket =/home/mysql/mydata/data2/socket/mysqld. sock
Port = 3307
Pid-file =/home/mysql/mydata/data2/mysqld. pid
Datadir =/home/mysql/mydata/data2
Log_bin =/home/mysql/mydata/data2/binlog/mysql-bin
Server-id = 2
Relay_log =/home/mysql/mydata/data2/relay_log/mysql-relay-bin
Log_slave_updates = 1
Read_only = 1
[Mysqld3]
Socket =/home/mysql/mydata/data3/socket/mysqld. sock
Port = 3308
Pid-file =/home/mysql/mydata/data3/mysqld. pid
Datadir =/home/mysql/mydata/data3
Log_bin =/home/mysql/mydata/data3/binlog/mysql-bin
Server-id = 3
Relay_log =/home/mysql/mydata/data3/relay_log/mysql-relay-bin
Log_slave_updates = 1
Read_only = 1
The above paths must be created by the mysql user. We will not describe them here.
4. You can initialize the database:
/Usr/local/mysql/scripts/mysql_install_db -- user = mysql -- basedir =/usr/local/mysql -- datadir =/home/mysql/mydata/data1
/Usr/local/mysql/scripts/mysql_install_db -- user = mysql -- basedir =/usr/local/mysql -- datadir =/home/mysql/mydata/data2
/Usr/local/mysql/scripts/mysql_install_db -- user = mysql -- basedir =/usr/local/mysql -- datadir =/home/mysql/mydata/data3
In this way, all the databases on a server are created, and the same process is done on server 130, but I am modifying my. when cnf is used, you must note that the server-id should be modified. The server-id should not be the same as the server 129 after 4.
The following command can start the database:
Mysqld_multi -- defaults-extra-file =/etc/my. cnf start 1, 2, 3
This will start the three databases. You can use the following statement to check:
Mysqld_multi -- defaults-extra-file =/etc/my. cnf report
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
MySQL server from group: mysqld3 is running
Three-master-slave Configuration
1. Create a replication user for the master database:
On 192.168.202.129:
$ Mysql-uroot-P3306-p127.0.0.1
Grant replication slave, replication client on *. * to repl @ '192. 192.% 'identified by 'repl'; -- this is restricted within the LAN
2 slave Database Configuration:
On 192.168.202.129:
$ Mysql-uroot-P3307-p127.0.0.1
Change master to master_host = '192. 168.202.129 ', MASTER_PORT = 192, master_user = 'repl', master_password = 'repl', master_log_file = 'mysql-bin.000001 ', master_log_pos = 0;
Start slave;
$ Mysql-uroot-P3308-p127.0.0.1
Change master to master_host = '192. 168.202.129 ', MASTER_PORT = 192, master_user = 'repl', master_password = 'repl', master_log_file = 'mysql-bin.000001 ', master_log_pos = 0;
Start slave;
On 192.168.202.130:
$ Mysql-uroot-P3306-p127.0.0.1
Change master to master_host = '192. 168.202.129 ', MASTER_PORT = 192, master_user = 'repl', master_password = 'repl', master_log_file = 'mysql-bin.000001 ', master_log_pos = 0;
Start slave;
$ Mysql-uroot-P3307-p127.0.0.1
Change master to master_host = '192. 168.202.129 ', MASTER_PORT = 192, master_user = 'repl', master_password = 'repl', master_log_file = 'mysql-bin.000001 ', master_log_pos = 0;
Start slave;
$ Mysql-uroot-P3308-p127.0.0.1
Change master to master_host = '192. 168.202.129 ', MASTER_PORT = 192, master_user = 'repl', master_password = 'repl', master_log_file = 'mysql-bin.000001 ', master_log_pos = 0;
Start slave;
In this way, the configuration is complete.
3. After the configuration is complete, there will be a process from slave on the master database:
Mysql> show processlist;
There are several slave, and there will be several processes here.
4
# Ln-s/usr/local/mysql/bin/mysqlbinlog/usr/bin/mysqlbinlog
# Ln-s/usr/local/mysql/bin/mysql/usr/bin/mysql
For more details, please continue to read the highlights on the next page: