LVS/DR+keepalived配置实例(详细)

1.环境准备

一台NFS服务器,采用内网192.168.100.20/24,共享目录为data1、data2
两台后端服务器,分别采用外网192.168.100.60/24、192.168.100.70/24和内网192.168.1.130/24、192.168.1.132/24。网页目录分别挂载为NFS上data1和data2
两台负载调度器,一主一备。均采用外网192.168.100.234/24、192.168.100.235/24。
VIP为192.168.100.236/32

2.NFS配置

[root@nfs-server ~]# yum -y install rpcbind nfs-utils
[root@nfs-server ~]# mkdir /data{1,2}
vi /etc/exports
/data1 192.168.1.0/24(rw)
/data2 192.168.1.0/24(rw)
[root@nfs-server ~]# echo “This is apache1” > /data1/index.html
[root@nfs-server ~]# echo “This is apache2” > /data2/index.html

2.1 启动NFS服务

[root@nfs-server ~]# systemctl start rpcbind nfs
LVS/DR+keepalived配置实例(详细)_第1张图片

3.RS配置

3.1 软件包安装

[root@apache1 ~]# yum -y install httpd rpcbind

3.2 配置VIP

[root@apache1 ~]# cd /etc/sysconfig/network-scripts
[root@apache1 network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@apache1 network-scripts]# vi ifcfg-lo:0
LVS/DR+keepalived配置实例(详细)_第2张图片
[root@apache1 network-scripts]# ifup ifcfg-lo:0

LVS/DR+keepalived配置实例(详细)_第3张图片

3.3 调整/proc响应参数

[root@apache1 ~]# vi /sysctl .conf
LVS/DR+keepalived配置实例(详细)_第4张图片
LVS/DR+keepalived配置实例(详细)_第5张图片

3.4 挂载共享目录

[root@apache1 ~]# systemctl start rpcbind
[root@apache1 ~]# mount 192.168.1.20:/data1 /var/www/html/
LVS/DR+keepalived配置实例(详细)_第6张图片
在apache2做出类似配置

4.LB配置

4.1 安装keepalived

[root@master-server ~]# yum -y install keeplived

4.2 配置keepalived

[root@master-server ~]# cd /etc/keepalived/
[root@master-server keepalived]# mv keepalived.conf keepalived.conf.bak
[root@master-server keepalived]# vi keepalived.conf
LVS/DR+keepalived配置实例(详细)_第7张图片
注:在backup保持相同配置,只须修改router_id 、stat、priority参数

4.3 调整proc响应参数

[root@master-server ~]# vi /etc/sysctl.conf LVS/DR+keepalived配置实例(详细)_第8张图片
在这里插入图片描述

4.4 启动keepalived,查看效果

[root@master-server ~]# systemctl start keepalived

4.4.1 IP地址查看

LVS/DR+keepalived配置实例(详细)_第9张图片

4.4.2 LVS实现查看

LVS/DR+keepalived配置实例(详细)_第10张图片

你可能感兴趣的:(负载均衡)