MySQL installation-read and write separation(7)

Environment
1 Master 1 Slave 1 MySQL-proxy
192.168.1.71 MySQL1.test.com MySQL1
192.168.1.72 MySQL2.test.com MySQL2
192.168.1.73 MySQL3.test.com MySQL3 Install MySQL on the
master-slave server
[root@MySQL1 ~]# yum install -y MySQL MySQL-server MySQL-devel
MySQL installation-read and write separation(7)
Start the MySQL service
to execute on the master-slave server
[root@MySQL1 ~]# /etc/init.d/MySQLd start
MySQL installation-read and write separation(7)
Set the master-slave configuration file The
configuration file is in /etc/my.cnf, after setting it up The configuration must restart the MySQL service
master
[MySQLd]
datadir=/var/lib/MySQL
socket=/var/lib/MySQL/MySQL.sock
user=MySQL
symbolic-links=0

log-bin=MySQL-bin
server-id= 1
auto_increment_offset=1
auto_increment_increment=2
[MySQLd_safe]
log-error=/var/log/MySQLd.log
pid-file=/var/run/MySQLd/MySQLd.pid
MySQL installation-read and write separation(7)

[MySQLd]
datadir=/var/lib/MySQL
socket=/var/lib/MySQL/MySQL.sock
user=MySQL
symbolic-links=0

log-bin=MySQL-bin
server-id= 2
auto_increment_offset=2
auto_increment_increment=2

[Mysqld_safe]
log-error = / var / log / mysqld.log
PID-File = / var / RUN / the MySQLd / MySQLd.pid
Master-Connect-the retry = 60
replicate-do-DB = All
Skip-name-Resolve
MySQL installation-read and write separation(7)
main sign MySQL server, create an access account
[root@MySQL1 ~]# MySQL -uroot -p
MySQL> create database testing;
MySQL> show master status;
MySQL installation-read and write separation(7)
MySQL> GRANT REPLICATION SLAVE ON . TO'tongbu'@'%' IDENTIFIED BY'P@ ssw0rd';
MySQL installation-read and write separation(7)
bin-log file
MySQL> show master status;
MySQL installation-read and write separation(7)
from the library is from bin-log 1055 after synchronization
MySQL-bin.000001 The file location is /var/lib/MySQL/
[root@MySQLcluster1 ~]# ll /var/lib /MySQL
MySQL installation-read and write separation(7)
View the contents of the bin-log file
[root@MySQLcluster1 MySQL]# MySQLbinlog MySQL-bin.000001 |more
Bin-log file contains some execution steps that
record the execution content in the time period and number period
MySQL installation-read and write separation(7)
Set the slave database, execute change master

  1. MySQL>CHANGE MASTER TO
    1. MASTER_HOST='X.X.X.X',
    2. MASTER_USER='user',
    3. MASTER_PASSWORD='password',
    4. MASTER_PORT=3306,
    5. MASTER_LOG_FILE='MySQL-bin.000001',
    6. MASTER_LOG_POS=98,
    7. MASTER_CONNECT_RETRY=10;
      MASTER_HOST: IP of the main server.
      MASTER_USER: the user name established when configuring the master server
      MASTER_PASSWORD: user password
      MASTER_PORT: the MySQL port of the master server, if it has not been modified, the default is fine.

MySQL> change master to master_host='192.168.1.71',
-> master_user='tongbu',
-> master_password='P@ssw0rd',
-> master_log_file='MySQL-bin.000001',
-> master_log_pos=1055;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
change master to master_host='192.168.1.71',master_user='tongbu',master_password='P@ssw0rd',master_log_file='MySQL-bin.000001',MASTER_LOG_POS=1055 ;
MySQL installation-read and write separation(7)
Start the slave service
MySQL> start slave;
MySQL installation-read and write separation(7)
add a database to the main database, view the status
MySQL installation-read and write separation(7)
from the database, execute show slave status\G from the database and view the database
MySQL> show slave status\G
MySQL installation-read and write separation(7)
encounter problems
1 view logs
2 view firewall
3 view selinux
[root@MySQL1 MySQL]# chkconfig iptables off
[root@MySQL1 MySQL]# /etc/init.d/iptables stop
MySQL installation-read and write separation(7)
view relay-log log
[root@MySQL2 ~]# cd /var/lib/MySQL/
[root@MySQL2 MySQL]# ll
MySQL installation-read and write separation(7)
[root@MySQL2 MySQL]# MySQLbinlog MySQLd-relay-bin.000002
MySQL installation-read and write separation(7)
master.info file
Master.info file on the slave machine ,
Which mainly records the synchronization account and password [root@MySQL2 MySQL]# cat master.info
MySQL installation-read and write separation(7)
download MySQL-proxy Install
on the middleware machine, perform the following steps to
download
MySQL installation-read and write separation(7)
http://ftp.ntu.edu.tw/pub/MySQL/ Downloads/MySQL-Proxy/

http://ftp.ntu.edu.tw/pub/MySQL/Downloads/MySQL-Proxy/MySQL-proxy-0.8.5-linux-el6-x86-64bit.tar.gz
MySQL installation-read and write separation(7)
unzip to the specified folder
[root@MySQL3 ~]# tar zxvf MySQL-proxy-0.8.5-linux-el6-x86-64bit.tar.gz
[root@MySQL3 ~]# mv MySQL-proxy-0.8.5-linux-el6-x86-64bit /var/ lib/MySQL-proxy
[root@MySQL3 MySQL-proxy]# pwd
[root@MySQL3 MySQL-proxy]# lsinstallation
MySQL installation-read and write separation(7)
environment software
[root@MySQL3 ~]# yum -y install gcc gcc-c++ autoconf automake zlib libxml ncurses-devel libmcrypt libtool flex pkgconfig libevent glib*
MySQL installation-read and write separation(7)
Add environment variables
[root@MySQL3 MySQL-proxy]# ls
bin include lib libexec licenses share
[root@MySQL3 MySQL-proxy]# pwd
/var/lib/MySQL-proxy
[root@MySQL3 MySQL-proxy]# echo "export PATH=$PATH:/var/lib/MySQL-proxy/bin/" >> / etc/profile
[root@MySQL3 MySQL-proxy]# source /etc/profile
[root@MySQL3 MySQL-proxy]# echo $PATH
MySQL installation-read and write separation(7)
starts MySQL-proxy
MySQL proxy Command introduction
--help-all ———— For all help Information
–proxy-address=host:port ———— The address and port that the proxy service monitors (default is 4040)
–admin-address=host:port ———— Specify the management host address and port (default is 4041)
–Proxy-backend-addresses=host:port ——The
abbreviation of the backend MySQL server address and port (primary server) : -b
–proxy-read-only-backend-addresses=host:port ———— Backend read-only The address and port of the MySQL server (from the server) is abbreviated: -r
--proxy-lua-script=file ———— Lua script file that specifies the MySQL proxy function —daemon ———— Start MySQL-proxy
–defaults in daemon mode -file=/path/to/conf_file_name ———— The default configuration file path
--Log-file=/path/to/log_file_name ———— log file name
–log-level=level ———— log level
–user=user_name ———— user running MySQL-proxy process
–admin-username= user ———— Specify the user name to log in to the MySQL-proxy management interface –admin-password=pass ———— Specify the user’s password to log in to the MySQL-proxy management interface
–admin-lua-script=script-file ——— —Lua script file path of management module (create management interface)
—plugins=admin ———— Load management plug-in
can use MySQL-proxy –help View help
[root@MySQL3 ~]# MySQL-proxy --daemon --log-level=debug --user=root --keepalive --log-file=/var/log/MySQL-proxy.log --plugins="proxy "--proxy-backend-addresses="192.168.1.71:3306" --proxy-read-only-backend-addresses="192.168.1.72:3306" --proxy-lua-script="/var/lib/MySQL -proxy/lib/MySQL-proxy/lua/rw-splitting.lua" --plugins=admin --admin-username="admin" --admin-password="admin" --admin-lua-script="/ var/lib/MySQL-proxy/lib/MySQL-proxy/lua/admin.lua "
Check that the startup port has no problem.
MySQL installation-read and write separation(7)
Check whether the
database is correctly logged in. Remote view
[root@MySQL2 ~]# MySQL -h192.168.1.73 -uadmin -padmin -P4041
MySQL> select * from backends;
MySQL installation-read and write separation(7)

Guess you like

Origin blog.51cto.com/huxiaoqiu/2539800