How to achieve master-slave replication and read-write separation in MYSQL
Today, I will talk to you about how to achieve master-slave replication and read-write separation in MYSQL. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
Install MySQL on master,slave1,slave2 separately
[root@master1 ~] # mkdir / abc # # create mount point [root@master1 ~] # mount.cifs / / 192.168.100.1/LNMP-C7 / abc/ # # remote mount Password for root@//192.168.100.1/LNMP-C7: [root@master1 ~] # cd / abc/ [root@master1 abc] # ls mysql-5.5.24 [root@master1 abc] # tar zxvf mysql-5 .5.24.tar.gz-C / opt/ # # decompress [root@master1 opt] # yum install-y\ > gcc gcc-c++\ > ncurses\ > ncurese-devel\ # Control Terminal screen display Library > bison\ # # Syntax Analysis > make > cmake # # cmake tool > libaio-devel # system Unified call to implement asynchronous IO [root@slave1 opt] # useradd-s / sbin/nologin mysql # # add unlogged mysql users [root@slave1 opt] # cd / opt/mysql-5.5.24/ [root@slave1 mysql-5.5.24] # mkdir / usr/local/mysql # # create installation directory [root@slave1 mysql-5.5.24] # cmake\ # configuration >-DCMAKE _ INSTALL_PREFIX=/usr/local/mysql\ # # installation path >-DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock\ # # sock file path >-DDEFAULT_CHARSET=utf8\ # # character set >-DDEFAULT_COLLATION=utf8_general_ci\ >-DWITH_EXTRA_CHARSETS=all\ >-DWITH_MYISAM_STORAGE_ENGINE=1\ # # Storage engine >-DWITH_INNOBASE_STORAGE_ENGINE=1\ > -DWITH_MEMORY_STORAGE_ENGINE=1\ >-DWITH_READLINE=1\ >-DENABLED_LOCAL_INFILE=1\ >-DMYSQL_DATADIR=/home/mysql\ # # data file path >-DMYSQL_USER=mysql\ # user >-DMYSQL_TCP_PORT=3306 # # port [root@slave1 mysql-5.5.24] # make & & make install # # compile and install [root@master1 mysql-5.5. 24] # chown-R mysql.mysql / usr/local/mysql # # set the mysql master group [root@master1 mysql-5.5.24] # vim / etc/profile # # configuration environment variables to facilitate the system to identify export PATH=$PATH:/usr/local/mysql/bin/ [root@master1 mysql-5.5.24] # source / etc/profile # # refresh configuration file [root@master1 mysql-5.5.24] # cp support -files/my-medium.cnf / etc/my.cnf # # main configuration file cp: is "/ etc/my.cnf" overwritten? Yes [root@master1 mysql-5.5.24] # cp support-files/mysql.server / etc/init.d/mysqld # # Startup file [root@master1 mysql-5.5.24] # chmod 755 / etc/init.d/mysqld # # set permissions [root@master1 mysql-5.5.24] # chkconfig-- add / etc/init.d/mysqld # # add to service management [root@master1 mysql-5. 5.24] # chkconfig mysqld-- level 35 on # # Boot self-boot [root@master1 mysql-5.5.24] # / usr/local/mysql/scripts/mysql_install_db\ # # initialize database >-- user=mysql\ >-- ldata=/var/lib/mysql\ >-- basedir=/usr/local/mysql\ >-- datadir=/home/mysql [root@master1 mysql-5.5.24] # vim / etc/init.d/mysqld # # Edit the startup script file basedir=/usr/local/mysql # # find the path datadir=/home/mysql [root@master1 mysql-5.5.24] # service mysqld start # # start MySQL Starting MySQL.. here SUCCESS! [root@master1 mysql-5.5.24] # mysqladmin-u root password 'abc123' # # set password
So far, the synchronization of database master and slave is successful!
11, modify the amoeba server configuration file
[root@amoeba conf] # vim amoeba.xml # # modify the main configuration file # Line 30 amoeba # # synchronize the user password of the primary server from the server # line 32 123456 # line 117 remove comments master master slaves [root@amoeba conf] # vim conf/dbServers.xml # # configuration database configuration file # remove comments test from lines 26 to 29 123.com # Line 42 add master server address 192.168.142.151 Line 52 add slave server slave1 address 192.168.142.163 # # copy 6 lines add server slave2 address 192.168.142.145 # 65 Line Authorization synchronization # Last line add slave server name slave1 Slave2 [root@amoeba conf] # / usr/local/amoeba/bin/amoeba start& # # enable the amoeba service [root@amoeba ~] # netstat-anpt | grep java # # Open another terminal to check whether it is enabled. Tcp6 0 0127.0.0.1 Frev 26268: * LISTEN 40925/java tcp6 0 0:: 8066:: * LISTEN 40925/java tcp6 0 192.168.142.160 LISTEN 40925/java tcp6 34090 192.168.142.151 ESTABLISHED 40925/java tcp6 0 0192.168.142.160 ESTABLISHED 40925/java tcp6 0 192.168.142.160 ESTABLISHED 40925/java 55984 192.168.142.163 ESTABLISHED 40925/java read the above content Do you have any further understanding of how to achieve master-slave replication and read-write separation in MYSQL? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.