set vmcentos[0]=CentOS7X64-Client
set vmcentos[1]=CentOS7X64-Gateway
set vmcentos[2]=CentOS7X64-LVS101
set vmcentos[3]=CentOS7X64-RS201
set vmcentos[4]=CentOS7X64-RS202
set vmsour="d:\VirtualMachine.Spaces\CentOS7X64.Core\CentOS7X64.Core.vmx"
:: vmname注意不能用引号,否则被作为字符串中字符处理
set vmname=%vmcentos[0]%
set vmdest="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun.exe -T ws clone %vmsour% %vmdest% full -cloneName=%vmname%
set vmname=%vmcentos[1]%
set vmdest="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun.exe -T ws clone %vmsour% %vmdest% full -cloneName=%vmname%
set vmname=%vmcentos[2]%
set vmdest="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun.exe -T ws clone %vmsour% %vmdest% full -cloneName=%vmname%
set vmname=%vmcentos[3]%
set vmdest="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun.exe -T ws clone %vmsour% %vmdest% full -cloneName=%vmname%
set vmname=%vmcentos[4]%
set vmdest="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun.exe -T ws clone %vmsour% %vmdest% full -cloneName=%vmname%
:: vmname注意不能用引号,否则被作为字符串中字符处理
set vmname=%vmcentos[0]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
set vmshot=20220128
vmrun.exe -T ws snapshot %vmpath% %vmshot%
vmrun.exe -T ws listSnapshots %vmpath%
set vmname=%vmcentos[1]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
set vmshot=20220128
vmrun.exe -T ws snapshot %vmpath% %vmshot%
vmrun.exe -T ws listSnapshots %vmpath%
set vmname=%vmcentos[2]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
set vmshot=20220128
vmrun.exe -T ws snapshot %vmpath% %vmshot%
vmrun.exe -T ws listSnapshots %vmpath%
set vmname=%vmcentos[3]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
set vmshot=20220128
vmrun.exe -T ws snapshot %vmpath% %vmshot%
vmrun.exe -T ws listSnapshots %vmpath%
set vmname=%vmcentos[4]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
set vmshot=20220128
vmrun.exe -T ws snapshot %vmpath% %vmshot%
vmrun.exe -T ws listSnapshots %vmpath%
:: vmname注意不能用引号,否则被作为字符串中字符处理
set vmname=%vmcentos[0]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun -T ws start %vmpath%
set vmname=%vmcentos[1]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun -T ws start %vmpath%
set vmname=%vmcentos[2]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun -T ws start %vmpath%
set vmname=%vmcentos[3]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun -T ws start %vmpath%
set vmname=%vmcentos[4]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun -T ws start %vmpath%
:: vmname注意不能用引号,否则被作为字符串中字符处理
set vmname=%vmcentos[0]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun -T ws suspend %vmpath%
set vmname=%vmcentos[1]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun -T ws suspend %vmpath%
set vmname=%vmcentos[2]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun -T ws suspend %vmpath%
set vmname=%vmcentos[3]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun -T ws suspend %vmpath%
set vmname=%vmcentos[4]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun -T ws suspend %vmpath%
:: vmname注意不能用引号,否则被作为字符串中字符处理
set vmname=%vmcentos[0]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
set vmshot=20220128
vmrun.exe -T ws revertToSnapshot %vmpath% %vmshot%
set vmname=%vmcentos[1]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
set vmshot=20220128
vmrun.exe -T ws revertToSnapshot %vmpath% %vmshot%
set vmname=%vmcentos[2]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
set vmshot=20220128
vmrun.exe -T ws revertToSnapshot %vmpath% %vmshot%
set vmname=%vmcentos[3]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
set vmshot=20220128
vmrun.exe -T ws revertToSnapshot %vmpath% %vmshot%
set vmname=%vmcentos[4]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
set vmshot=20220128
vmrun.exe -T ws revertToSnapshot %vmpath% %vmshot%
:: vmname注意不能用引号,否则被作为字符串中字符处理
set vmname=%vmcentos[0]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun -T ws stop %vmpath%
set vmname=%vmcentos[1]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun -T ws stop %vmpath%
set vmname=%vmcentos[2]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun -T ws stop %vmpath%
set vmname=%vmcentos[3]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun -T ws stop %vmpath%
set vmname=%vmcentos[4]%
set vmpath="d:\VirtualMachine.Spaces\%vmname%\%vmname%.vmx"
vmrun -T ws stop %vmpath%
客户端 | GW | LVS | RS | |
---|---|---|---|---|
网段 | CentOS7X64-Client | CentOS7X64-Gateway | CentOS7X64-LVS101 | CentOS7X64-RS201 CentOS7X64-RS202 |
133.15.6.0/24 (NAT模式) | 133.15.6.199 GW: 133.15.6.200 | 133.15.6.200 | ||
199.31.81.0/24 (仅主机模式) | 199.31.81.200 | 199.31.81.101 GW: 199.31.81.200 | 199.31.81.201 199.31.81.202 GW: 199.31.81.200 | |
lo网卡 | 199.31.81.100 | 199.31.81.100 199.31.81.100 |
注意:一定要关闭防火墙,或是添加相关端口!
# 使用模板的ip(133.15.6.81)登录, 随机配置相关信息
ssh root@133.15.6.81
# CLI-199
hostnamectl set-hostname cli-199
cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33.bak
cat /etc/sysconfig/network-scripts/ifcfg-ens33
sed -i 's/IPADDR=133.15.6.81/IPADDR=133.15.6.199/g' /etc/sysconfig/network-scripts/ifcfg-ens33
sed -i 's/^GATEWAY=133.15.6.1/GATEWAY=133.15.6.200/g' /etc/sysconfig/network-scripts/ifcfg-ens33
systemctl restart network
# GW200
hostnamectl set-hostname gw-200
cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33.bak
cat /etc/sysconfig/network-scripts/ifcfg-ens33
sed -i 's/IPADDR=133.15.6.81/IPADDR=133.15.6.200/g' /etc/sysconfig/network-scripts/ifcfg-ens33
sed -i 's/^GATEWAY=133.15.6.1//g' /etc/sysconfig/network-scripts/ifcfg-ens33
cp /etc/sysconfig/network-scripts/ifcfg-ens33.bak /etc/sysconfig/network-scripts/ifcfg-ens38
sed -i 's/ens33/ens38/g' /etc/sysconfig/network-scripts/ifcfg-ens38
sed -i 's/IPADDR=133.15.6.81/IPADDR=199.31.81.200/g' /etc/sysconfig/network-scripts/ifcfg-ens38
sed -i 's/^GATEWAY=133.15.6.1//g' /etc/sysconfig/network-scripts/ifcfg-ens38
systemctl restart network
# LVS101
hostnamectl set-hostname LVS-101
cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33.bak
cat /etc/sysconfig/network-scripts/ifcfg-ens33
sed -i 's/IPADDR=133.15.6.81/IPADDR=199.31.81.101/g' /etc/sysconfig/network-scripts/ifcfg-ens33
sed -i 's/^GATEWAY=133.15.6.1/GATEWAY=133.15.6.200/g' /etc/sysconfig/network-scripts/ifcfg-ens33
systemctl restart network
# RS201
hostnamectl set-hostname RS-201
cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33.bak
cat /etc/sysconfig/network-scripts/ifcfg-ens33
sed -i 's/IPADDR=133.15.6.81/IPADDR=199.31.81.201/g' /etc/sysconfig/network-scripts/ifcfg-ens33
sed -i 's/^GATEWAY=133.15.6.1/GATEWAY=199.31.81.200/g' /etc/sysconfig/network-scripts/ifcfg-ens33
systemctl restart network
# RS202
hostnamectl set-hostname RS-202
cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33.bak
cat /etc/sysconfig/network-scripts/ifcfg-ens33
sed -i 's/IPADDR=133.15.6.81/IPADDR=199.31.81.202/g' /etc/sysconfig/network-scripts/ifcfg-ens33
sed -i 's/^GATEWAY=133.15.6.1/GATEWAY=199.31.81.200/g' /etc/sysconfig/network-scripts/ifcfg-ens33
systemctl restart network
注意:网络配置好了一定要移除附加的桥接网络,否则网络route出现问题,无法访问
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
systemctl disable firewalld
systemctl stop firewalld
# 确认路由
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.0.1 0.0.0.0 UG 101 0 0 ens37
0.0.0.0 133.15.6.200 0.0.0.0 UG 102 0 0 ens33
133.15.6.0 0.0.0.0 255.255.255.0 U 102 0 0 ens33
192.168.0.0 0.0.0.0 255.255.255.0 U 101 0 0 ens37
配置路由
# 开启net.ipv4.ip_forward
echo net.ipv4.ip_forward=1 >> /etc/sysctl.conf
# 加载并生效
sysctl -p
注意:不能配置网关为自身,否则转发出现问题
配置ipvsadm
yum install ipvsadm -y
#增加集群
ipvsadm -A -t 199.31.81.100:80 -s rr
#增加RS服务器
ipvsadm -a -t 199.31.81.100:80 -r 199.31.81.201 -g
ipvsadm -a -t 199.31.81.100:80 -r 199.31.81.202 -g
ipvsadm -Ln
# 保存规则
ipvsadm -S -n > /etc/sysconfig/ipvsadm
sudo systemctl enable ipvsadm
sudo systemctl start ipvsadm
配置lo网卡
cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-lo.bak
echo '' >> /etc/sysconfig/network-scripts/ifcfg-lo
echo IPADDR1=199.31.81.100 >> /etc/sysconfig/network-scripts/ifcfg-lo
echo NETMASK1=255.255.255.255 >> /etc/sysconfig/network-scripts/ifcfg-lo
echo PREFIX1=32 >> /etc/sysconfig/network-scripts/ifcfg-lo
systemctl restart network
# 临时配置lo网卡为vip 199.31.81.100
ifconfig lo:0 199.31.81.100/32 # 注意这里掩码只能是32/0, 否则转发有问题
配置httpd服务
yum install -y httpd
echo 199.31.81.201 RS201 > /var/www/html/index.html
systemctl start httpd
systemctl enable httpd
curl 199.31.81.201
# 移除附加外网适配器,ens33切换到仅主机模式
配置lo网卡
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-lo.bak
echo '' >> /etc/sysconfig/network-scripts/ifcfg-lo
echo IPADDR1=199.31.81.100 >> /etc/sysconfig/network-scripts/ifcfg-lo
echo NETMASK1=255.255.255.255 >> /etc/sysconfig/network-scripts/ifcfg-lo
echo PREFIX1=32 >> /etc/sysconfig/network-scripts/ifcfg-lo
systemctl restart network
# 临时配置lo网卡为vip 199.31.81.100
ifconfig lo:0 199.31.81.100/32 # 注意这里掩码只能是32/0, 否则转发有问题
配置httpd服务
yum install -y httpd
echo 199.31.81.202 RS202 > /var/www/html/index.html
systemctl start httpd
systemctl enable httpd
curl 199.31.81.202
# 移除附加外网适配器,ens33切换到仅主机模式
配置lo网卡
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-lo.bak
echo '' >> /etc/sysconfig/network-scripts/ifcfg-lo
echo IPADDR1=199.31.81.100 >> /etc/sysconfig/network-scripts/ifcfg-lo
echo NETMASK1=255.255.255.255 >> /etc/sysconfig/network-scripts/ifcfg-lo
echo PREFIX1=32 >> /etc/sysconfig/network-scripts/ifcfg-lo
systemctl restart network
# 临时配置lo网卡为vip 199.31.81.100
ifconfig lo:0 199.31.81.100/32 # 注意这里掩码只能是32/0, 否则转发有问题
# 查看规则
cat /proc/net/ip_vs
# 查看连接
cat /proc/net/ip_vs_conn
# 查看当前规则
ipvsadm-save -n 或 sudo ipvsadm -S -n
# 保存规则
sudo ipvsadm -S -n > ipvsadm & sudo mv ipvsadm /etc/sysconfig/
# 清理规则
sudo ipvsadm -C
# 重载规则
sudo ipvsadm -R < /etc/sysconfig/ipvsadm
# 查询ipvsadm相关信息
rpm -ql ipvsadm
# 配置开机启动, 会清除/etc/sysconfig/ipvsadm 的内容,测试不通过
sudo systemctl enable ipvsadm
sudo systemctl start ipvsadm