1.在虚拟机中安装centos系统
2.改为默认命令行模式(可选)
systemctl set-default multi-user.target
3.激活网卡(可选)
cd /etc/sysconfig/network-scripts/
在这个文件夹下 有一个以ifcfg-eno为开头的文件,如ifcfg-eno32
编辑这个文件 vi ifcg-eno32
ONBOOT="yes"
保存退出
重启网络 service network restart
用ping命令 查看网络是否连通
4.查看是否有jdk环境,java -version,如果没有,安装jdk
5.关闭防火墙
systemctl stop firewalld.service
禁止开机启动
systemctl disable firewalld.service
查看防火墙状态
firewall-cmd --state
关闭状态应显示:not running
6.安装tomcat http://tomcat.apache.org/download-80.cgi
7.将该虚拟机 完整克隆三份。
四台虚拟机 ip依次 记为:
192.168.72.134(负载调度器DS1)
192.168.72.135(负载调度器 备用 DS2)
192.168.72.136(web服务器1 RS1)
192.168.72.137(web服务器2 RS2)
8.在DS1和DS2 上安装lvs 和keepalived
yum -y install ipvsadm
yum -y install keepalived
9.编辑主从服务器的 keepalived.conf 文件(192.168.72.110为虚拟ip)
vi /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state MASTER #备用服务器上为 BACKUP
interface eno32
virtual_router_id 51
priority 100 #备用服务器上为90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.72.110
}
}
virtual_server 192.168.72.110 8080 {
delay_loop 6 #(每隔10秒查询realserver状态)
lb_algo rr #(lvs 算法)
lb_kind DR #(Direct Route)
persistence_timeout 60 #(同一IP的连接60秒内被分配到同一台realserver)
protocol TCP #(用TCP协议检查realserver状态)
real_server 192.168.72.136 8080 {
weight 100 #(权重)
TCP_CHECK {
connect_timeout 10 #(10秒无响应超时)
nb_get_retry 3
delay_before_retry 3
connect_port 8080
}
}
real_server 192.168.72.137 8080 {
weight 100
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 8080
}
}
}
10.启动keepalived.service
systemctl start keepavlied.service
11.启动两台rs的tomcat 并修改lvs_dr_rs.sh
vim /usr.local.sbin.lvs_dr_rs.sh
#! /bin/bash
vip=192.168.72.110
ifconfig lo:0 down
ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip lo:0
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce