1、实现LVS+keepalived高可用集群
2、安装配置kvm虚拟机,并创建虚拟机
-----------------------------------------------------------------------------------------------------------------
1、实现LVS+keepalived高可用集群
1.1 环境
Keepalived主节点、LVS 1为同一主机 #10.0.0.7
Keepalived从节点、LVS 2为同一主机 #10.0.0.100
Real_server1 #10.0.0.27
Real_server2 #10.0.0.37
VIP #10.0.0.248
1.2 Keepalived主节点配置
global_defs { ... vrrp_iptables } vrrp_instance test_web { state MASTER interface eth0 virtual_router_id 41 priority 100 advert_int 1 vrrp_strict authentication { auth_type PASS auth_pass 1q2w3e4r } virtual_ipaddress { 10.0.0.248/24 dev eth0 label eth0:0 } } virtual_server 10.0.0.248 80 { delay_loop 3 lb_algo rr lb_kind DR #persistence_timeout 120 protocol TCP #sorry_server 192.168.200.200 1358 real_server 10.0.0.27 80 { weight 1 #notify_up "/etc/keepalived/notify.sh rsup" #notify_down "/etc/keepalived/notify.sh rsup"HTTP_GET { url { path /test.html status_code 200 } #connect_ip 10.0.0.127 #connect_port 8080 #bindto 10.0.0.17 #bind_port 12345 connect_timeout 5 nb_get_retry 3 delay_before_retry 3 } } real_server 10.0.0.37 80 { weight 1 TCP_CHECK { connect_ip 10.0.0.37 connect_port 80 #bindto 10.0.0.17 #bind_port 12345 connect_timeout 3 delay_before_retry 3 } } }
#启动服务
# systemctl enable --now keepalived
1.3 Keepalived从节点配置
global_defs { ... vrrp_iptables } vrrp_instance test_web { state BACKUP interface eth0 virtual_router_id 41 priority 80 advert_int 1 vrrp_strict authentication { auth_type PASS auth_pass 1q2w3e4r } virtual_ipaddress { 10.0.0.248/24 dev eth0 label eth0:0 } } virtual_server 10.0.0.248 80 { delay_loop 3 lb_algo rr lb_kind DR #persistence_timeout 120 protocol TCP #sorry_server 192.168.200.200 1358 real_server 10.0.0.27 80 { weight 1 #notify_up "/etc/keepalived/notify.sh rsup" #notify_down "/etc/keepalived/notify.sh rsup"HTTP_GET { url { path /test.html status_code 200 } #connect_ip 10.0.0.127 #connect_port 8080 #bindto 10.0.0.17 #bind_port 12345 connect_timeout 5 nb_get_retry 3 delay_before_retry 3 } } real_server 10.0.0.37 80 { weight 1 TCP_CHECK { connect_ip 10.0.0.37 connect_port 80 #bindto 10.0.0.17 #bind_port 12345 connect_timeout 3 delay_before_retry 3 } } }
#启动服务
# systemctl enable --now keepalived
1.4 Real_server1、2配置
#yum安装nginx # yum -y install nginx #准备测试资源 # hostname -I > /usr/share/nginx/html/index.html #配置VIP # ip addr add dev lo label lo:0 10.0.0.248/32 #更改内核参数 # vi /etc/sysctl.conf net.ipv4.conf.all.arp_ignore = 1 net.ipv4.conf.lo.arp_ignore = 1 net.ipv4.conf.all.arp_announce = 2 net.ipv4.conf.lo.arp_announce = 2 # sysctl -p
#启动服务
# systemctl enable --now nginx
1.5 客户端测试
# tail -n1 /etc/hosts 10.0.0.248 www.testou.com # while :; do curl http://www.testou.com;sleep 0.5;done 10.0.0.27 10.0.0.37 10.0.0.27 10.0.0.37
2、安装配置kvm虚拟机,并创建虚拟机
2.1
#创建桥接网卡 # nmcli connection add ifname br0 con-name br0 type bridge ipv4.method manual ipv4.addresses 10.0.0.7/24 ipv4.gateway 10.0.0.2 ipv4.dns 223.5.5.5,180.76.76.76 ipv4.ignore-auto-dns yes # nmcli connection add ifname eth0 con-name br0-eth0 type bridge-slave master br0 # nmcli connection delete eth0 && ip link set br0 up #安装KVM工具包 # yum -y install qemu-kvm qemu-kvm-tools libvirt libvirt-client virt-manager virt-install # systemctl enable --now libvirtd #创建磁盘 # qemu-img create -f qcow2 /var/lib/libvirt/images/Centos7.9.qcow2 10G #创建桥接虚拟机 # virt-install --virt-type kvm \ --name centos7 \ --vcpus 1,maxvcpus=10 --memory 1024,maxmemory=4096 \ --disk path=/var/lib/libvirt/images/Centos7.9.qcow2 \ --network bridge=br0 \ --graphics vnc,listen=0.0.0.0 \ --noautoconsole \ --autostart \ --cdrom=/usr/local/src/CentOS-7-x86_64-Everything-2009.iso #打开virt-manager安装 # virt-manager #查看所有虚拟机 # virsh list --all #不加--all只显示开机的虚拟机 #开启虚拟机 # virsh start centos7 #关闭虚拟机 # virsh shutdown centos7