网站首页 > 技术教程 正文
概述
前面大家已经对基本概念有个了解了,接下来就是搭建过程了~
需求
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-13 nginx的集群原理与常用的调度算法
- 2024-10-13 自己动手在阿里云部署 K8S 集群(阿里云 slb k8s)
- 2024-10-13 Kubernetes集群的自动化部署和管理
- 2024-10-13 最新Minio+Docker+Nginx多机集群(多台nginx集群方案)
- 2024-10-13 基于 consul + nginx 的Spring boot微服务集群部署
- 2024-10-13 k8s集群中部署nginx(k8s nginx ingress)
- 2024-10-13 完美!Kubernetes 集群的零停机服务器更新
- 2024-10-13 高级架构技术点之安装redis 集群(redis 安装配置)
- 2024-10-13 K8s Helm部署 ES集群 &Kibana 收集展示日志
- 2024-09-30 认识Kubernetes以及搭建Kubernetes集群
你 发表评论:
欢迎- 最近发表
-
- Oracle 在其新的 Linux 内核中引入了热补丁功能
- CentOS 7.6下安装Oracle 11.2.0.4
- ORACLE体系 - 2(oracle体系讲解)
- ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务
- Hadoop自学系列集(二) ---- CentOS下安装JDK
- 如何升级oracle数据库安全补丁(oraclepsu补丁升级)
- 搭建Oracle数据库服务器(oracle服务器创建用户)
- OGG同步到Kafka(oggforbigdata到kafka)
- oracle是什么软件?(oracle是干什么用的)
- 脚本化修改Oracle用户的密码以及执行sql(增删改查等)
- 标签列表
-
- 下划线是什么 (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)
本文暂时没有评论,来添加一个吧(●'◡'●)