mysql双节点安装_快速安装及配置MySQL Replication双主节点集群--及改变数据保存目录...
192.168.1.101??master/slave
192.168.1.102??slave
192.168.1.103??slave
操作系統(tǒng)均為centos6.5
原理圖:
1. 分別安裝mysql (192.168.1.100~103)
1)下載repo,wget?http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
或從MySQL Yum倉庫(http://dev.mysql.com/downloads/repo/yum/?)手動下載
2)安裝repo:yum localinstall mysql-community-release-el6-5.noarch.rpm
可以通過下面的命令來確認這個倉庫被成功添加:yum repolist enabled | grep community
3)yum install mysql-community-server
2. 配置文件(192.168.1.100~103)
注:這個配置是通用配置,配置好后,每個節(jié)點都可以是主節(jié)點,也可以是從節(jié)點,關(guān)鍵是是否啟用
vim /etc/my.cnf
[client]
socket=/root/data/mysql/mysql.sock
[mysqld]
datadir=/root/data/mysql?#修改默認datadir
socket=/root/data/mysql/mysql.sock
server_id=100#每臺主機不一樣,根據(jù)實際情況填寫唯一ID
log_bin=mysql_bin_log
binlog_format=row
relay_log = mysql_relay_bin_log
log_slave_updates = 1
read_only = 1
slave-skip-errors = 1062,1032,1060???#skip some errors such as keys conflict,data‘s not exists,table already exists
修改默認datadir:
vim /etc/init.d/mysqld
修改這一行為:get_mysql_option mysqld datadir "/root/data/mysql"
建立數(shù)據(jù)保存目錄并賦予讀寫權(quán)限
chmod 755 /root
mkdir -p?/root/data/mysql
chown?-R?mysql:mysql?/root/data/mysql
chgrp -R mysql?/root/data/mysql
chmod -R 755?/root/data/
3.初始化表并啟動mysql
mysql_install_db --user=mysql
service mysqld start
4.賬號配置
在master主機(192.168.1.100/101)上配置replication專用賬號 repl,并授權(quán)
create?user?‘repl‘@‘10.%‘?identified?by?‘repl‘;
GRANT REPLICATION SLAVE ON *.* TO ‘repl‘@‘10.%‘ IDENTIFIED BY ‘repl‘;
注意:建議在slave上也相同的配置repl用戶,方便主從切換
設(shè)置主節(jié)點(192.168.100/101)讀寫密碼,
從節(jié)點不設(shè)置write密碼和遠程登錄權(quán)限,防止使用slave查詢過程中誤用更新插入類寫入語句導(dǎo)致產(chǎn)生不同步的數(shù)據(jù))
create?user?‘write‘@‘%‘?identified?by?‘123456‘;
grant?all?privileges?on?*.*?to?‘write‘@‘%‘?identified?by?‘123456‘;
flush privileges;
在從節(jié)點(192.168.1.102/103)上配置replication只讀專用賬號?read
create?user?‘read‘@‘%‘?identified?by?‘123456‘;
GRANT select ON *.* TO ‘read‘@‘%‘ IDENTIFIED BY ‘123456‘;
5.啟動從服務(wù)器Replicate
除了192.168.1.101主機要從192.168.1.100同步外,其它全部從192.168.1.101同步(請看原理圖)
stop slave;
CHANGE MASTER TO MASTER_HOST=‘192.168.1.101‘,
MASTER_USER=‘repl‘,
MASTER_PASSWORD=‘repl‘,
MASTER_LOG_FILE=‘mysql-bin.000001‘,
MASTER_LOG_POS=0;
start slave;
查看從節(jié)點狀態(tài):show slave status \g
第一次配置一般都會出現(xiàn)錯誤1:
錯誤1:Got fatal error 1236 from master when reading data from binary log: ‘Could not find first log file name in b
在master那邊,執(zhí)行:flush logs; ??show master status;
+----------------------+------------+--------------+------------------+-------------------+
|?File ? ? ? ? ? ? ? ? ? ? ?|?Position ??| Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+----------------------+------------+--------------+------------------+-------------------+
|?mysql_bin_log.000002?|?120| ? ? ? ? ? ? ?| ? ? ? ? ? ? ? ? ?| ? ? ? ? ? ? ? ? ? |
+----------------------+------------+--------------+------------------+-------------------+
記下File, Position。在slave端,執(zhí)行:
stop?slave;
CHANGE MASTER TO MASTER_LOG_FILE=‘mysql_bin_log.000002‘,MASTER_LOG_POS=120;
start?slave;
查看狀態(tài):show slave status \g
成功:
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host:?192.168.1.101
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql_bin_log.000006
Read_Master_Log_Pos: 120
Relay_Log_File: mysql_relay_bin_log.000002
Relay_Log_Pos: 287
Relay_Master_Log_File: mysql_bin_log.000006
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
.....
6.如何跳過一個錯誤?
錯誤2: Last_SQL_Errno: 1418
Last_SQL_Error: Error ‘This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe ? ? ? ? ? ? ? ? ? ? log_bin_trust_function_creatorsvariable)‘ on query.
解決方法一:
處理臨時錯誤,主動跳過一個錯誤的事務(wù)(這是我在新建一個函數(shù)是出現(xiàn)的,其它情況可以類似處理)
stop slave;
set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
start?slave;
如果此類錯較多,則在配置中忽略這種錯誤,
vim etc/my.cnf
在slave-skip-errors后面加 1418:
slave-skip-errors = .. ,1418 ?#跳過1418錯誤
重啟mysql: serveice mysqld restart;
解決方法二:
show variables?like?‘log_bin_trust_function_creators‘;
發(fā)現(xiàn)是off狀態(tài),
配置文件中增加一行
log_bin_trust_function_creators=1
7.注意事項
建表時不要以自增字段作為主鍵,否則雙機相互同步的時候難免會出現(xiàn)主鍵沖突,導(dǎo)致同步失敗或數(shù)據(jù)丟失,建議使用guid(uuid)作為主鍵
快速安裝及配置MySQL Replication雙主節(jié)點集群--及改變數(shù)據(jù)保存目錄
標(biāo)簽:
本條技術(shù)文章來源于互聯(lián)網(wǎng),如果無意侵犯您的權(quán)益請點擊此處反饋版權(quán)投訴
本文系統(tǒng)來源:http://www.cnblogs.com/zhaohz/p/4691586.html
總結(jié)
以上是生活随笔為你收集整理的mysql双节点安装_快速安装及配置MySQL Replication双主节点集群--及改变数据保存目录...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于ms17010渗透
- 下一篇: jsdbc mysql.ocx_JS直接