您好,登錄后才能下訂單哦!
注:
同一時(shí)刻只允許一個(gè)主進(jìn)行寫入,額外主提供部分讀的服務(wù)
實(shí)驗(yàn)環(huán)境:
六臺(tái)Centos6,兩臺(tái)主mysql(master01、master02),兩臺(tái)從mysql(slave01、slave02),一臺(tái)監(jiān)控(mmm_mond),一臺(tái)讀寫調(diào)度器(amoeba)
Master01
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.1.10
NETMASK=255.255.255.0
vim /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=dhcp
vim /etc/hosts
192.168.1.10 db1
192.168.1.20 db2
192.168.1.30 db3
192.168.1.40 db4
vim /etc/sysconfig/network
HOSTNAME=db1
reboot
rm -rf /etc/yum.repos.d/*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
yum -y install epel-release
yum -y install mysql-mmm* mysql mysql-server mysql-devel
/etc/init.d/mysqld start && chkconfig --level 35 mysqld on
mysqladmin -uroot password "123"
cp /usr/share/doc/mysql-server-5.1.73/my-medium.cnf /etc/my.cnf
vim /etc/my.cnf
[mysqld]
50 log-slave-updates
/etc/init.d/mysqld restart
mysql -u root -p
mysql> grant replication slave on *.* to 'slave'@'192.168.1.%' identified by '123';
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 647 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
mysql> change master to master_host='192.168.1.20',master_user='slave',master_password='123',master_log_file='mysql-bin.000001',master_log_pos=481;
//所跟IP、log、pos等信息都為第二臺(tái)主的信息
mysql> start slave;
mysql> show slave status\G;
//查看同步狀態(tài),I/0和SQL線程狀態(tài)為yes則正確
Master02
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.1.20
NETMASK=255.255.255.0
vim /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=dhcp
vim /etc/hosts
192.168.1.10 db1
192.168.1.20 db2
192.168.1.30 db3
192.168.1.40 db4
vim /etc/sysconfig/network
HOSTNAME=db2
reboot
rm -rf /etc/yum.repos.d/*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
yum -y install epel-release
yum -y install mysql-mmm* mysql mysql-server mysql-devel
/etc/init.d/mysqld start && chkconfig --level 35 mysqld on
mysqladmin -uroot password "123"
cp /usr/share/doc/mysql-server-5.1.73/my-medium.cnf /etc/my.cnf
vim /etc/my.cnf
[mysqld]
50 log-slave-updates
58 server-id = 2
/etc/init.d/mysqld restart
mysql -u root -p
mysql> grant replication slave on *.* to 'slave'@'192.168.1.%' identified by '123';
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 481 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
mysql> change master to master_host='192.168.1.10',master_user='slave',master_password='123',master_log_file='mysql-bin.000001',master_log_pos=647;
//所跟IP、log、pos等信息都為第一臺(tái)主的信息
mysql> start slave;
mysql> show slave status\G;
Slave01
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.1.30
NETMASK=255.255.255.0
vim /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=dhcp
vim /etc/hosts
192.168.1.10 db1
192.168.1.20 db2
192.168.1.30 db3
192.168.1.40 db4
vim /etc/sysconfig/network
HOSTNAME=db3
reboot
rm -rf /etc/yum.repos.d/*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
yum -y install epel-release
yum -y install mysql-mmm* mysql mysql-server mysql-devel
/etc/init.d/mysqld start && chkconfig --level 35 mysqld on
mysqladmin -uroot password "123"
cp /usr/share/doc/mysql-server-5.1.73/my-medium.cnf /etc/my.cnf
vim /etc/my.cnf
[mysqld]
50 relay-log=relay-log-bin
51 relay-log-index=slave-relay-bin.index
59 server-id = 3
/etc/init.d/mysqld restart
mysql -u root -p
mysql> change master to master_host='192.168.1.10',master_user='slave',master_password='123',master_log_file='mysql-bin.000001',master_log_pos=647;
//所跟IP、log、pos等信息都為第一臺(tái)主的信息
mysql> start slave;
mysql> show slave status\G;
Slave02
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.1.40
NETMASK=255.255.255.0
vim /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=dhcp
vim /etc/hosts
192.168.1.10 db1
192.168.1.20 db2
192.168.1.30 db3
192.168.1.40 db4
rm -rf /etc/yum.repos.d/*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
yum -y install epel-release
yum -y install mysql-mmm* mysql mysql-server mysql-devel
/etc/init.d/mysqld start && chkconfig --level 35 mysqld on
mysqladmin -uroot password "123"
cp /usr/share/doc/mysql-server-5.1.73/my-medium.cnf /etc/my.cnf
vim /etc/my.cnf
[mysqld]
50 relay-log=relay-log-bin
51 relay-log-index=slave-relay-bin.index
59 server-id = 4
/etc/init.d/mysqld restart
mysql -u root -p
mysql> change master to master_host='192.168.1.20',master_user='slave',master_password='123',master_log_file='mysql-bin.000001',master_log_pos=647;
//所跟IP、log、pos等信息都為第二臺(tái)主的信息
mysql> start slave;
mysql> show slave status\G;
Master01
mysql> grant super,replication client,process on *.* to 'mmm_agent'@'192.168.1.%' identified by '123';//主服務(wù)器授權(quán),從服務(wù)器自動(dòng)同步
mysql> grant replication client on *.* to 'mmm_monitor'@'192.168.1.%' identified by '123'; //主服務(wù)器授權(quán),從服務(wù)器自動(dòng)同步
mysql> grant all on *.* to 'test'@'192.168.1.%' identified by '123'; //新建測(cè)試用戶
vim /etc/mysql-mmm/mmm_common.conf
active_master_role writer
<host default>
cluster_interface eth0 //集群IP承載的接口
pid_path /var/run/mysql-mmm/mmm_agentd.pid //PID文件位置(存放MMM的進(jìn)程號(hào))
bin_path /usr/libexec/mysql-mmm/ //運(yùn)行命令位置
replication_user slave //需使用主從同步時(shí)授權(quán)用戶
replication_password 123
agent_user mmm_agent //代理連接
agent_password 123
</host>
<host db1>
ip 192.168.1.10
mode master
peer db2 //當(dāng)db1主機(jī)不能使用,自動(dòng)切換到db2
</host>
<host db2>
ip 192.168.1.20
mode master //當(dāng)前服務(wù)器作為主服務(wù)器(寫)
peer db1 //當(dāng)db2主機(jī)不能使用,自動(dòng)切換到db1
</host>
<host db3>
ip 192.168.1.30
mode slave
</host>
<host db4>
ip 192.168.1.40
mode slave //當(dāng)前主機(jī)作為從服務(wù)器(讀)
</host>
<role writer>
hosts db1, db2
ips 192.168.1.250 //寫服務(wù)器VIP
mode exclusive //只有一個(gè)host可以writer
</role>
<role reader>
hosts db3, db4
ips 192.168.1.251, 192.168.1.252 //讀服務(wù)器VIP
mode balanced //多個(gè)host可以reader
</role>
vim /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
this db1
scp /etc/mysql-mmm/mmm_common.conf root@192.168.1.20:/etc/mysql-mmm/
scp /etc/mysql-mmm/mmm_common.conf root@192.168.1.30:/etc/mysql-mmm/
scp /etc/mysql-mmm/mmm_common.conf root@192.168.1.40:/etc/mysql-mmm/
/etc/init.d/mysql-mmm-agent restart && chkconfig --level 35 mysql-mmm-agent on
Master02
vim /etc/mysql-mmm/mmm_agent.conf
this db2
/etc/init.d/mysql-mmm-agent restart && chkconfig --level 35 mysql-mmm-agent on
Slave01
vim /etc/mysql-mmm/mmm_agent.conf
this db3
/etc/init.d/mysql-mmm-agent restart && chkconfig --level 35 mysql-mmm-agent on
Slave02
vim /etc/mysql-mmm/mmm_agent.conf
this db4
/etc/init.d/mysql-mmm-agent restart && chkconfig --level 35 mysql-mmm-agent on
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.1.50
NETMASK=255.255.255.0
vim /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=dhcp
vim /etc/hosts
192.168.1.10 db1
192.168.1.20 db2
192.168.1.30 db3
192.168.1.40 db4
reboot
rm -rf /etc/yum.repos.d/*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
yum -y install epel-release
yum -y install mysql-mmm* mysql
scp 192.168.1.10:/etc/mysql-mmm/mmm_common.conf /etc/mysql-mmm/
vim /etc/mysql-mmm/mmm_mon.conf
include mmm_common.conf
<monitor>
ip 127.0.0.1
ping_ips 192.168.1.10,192.168.1.20,192.168.1.30,192.168.1.40
</monitor>
<host default>
monitor_user mmm_monitor
monitor_password 123
</host>
debug 0
/etc/init.d/mysql-mmm-monitor restart && chkconfig --level 35 mysql-mmm-monitor on //監(jiān)控端啟動(dòng)
mmm_control show //查看節(jié)點(diǎn)狀態(tài)
mysql -u test -p -h 192.168.1.250
報(bào)錯(cuò)解決方案:
[root@localhost ~]# mysql -u test -p -h 192.168.1.250
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.254' (113)
主服務(wù)器:
grant super,replication client,process on *.* to 'mmm_agent'@'db1' identified by '123';
grant super,replication client,process on *.* to 'mmm_agent'@'db2' identified by '123';
grant super,replication client,process on *.* to 'mmm_agent'@'db3' identified by '123';
grant super,replication client,process on *.* to 'mmm_agent'@'db4' identified by '123';
日志查看:
tail -f /var/log/mysql-mmm/mmm_agentd.log //MySQL端的Agent日志
tail -f /var/log/mysql-mmm/mmm_mond.log //監(jiān)控機(jī)端的Monitor日志
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.1.254
NETMASK=255.255.255.0
yum -y erase java-*
chmod +x jdk-6u14-linux-x64.bin
./jdk-6u14-linux-x64.bin
mv jdk1.6.0_14/ /usr/local/jdk1.6
vim /etc/profile
export JAVA_HOME=/usr/local/jdk1.6
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/bin/:$PATH:$HOME/bin
export AMOEBA_HOME=/usr/local/amoeba
export PATH=$PATH:$AMOEBA_HOME/bin
source /etc/profile && java -version
mkdir /usr/local/amoeba
tar zxvf amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba/
chmod -R 755 /usr/local/amoeba/
mysql -u root -p
mysql> grant all on *.* to haha@'192.168.1.%' identified by '123';
vim /usr/local/amoeba/conf/amoeba.xml
30 <property name="user">hehe</property> //設(shè)置連接Amoeba用戶
31
32 <property name="password">123</property> //設(shè)置連接Amoeba用戶
115 <property name="defaultPool">slaves</property>
116
117 <property name="writePool">master</property> 注意刪除<!-- -->的注釋
118 <property name="readPool">slaves</property> //定義讀服務(wù)器池
vim /usr/local/amoeba/conf/dbServers.xml
25 <!-- mysql user -->
26 <property name="user">haha</property> //設(shè)置連接Mysql的用戶
27
28 <property name="password">123</property> //設(shè)置連接mysql的密碼
注意刪除<!-- -->的注釋
43 <dbServer name="master" parent="abstractServer">
44 <factoryConfig>
45 <!-- mysql ip -->
46 <property name="ipAddress">192.168.1.254</property> //定義寫服務(wù)器IP
47 </factoryConfig>
48 </dbServer>
49 <dbServer name="slave1" parent="abstractServer">
50 <factoryConfig>
51 <!-- mysql ip -->
52 <property name="ipAddress">192.168.1.30</property> //定義讀服務(wù)器IP
53 </factoryConfig>
54 </dbServer>
55 <dbServer name="slave2" parent="abstractServer">
56 <factoryConfig>
57 <!-- mysql ip -->
58 <property name="ipAddress">192.168.1.40</property> //定義讀服務(wù)器IP
59 </factoryConfig>
60
61 </dbServer>
62 <dbServer name="slaves" virtual="true">
68 <property name="poolNames">slave1,slave2</property> //定義輸入slaves讀服務(wù)器池的主機(jī)
69 </poolConfig>
amoeba start &
netstat -utpln | grep 8066
client:mysql -u hehe -p -h 192.168.1.254 -P 8066
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。