786yr 发表于 2014-7-22 09:08:02

Redhat5.8 64位LVS实例环境讲解【一】

一、服务器环境1、拓扑图
OS:Redhat 5.864位系统LVS-Master : 192.168.19.60LVS-Backup : 192.168.19.61LVS-VIP : 192.168.19.65Realserver-1 : 192.168.19.62   (Apache)Realserver-2 : 192.168.19.63   (Nginx)Realserver-2 : 192.168.19.64   (IIS)2、安装LVS依赖软件?

1
# yum install -y gcc gcc-c++ make openssl-devel kernel-devel




注:系统采用最少化方法安装所有服务器关闭Selinux?

1
2
3
4
5
6
7
8
9
10
11
# vim /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted





把SELINUX=disabled保存,然后重启服务器即可。二、安装ipvsadm1、建立编译时必须的一个软链接?

1
# ln -s /usr/src/kernels/2.6.18-308.el5-x86_64/ /usr/src/linux




(这里如果找不到以上内核目录,是因为kernerl-devel没有装,先去安装上就有了)?

1
# ll /usr/src/linux







2、下载 ipvsadm?

1
# wget http://www.linuxvirtualserver.or ... ipvsadm-1.24.tar.gz






3、解压缩?

1
2
3
# tar -zxvf ipvsadm-1.24.tar.gz

# cd ipvsadm-1.24




4、编译安装?

1
# make && make install




5、确认安装成功?

1
# whereis ipvsadm





?

1
# ipvsadm --version






三、安装keepalived1、下载keepalived?

1
# wget http://www.keepalived.org/software/keepalived-1.2.2.tar.gz






2、解压keepalived
?

1
2
3
# tar -zxvf keepalived-1.2.2.tar.gz
# cd keepalived-1.2.2
# ./configure







(注意这个步骤要看到以上字样才是正常的)
3、安装?

1
# make && make install




如果报错,如图所示这样
注意:把#include linux/types.h /* For __beXX types in userland */移到#include sys/types.h 这行的下面再编译就可以通过了。(这个可能是keepalived版本问题)# vim keepalived/libipvs-2.6/ip_vs.h


4. 配置先看下有没有文件
?

1
2
3
4
5
6
7
8
9
10
11
# 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/

# chkconfigkeepalived on




# service keepalived restart

查看keepalived进程在不在
5、从 keepalived跟主keepalived服务器同样的安装方法,唯一不同的就是keepalived.conf配置文件不同。
四、keepalived.conf配置文件解释
1、keepalived.conf主配置文件内容
?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
! Configuration File for keepalived

global_defs {
   notification_email {
         790028862@qq.com #表示发送通知邮件时邮件源地址是谁
   }
   notification_email_from 790028862@qq.com
   smtp_server 127.0.0.1 #表示发送email时使用的smtp服务器地址,这里可以用本地的sendmail来实现
# smtp_connect_timeout 30 #连接smtp连接超时时间
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state MASTER# 备份LB将MASTER改为BACKUP
    interface eth0 #实例绑定的网卡,因为在配置虚拟IP的时候必须是在已有的网卡上添加的
    virtual_router_id 51#这里设置VRID,这里非常重要,相同的VRID为一个组,他将决定多播的MAC地址
    priority 100 # 优先级,备份LB值改为比这个值小
    advert_int 1 #检查间隔,默认为1秒
    authentication { #这里设置认证
      auth_type PASS #认证方式,可以是PASS或AH两种认证方式
      auth_pass 1111 #认证密码
    }
    virtual_ipaddress {
      192.168.19.65 # 多个VIP换行写
    }
}

    virtual_server 192.168.19.65 80 {
      delay_loop 6#每隔6秒查询realserver状态
      lb_algo wlc # LVS 算法
      lb_kind DR# LVS模式 DR是直接路由
      persistence_timeout 60 #同一IP连接60秒内分配到同一台realserver
      protocol TCP #TCP协议检测realserver状态

    real_server 192.168.19.62 80 {
      weight 3 #权重
      TCP_CHECK {
      connect_timeout 10 #10秒无响应超时
      nb_get_retry 3 #重连次数
      delay_before_retry 3 #重连间隔
      connect_port 80 #监控检查的端口
      }
    }
    real_server 192.168.19.63 80 {
      weight 3
      TCP_CHECK {
      connect_timeout 10
      nb_get_retry 3
      delay_before_retry 3
      connect_port 80
      }
   }
    real_server 192.168.19.64 80 {
      weight 3
      TCP_CHECK {
      connect_timeout 10
      nb_get_retry 3
      delay_before_retry 3
      connect_port 80
      }
   }
}




2、keepalived.conf从配置文件内容?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
! Configuration File for keepalived

global_defs {
   notification_email {
         790028862@qq.com
   }
   notification_email_from 790028862@qq.com
   smtp_server 127.0.0.1
# smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    virtual_ipaddress {
      192.168.19.65
    }
}

    virtual_server 192.168.19.65 80 {
      delay_loop 6
      lb_algo wlc
      lb_kind DR
      persistence_timeout 60
      protocol TCP

    real_server 192.168.19.62 80 {
      weight 3
      TCP_CHECK {
      connect_timeout 10
      nb_get_retry 3
      delay_before_retry 3
      connect_port 80
      }
    }
    real_server 192.168.19.63 80 {
      weight 3
      TCP_CHECK {
      connect_timeout 10
      nb_get_retry 3
      delay_before_retry 3
      connect_port 80
      }
   }
    real_server 192.168.19.64 80 {
      weight 3
      TCP_CHECK {
      connect_timeout 10
      nb_get_retry 3
      delay_before_retry 3
      connect_port 80
      }
   }
}




到此主从LVS配置完成,下一篇讲物理机的配置(也就是real_server)
页: [1]
查看完整版本: Redhat5.8 64位LVS实例环境讲解【一】