亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MySQL5.7+keepalived+LVS從庫負載均衡搭建

發布時間:2020-08-12 07:26:47 來源:ITPUB博客 閱讀:242 作者:StevenBeijing 欄目:MySQL數據庫

數據庫架構:一主三從

master:192.168.8.57

slave1:192.168.8.58

slave2:192.168.8.59

slave3:192.168.8.61

manager:192.168.8.60

工具包:

mha4mysql-manager-0.58.tar.gz

mha4mysql-node-0.58.tar.gz

keepalived-1.4.5.tar.gz

        此項目數據庫架構中,master和slave1利用MHA和keepalived實現故障自動切換,slave2和slave3利用 keepalived和LVS實現負載均衡,本文著重講解負載均衡的搭建過程。

一、安裝ipvsadm

在slave2和slave3安裝

mount /dev/cdrom /media
yum install -y ipvsadm

二、安裝keepalived

tar zxvf keepalived-1.4.5.tar.gz
cd keepalived-1.4.5
./configure --prefix=/usr/local/keepalived/
make && make install

設置開機自動啟動

systemctl enable keepalived

三、更改keepalived日志位置

keepalived日志默認位置為/var/log/messages

把日志單獨存放

修改 vi /usr/local/keepalived/etc/sysconfig/keepalived

把 KEEPALIVED_OPTIONS="-D" 修改為:KEEPALIVED_OPTIONS="-D -d -S 0"

vi /usr/local/keepalived/etc/sysconfig/keepalived
# Options for keepalived. See `keepalived --help' output and keepalived(8) and
# keepalived.conf(5) man pages for a list of all options. Here are the most
# common ones :
#
# --vrrp               -P    Only run with VRRP subsystem.
# --check              -C    Only run with Health-checker subsystem.
# --dont-release-vrrp  -V    Dont remove VRRP VIPs & VROUTEs on daemon stop.
# --dont-release-ipvs  -I    Dont remove IPVS topology on daemon stop.
# --dump-conf          -d    Dump the configuration data.
# --log-detail         -D    Detailed log messages.
# --log-facility       -S    0-7 Set local syslog facility (default=LOG_DAEMON)
#
KEEPALIVED_OPTIONS="-D -d -S 0"

重啟服務

systemctl restart rsyslog

四、修改keepalived配置文件

192.168.8.59

vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived
global_defs {
router_id 859
notification_email {
zdd5503@163.com
}
notification_email_from zdd5503@163.com
smtp_server stmp.163.com
smtp_connect_timeout 30
}
vrrp_instance v_mysql_slave_wgpt1 {
state MASTER
interface enp0s3
virtual_router_id 98
priority 100
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass steven
}
virtual_ipaddress {
192.168.8.98/24
}
}
virtual_server 192.168.8.98 3306 {
delay_loop 2
lb_algo rr
lb_kind DR
persistence_timeout 0
protocol TCP
real_server 192.168.8.59 3306 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
real_server 192.168.8.61 3306 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}

192.168.8.61

vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived
global_defs {
router_id 861
notification_email {
zdd5503@163.com
}
notification_email_from zdd5503@163.com
smtp_server stmp.163.com
smtp_connect_timeout 30
}
vrrp_instance v_mysql_slave_wgpt1 {
state BACKUP
interface enp0s3
virtual_router_id 98
priority 80
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass steven
}
virtual_ipaddress {
192.168.8.98/24
}
}
virtual_server 192.168.8.98 3306 {
delay_loop 2
lb_algo rr
lb_kind DR
persistence_timeout 0
protocol TCP
real_server 192.168.8.59 3306 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
real_server 192.168.8.61 3306 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}

systemctl daemon-reload

systemctl start keepalived

systemctl enable keepalived

ps -ef |grep keepalived

ip a

五、lo:0綁定VIP地址、抑制ARP廣播

192.168.8.59

vi /etc/rc.d/init.d/lvsmysql.sh

#!/bin/bash
#
. /etc/rc.d/init.d/functions
VIP1=$1
case "$2" in
start)
echo " Start LVS of MySQL Slave REALServer"
/sbin/ifconfig lo:0 $VIP1 broadcast $VIP1 netmask 255.255.255.255 up
/sbin/route add -host $VIP1 dev lo:0
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p >/dev/null 2>&1
;;
stop)
/sbin/ifconfig lo:0 down
/sbin/route del $VIP1 >/dev/null 2>&1
echo "Stoped LVS of MySQL Slave Directorserver"
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
status)
isLoOn=`/sbin/ifconfig lo:0 | grep "$VIP"`
isRoOn=`/bin/netstat -rn | grep "$VIP"`
if [ "$isLoON" == "" -a "$isRoOn" == "" ]; then
echo "LVS-DR real server has run yet."
else
echo "LVS-DR real server is running."
fi
exit 3
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 1
esac
exit 0

192.168.8.61

vi /etc/rc.d/init.d/lvsmysql.sh

#!/bin/bash
#
. /etc/rc.d/init.d/functions
VIP1=$1
case "$2" in
start)
echo " Start LVS of MySQL Slave REALServer"
/sbin/ifconfig lo:0 $VIP1 broadcast $VIP1 netmask 255.255.255.255 up
/sbin/route add -host $VIP1 dev lo:0
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p >/dev/null 2>&1
;;
stop)
/sbin/ifconfig lo:0 down
/sbin/route del $VIP1 >/dev/null 2>&1
echo "Stoped LVS of MySQL Slave Directorserver"
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
status)
isLoOn=`/sbin/ifconfig lo:0 | grep "$VIP"`
isRoOn=`/bin/netstat -rn | grep "$VIP"`
if [ "$isLoON" == "" -a "$isRoOn" == "" ]; then
echo "LVS-DR real server has run yet."
else
echo "LVS-DR real server is running."
fi
exit 3
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 1
esac
exit 0

六、測試負載均衡

/etc/rc.d/init.d/lvsmysql.sh 192.168.8.59 start

/etc/rc.d/init.d/lvsmysql.sh 192.168.8.59 stop

/etc/rc.d/init.d/lvsmysql.sh 192.168.8.61 start

/etc/rc.d/init.d/lvsmysql.sh 192.168.8.61 stop

echo "/etc/rc.d/init.d/lvsmysql.sh 192.168.1.65 start" >>

/etc/rc.d/rc.local

echo "ipvsadm --set 15 5 15" >> /etc/rc.d/rc.local

ifconfig

ipvsadm -L

mysql -uroot -pmysql -h292.168.8.59 -e "select @@hostname;"

mysql -uroot -pmysql -h292.168.8.61 -e "select @@hostname;



向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

赣榆县| 柘城县| 桓台县| 韩城市| 大城县| 东海县| 大渡口区| 汉寿县| 义乌市| 故城县| 安康市| 驻马店市| 临江市| 新郑市| 昌江| 威海市| 崇信县| 县级市| 唐河县| 沁源县| 江门市| 合阳县| 大宁县| 建宁县| 太康县| 郁南县| 炉霍县| 剑川县| 城口县| 宁阳县| 扶余县| 隆尧县| 滦南县| 乌鲁木齐市| 甘南县| 阿拉尔市| 清新县| 东山县| 夏河县| 华坪县| 建德市|