How to configure master-slave server architecture in Mysql
Mysql how to configure the master-slave server architecture, for this problem, this article details the corresponding analysis and solutions, hoping to help more small partners who want to solve this problem find a simpler and easier way.
The role of replication:
1. data component
2. Implementing Read Load Balancer
3. Backup (cannot backup itself, but can provide a backup machine)
4. High availability and failover capabilities
5. Testing Mysql upgrades
Type of copy:
a. Statement-based replication
b. Row-based replication
c. Mixed replication (combination of a and b)
Address planning for servers
Primary Server IP: 192.168.1.108
Server IP: 192.168.1.110
Experimental topology:
master_mysql-----------------client_mysql
1. install MySQL
#mkdir -vp /mydata/data
#groupadd -g 3306 mysql
#useradd -g mysql -s /sbin/nologin -M -u 3306 mysql
#chown -R mysql:mysql /www/mydata/
# tar x mysql-5.5.15-linux2.6-i686.tar.gz -C /usr/local
#ln -vs /usr/local/mysql-5.5.15-linux2.6-i686 /usr/local/mysql
#cd /usr/local/mysql
#chown -R mysql:mysql .
#scripts/mysql_install_db --user=mysql --datadir=/mydata/data
#chown -R root .
#cp support-files/mysql.server /etc/init.d/mysqld
#chkconfig --add mysqld
#cp support-files/my-large.cnf /etc/my.cnf
#vim /etc/my.cnf
Add: datadir=/mydata/data
service mysqld start
Specify mysql binary file:
#export PATH=$PATH:/usr/local/mysql/bin (temporary)
#vim /etc/profile
Add PATH=$PATH:/usr/local/mysql/bin (permanently)
Specify lib file
#vim /etc/ld.so.conf.d/mysql.conf
Add: /usr/local/mysql/lib
ldconfig synchronize
#ldconfig -v | grep mysql
Header file:
#ln -sv /usr/local/mysql/include /usr/include/mysql
Help information:
#vim /etc/man.config
Add: MANPATH /usr/local/mysql/man
This configuration requires configuration on both servers
2. Next, the configuration of the real master-slave mysql server began.
The configuration of the primary server is as follows
#vim /etc/my.cnf Add the following information
log-bin=mysql-bin
log-bin-index=mysql-bin.index
binlog-format=maxed
server id = 1
Save after modification, restart Mysql
#service mysqld restart
Then log in to Mysql for 192.168.1.110 Host Authorization
#mysql
mysql> GRANT REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO IDENTIFIED BY 'redhat';
mysql> FLUSH PRIVILEGES;
3. From File Configuration
#vim /etc/my.cnf
Comment out log-bin=mysql-bin,binlog-format=maxed
Add relay-log=relay-bin.index, relay-log=relay-bin, replicate-ignore-db =mysql
Change server-id = 2
Restart Mysql after saving the configuration file
#service mysqld restart
#mysql
mysql> CHANGE MASTER TO MASTER_HOST='192.168.1.108',MASTER_USER='repl',MASTER_PASSWORD='redhat';
mysql> START SLAVE;
mysql> SHOW SLAVE STATUS\G; View slave server health status
You can determine that information has been copied from the master server to the slave server if the following message appears
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| luowei |
| mysql |
| performance_schema |
| test |
+--------------------+
mysql> SELECT * FROM st;
+----+------+
| ID | Name |
+----+------+
| 1 | a |
| 2 | b |
| 3 | c |
| 5 | E |
+----+------+
About Mysql how to configure the master-slave server architecture problem answer to share here, I hope the above content can have some help for everyone, if you still have a lot of doubts not solved, you can pay attention to the industry information channel to learn more related knowledge.