LVS-NAT实验
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LVS-NAT实验相关的知识,希望对你有一定的参考价值。
实验环境:
LVS 调度器(BL)作为Web1、Web2 两台Web 服务器池的网关
BL 两块网卡,分别连接内外网
BL 主机(负载调度器):
外网地址:192.168.102.100/24,同时也作为整个群集的VIP
内网地址:192.168.108.113/24
Web1 主机:192.168.108.111/24
Web2 主机:192.168.108.112/24
NFS 主机:192.168.108.113/24
使用轮询(rr)调度算法
一,开启两台web服务器,访问测试
192.168.108.111
192.168.108.222
二,开一台作为BL主机;
外网地址是192.168.102.100
内网地址是192.168.108.113
LVS-NAT部署
(1) 加载ip_vs 模块,安装ipvsadm 工具
[[email protected] ~]# modprobe ip_vs
[[email protected] ~]# yum -y install ipvsadm
(2) 配置负载调度器SNAT 转发规则
[[email protected] ~]# ipvsadm -A -t 192.168.102.100:80 -s rr
[[email protected] ~]# ipvsadm -a -t 192.168.102.100:80 -r 192.168.108.111:80 -m -w 1
[[email protected] ~]# ipvsadm -a -t 192.168.102.100:80 -r 192.168.108.112:80 -m -w 1
[[email protected] ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.102.100:80 rr
-> 192.168.108.111:80 Masq 1 0 0
-> 192.168.108.112:80 Masq 1 0 0
[[email protected] ~]# /etc/init.d/ipvsadm save
ipvsadm: Saving IPVS table to /etc/sysconfig/ipvsadm: [确定]
[[email protected] ~]# chkconfig ipvsadm on
(3)开启路由转发功能
[[email protected] ~]# sed -i ‘/net.ipv4.ip_forward/ s/0/1/‘ /etc/sysctl.conf
[[email protected] ~]# sysctl –p
三,客户机访问,测试rr轮换机制:
四,再开一台虚拟机,作NFS 共享储存部署
(1) 安装nfs-utils、rpcbind 软件包
[[email protected] ~]# rpm -q nfs-utils rpcbind
nfs-utils-1.2.3-75.el6.x86_64
rpcbind-0.2.0-13.el6.x86_64
(2) 设置共享目录,将/opt/www 作为共享目录,要求192.168.108.0/24 网段只读权限访问网页数据(若增加读写速度和安全性,可结合raid5+LVM)
[[email protected] ~]# mkdir /opt/www
[[email protected] ~]# vim /etc/exports
/opt/www 192.168.108.0/24(ro,sync,no_root_squash)
(3) 启动服务并查看共享目录
[[email protected] ~]# /etc/init.d/rpcbind start
[[email protected] ~]# /etc/init.d/nfs start
启动 NFS 服务: [确定]
关掉 NFS 配额: [确定]
启动 NFS mountd: [确定]
启动 NFS 守护进程: [确定]
正在启动 RPC idmapd: [确定]
[[email protected] ~]# showmount -e 192.168.108.114
Export list for 192.168.108.114:
/opt/www 192.168.108.0/24
[[email protected] ~]# chkconfig rpcbind on
[[email protected] ~]# chkconfig nfs on
[[email protected] ~]# echo "<h1>哈哈哈</h1>" > /opt/www/index.html
(4) Web1服务器配置
[[email protected] ~]# yum -y install nfs-utils
[[email protected] ~]# mount 192.168.108.114:/opt/www/ /var/www/html/
[[email protected] ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 ext4 18G 4.5G 12G 28% /
tmpfs tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 ext4 283M 35M 233M 14% /boot
192.168.108.114:/opt/www/
nfs 18G 4.5G 13G 27% /var/www/html
[[email protected] ~]# cp -p /etc/fstab /etc/fstab.bak
[[email protected] ~]# vim /etc/fstab
192.168.108.114:/opt/www/ /var/www/html/ nfs defaults,_netdev 1 2
[[email protected] ~]# umount /var/www/html/
[[email protected] ~]# mount -a
[[email protected] ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 ext4 18G 4.5G 12G 28% /
tmpfs tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 ext4 283M 35M 233M 14% /boot
192.168.108.114:/opt/www/
nfs 18G 4.5G 13G 27% /var/www/html
(5) Web2 服务器配置
同web1
五,客户机访问测试:
BL主机查看:
以上是关于LVS-NAT实验的主要内容,如果未能解决你的问题,请参考以下文章