RHEL 6.5----LVS(DR)
2024-10-20 11:40:57
主机名 | IP | 所需软件 |
master |
eth0==>192.168.30.140(Nat) eth0:1==>192.168.17.130(Nat) |
ipvsadm |
node-1 | eth0==>192.168.17.131 | httpd |
node-2 | eth0==>192.168.17.132 |
在master上安装及开启ipvsadm
[root@master ~]# yum install -y ipvsadm
[root@master ~]# cd /etc/sysconfig/network-scripts/
[root@master network-scripts]# cp ifcfg-eth0 ifcfg-eth:
[root@master network-scripts]# vim ifcfg-eth0:1 #只需修改绿色部分三处,其他不要动
DEVICE=eth0:
TYPE=Ethernet
UUID=a186cc9d-8d79--a180-a1b17d884a7b
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
HWADDR=:0C::4D::
IPADDR=192.168.30.130
PREFIX=
GATEWAY=192.168.30.2
DNS1=119.29.29.29
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0:1"
重启网络服务
[root@master ~]# service network restart
Shutting down interface eth0: Device state: (disconnected)
[ OK ]
Shutting down interface eth1: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Active connection state: activated
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/
[ OK ]
[root@master ~]# ifconfig
eth0 Link encap:Ethernet HWaddr :0C::4D::
inet addr:192.168.30.140 Bcast:192.168.30.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe4d:/ Scope:Link
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (8.4 KiB) TX bytes: (8.0 KiB) eth0: Link encap:Ethernet HWaddr :0C::4D:: #MAC地址一定要与eth0的一样
inet addr:192.168.30.130 Bcast:192.168.30.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU: Metric:
添加规则
确保这里是0
[root@master ~]# sysctl -p
net.ipv4.ip_forward =
..........
添加规则
[root@master ~]# ipvsadm -A -t 192.168.30.130: -s rr
[root@master ~]# ipvsadm -a -t 192.168.30.130: -r 192.168.30.131 -g
[root@master ~]# ipvsadm -a -t 192.168.30.130: -r 192.168.30.132 -g
[root@master ~]# ipvsadm -L -n
IP Virtual Server version 1.2. (size=)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.30.130: rr
-> 192.168.30.131: Route
-> 192.168.30.132: Route
保存规则
[root@master ~]# /etc/init.d/ipvsadm save
ipvsadm: Saving IPVS table to /etc/sysconfig/ipvsadm: [ OK ]
在realserver(node-1和node-2)上
生成ifcfg-lo:1文件
[root@node- ~]# cd /etc/sysconfig/network-scripts/
[root@node- network-scripts]# cp ifcfg-lo ifcfg-lo:
[root@node- network-scripts]# vim ifcfg-lo:
DEVICE=lo:
IPADDR=192.168.30.130
NETMASK=255.255.255.255
# If you're having problems with gated making 127.0.0.0/8 a martian,
# you can change this to something else (255.255.255.255, for example)
ONBOOT=yes
NAME=loopback
关闭ARP转发
[root@node- ~]# vim /etc/sysctl.conf #末未添加
net.ipv4.conf.eth0.arp_ignore =
net.ipv4.conf.eth0.arp_announce =
[root@node- ~]# sysctl -p #使立即生效
net.ipv4.ip_forward =
.....
net.ipv4.conf.eth0.arp_ignore =
net.ipv4.conf.eth0.arp_announce =
修改网关
[root@node- ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
GATEWAY=192.168.30.2
#网关修改为指向外网出口的路由器IP
创建测试页面
[root@node- ~]# echo "<h1>This is the node-1 Web-Server:192.168.17.131</h1>" > /var/www/html/index.html
在node-2上
[root@node- ~]# cd /etc/sysconfig/network-scripts/
[root@node- network-scripts]# cp ifcfg-lo ifcfg-lo:
[root@node- network-scripts]# vim ifcfg-lo:
DEVICE=lo:
IPADDR=192.168.30.130
NETMASK=255.255.255.255
# If you're having problems with gated making 127.0.0.0/8 a martian,
# you can change this to something else (255.255.255.255, for example)
ONBOOT=yes
NAME=loopback
[root@node- ~]# service network restart
Shutting down interface eth0: Device state: (disconnected)
[ OK ]
Shutting down interface eth1: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Active connection state: activated
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/
[ OK ]
[root@node- ~]# ifconfig
eth0 Link encap:Ethernet HWaddr :::2F::4D
inet addr:192.168.30.132 Bcast:192.168.30.255 Mask:255.255.255.0
inet6 addr: fe80:::56ff:fe2f:844d/ Scope:Link
...................
lo: Link encap:Local Loopback
inet addr:192.168.30.130 Mask:255.255.255.255
UP LOOPBACK RUNNING MTU: Metric:
关闭ARP转发通node-1操作一样;
创建测试页面
[root@node- ~]# echo "<h1>This is the node-2 Web-Server:192.168.17.132</h1>" > /var/www/html/index.html
[root@node- ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
物理机使用浏览器访问测试
最新文章
- 在 Laravel 中使用图片处理库 Integration/Image
- Android 中关于Fragment嵌套Fragment的问题
- Codeforces Round #384 (Div. 2) C. Vladik and fractions(构造题)
- ComponentOne 2016 V3 发布
- Android开发使用TotalControl调试遇到的问题(备注)
- python用来压缩目录的脚本
- ios 取出subviews中指定subview
- android 项目学习随笔二十一(IM、语音识别、机器人、统计、扫描二维码、条形码)
- SQL Server中内连接和外连接的区别
- Extjs4使用iframe注意事项
- Sublime Text 皮肤插件安装
- MySQL之字符串函数
- C#中Form窗体中读取EXCEL的数据
- Docker基础入门及示例
- String 类的实现(3)引用计数实现String类
- Redis .Net 基本类型使用之南
- sqoop:mysql to hdfs
- iOS 使用Instruments的工具小结
- linux下查看主板内存槽与内存信息
- Linux下清理内存和Cache方法
热门文章
- python 目录下的__init__.py
- C++ HOJ 火车进站
- miller_rabin模板
- Silverlight实用窍门系列:1.Silverlight读取外部XML加载配置---(使用WebClient读取XAP包同目录下的XML文件))【附带实例源码】
- AJAX 用户验证方法
- oracle重命名数据文件
- Transformations
- 单片机和Linux都想学_换个两全的方法学习单片机
- border-collapse
- django上课笔记5-FK关联