The master-slave configuration is relatively simple. Record it briefly.
Set the ip addresses of the two servers to 192.168.16.211 and 212 respectively.
For the convenience of the experiment, the root password of Mysql is empty.
Add server load balancer users for mysql respectively. The password is server load balancer. You can log on to any host and have all permissions.
To add a user, see create a user in mysql in Linux and grant the user permissions.
First install mysql-server.
Yum groupinstall mysql
Modify the mysql configuration file.
Modify/etc/my. cnf
To enable the binlog function for both MySQL instances, add log-bin = MySQL-bin in the [MySQLd] section of the mysql configuration file.
The server-ID of the two MySQL instances cannot be the same. By default, the serverID of the two MySQL instances is 1 and you need to change one of them to 2.
Add the following under [mysqld:
Server-id = 2
Log_bin = mysql-bin
Start mysqld.
Service mysqld restart
Log on to the mysql console and set the master-slave relationship.
Mysql-u root
211 view:
Mysql> show master status;
+ ------------------ + ---------- + -------------- + ------------------ +
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+ ------------------ + ---------- + -------------- + ------------------ +
| Mysql-bin.000002 | 187 |
+ ------------------ + ---------- + -------------- + ------------------ +
1 row in set (0.00 sec)
Configure on machine 212
Change master to master_host = '192. 168.16.211 ', master_user = 'Slave', master_password = 'Slave ', master_log_file = 'MySQL-bin.000002', master_log_pos = 192;
211 The Configuration method is the same as above. First check the master status of 212, and then set the parameters.
After setting, run the following command to start slave:
Start slave;
View Status:
Mysql> show slave statusG
* *************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.16.212
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 106
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 251
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Yes
Slave_ SQL _Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 106
Relay_Log_Space: 407
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_ SQL _Errno: 0
Last_ SQL _Error:
1 row in set (0.00 sec)
At this point, the dual-host configuration is complete.