真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Mysql+keepalive高可用搭建

               MySQL + keepalive高可用搭建

系統(tǒng)環(huán)境:centos6.8
Ip:192.168.137.36 主庫(kù)
192.168.137.38 從庫(kù)

創(chuàng)新互聯(lián)建站于2013年成立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元濟(jì)南做網(wǎng)站,已為上家服務(wù),為濟(jì)南各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:18980820575

VIP(虛擬ip/浮動(dòng)ip):192.168.137.100

軟件版本:mysql 5.7.20
Keepalived 1.2.13

主從搭建略
Mysql1
vim /etc/my.cnf
binlog-do-db=test
log-bin=mysql-bin
server-id=1
gtid-mode=ON
enforce-gtid-consistency

Mysql2
Vim /etc/my.cnf
gtid-mode=ON
enforce-gtid-consistency
log-bin=mysql-bin
log-slave-updates=ON
server-id=3
binlog-do-db=test

安裝keepalived
yum install keepalived

在192.168.137.36主庫(kù)修改keepalived的配置文件
注意:加顏色部分為修改部分

[root@zabbix ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs{
notification_email {
root@localhost
}
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
#VIP1
vrrp_instance VI_1 {
state BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 151
priority 100
advert_int 5
nopreempt
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
192.168.137.100
}
}
virtual_server 192.168.137.100 3306 {
delay_loop 6
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.137.36 3306 {
weight 100
notify_down /data/sh/mysql.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}

保存退出
在192.168.137.38從庫(kù)修改keepalived的配置文件
[root@localhost sh]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs{
notification_email {
root@localhost
}
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
#VIP1
vrrp_instance VI_1 {
state BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 151
priority 98
advert_int 5
nopreempt
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
192.168.137.100
}
}
virtual_server 192.168.137.100 3306 {
delay_loop 6
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.137.38 3306 {
weight 98
notify_down /data/sh/mysql.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
保存退出
上面的配置簡(jiǎn)單說明:
state BACKUP??表示為備模式,nopreempt?為不搶占,雙方都配為備模式,并且不搶占,可以避免“腦裂”問題,priority 100?為權(quán)重,數(shù)字越高,權(quán)重越高,當(dāng)雙方都配為BACKUP模式,并且配置nopreempt時(shí),keepalived靠這個(gè)數(shù)字來判斷誰(shuí)是主,誰(shuí)是備
主從都要?jiǎng)?chuàng)建/data/sh/mysql.sh腳本
mkdir /data/sh
vim?/data/sh/mysql.sh?加入以下內(nèi)容:
#!/bin/bash
/etc/init.d/keepalived? stop
?
chmod??755? /data/sh/mysql.sh
modprobe ?ip_vs??#加載ip_vs模塊?虛擬IP要用
lsmod?|? grep? ip_vs??查看ip_vs模塊有沒有加載,如果看到下面的內(nèi)容,就表示加載成功:
Mysql + keepalive高可用搭建

/etc/init.d/mysqld? start??#啟動(dòng)mysql
/etc/init.d/keepalive? start???#啟動(dòng)keepalived
在36上的操作和38上一樣,只是keepalived.conf配置文件里priority 100?改為?priority 98
?
real_server 192.168.137.36?改為?real_server 192.168.137.38其他不變。
?
查看VIP情況命令: ip a
Mysql + keepalive高可用搭建
?
至此mysql的主從高可用就做好了,可以在36上測(cè)試挺掉mysql服務(wù),看看vip會(huì)不會(huì)漂移到38上,一般來說都是沒問題的,如果有問題,請(qǐng)檢查你的配置,步驟是不是有錯(cuò)誤,還有selinux,防火墻是否關(guān)閉等


當(dāng)前名稱:Mysql+keepalive高可用搭建
網(wǎng)址分享:http://weahome.cn/article/ipodic.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部