网站首页 > 技术教程 正文
概述
前面大家已经对基本概念有个了解了,接下来就是搭建过程了~
需求
1、LVS给两台nginx做负载均衡
2、keepalived做lvs高可用,同时做Real-Server健康检查,如果发现Real-Server80端口没开,就认为故障,从集群中剔除
3、在keepalived配置文件内就能配置LVS
环境说明
这里大家要准备4台服务器,5个IP(其中一个是虚拟IP)来做。
在负载均衡器端配置lvs+keepalived
1、配置linux系统内核参数
LVS主备上面,配置linux系统内核参数:开启内核的路由模式
#vim /etc/sysctl.conf net.ipv4.ip.forward = 1
立即生效
# sysctl -p
2、LVS主备关闭iptables服务
#service iptables stop
3、LVS主备安装LVS
可以选择yum或源码包的安装方式,这里我选择yum安装
#yum install ipvsadm
4、在主备服务器编译安装keepalived
(keepalived官网:http://www.keepalived.org/)
1)安装popt的开发包
#yum install popt-devel -y
2)安装openssl
#yum install openssl-devel -y
3)安装gcc
#yum install gcc -y
4)安装keepalived
#wget http://www.keepalived.org/software/keepalived-1.2.4.tar.gz #tar –zxvf keepalived-1.2.4.tar.gz #./configure –prefix=/usr/local/keepalived #make && make install
5、LVS主备将keepalived设置开机启动服务
#mkdir -p /etc/keepalived/ #cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/ #cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/ #cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/ #cp /usr/local/keepalived/sbin/keepalived /usr/sbin/ # chkconfig --add keepalived # chkconfig --level 35 keepalived on
6、LVS主备配置keepalived.conf
注意LVS网卡为eth1,下面介绍两个配置文件
6.1、主LVS上面的keepalived的配置文件
! Configuration File for keepalived
global_defs { #全局配置部分
notification_email { #email 通知,基本不用此处可注释掉
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc #定义发送邮件的邮箱
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL # 设置lvs的id,在一个网络内应该是唯一的
}
vrrp_instance VI_1 { #vrrp实例定义部分
state MASTER #设置lvs的状态,报错MASTER和BACKUP两种,必须大写
interface eth1 #指定LVS网卡,设置对外服务的接口
virtual_router_id 51 #虚拟路由的标志,一组lvs的虚拟路由标识必须相同,这样才能切换
priority 100 #定义优先级,数字越大优先级越高,在一个vrrp——instance下,master的优先级必须大于backup
advert_int 1 #设定master与backup负载均衡器之间同步检查的时间间隔,单位是秒
authentication { #设置验证类型和密码
auth_type PASS #主要有PASS和AH两种
auth_pass 1111
}
virtual_ipaddress { #设置虚拟ip地址,可以设置多个,每行一个
xx.xx.xx.E
}
}
virtual_server xx.xx.xx.E 80 { #设置虚拟服务器,需要指定虚拟ip和服务端口
delay_loop 2 #健康检查时间间隔
lb_algo wrr #负载均衡调度算法
lb_kind DR #负载均衡转发规则
#net_mask 255.255.255.0
persistence_timeout 60 #设置会话保持时间,对动态网页非常有用
protocol TCP #指定转发协议类型,有TCP和UDP两种
real_server xx.xx.xx.C 80 { #配置服务器节点1,需要指定real server的真实IP地址和端口
weight 1 #设置权重,数字越大权重越高
TCP_CHECK { #realserver的状态监测设置部分单位秒
connect_timeout 3 #超时时间
nb_get_retry 3 #重试次数
delay_before_retry 3 #重试间隔
connect_port 80 #监测端口
}
}
real_server xx.xx.xx.D 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
6.2、LVS-backup的配置文件
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
xx.xx.xx.E
}
}
virtual_server xx.xx.xx.E 80 {
delay_loop 2
lb_algo wrr
lb_kind DR
#net_mask 255.255.255.0
persistence_timeout 60
protocol TCP
real_server xx.xx.xx.C 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server xx.xx.xx.D 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
到这里关于lvs和keepalived部分就已经配置好了。
篇幅有限,关于LVS+KEEPALIVED部分就介绍到这了,后面主要介绍在relay_server端安装配置nginx部分和测试集群是否生效,能不能自动漂移,感兴趣的朋友可以关注下!
猜你喜欢
- 2024-10-09 中小规模网站架构设计:Nginx与HAProxy负载均衡比较
- 2024-09-08 理解Nginx的反向代理与负载均衡(理解nginx的反向代理与负载均衡分析)
- 2024-09-08 架构之路:Nginx与IIS服务器搭建集群实现负载均衡
- 2024-09-08 Linux 下配置nginx到php的连接(linux nginx php)
- 2024-09-08 注意这几点,轻轻松松配置 Nginx + Tomcat 的集群和负载均衡
- 2024-09-08 如何理解Nginx和Tomcat?(nginx和tomcat的关系)
- 2024-09-08 一文看懂nginx如何配置跨域,值得收藏
- 2024-09-08 这样搭建Nginx+Tomcat集群,实现负载均衡及动静分离,太轻松!
- 2024-09-08 通过nginx进行wss和ws协议转换(ftp文件传输协议对应于osi的)
- 2024-09-08 Nginx与安全有关的几个配置(nginx 安全设置)
欢迎 你 发表评论:
- 12-17分区工具怎么用(分区工具教程)
- 12-17数据库软件有哪几种(数据库说白了是干什么的)
- 12-17wms系统(WMS系统的功能有哪些)
- 12-17win8适合打游戏吗(win8.1玩游戏好不好)
- 12-17路由器显示无法连接互联网(连接路由器显示无法连接互联网)
- 12-17win11安装包下载(windows11安装包下载)
- 12-17惠普bios设置启动顺序(惠普bios怎么调启动项)
- 12-17win8 安装密钥(win8安装需要密钥)
- 最近发表
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)

本文暂时没有评论,来添加一个吧(●'◡'●)