踏雪寻梅 发表于 2018-12-31 09:46:51

Lvs+keepalived架构简单案列

Lvs(DR) +keepalived的架构部署
  IP地址规划:
http://s3.运维网.com/wyfs02/M00/5D/BA/wKioL1Uj6xnTMqRAAATf1lFXUAo961.jpg
1.环境的大家和软件的安装

检查Linux内核版本是否支持ipvsadm模块
http://s3.运维网.com/wyfs02/M01/5D/BE/wKiom1Uj6hqQo8-FAASs2nmkGfo861.jpg
  (1)源码编译安装
  wgethttp://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
  wget http://www.keepalived.org/software/keepalived-1.1.17.tar.gz
  uname -r                           (查看内核版本,下面的要和查看到的内核版本一样)
  ln -s/usr/src/kernels/2.6.32-358.23.2.el6.x86_64/ /usr/src/linux   (如果/usr/src/kernels下面没有内容,可使用yum-y install kernel-devel安装即可)
  2)安装依赖包
  yum -yinstallopenssl-devel librarie*popt-devel
  3)安装主要软件
  tar -zxvf ipvsadm-1.24.tar.gz
  cd ipvsadm-1.24
  make && make install
  cd ..
  tar -zxvf keepalived-1.1.17.tar.gz
  cd keepalived-1.1.17
  ./configure
  make && make install
  编译的时候出现这个提示,说明keepalived和内核结合了,如果不是这样的,需要加上这个参数./configure --with-kernel-
  dir=/kernel/path
  Keepalived configuration
  ------------------------
  Keepalived version       : 1.1.17
  Compiler               : gcc
  Compiler flags         : -g -O2
  Extra Lib                : -lpopt -lssl -lcrypto
  UseIPVS Framework       : Yes
  IPVS sync daemon support : Yes
  Use VRRP Framework       : Yes
  Use LinkWatch            : No
  Use Debug flags          : No
  (2)yum配置安装
  yum -y install ipvsadm
  yum -y install keepalived
  进行安装即可,用yum安装完直接进行修改配置文件即可
2.配置单实例的lvs的DR模型
http://s3.运维网.com/wyfs02/M00/5D/BE/wKiom1Uj6lSiSRp_AAC2m9oYb1w434.jpg
  

  (1)手动配置
  配置顺利我们关闭iptbales 和seLinux
Service iptables stop
Setenforce 0
  (2)配置配置director的服务器的192.168.201.176的vip 192.168.201.170
Ifconfigeht0:0192.168.201.170netmask 255.255.255.0 up
添加路由routeadd–host192.168.201.170dev eth0:0
http://s3.运维网.com/wyfs02/M01/5D/BA/wKioL1Uj69XQSaDXAAGDXJt9HAQ706.jpg
  (2)配置RealServer1和Real Server2
  设置vip4的配置
  开启arp防护
  cd /proc/sys/net/ipv4/conf/
  修改
  sysctl -w net.ipv4.conf.eth0.arp_announce=2
  sysctl -w net.ipv4.conf.all.arp_announce=2
  echo 1 >/proc/sys/net/ipv4/conf/eth0/arp_ignore
  echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
  配置RealServer1 的viplo:0
  Ifconfig lo:0 192.168.201.170broadcast192.168.201.1netmask 255.255.255.255 up
  Route add-host192.168.201.170dev lo:0
  安装httpd服务
  yum install httpd –y
  修改index.html主页面
  echo 'zzx.178.com' >/var/www/html/index.html
  service httpd restart
  
  配置Real Server2 的viplo:0
  Ifconfiglo:0192.168.201.170broadcast192.168.201.1netmask 255.255.255.255 up
  Routeadd-host 192.168.201.170devlo:0
  安装httpd服务
  yum install httpd –y
  修改index.html主页面
  echo 'zzx.179.com' >/var/www/html/index.html
  service httpdrestart
  
3.配置lvs的Director Server1wcl
  添加ipvsadm规则
  ipvsadm -C --清空
  ipvsadm -A -t 192.168.201.170:80 -s rr --统计
  ipvsadm -a -t 192.168.201.170:80 -r192.168.201.179 -g -w 2 --配置权重
  ipvsadm -a -t 192.168.201.170:80 -r192.168.201.178 -g -w 1 --配置权重
  ipvsadm -L -n--查看链接数
  ipvsadm -L -n --stats -查看速率
  查看结果:
http://s3.运维网.com/wyfs02/M02/5D/BE/wKiom1Uj6sGya3XSAADGEVXzX9A806.jpg
  

  测试结果
http://s3.运维网.com/wyfs02/M02/5D/BA/wKioL1Uj7C-iPTtTAABmB4dZuuw098.jpg
4.配置lvs+keepalived的架构
http://s3.运维网.com/wyfs02/M01/5D/BE/wKiom1Uj6yeyk1EgAATf1lFXUAo955.jpg
  配置keepalived 的主备模式
  176为keepalived主state MASTER
  177为keepalived备state BACKUP
  修改virtual_router_id主和备不要一致
  vi /etc/keepalived/keepalived.conf
  !Configuration File for keepalived
  global_defs {
  router_id LVS_DEVEL
  }
  # VIP1
  vrrp_instance VI_1 {
  state MASTER
  interface eth0
  lvs_sync_daemon_intefaceeth0
  virtual_router_id 67
  priority 100
  advert_int 5
  authentication {
  auth_type PASS
  auth_pass 1122
  }
  virtual_ipaddress {
  192.168.201.170
  }
  }
  virtual_server192.168.201.170 80 {
  delay_loop 6
  lb_algo rr
  lb_kind DR
  persistence_timeout 60
  protocol TCP
  real_server 192.168.201.178 80 {
  # weight 100
  TCP_CHECK {
  connect_timeout 10
  nb_get_retry 3
  delay_before_retry 3
  connect_port 80
  }
  }
  real_server 192.168.201.179 80 {
  # weight 100
  TCP_CHECK {
  connect_timeout 10
  nb_get_retry 3
  delay_before_retry 3
  connect_port 80
  }
  }
  }
  
  重启keepalived
  /etc/init.d/keepalived/restart
  验证效果
http://s3.运维网.com/wyfs02/M00/5D/BA/wKioL1Uj7KXB-6-PAACH5mb5Y9U852.jpg
  

  

  请大家多多指导,谢谢



页: [1]
查看完整版本: Lvs+keepalived架构简单案列