lvs+keepalived 负载均衡

1.先开4台机器,因为想做lvs 的keepalived高可用所以开四台

在这里插入图片描述

1.下载keepallived 和 ipvsadm (ipvsadm是一个查看配置的工具)

       开始就把防火墙关掉
yum -y install keepalived ipvsadm #安装
vim /etc/keepalived/keepalived.conf #修改配置文件

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

2.发送配置文件

scp /etc/keepalived/keepalived.conf root@192.168.242.134:/etc/keepalived/keepalived.conf
把从上面的向上面改一下  MASTER改为BACKUP  100改为90

3.在web上操作另一台web上也要操作

yum -y install httpd  #下载httpd
echo "web1" > /var/www/html/index.html  #改个页面

4.复制网卡

cd /etc/sysconfig/network-scripts/
cp ifcfg-lo ifcfg-lo:0DEVICE=lo:0

5.修改网卡的配置文件

vim ifcfg:0     #底下是没修改前
IPADDR=192.168.242.100             #VIP
NETMASK=255.255.255.255            #子网掩码
ONBOOT=yes  

在这里插入图片描述

6.启动网卡查看网卡

ifup lo:0
[root@localhost network-scripts]  ifconfig lo:0
lo:0: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 192.168.242.100  netmask 255.255.255.255            出现则为成功
        loop  txqueuelen 1000  (Local Loopback)

7.加6行

vim /etc/sysctl.conf 
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
下面是添加的
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 

8.检测添加的有没问题

[root@localhost network-scripts]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2

9.router

vim /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
/sbin/route add -host 192.168.242.100 dev lo:0            #加这一行

10.在命令行执行一遍

[root@localhost network-scripts]# route add -host 192.168.242.100 dev lo:0

11.另一台相同操作

12.测试

在这里插入图片描述在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值