博客
关于我
centos7配置lvs+keepalived高可用生产环境配置
阅读量:393 次
发布时间:2019-03-05

本文共 2017 字,大约阅读时间需要 6 分钟。

LVS和Keepalived配置实践指南

在本文中,我们将详细介绍如何在实验环境中部署并配置LVS(Linux Virtual Server)和Keepalived,实现服务的负载均衡和故障转移。

1. 安装并配置LVS和Keepalived

1.1 安装工具

首先,我们需要安装LVS管理工具ipvsadmkeepalived。在 CentOS 系stem 中,可以通过以下命令进行安装:

yum -y install ipvsadm keepalived

1.2 配置LVS主备服务器运行脚本

接下来,我们需要创建一个脚本来配置LVS主备服务器。以下是一个示例脚本:

#!/bin/bashVIP=192.168.5.100RIP1=192.168.5.104RIP2=192.168.5.105

将脚本保存为 /sbin/lvsdr.sh,并设置适当的权限:

chmod 755 /sbin/lvsdr.sh

然后运行脚本并启动LVS服务:

/sbin/lvsdr.sh start

1.3 启动脚本自启动

为了确保服务在系统重启后自动启动,我们需要将脚本添加到/etc/rc.local中:

echo "/sbin/lvsdr.sh start" >> /etc/rc.local

2. Keepalived配置

2.1 Keepalived主服务器配置

Keepalived的配置文件通常位于 /etc/keepalived/keepalived.conf。以下是一个示例配置:

global_defs {    router_id LVS_DEVEL}vrrp_instance VI_1 {    state MASTER    interface ens33    virtual_router_id 51    priority 100    advert_int 1    authentication {        auth_type PASS        auth_pass 1111    }    virtual_ipaddress {        192.168.5.100    }}

将此配置文件复制到远程备份服务器,并根据需要修改相关配置。

2.2 Keepalived实例配置

tomcat1tomcat2上配置Keepalived实例,确保服务的负载均衡和故障转移。以下是一个示例配置:

virtual_server 192.168.5.100 80 {    delay_loop 6    lb_algo rr    lb_kind DR    persistence_timeout 0    protocol TCP    real_server 192.168.5.104 80 {        weight 1        TCP_CHECK {            connect_timeout 10            nb_get_retry 3            delay_before_retry 3            connect_port 80        }    }    real_server 192.168.5.105 80 {        weight 1        TCP_CHECK {            connect_timeout 10            nb_get_retry 3            delay_before_retry 3            connect_port 80        }    }}

将此配置文件复制到远程备份服务器,并根据需要修改相关配置。

3. 配置Keepalived的自启动

为了确保Keepalived服务在系统重启后自动启动,我们需要将其添加到/etc/rc.local中:

echo "/etc/keepalived/keepalived.conf" >> /etc/rc.local

4. 防火墙配置

在实验环境中,通常需要关闭防火墙以确保服务能够正常通信。可以使用以下命令关闭防火墙:

systemctl stop firewalldsystemctl disable firewalld

5. 实验验证

为了确保配置的正确性,可以运行以下命令查看LVS的状态:

ipvsadm -ln

此外,可以通过浏览器访问VIP地址(如 http://192.168.5.100)验证服务是否正常运行。

6. 部署到生产环境

在生产环境中部署前,请务必进行充分的测试和验证。确保所有服务器的网络环境、防火墙配置和负载均衡策略都已正确配置。

通过以上步骤,您可以成功部署并配置LVS和Keepalived,实现服务器的负载均衡和故障转移。

转载地址:http://ybhwz.baihongyu.com/

你可能感兴趣的文章
prometheus 安装node_exporter, node_exporter 安装最新版 普罗米修思安装监控服务器client
查看>>
Prometheus 安装部署实战
查看>>
prometheus 持久化存储方案
查看>>
Prometheus 监控系统企业级实战
查看>>
Prometheus 监控系统简介
查看>>
Prometheus 配置详解
查看>>
Prometheus 采集器使用详解
查看>>
Prometheus 黑盒监控实战
查看>>
prometheus+alertmanager+grafana监控部署教程
查看>>
Prometheus+Grafana构建智能化Kubernetes监控系统实战
查看>>
Prometheus+SpringBoot应用监控全过程详解
查看>>
Prometheus+SpringBoot应用监控全过程详解
查看>>
prometheus安装
查看>>
Prometheus实战教程:监控Kafka消息
查看>>
Prometheus实战教程:监控mysql数据库
查看>>
Prometheus实战教程:监控Nginx状态
查看>>
prometheus常用exporter下载地址大全
查看>>
Prometheus快速搭建与监控Linux系统实战
查看>>
prometheus报警与恢复告警的格式
查看>>
Pytorch中安装 torch_geometric 详细图文操作(全)
查看>>