MySQL主從同步、讀寫分別設置裝備擺設步調。本站提示廣大學習愛好者:(MySQL主從同步、讀寫分別設置裝備擺設步調)文章只能為提供參考,不一定能成為您想要的結果。以下是MySQL主從同步、讀寫分別設置裝備擺設步調正文
如今應用的兩台辦事器曾經裝置了MySQL,滿是rpm包裝的,能正常應用。
為了不不用要的費事,主從辦事器MySQL版本盡可能堅持分歧;
情況:192.168.0.1 (Master)
192.168.0.2 (Slave)
MySQL Version:Ver 14.14 Distrib 5.1.48, for pc-linux-gnu (i686) using readline 5.1
1、登錄Master辦事器,修正my.cnf,添加以下內容;
server-id = 1 //數據庫ID號, 為1時表現為Master,個中master_id必需為1到232–1之間的一個正整數值;
log-bin=mysql-bin //啟用二進制日記;
binlog-do-db=data //須要同步的二進制數據庫名;
binlog-ignore-db=mysql //分歧步的二進制數據庫名;這個同步後據說很費事,我沒有同步;
log-bin=/var/log/mysql/updatelog //設定生成的log文件名;
log-slave-updates //把更新的記載寫到二進制文件中;
slave-skip-errors //跳錯誤誤,持續履行復制;
2、樹立復制所要應用的用戶;
mysql>grant replication slave on *.* to
[email protected] identified by '********'
3、重啟mysql;
/usr/bin/mysqladmin -uroot shutdown;
/usr/bin/mysql_safe &
4、如今備份Master上的數據;
鎖定後我直接tar.gz data這個庫文件;
mysql>FLUSH TABLES WITH READ LOCK;
cd /var/lib/mysql
tar data.tar.gz data
接著直接履行了長途scp;
scp ./data.tar.gz
[email protected]:/var/lib/mysql
5、登錄Slave數據庫辦事器,修正my.cnf;
server-id = 3 //2曾經被用在另外一個辦事器上了,假如今後要再加Slave號接著往後數就OK了;
log-bin=mysql-bin
master-host = 192.168.0.1
master-user = test
master-password = ******
master-port = 3306
master-connect-retry=60 //假如發明主辦事器斷線,從新銜接的時光差;
replicate-ignore-db=mysql //不須要備份的數據庫;
replicate-do-db=data //須要備份的數據庫
log-slave-update
slave-skip-errors
6、解壓適才從Master scp過去的文件,此處不消改權限、屬主,默許沒有轉變,可以依據現實情形停止修正;
7、上述完成後,可以啟動slave了;檢查slave狀況;
mysql>slave start;
mysql>show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.0.1
Master_User: test
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: updatelog.000001
Read_Master_Log_Pos: 106
Relay_Log_File: onlinevc-relay-bin.000013
Relay_Log_Pos: 1069
Relay_Master_Log_File: updatelog.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: data
Replicate_Ignore_DB: mysql
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: 1681
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)
ERROR:
No query specified
8、檢查Master下面的狀況;
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| updatelog.000012 | 15016 | data | mysql |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
因而可知二者的File、Position存在成績,所要要去Slave上設置對應主庫的Master_Log_File、Read_Master_Log_Pos;履行以下語句;
mysql>slave stop;
mysql>CHANGE MASTER TO MASTER_HOST='192.168.0.1',MASTER_USER='test', MASTER_PASSWORD='******',MASTER_LOG_FILE='updatelog.000012',MASTER_LOG_POS=15016;
確保 Slave_IO_Running: Yes 、Slave_SQL_Running: Yes都要為YES能力證實Slave的I/O和SQL停止正常。
9、解鎖主庫表;
UNLOCK TABLES;
到此主從MySQL辦事器設置裝備擺設完成,測試成果以下;
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| updatelog.000012 | 717039 | data | mysql |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.0.1
Master_User: test
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: updatelog.000012
Read_Master_Log_Pos: 717039
Relay_Log_File: onlinevc-relay-bin.000013
Relay_Log_Pos: 1222
Relay_Master_Log_File: updatelog.000012
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: data
Replicate_Ignore_DB: mysql
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: 717039
Relay_Log_Space: 1834
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)
ERROR:
No query specified
#################################### 以下是MySQL數據庫讀寫分別操作步調 ##########################################
此處應用MySQL本身(Mysql-proxy)的署理完成數據庫的讀寫分別;
所須要裝置包以下;
1、check-0.9.8
2、glib-2.18.4
3、libevent-2.0.6-rc
4、lua-5.1.4
wget http://www.lua.org/ftp/lua-5.1.4.tar.gz
5、pkg-config-0.23
6、mysql-5.0.56
7、mysql-proxy-0.8.0
http://mysql.cdpa.nsysu.edu.tw/Downloads/MySQL-Proxy/mysql-proxy-0.8.0.tar.gz
其余裝置包地址其時沒有記下載地址,不外年夜部門都在這個網站上找的;http://sourceforge.net/
&&&&&&&&&& 裝置開端 &&&&&&&&
1、tar -zxvf check-0.8.4.tar.gz
cd check-0.8.4
./configure
make
make install
2、tar -zxvf glib-2.18.4.tar.gz //體系rpm包能夠版本低湧現了成績3;
./configure
make
make install
3、tar -zxvf libevent-2.0.6-rc.tar.gz
cd libevent-2.0.6-rc
./configure --prefix=/usr/local/libevent
make && make install
4、tar -zxvf lua-5.1.4.tar.gz
INSTALL_TOP= /usr/local/lua // 為了把lua裝置到/var/lib/lua下,故要修正其下的Makefile;
或許直接履行:sed -i 's#INSTALL_TOP= /usr/local#INSTALL_TOP= /usr/local/lua#' Makefile
root@testmysql [/software/lua-5.1.4]# make
Please do
make PLATFORM
where PLATFORM is one of these:
aix ansi bsd freebsd generic linux macosx mingw posix solaris
See INSTALL for complete instructions.
這處是要你選擇辦事器所應用的平台;
履行:make linux //此處履行後湧現了毛病,處理方法鄙人面成績處理區1處,此處先跳過;
再履行:make install
設置情況變量:
export LUA_CFLAGS="-I/usr/local/lua/include" LUA_LIBS="-L/usr/local/lua/lib -llua -ldl" LDFLAGS="-L/usr/local/libevent/lib -lm"
export CPPFLAGS="-I/usr/local/libevent/include"
export CFLAGS="-I/usr/local/libevent/include"
5、tar -zxvf pkg-config-0.23.tar.gz
cd pkg-config-0.23
./configure
make
make install
裝置完以後要履行:cp etc/lua.pc /usr/local/lib/pkgconfig/lua5.1.pc //緣由見上面的成績處理區2處;
6、裝置MySQL客戶端;
由於此辦事器體系是默許裝置了MySQL,沒有裝置客戶端,我又裝了client、devel以下所示已裝置的rpm包;
root@testmysql [/software/lua-5.1.4]# rpm -qa | grep MySQL
MySQL-client-5.1.48-0.glibc23
MySQL-bench-5.0.91-0.glibc23
MySQL-test-5.1.48-0.glibc23
MySQL-shared-5.1.48-0.glibc23
MySQL-server-5.1.48-0.glibc23
MySQL-devel-5.1.48-0.glibc23
爾後的Mysql-proxy時老是一向報錯,編譯不外去,無法之下用源碼包客戶端;(此時的rpm包都沒有卸載,直接履行了上面的裝置)//此處成績見成績處理區4處;
tar zxvf mysql-5.0.56.tar.gz //此處我直接應用了mysql的5.0.56的源碼包;
cd mysql-5.0.56
./configure --prefix=/usr/local/mysql --without-server
make && make install
7、tar xvf mysql-proxy-0.8.0.tar.gz
cd mysql-proxy-0.8.0
./configure --prefix=/usr/local/mysql-proxy --with-mysql=/usr/local/mysql --with-lua //成績處理處4有引見;
Make && Make install
8、在/var/lib/bin創立mysql-proxy.sh,內容以下;
#!/bin/bash
LUA_PATH="/usr/local/mysql-proxy/lib/mysql-proxy/lua/?.lua" /usr/local/mysql-proxy/bin/mysql-proxy --proxy-backend-addresses=192.168.0.1:3306 --proxy-read-only-backend-addresses=192.168.0.2:3306 --proxy-lua-script=/usr/local/mysql-proxy/lib/mysql-proxy/rw-splitting.lua >> /var/log/mysql-proxy.log &
然後加上可履行權限;
chmod a+x /var/lib/bin/mysql-proxy.sh
履行:/var/lib/bin/mysql-proxy.sh 啟動辦事;
9、驗證能否開戶了:4040、4041;
root@testmysql [/usr/local/bin]# netstat -an | grep 404*
tcp 0 0 0.0.0.0:4040 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:4041 0.0.0.0:* LISTEN
10、測試讀寫分別,此步略過,一切設置裝備擺設曾經完成。
&&&&&&&&&&&&&&&&&&&&&&&&&&& 成績處理區 &&&&&&&&&&&&&&&&&&&&&&&&&&&&
1、在裝置的第四步履行make linux時報錯以下:
root@testmysql [/software/lua-5.1.4]# make linux
cd src && make linux
make[1]: Entering directory `/software/lua-5.1.4/src'
make all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
make[2]: Entering directory `/software/lua-5.1.4/src'
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lapi.o lapi.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lcode.o lcode.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ldebug.o ldebug.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ldo.o ldo.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ldump.o ldump.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lfunc.o lfunc.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lgc.o lgc.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o llex.o llex.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lmem.o lmem.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lobject.o lobject.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lopcodes.o lopcodes.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lparser.o lparser.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lstate.o lstate.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lstring.o lstring.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ltable.o ltable.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ltm.o ltm.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lundump.o lundump.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lvm.o lvm.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lzio.o lzio.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lauxlib.o lauxlib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lbaselib.o lbaselib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ldblib.o ldblib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o liolib.o liolib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lmathlib.o lmathlib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o loslib.o loslib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o ltablib.o ltablib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lstrlib.o lstrlib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o loadlib.o loadlib.c
gcc -O2 -Wall -DLUA_USE_LINUX -c -o linit.o linit.c
ar rcu liblua.a lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o lstrlib.o loadlib.o linit.o
ranlib liblua.a
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lua.o lua.c
In file included from lua.h:16,
from lua.c:15:
luaconf.h:275:31: error: readline/readline.h: No such file or directory
luaconf.h:276:30: error: readline/history.h: No such file or directory
lua.c: In function 鈥榩ushline鈥?
lua.c:182: warning: implicit declaration of function 鈥榬eadline鈥?
lua.c:182: warning: assignment makes pointer from integer without a cast
lua.c: In function 鈥榣oadline鈥?
lua.c:210: warning: implicit declaration of function 鈥榓dd_history鈥?
make[2]: *** [lua.o] Error 1
make[2]: Leaving directory `/software/lua-5.1.4/src'
make[1]: *** [linux] Error 2
make[1]: Leaving directory `/software/lua-5.1.4/src'
make: *** [linux] Error 2
處理辦法:yum install libtermcap-devel
yum install ncurses-devel
yum install libevent-devel
yum install readline-devel
2、裝置MySQL-proxy時報錯:
checking for LUA... configure: error: Package requirements (lua5.1 >= 5.1) were not met:
No package 'lua5.1' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables LUA_CFLAGS
and LUA_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
處理方法:
cp etc/lua.pc /usr/local/lib/pkgconfig/lua5.1.pc
3、裝置MySQL-proxy時報錯:
checking for GLIB... configure: error: Package requirements (glib-2.0 >= 2.16.0) were not met:
No package 'glib-2.0' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables GLIB_CFLAGS
and GLIB_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
處理方法:
1、檢查體系曾經裝置glib的rpm包;
glibc-2.5-49.el5_5.4
glibc-headers-2.5-49.el5_5.4
glib2-2.12.3-4.el5_3.1
glibc-common-2.5-49.el5_5.4
glibc-devel-2.5-49.el5_5.4
2、下載裝置glib-2.18.4.tar.gz
4、剛開端應用體系裡rpm所指定的mysq_config時,mysql-proxy裝置報錯,信息以下;
configure: error: mysql_config not exists or not executable, use $ ./configure --with-mysql=/path/to/mysql_config
看到贊助裝置文檔裡請求以下:
--with-mysql[=PATH] Include MySQL support. PATH is the path to 'mysql_config'。
處理方法就是:裝置包中的第6步。