vmcentos[0]=CentOS7X64-keep01
vmcentos[1]=CentOS7X64-keep02
parentPath="/media/WNTime/本地磁盘/VirtualMachine.Spaces"
vmsour="$parentPath/CentOS7X64.Core/CentOS7X64.Core.vmx"
for item in ${vmcentos[*]};
do
vmdest="$parentPath/$item/$item.vmx"
echo "Clone: $vmdest"
vmrun -T ws clone $vmsour $vmdest full -cloneName=$item
sleep 5s;
done;
parentPath="/media/WNTime/本地磁盘/VirtualMachine.Spaces"
for item in ${vmcentos[*]};
do
vmdest="$parentPath/$item/$item.vmx"
vmshot=`date +%Y%m%d`
echo "Snapshot: $vmdest"
vmrun -T ws snapshot $vmdest $vmshot
vmrun -T ws listSnapshots $vmdest
sleep 5s;
done;
parentPath="/media/WNTime/本地磁盘/VirtualMachine.Spaces"
for item in ${vmcentos[*]};
do
vmdest="$parentPath/$item/$item.vmx"
vmshot=`date +%Y%m%d%H%M`
echo "Start: $vmdest"
vmrun -T ws start $vmdest
sleep 5s;
read -p "按任意键继续..."
done;
parentPath="/media/WNTime/本地磁盘/VirtualMachine.Spaces"
for item in ${vmcentos[*]};
do
vmdest="$parentPath/$item/$item.vmx"
vmshot=`date +%Y%m%d%H%M`
echo "Suspend: $vmdest"
vmrun -T ws suspend $vmdest
sleep 5s;
done;
parentPath="/media/WNTime/本地磁盘/VirtualMachine.Spaces"
vmshot=`date +%Y%m%d`
for item in ${vmcentos[*]};
do
vmdest="$parentPath/$item/$item.vmx"
vmshot=`date +%Y%m%d`
echo "Revert: $vmdest"
vmrun -T ws revertToSnapshot $vmdest $vmshot
sleep 5s;
done;
parentPath="/media/WNTime/本地磁盘/VirtualMachine.Spaces"
for item in ${vmcentos[*]};
do
vmdest="$parentPath/$item/$item.vmx"
vmshot=`date +%Y%m%d%H%M`
echo "Stop: $vmdest"
vmrun -T ws stop $vmdest
sleep 5s;
done;
Keepalived | Keepalived | |
---|---|---|
网段 | keep-101 | keep-102 |
192.168.86.0(NAT模式) | 192.168.88.101 | 192.168.88.102 |
VIP1 | 192.168.86.251(MASTER) | 192.168.86.251(BACKUP) |
VIP2 | 192.168.86.252(BACKUP) | 192.168.86.252(MASTER) |
注意:一定要关闭防火墙,或是添加相关端口!
## 101
# vim /etc/sysconfig/network-script/ifcfg-en33
sudo hostnamectl set-hostname keep-101
sudo sed -i 's/192.168.86.6/192.168.86.101/g' /etc/sysconfig/network-scripts/ifcfg-ens33
sudo systemctl restart network
## 102
# vim /etc/sysconfig/network-script/ifcfg-en33
sudo hostnamectl set-hostname keep-102
sudo sed -i 's/192.168.86.6/192.168.86.102/g' /etc/sysconfig/network-scripts/ifcfg-ens33
sudo systemctl restart network
keep-101, keep-102
sudo yum makecache
sudo yum install -y wget
sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sudo yum makecache
wget https://www.keepalived.org/software/keepalived-2.1.5.tar.gz --no-check-certificate
sudo yum install -y libnl libnl-devel libnl3-devel net-snmp-devel libnfnetlink-devel gcc make openssl-devel popt-devel curl
tar -xzf keepalived-2.1.5.tar.gz
cd keepalived-2.1.5/
./configure --prefix=/usr/local/keepalived --sysconf=/etc
make && sudo make install
# 测试安装
/usr/local/keepalived/sbin/keepalived -v
安装成功
ls -l /etc/keepalived/
keep-101, keep-102
# ~/keepalived-2.1.5 是解压出来的文件夹,根据你的解压路径来,不是安装目录
sudo cp ~/keepalived-2.1.5/keepalived/etc/init.d/keepalived /etc/init.d/
sudo cp ~/keepalived-2.1.5/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
sudo systemctl daemon-reload
sudo systemctl enable keepalived
sudo systemctl status keepalived
keep-101
global_defs {
router_id keep_vip1
}
vrrp_instance VIP_251 {
# 主用机设置为 MASTER
state MASTER
interface ens33
virtual_router_id 251
priority 100
advert_int 1
nopreempt
#preempt_delay 300
authentication {
auth_type PASS
auth_pass 12345678
}
virtual_ipaddress {
192.168.86.251
}
}
vrrp_instance VIP_252{
# 主用机设置为 BACKUP
state BACKUP
interface ens33
virtual_router_id 252
priority 90
advert_int 1
nopreempt
#preempt_delay 300
authentication {
auth_type PASS
auth_pass 12345678
}
virtual_ipaddress {
192.168.86.252
}
}
/usr/local/keepalived/sbin/keepalived -t
sudo systemctl restart keepalived
sudo systemctl status keepalived
keep-102
global_defs {
router_id keep_vip2
}
vrrp_instance VIP_251 {
# 主用机设置为 BACKUP
state BACKUP
interface ens33
virtual_router_id 251
priority 90
advert_int 1
nopreempt
#preempt_delay 300
authentication {
auth_type PASS
auth_pass 12345678
}
virtual_ipaddress {
192.168.86.251
}
}
vrrp_instance VIP_252{
# 主用机设置为 MASTER
state MASTER
interface ens33
virtual_router_id 252
priority 100
advert_int 1
nopreempt
preempt_delay 300
authentication {
auth_type PASS
auth_pass 12345678
}
virtual_ipaddress {
192.168.86.252
}
}
/usr/local/keepalived/sbin/keepalived -t
sudo systemctl restart keepalived
sudo systemctl status keepalived
keep-101, keep-102
sudo yum install -y httpd
sudo systemctl stop firewalld
echo " sed -i 's/123/$HOSTNAME/' /usr/share/httpd/noindex/index.html" | sudo bash -
sudo systemctl restart httpd
# 测试服务是否可以访问
while true; do curl http://192.168.86.251 -s |grep keep && date; sleep 1s; done;
while true; do curl http://192.168.86.252 -s |grep keep && date; sleep 1s; done;