Keepalived+lvs

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:
1
# yum install ipvsadm

Keepalived :

1. get keepalived.

1
# wget http://www.keepalived.org/software/keepalived-1.2.12.tar.gz

2.解压keepalived.

1
# tar xzvf keepalived-1.2.12.tar.gz

3. 进入目录

1
# cd keepalived-1.2.12

4. 安装包.

1
# yum install openssl-devel.x86_64 kernel-headers kernel-devel

5. 配置keepalived.

1
#./configure

6. 编译.

1
# make

7. 编译安装.

1
# make install

8.自启动服务.

1
2
3
4
5
6
7
8
9
#  cd /etc/sysconfig 
#  ln -s /usr/local/etc/sysconfig/keepalived . 
#  cd /etc/rc3.d/ 
#  ln -s /usr/local/etc/rc.d/init.d/keepalived S100keepalived 
#  cd /etc/init.d/ 
#  ln -s /usr/local/etc/rc.d/init.d/keepalived
#  ln -s /usr/local/sbin/keepalived /usr/sbin/
#  cd /etc/keepalived
#  ln -s /usr/local/etc/keepalived/keepalived.conf .

keepalived.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
! Configuration File  for  keepalived
global_defs { 
    router_id MYSQLD 
}
vrrp_instance MYSQLD_3306 { 
         state MASTER 
         interface em2 
         virtual_router_id 22 
         priority 101 
         advert_int 1 
         mcast_src_ip 192.168.253.9 
         authentication { 
                 auth_type PASS 
                 auth_pass lekan 
         }
         virtual_ipaddress { 
                 192.168.253.100 /24  dev em2 scope global 
        
         notify_master  "/etc/keepalived/notification_email.sh master" 
         notify_backup  "/etc/keepalived/notification_email.sh backup" 
}
virtual_server 192.168.253.100 3306 { 
         delay_loop 2 
         lb_algo rr 
         lb_kind DR 
         persistence_timeout 10 
         protocol TCP
         real_server 192.168.253.6 3306 { 
                 weight 1 
                 inhibit_on_failure 
                 notify_up  "/etc/keepalived/mysql.sh up" 
                 notify_down  "/etc/keepalived/mysql.sh down" 
                 TCP_CHECK { 
                         connect_timeout 3 
                         nb_get_retry 3 
                         delay_before_retry 3 
                         connect_port 3306 
                
         }
         real_server 192.168.253.8 3306 { 
                 weight 1 
                 inhibit_on_failure 
                 notify_down  "/etc/keepalived/mysql.sh down" 
                 notify_up  "/etc/keepalived/mysql.sh up" 
                 TCP_CHECK { 
                         connect_timeout 3 
                         nb_get_retry 3 
                         delay_before_retry 3 
                         connect_port 3306 
                
        
}

mysql.sh

1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash
case  $1  in 
         up) 
                 echo  "mysqld up"  | mutt -s  "keepalived mysqld"  tong.li@mail.lekan.com 
         ;; 
         down) 
                 echo  "mysqld down"  | mutt -s  "keepalived mysqld"  tong.li@mail.lekan.com 
         ;; 
         *) 
                 echo  "keepalived"  >>  /home/tong .li /keepalived .txt 
         ;; 
esac

notification_email.sh

1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash
case  $1  in 
         master) 
                 echo  "keepalived master failover"  | mutt -s  "keepalived"  tong.li@mail.lekan.com 
         ;; 
         backup) 
                 echo  "keepalived backup failover"  | mutt -s  "keepalived"  tong.li@mail.lekan.com 
         ;; 
         *) 
                 echo  "keepalived"  >>  /home/tong .li /keepalived .txt 
         ;; 
esac

realserver.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
#description:start realserver
VIP=192.168.253.100
/etc/rc .d /init .d /functions
case  "$1"  in
start)
     /sbin/ifconfig  lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
     /sbin/route  add -host $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  "start LVS of RealServer DR"
     ;;
stop)
     /sbin/ifconfig  lo:0 down
     route del $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  "close LVS of RealServer DR"
     ;;
*)
     echo  "Usage:$0 {start|stop}"
     exit  1
;;
esac










本文转自 Art_Hero 51CTO博客,原文链接:http://blog.51cto.com/curran/1387497,如需转载请自行联系原作者
相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
负载均衡 应用服务中间件 Linux
Nginx系列教程(14) - LVS+KeepAlived+Nginx实现高性能负载均衡集群
Nginx系列教程(14) - LVS+KeepAlived+Nginx实现高性能负载均衡集群
1137 0
|
2月前
|
运维 负载均衡 网络协议
LVS+Keepalived 负载均衡
LVS+Keepalived 负载均衡
72 8
LVS+Keepalived 负载均衡
|
2月前
|
域名解析 运维 负载均衡
LVS+Keepalived 负载均衡(二)28-1
【8月更文挑战第28天】LVS+Keepalived 负载均衡 配置 LVS VIP
63 5
|
6月前
|
运维 负载均衡 监控
keepalived+LVS实现高可用性集群
通过结合keepalived和LVS,你可以创建一个高可用性的负载均衡集群,确保服务器的稳定性和性能。这对于托管Web服务、应用服务器等关键服务的服务器集群非常有用。
119 1
|
6月前
|
负载均衡 监控 Linux
CentOS6.5高可用集群LVS+Keepalived(DR模式)
CentOS6.5高可用集群LVS+Keepalived(DR模式)
|
6月前
|
负载均衡 监控 调度
Keepalived+Lvs(dr)调度器主备配置小实验
Keepalived和LVS(Linux Virtual Server)是两个常用的开源软件,通常结合使用以提供高可用性和负载均衡的解决方案。 Keepalived是一种用于实现高可用性的软件,它可以监控服务器的健康状态,并在主服务器出现故障时自动切换到备份服务器。
213 2
|
负载均衡 算法 网络协议
Keepalived+LVS搭建高可用负载均衡
Keepalived+LVS搭建高可用负载均衡
385 1
|
11月前
|
负载均衡 网络协议 Linux
小白带你学习linux的keepalived+lvs和keepalived双机热备(三十七)
小白带你学习linux的keepalived+lvs和keepalived双机热备(三十七)
175 0
|
负载均衡 监控 Linux
LVS + keepalived
LVS + keepalived
166 1
|
负载均衡 测试技术
LVS+KeepAlived构建高可用集群
LVS+KeepAlived构建高可用集群
108 0