博客
关于我
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/

你可能感兴趣的文章
Now trying to drop the old temporary tablespace, the session hangs.
查看>>
nowcoder—Beauty of Trees
查看>>
np.arange()和np.linspace()绘制logistic回归图像时得到不同的结果?
查看>>
np.power的使用
查看>>
NPM 2FA双重认证的设置方法
查看>>
npm build报错Cannot find module ‘webpack/lib/rules/BasicEffectRulePlugin‘解决方法
查看>>
npm build报错Cannot find module ‘webpack‘解决方法
查看>>
npm ERR! ERESOLVE could not resolve报错
查看>>
npm ERR! fatal: unable to connect to github.com:
查看>>
npm ERR! Unexpected end of JSON input while parsing near '...on":"0.10.3","direc to'
查看>>
npm ERR! Unexpected end of JSON input while parsing near ‘...“:“^1.2.0“,“vue-html-‘ npm ERR! A comp
查看>>
npm error Missing script: “server“npm errornpm error Did you mean this?npm error npm run serve
查看>>
npm error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,1) 安装
查看>>
npm install CERT_HAS_EXPIRED解决方法
查看>>
npm install digital envelope routines::unsupported解决方法
查看>>
npm install 卡着不动的解决方法
查看>>
npm install 报错 EEXIST File exists 的解决方法
查看>>
npm install 报错 ERR_SOCKET_TIMEOUT 的解决方法
查看>>
npm install 报错 Failed to connect to github.com port 443 的解决方法
查看>>
npm install 报错 fatal: unable to connect to github.com 的解决方法
查看>>