数据库|mysql教程
服务器
数据库-mysql教程
android mp3 源码,ubuntu分区被上锁,爬虫调查用户搜索,php emsp,尖端seo郑州lzw
MySQL + KeepAlived + LVS单点写入主主同步高可用架构实验
云免流apk源码,vscode文件绿色的u,Ubuntu桌面挂掉,tomcat默认界面漏洞,通用爬虫方案,php ascii转中文,短视频抖音seo优化,服务器租用网站源码,自选菜单模板lzw
㈠ 实战环境
php源码报名登记系统,恢复ubuntu启动菜单,tomcat局域网无法连接,中国全部银行爬虫,微信机器人php开源,seo犯法吗lzw
服务器名· IP OS MySQL
192.168.1.116 RHEL-5.8 5.5.16
192.168.1.115 RHEL-5.8 5.5.16
㈡ 方案优缺点
优点
● 安装配置简单, 实现方便,高可用效率好,可以根据服务与系统的可用性多方面进行切换
● 可以将写 VIP 和读 VIP 分别进行设置,为读写分离做准备
● 可以在后面添加多个从服务器,并做到负载均衡
缺点
● 在启动或者恢复后会立即替换掉定义的 sorry_server
因此如果要实现指定条件替换或者不替换需要通过其他方式实现,比如:临时更改MySQL的端口等
● 扩展不是很方便
● 切换需要 1s 左右的时间
㈢ 方案适用场景
这个方案适用于只有两台数据库服务器并且还没有实现数据库的读写分离的情况、读和写都配置 VIP
这个方案能够便于单台数据库的管理维护以及切换工作
比如进行大表的表结构更改、数据库的升级等都是非常方便的
㈣ 方案架构图
㈤ 部署步骤
⑴ MySQL 安装
请查阅我之前的一篇文章:
MySQL 5.5 三大安装方式:【二进制、源代码编译和RPM包】安装步骤及优缺点比较
/database/04/202705.html
⑵ MySQL主主同步配置
这也请查阅我之前的文章哈:MySQL主主同步配置
/database/05/207858.html
⑶ LVS 安装
在ODD EVEN:
# wget /software/kernel-2.6/ipvsadm-1.24.tar.gz
# ln -s /usr/src/kernels/2.6.18-308.el5xen-i686/ /usr/src/linux
# tar -zxv -f ipvsadm-1.24.tar.gz
# cd ipvsadm-1.24
# make
# make install
⑷ KeepAlived安装
在ODD EVEN:
# wget /software/keepalived-1.1.19.tar.gz
# tar -zxv -f keepalived-1.1.19.tar.gz
# cd keepalived-1.1.19
# ./configure –prefix=/usr/local/keepalived
# make
# make install
# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
# mkdir /etc/keepalived
⑸ KeepAlived配置
在 ODD
[plain]
global_defs {
notification_email {
linwaterbin@
}
notification_email_from bychjzh@
smtp_server
smtp_connect_timeout 30
router_id LVS1
}
vrrp_sync_group test {
group {
loadbalance
}
}
vrrp_instance loadbalance {
state BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.128 dev eth0 label eth0:1
}
}
virtual_server 192.168.1.128 3306 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 20
protocol TCP
sorry_server 192.168.1.115 3306
real_server 192.168.1.116 3306 {
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
在EVEN:
大部分都和 ODD 一样、只有 2 处:
● state BACKUP
● priority 150
⑹ ODD EVEN 的 realsever 配置
在 ODD EVEN 上
[plain]
#!/bin/bash
# description: Config realserver lo and apply noarp
SNS_VIP=192.168.1.128
/etc/rc.d/init.d/functions
case “$1” in
start)
ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP
/sbin/route add -host $SNS_VIP 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
echo “RealServer Start OK”
;;
stop)
ifconfig lo:0 down
route del $SNS_VIP >/dev/null 2>&1
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
echo “RealServer Stoped”
;;
*)
echo “Usage: $0 {start|stop}”
exit 1
esac
exit 0
⑺ 启动 KeepAlived和 realsever
在 ODD EVEN
# /etc/rc.d/init.d/realserver.sh start
# /etc/rc.d/init.d/keepalived start
# echo “/etc/rc.d/init.d/realserver.sh start” >> /etc/rc.local
# echo “/etc/rc.d/init.d/keepalived start” >> /etc/rc.local
配置到这边大概都已经差不多了、接下来看看测试
㈥ 简单测试
停掉ODD MySQL Server 、看看能否自动却换到 sorry_server
[plain]
停止前:
[root@odd keepalived]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.1.128:3306 rr persistent 20
-> 192.168.1.116:3306 Local 300
停止:
[mysql@odd ~]$ mysqladmin shutdown
130508 00:53:50 mysqld_safe mysqld from pid file /home/mysql/mysql/data/.pid ended
[1]+ Done mysqld_safe
停止后:
[root@odd keepalived]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.1.128:3306 rr persistent 20
-> 192.168.1.115:3306 Route 100
成功!!
如果觉得《MySQL + KeepAlived + LVS单点写入主主同步高可用架构实验【MySQL】》对你有帮助,请点赞、收藏,并留下你的观点哦!