目录
一、服务器准备
二、操作步骤
1.部署web服务器
2.部署LVS主备调度器
测试
部署NFS共享服务器
一、服务器准备
.准备6台虚拟机,2台做LVS主备调度器,2台做web服务器,1台做存储,1台客户机验证
1.LVS主调度器 (master):192.168.1.12
2.LVS备调度器(backup):192.168.1.133
3.web1:192.168.1.134
4.web2:192.168.1.135
5.存储(nfs):192.168.1.138
6.客户机(cli):192.168.1.139
虚拟ip:192.168.1.222
二、操作步骤
1.部署web服务器
[root@web1 ~] vim /etc/sysctl.conf # 调整web1与web2的ARP参数
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
[root@web1 ~] yum -y install httpd #web1与web2安装 http
[root@web1 ~] echo "skl111" > /var/www/html/index.html # web1与web2分别写一个index.html用于测试(/var/www/html/ )httpd的网站根目录
[root@web1 ~]# cd /etc/sysconfig/network-scripts/
[root@web1 network-scripts] cp ifcfg-lo ifcfg-lo:0 # web1与web2创建虚拟ip
[root@web1 network-scripts] vim ifcfg-lo:0
[root@web1 network-scripts] systemctl restart network
[root@web1 network-scripts] ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.135 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::10ee:1215:db1e:47e5 prefixlen 64 scopeid 0x20<link>
inet6 fe80::d6d9:dbed:4ad1:b012 prefixlen 64 scopeid 0x20<link>
inet6 fe80::b938:12f9:f741:d867 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:52:40:87 txqueuelen 1000 (Ethernet)
RX packets 207440 bytes 24892876 (23.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6970 bytes 583107 (569.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo:0: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 #创建完毕
inet 192.168.1.222 netmask 255.255.255.255
loop txqueuelen 1000 (Local Loopback)
[root@web1 network-scripts] route add -host 192.168.1.222/32 dev lo:0 #web1与web2添加回环路由
[root@web1 network-scripts] systemctl start httpd #启动web服务
2.部署LVS主备调度器
[root@master ~] vim /etc/sysctl1.conf #调整master和backup的ARP参数(一致)
[root@backup ~] vim /etc/sysctl1.conf
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects=0
net.ipv4.conf.ens33.send_redirects = 0
[root@master ~] yum -y install keepalived ipvsadm #master和backup安装keepalived ipvsadm
[root@master ~] vim /etc/sysconfig/ipvsadm-config #配置keepalived master
global_defs {
router_id LVS_DEVEL1
}
vrrp_instance master {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.222 #虚拟IP
}
}
virtual_server 192.168.1.222 { #虚拟IP
delay_loop 6
lb_algo rr
lb_kind DR
#persistence_timeout 50
protocol TCP
real_server 192.168.1.134 { #web1
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.135 80 { #web2
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
[root@backup ~] vim /etc/sysconfig/ipvsadm-config #配置keepalived backup
global_defs {
router_id LVS_DEVEL2
}
vrrp_instance backup {
state BACKUP
interface ens33
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.222
}
}
virtual_server 192.168.1.222 80 {
delay_loop 6
lb_algo rr
lb_kind DR
#persistence_timeout 50
protocol TCP
real_server 192.168.1.134 80 {
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.135 80 {
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
启动master和backup的keepalived与ipvsadm
[root@master ~] systemctl start keepalived
[root@master ~]# touch /etc/sysconfig/ipvsadm
[root@master ~] systemctl start ipvsadm.service
[root@master ~] modprobe ip_vs #master和backup加载ip_vs模块
[root@master ~] ipvsadm -ln #查看lvs节点状态
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.1.222:80 rr
-> 192.168.1.134:80 Route 1 0 0
-> 192.168.1.135:80 Route 1 0 0
测试
[root@master ~]# curl 192.168.1.222
web2
[root@master ~]# curl 192.168.1.222
web1
[root@master ~]# systemctl stop keepalived.service
部署NFS共享服务器
存储配置文件
[root@nfs network-scripts] yum -y install nfs-utils
[root@nfs network-scripts] vim /etc/exports
/data/www/html/ 192.168.1.0/24(rw)
[root@nfs ] mkdir -p /data/www/html
[root@nfs ] echo "web 1 2" >/data/www/html/index.html
[root@nfs ] systemctl start nfs
[root@master ~] mount 192.168.1.138:/data/www/html /var/www/html/
[root@backup ~] mount 192.168.1.138:/data/www/html /var/www/html/