標籤:lin 軟體包 file 節點 sts comm 資料庫 4.6 my.cnf
部署mysql高可用叢集(mysql-mmm+主從同步)
4台資料庫伺服器:
四個資料庫之保留初始的四個庫,其他庫全部刪除
主機158
主機137
主機99
主機67
主機102(可與其他四台ping通即可)
5台主機的公用配置:
下載mysql-mmm.zip
配置yum源
service iptables stop
setenforce 0
yum -y install perl perl-*
主機158與主機137配置為主主結構:
主機158:
mysql> grant replication slave on *.* to [email protected]"%" identified by "Anonymous";
[[email protected] ~]# vim /etc/my.cnf
[mysqld]
log-bin=master158
server_id=158
[[email protected] ~]# /etc/init.d/mysql restart
mysql> show master status\G;(在192.168.4.137上查看節點)
mysql> change master to master_host="192.168.4.137",master_user="hydra",master_password="Anonymous",master_log_file="master137.000001",master_log_pos=120;
mysql> start slave;
主機137:
mysql> grant replication slave on *.* to [email protected]"%" identified by "Anonymous";
[[email protected] ~]# vim /etc/my.cnf
[mysqld]
log-bin=master137
server_id=137
log-slave-updates
[[email protected] ~]# /etc/init.d/mysql restart
mysql> show master status\G;(在192.168.4.158上查看節點)
mysql> change master to master_host="192.168.4.158",master_user="hydra",master_password="Anonymous",master_log_file="master158.000001",master_log_pos=120;
mysql> start slave;
主機99和主機67同時配置為主機137的從資料庫,並能夠讓主機99和主機67能同步主機158上的資料:
主機99:
[[email protected] ~]# vim /etc/my.cnf
[mysqld]
server-id=99
[[email protected] ~]# /etc/init.d/mysql restart
mysql> show master status\G;(在192.168.4.137上查看節點)
mysql> change master to master_host="192.168.4.137",master_user="hydra",master_password="Anonymous",master_log_file="master137.000001",master_log_pos=120;
mysql> start slave;
主機67:
[[email protected] ~]# vim /etc/my.cnf
[mysqld]
server_id=67
[[email protected] ~]# /etc/init.d/mysql restart
mysql> show master status\G;(在192.168.4.137上查看節點)
mysql> change master to master_host="192.168.4.137",master_user="hydra",master_password="Anonymous",master_log_file="master137.000001",master_log_pos=120;
mysql> start slave;
測試主從同步配置:
使用158的資料庫做使用者授權,在其他三台資料庫伺服器能夠查看到授權使用者
mysql> grant all on bbs.* to [email protected]"%" identified by "123";
mysql> select user,host from mysql.user;(在其他三台資料庫伺服器測試)
+-------+-----------+
| user | host |
+-------+-----------+
| hydra | % |
| stu | % |
| root | 127.0.0.1 |
| root | 137 |
| root | ::1 |
| root | localhost |
+-------+-----------+
在用戶端測試授權使用者:
[[email protected] ~]# mysql -h192.168.4.158 -ustu -p123(測試可以串連)
mysql> create database bbs;
mysql> create table bbs.t1(id int);
mysql> insert into bbs.t1 values(911);
在其他資料庫伺服器查看:
mysql> select * from bbs.t1;
+------+
| id |
+------+
| 911 |
+------+
配置mysql-mmm
mysql主主複製管理器,監控,容錯移轉和管理的一套指令碼套件
用perl語言編寫,能對居於標準的主從配置的任意數量的從伺服器進行讀負載平衡
和實現資料備份,mysql本身沒有提供容錯移轉的方案,從而實現資料庫伺服器的高可用
mysql-mmm架構
mmm-monitor:管理節點,運行在監控伺服器上,負責所有的監控工作的監控
mmm-agent:資料庫節點,運行在資料庫伺服器上,提供簡單的遠程服務集,提供給監控節點
在所有的伺服器上安裝mysql-mmm
[[email protected] ~]# unzip mysql-mmm.zip
[[email protected] mysql-mmm]# ls
Algorithm-Diff-1.1902.tar.gz mysql-mmm-P.txt
install.sh Net-ARP-1.0.8.tgz
mysql-mmm-2.2.1.tar.gz perl-Log-Log4perl-1.26-1.el6.rf.noarch.rpm
mysql-mmm-L.docx Proc-Daemon-0.03.tar.gz
[[email protected] mysql-mmm]# tar -xf mysql-mmm-2.2.1.tar.gz
[[email protected] mysql-mmm-2.2.1]# ls
bin COPYING etc INSTALL lib Makefile README sbin UPGRADE VERSION
[[email protected] mysql-mmm-2.2.1]# make install(安裝)
[[email protected] ~]# ls /etc/mysql-mmm/*.conf(設定檔)
/etc/mysql-mmm/mmm_agent.conf /etc/mysql-mmm/mmm_mon.conf
/etc/mysql-mmm/mmm_common.conf /etc/mysql-mmm/mmm_tools.conf
設定檔說明:
mmm_agent.conf(是mmm_agent服務的主設定檔)
mmm_mon.conf(是mmm_monitor的主設定檔)
mmm_common.conf(公用設定檔,所有的伺服器上都要)
配置mysql-mmm的ip規劃:
寫ip地址 192.168.4.119 (在主機158和主機137之間浮動)
讀ip地址 192.168.4.200 (在主機99和主機67之間浮動)
192.168.4.201
修改mmm_common.conf設定檔之前,在所有資料庫伺服器上做如下授權:
mysql> grant replication client,process,super on *.* to [email protected]"%" identified by "Anonymous";
更改mmm_common.conf設定檔:
[[email protected] mysql-mmm]# sed -i ‘/^$/d‘ mmm_common.conf(刪除空行)
[[email protected] mysql-mmm]# vim mmm_common.conf
<host default>(本機配置)
cluster_interface eth0(本機網卡)
pid_path /var/run/mmm_agentd.pid(進程pid號存放處)
bin_path /usr/lib/mysql-mmm/(可執行命令安裝路徑)
replication_user hydra(拷貝資料許可權的使用者名稱)
replication_password Anonymous(被授權使用者密碼)
agent_user agent(有agent許可權的使用者名稱)
agent_password Anonymous(密碼)
</host>
<host master158>(主機名稱)
ip 192.168.4.158(主機的ip地址)
mode master(主機的類型)
peer master137(同類型)
</host>
<host master137>(主機名稱)
ip 192.168.4.137(主機的ip地址)
mode master(主機的類型)
peer master158(同類型)
</host>
<host slave99>(從主機名稱)
ip 192.168.4.99(主機的ip地址)
mode slave(主機的類型)
</host>
<host slave67>(從主機名稱)
ip 192.168.4.67(主機的ip地址)
mode slave(主機的類型)
</host>
<role writer>(寫類型)
hosts master158,master137(寫類型的主機名稱)
ips 192.168.4.119(浮動ip)
mode exclusive(獨佔模式)
</role>
<role reader>(讀類型)
hosts slave99,slave67(讀類型的主機名稱)
ips 192.168.4.200,192.168.4.201(浮動ip)
mode balanced(共用模式)
</role>
[[email protected] mysql-mmm]# scp mmm_common.conf [email protected]:/etc/mysql-mmm/(儲存後把此設定檔發送到所有的伺服器上)
更改mmm_agent.conf設定檔
修改mmm_agent.con檔案
[[email protected] mysql-mmm]# vim mmm_agent.conf
include mmm_common.conf(先載入此設定檔)
this master158(本機在mmm_common.conf檔案裡的主機名稱)
修改mmm_agent.con檔案
[[email protected] mysql-mmm]# vim mmm_agent.conf
include mmm_common.conf
this master137(本機在mmm_common.conf檔案裡的主機名稱)
修改mmm_agent.con檔案
[[email protected] mysql-mmm]# vim mmm_agent.conf
include mmm_common.conf
this slave99(本機在mmm_common.conf檔案裡的主機名稱)
修改mmm_agent.con檔案
[[email protected] mysql-mmm]# vim mmm_agent.conf
include mmm_common.conf
this slave67(本機在mmm_common.conf檔案裡的主機名稱)
修改mmm_mon.conf設定檔之前,在所有資料庫伺服器上做如下授權:
mysql> grant replication client on *.* to [email protected]"%" identified by "Anonymous";
更改mmm_mon.conf設定檔:(在監控端修改即可,被監控端不用改)
[[email protected] mysql-mmm]# vim mmm_mon.conf
include mmm_common.conf
<monitor>
ip 192.168.4.102(監控端ip)
pid_path /var/run/mmm_mond.pid(pid存放處)
bin_path /usr/lib/mysql-mmm/
status_path /var/lib/misc/mmm_mond.status
ping_ips 192.168.4.158, 192.168.4.137, 192.168.4.99, 192.168.4.67(被監控的伺服器ip地址)
</monitor>
<host default>
monitor_user monitor(授權使用者)
monitor_password Anonymous(密碼)
</host>
debug 0(1開啟,輸出啟動過程資訊)
啟動資料庫伺服器上的mmm_agent服務:
啟動服務:/etc/init.d/mysql-mmm-agent start
記錄檔:/var/log/mysql-mmm/mmm_agentd.log
連接埠:netstat -utnalp | grep :9989
安裝服務運行需要的軟體包
Algorithm-Diff-1.1902.tar.gz
Proc-Daemon-0.03.tar.gz
perl-Log-Log4perl-1.26-1.el6.rf.noarch.rpm
把安裝步驟寫成指令碼
進入在每台資料庫伺服器上包所在的目錄上執行
進入每台資料庫伺服器執行指令碼
[[email protected] ~]# vim xx.sh
#/bin/bash
tar -xf Proc-Daemon-0.03.tar.gz
cd Proc-Daemon-0.03
perl Makefile.PL
make
make install
cd..
rpm -ivh perl-Log-Log4perl-1.26-1.el6.rf.noarch.rpm
tar -xf Algorithm-Diff-1.1902.tar.gz
cd Algorithm-Diff-1.1902
perl Makefile.PL
make
make install
cd ..
[[email protected] ~]# chmod +x xx.sh
[[email protected] ~]# scp xx.sh 192.168.4.137:/root/(把指令碼上傳到其他伺服器上)
啟動mmm_monitor服務
依賴包和mmm_agent的一樣,執行指令碼即可
啟動服務:/etc/init.d/mysql-mmm-monitor start
記錄檔:/var/log/mysql-mmm/mmm_monitor.log
連接埠:netstat -utnalp | grep :9988
在所有資料庫伺服器上安裝擷取虛擬ip的程式
Net-ARP-1.0.8.tgz
[[email protected] ~]# vim xxx.sh
#/bin/bash
gunzip Net-ARP-1.0.8.tgz
tar -xf Net-ARP-1.0.8.tar
cd Net-ARP-1.0.8
perl Makefile.PL
make
make install
[[email protected] Net-ARP-1.0.8]# chmod +x xxx.sh (把執行指令碼上傳到所有資料庫伺服器上)
測試組態
在102上查看配置
mmm_control help(協助)
mmm_control show(查看狀態)
mmm_control set_online 主機名稱(線上狀態)
[[email protected] ~]# mmm_control set_online master158(設定主機158線上模式)
[[email protected] ~]# mmm_control show
master137(192.168.4.137) master/ONLINE. Roles:
master158(192.168.4.158) master/ONLINE. Roles: writer(192.168.4.119)
slave67(192.168.4.67) slave/ONLINE. Roles: reader(192.168.4.200)
slave99(192.168.4.99) slave/ONLINE. Roles: reader(192.168.4.201)
用戶端測試虛擬ip訪問:
[[email protected] ~]# ping192.168.4.119
[[email protected] ~]# mysql -h192.168.4.119 -uhydra -pAnonymous
mysql 叢集 監控