xsw222 发表于 2015-11-19 15:11:30

LVS+keepalived构建高可用负载均衡群集实验纯文本

  LVS+Keepalived高可用负载群集
Balancer 01的设置
1.设置网络环境
# ifconfig eth0
eth0      Link encap:EthernetHWaddr 00:0C:29:BD:E7:65
          inet addr:172.16.10.11Bcast:172.16.10.255Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:febd:e765/64 Scope:Link
          UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:50 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)TX bytes:7516 (7.3 KiB)
          Interrupt:18 Base address:0x2000
  # ifconfig eth1
eth1      Link encap:EthernetHWaddr 00:0C:29:BD:E7:6F
          inet addr:192.168.10.11Bcast:192.168.10.255Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:febd:e76f/64 Scope:Link
          UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
          RX packets:126 errors:0 dropped:0 overruns:0 frame:0
          TX packets:73 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:12173 (11.8 KiB)TX bytes:10660 (10.4 KiB)
          Interrupt:16 Base address:0x2080
2.安装Keepalived所需软件
# ln -s /usr/src/kernels/2.6.32-131.0.15.el6.i686/ /usr/src/linux
# cd /soft/LSS-2/chapter08/
# ls
keepalived-1.2.2.tar.gzrkhunter-1.3.8.tar.gz
# cd keepalived-1.2.2
# ./configure ; make ; make install
3.安装后的调整
# cd
# cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
# mkdir /etc/keepalived
# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
# cp /usr/local/sbin/keepalived /usr/sbin/
# service keepalived start
正在启动 keepalived:                                    [确定]
4.配置VIP脚本
#vi /opt/vip.sh
#!/bin/bash
VIP=192.168.10.19
/sbin/ifconfig eth1:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev eth1:0
echo "1" > /proc/sys/net/ipv4/ip_forward
# chmod +x /opt/vip.sh
# /opt/vip.sh
5.安装ipvsadm命令工具,设置DR模式的负载均衡群集
# mount /dev/cdrom /media/
# cd /media/Packages/
# rpm -ivh ipvsadm-1.25-9.el6.i686.rpm
warning: ipvsadm-1.25-9.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ###########################################
   1:ipvsadm                ###########################################
# ipvsadm -A -t 192.168.10.19:80 -s rr
WARNING: All config files need .conf: /etc/modprobe.d/vmware-tools, it will be ignored in a future release.
# ipvsadm -a -t 192.168.10.19:80 -r 192.168.10.13:80 -g
# ipvsadm -a -t 192.168.10.19:80 -r 192.168.10.14:80 -g
# ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port         Forward Weight ActiveConn InActConn
TCP192.168.10.19:http rr
-> 192.168.10.13:http         Route   1      0          0         
-> 192.168.10.14:http         Route   1      0          0   
6.保存ipvsadm设置到/etc/sysconfig/ipvsadm文件以后,下次启动可以直接执行“service ipvsadm start”命令,不再需要逐条输入命令。
# ipvsadm-save > /etc/sysconfig/ipvsadm
7.配置/etc/keepalived/keepalived.conf主配置文档
# vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
  global_defs {
   notification_email {
jishuweiwang@163.com
   }
   notification_email_from lvs@benet.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL_1
}
  vrrp_instance VI_1 {
    state MASTER
    interface eth1
    virtual_router_id 51
    priority 100
    advert_int 6
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    virtual_ipaddress {
      192.168.10.19
    }
}
virtual_server 192.168.10.19 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    protocol TCP
  real_server 192.168.10.13 80 {
      weight 1
            TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
    }
}
    real_server 192.168.10.14 80 {
      weight 1
            TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
    }
}
8.启动keepalived服务
# service keepalived restart
停止 keepalived:                                          [确定]
正在启动 keepalived:      
……………………………………………………………………………………………………………………
Balancer 02的设置
1.设置网络环境
# ifconfig eth0
eth0      Link encap:EthernetHWaddr 00:0C:29:80:40:63
          inet addr:172.16.10.12Bcast:172.16.10.255Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe80:4063/64 Scope:Link
          UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
          RX packets:1752 errors:0 dropped:0 overruns:0 frame:0
          TX packets:275 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:206538 (201.6 KiB)TX bytes:51374 (50.1 KiB)
          Interrupt:18 Base address:0x2000
  # ifconfig eth1
eth1      Link encap:EthernetHWaddr 00:0C:29:80:40:6D
          inet addr:192.168.10.12Bcast:192.168.10.255Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe80:406d/64 Scope:Link
          UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
          RX packets:2696 errors:0 dropped:0 overruns:0 frame:0
          TX packets:214 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:295776 (288.8 KiB)TX bytes:25420 (24.8 KiB)
          Interrupt:16 Base address:0x2080
2.安装Keepalived所需软件(需要提前将keepalived-1.2.2.tar.gz包上传到/soft/LSS-2/chapter08/)
# ln -s /usr/src/kernels/2.6.32-131.0.15.el6.i686/ /usr/src/linux
# cd /soft/LSS-2/chapter08/
# ls
keepalived-1.2.2.tar.gzrkhunter-1.3.8.tar.gz
# cd keepalived-1.2.2
# ./configure ; make ; make install
3.安装后的调整
# cd
# cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
# mkdir /etc/keepalived
# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
# cp /usr/local/sbin/keepalived /usr/sbin/
# service keepalived start
正在启动 keepalived:                                    [确定]
4.在Balancer01上,传送/opt/vip.sh到Balancer02上的/opt/下
# scp /opt/vip.sh root@192.168.10.12:/opt/
The authenticity of host '192.168.10.12 (192.168.10.12)' can't be established.
RSA key fingerprint is 15:ec:b9:77:4f:53:b4:98:bc:01:c3:a1:32:68:eb:97.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.10.12' (RSA) to the list of known hosts.
root@192.168.10.12's password:
vip.sh                  
5.执行/opt/vip.sh脚本
# /opt/vip.sh
# ifconfig eth1:0
eth1:0    Link encap:EthernetHWaddr 00:0C:29:80:40:6D
          inet addr:192.168.10.19Bcast:192.168.10.19Mask:255.255.255.255
          UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
          Interrupt:16 Base address:0x2080
6.安装ipvsadm-1.24-8.1.i386.rpm
# mount /dev/cdrom /media/
mount: block device /dev/sr0 is write-protected, mounting read-only
# cd /media/Packages/
# rpm -ivh ipvsadm-1.25-9.el6.i686.rpm
warning: ipvsadm-1.25-9.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ###########################################
   1:ipvsadm                ###########################################
7.配置/etc/keepalived/keepalived.conf主配置文档
# vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
  global_defs {
   notification_email {
jishuweiwang@163.com
   }
   notification_email_from lvs@benet.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL_2
}
  vrrp_instance VI_1 {
    state BACKUP
    interface eth1
    virtual_router_id 51
    priority 80
    advert_int 6
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    virtual_ipaddress {
      192.168.10.19
    }
}
virtual_server 192.168.10.19 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    protocol TCP
  real_server 192.168.10.13 80 {
      weight 1
            TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
      }
    }
    real_server 192.168.10.14 80 {
      weight 1
            TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
      }
}
  
  # /opt/vip.sh
SIOCSIFFLAGS: 无法指定被请求的地址
SIOCADDRT: 没有那个设备
  
  
  
  
  
  
  
  LVS+Keepalived高可用负载群集
Balancer 01的设置
1.设置网络环境
# ifconfig eth0
eth0      Link encap:EthernetHWaddr 00:0C:29:BD:E7:65
          inet addr:172.16.10.11Bcast:172.16.10.255Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:febd:e765/64 Scope:Link
          UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:50 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)TX bytes:7516 (7.3 KiB)
          Interrupt:18 Base address:0x2000
  # ifconfig eth1
eth1      Link encap:EthernetHWaddr 00:0C:29:BD:E7:6F
          inet addr:192.168.10.11Bcast:192.168.10.255Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:febd:e76f/64 Scope:Link
          UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
          RX packets:126 errors:0 dropped:0 overruns:0 frame:0
          TX packets:73 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:12173 (11.8 KiB)TX bytes:10660 (10.4 KiB)
          Interrupt:16 Base address:0x2080
2.安装Keepalived所需软件
# ln -s /usr/src/kernels/2.6.32-131.0.15.el6.i686/ /usr/src/linux
# cd /soft/LSS-2/chapter08/
# ls
keepalived-1.2.2.tar.gzrkhunter-1.3.8.tar.gz
# cd keepalived-1.2.2
# ./configure ; make ; make install
3.安装后的调整
# cd
# cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
# mkdir /etc/keepalived
# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
# cp /usr/local/sbin/keepalived /usr/sbin/
# service keepalived start
正在启动 keepalived:                                    [确定]
4.配置VIP脚本
#vi /opt/vip.sh
#!/bin/bash
VIP=192.168.10.19
/sbin/ifconfig eth1:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev eth1:0
echo "1" > /proc/sys/net/ipv4/ip_forward
# chmod +x /opt/vip.sh
# /opt/vip.sh
5.安装ipvsadm命令工具,设置DR模式的负载均衡群集
# mount /dev/cdrom /media/
# cd /media/Packages/
# rpm -ivh ipvsadm-1.25-9.el6.i686.rpm
warning: ipvsadm-1.25-9.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ###########################################
   1:ipvsadm                ###########################################
# ipvsadm -A -t 192.168.10.19:80 -s rr
WARNING: All config files need .conf: /etc/modprobe.d/vmware-tools, it will be ignored in a future release.
# ipvsadm -a -t 192.168.10.19:80 -r 192.168.10.13:80 -g
# ipvsadm -a -t 192.168.10.19:80 -r 192.168.10.14:80 -g
# ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port         Forward Weight ActiveConn InActConn
TCP192.168.10.19:http rr
-> 192.168.10.13:http         Route   1      0          0         
-> 192.168.10.14:http         Route   1      0          0   
6.保存ipvsadm设置到/etc/sysconfig/ipvsadm文件以后,下次启动可以直接执行“service ipvsadm start”命令,不再需要逐条输入命令。
# ipvsadm-save > /etc/sysconfig/ipvsadm
7.配置/etc/keepalived/keepalived.conf主配置文档
# vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
  global_defs {
   notification_email {
jishuweiwang@163.com
   }
   notification_email_from lvs@benet.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL_1
}
  vrrp_instance VI_1 {
    state MASTER
    interface eth1
    virtual_router_id 51
    priority 100
    advert_int 6
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    virtual_ipaddress {
      192.168.10.19
    }
}
virtual_server 192.168.10.19 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    protocol TCP
  real_server 192.168.10.13 80 {
      weight 1
            TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
    }
}
    real_server 192.168.10.14 80 {
      weight 1
            TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
    }
}
8.启动keepalived服务
# service keepalived restart
停止 keepalived:                                          [确定]
正在启动 keepalived:      
……………………………………………………………………………………………………………………
Balancer 02的设置
1.设置网络环境
# ifconfig eth0
eth0      Link encap:EthernetHWaddr 00:0C:29:80:40:63
          inet addr:172.16.10.12Bcast:172.16.10.255Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe80:4063/64 Scope:Link
          UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
          RX packets:1752 errors:0 dropped:0 overruns:0 frame:0
          TX packets:275 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:206538 (201.6 KiB)TX bytes:51374 (50.1 KiB)
          Interrupt:18 Base address:0x2000
  # ifconfig eth1
eth1      Link encap:EthernetHWaddr 00:0C:29:80:40:6D
          inet addr:192.168.10.12Bcast:192.168.10.255Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe80:406d/64 Scope:Link
          UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
          RX packets:2696 errors:0 dropped:0 overruns:0 frame:0
          TX packets:214 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:295776 (288.8 KiB)TX bytes:25420 (24.8 KiB)
          Interrupt:16 Base address:0x2080
2.安装Keepalived所需软件(需要提前将keepalived-1.2.2.tar.gz包上传到/soft/LSS-2/chapter08/)
# ln -s /usr/src/kernels/2.6.32-131.0.15.el6.i686/ /usr/src/linux
# cd /soft/LSS-2/chapter08/
# ls
keepalived-1.2.2.tar.gzrkhunter-1.3.8.tar.gz
# cd keepalived-1.2.2
# ./configure ; make ; make install
3.安装后的调整
# cd
# cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
# mkdir /etc/keepalived
# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
# cp /usr/local/sbin/keepalived /usr/sbin/
# service keepalived start
正在启动 keepalived:                                    [确定]
4.在Balancer01上,传送/opt/vip.sh到Balancer02上的/opt/下
# scp /opt/vip.sh root@192.168.10.12:/opt/
The authenticity of host '192.168.10.12 (192.168.10.12)' can't be established.
RSA key fingerprint is 15:ec:b9:77:4f:53:b4:98:bc:01:c3:a1:32:68:eb:97.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.10.12' (RSA) to the list of known hosts.
root@192.168.10.12's password:
vip.sh                  
5.执行/opt/vip.sh脚本
# /opt/vip.sh
# ifconfig eth1:0
eth1:0    Link encap:EthernetHWaddr 00:0C:29:80:40:6D
          inet addr:192.168.10.19Bcast:192.168.10.19Mask:255.255.255.255
          UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
          Interrupt:16 Base address:0x2080
6.安装ipvsadm-1.24-8.1.i386.rpm
# mount /dev/cdrom /media/
mount: block device /dev/sr0 is write-protected, mounting read-only
# cd /media/Packages/
# rpm -ivh ipvsadm-1.25-9.el6.i686.rpm
warning: ipvsadm-1.25-9.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ###########################################
   1:ipvsadm                ###########################################
7.配置/etc/keepalived/keepalived.conf主配置文档
# vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
  global_defs {
   notification_email {
jishuweiwang@163.com
   }
   notification_email_from lvs@benet.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL_2
}
  vrrp_instance VI_1 {
    state BACKUP
    interface eth1
    virtual_router_id 51
    priority 80
    advert_int 6
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    virtual_ipaddress {
      192.168.10.19
    }
}
virtual_server 192.168.10.19 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    protocol TCP
  real_server 192.168.10.13 80 {
      weight 1
            TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
      }
    }
    real_server 192.168.10.14 80 {
      weight 1
            TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
      }
}
  
  # /opt/vip.sh
SIOCSIFFLAGS: 无法指定被请求的地址
SIOCADDRT: 没有那个设备
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  本文出自 “技术成就未来” 博客,请务必保留此出处http://jishuweiwang.blog.iyunv.com/6977090/1208371
             版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: LVS+keepalived构建高可用负载均衡群集实验纯文本