小雪崩 发表于 2019-1-4 07:33:16

lvs快速安装

  

  安装完系统后 发现缺少rz命令    快速安装一个
  安装rz sz
  yum -y install lrzsz
  实验环境centos 5.4
  DR-master=192.168.0.35
  DR-backup=192.168.0.36
  虚拟VIP=192.168.0.100
  web1=192.168.0.39
  web2=192.168.0.40
  

  创建软连接,否则make时会报错
  ln -s /usr/src/kernels/2.6.18-164.el5-x86_64/ /usr/src/linux
  

  tar -zxvf ipvsadm-1.24.tar.gz解压
  cd ipvsadm-1.24
  make
  make install
  看下ipvsadm 路径
  find / -name ipvsadm
  

  tar -zxvf keepalived-1.1.17.tar.gz
  cd keepalived-1.1.17
  ./configure
  

  configure: error:
  !!! OpenSSL is not properly installed on your system. !!!
  !!! Can not include OpenSSL headers files.
  解决办法:
  yum -y install openssl-devel
  ./configure
  make
  make install
  ------------------------
  Keepalived version       : 1.1.17
  Compiler               : gcc
  Compiler flags         : -g -O2
  Extra Lib                : -lpopt -lssl -lcrypto
  Use IPVS Framework       : Yes
  IPVS sync daemon support : Yes
  Use VRRP Framework       : Yes
  Use LinkWatch            : No
  Use Debug flags          : No
  

  

  8、开启负载服务器路由机制//master和backup
  #      vi /etc/sysctl.conf 保证有如下内容
  把   net.ipv4.ip_forward = 0
  改为   net.ipv4.ip_forward = 1
  执行
  #      sysctl -p
  

  

  

  “======================= 配置keepalived ===========================
  

  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/sbin/keepalived /usr/sbin/
  vi /etc/keepalived/keepalived.conf
  ! Configuration File for keepalived
  

  global_defs {
  notification_email {
  34621926@qq.com
  }
  notification_email_from 34621926@qq.com
  smtp_server smtp.qq.com
  # smtp_connect_timeout 30
  router_id LVS_DEVEL
  }
  

  # VIP1
  vrrp_instance VI_1 {
  state MASTER             #备份服务器上将MASTER改为BACKUP
  interface eth0
  lvs_sync_daemon_inteface eth0
  virtual_router_id 51
  priority 100    # 备份服务上将100改为90
  advert_int 5
  authentication {
  auth_type PASS
  auth_pass 1111
  }
  virtual_ipaddress {
  192.168.0.100
  #(如果有多个VIP,继续换行填写.)
  }
  }
  

  virtual_server 192.168.0.100 80 {
  delay_loop 6                  #(每隔10秒查询realserver状态)
  lb_algo wlc                  #(lvs 算法)
  lb_kind DR                  #(Direct Route)
  persistence_timeout 60      #(同一IP的连接60秒内被分配到同一台realserver)
  protocol TCP                #(用TCP协议检查realserver状态)
  

  real_server 192.168.0.39 80 {
  weight 100               #(权重)
  TCP_CHECK {
  connect_timeout 10       #(10秒无响应超时)
  nb_get_retry 3
  delay_before_retry 3
  connect_port 80
  }
  }
  real_server 192.168.0.40 80 {
  weight 100
  TCP_CHECK {
  connect_timeout 10
  nb_get_retry 3
  delay_before_retry 3
  connect_port 80
  }
  }
  }
  

  /etc/init.d/keepalived start
  

  

  

  

  编写dr脚本
  vi /sbin/lvsdr.sh
  #!/bin/bash
  GW=192.168.0.250
  VIP=192.168.0.100
  RIP1=192.168.0.39
  RIP2=192.168.0.40
  /etc/rc.d/init.d/functions
  case "$1" in
  start)
  echo "start LVS of DirectorServer"
  #Set the Virtual IP Address
  /sbin/ifconfig eth0:1 $VIP broadcast $VIP netmask 255.255.255.255 up
  /sbin/route add -host $VIP dev eth0:1
  #Clear IPVS Table
  /sbin/ipvsadm -C
  #Set Lvs
  /sbin/ipvsadm -A -t $VIP:80 -s wrr -p 3
  /sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -g -w 1
  /sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g -w 1
  #Run Lvs
  /sbin/ipvsadm
  ;;
  stop)
  echo "Close LVS Directorserver"
  /sbin/ifconfig eth0:1 down
  /sbin/ipvsadm -C
  ;;
  *)
  echo "Usage0{start|stop}"
  exit 1
  esac
  

  chmod 755 /sbin/lvsdr.sh
  /sbin/lvsdr.sh start
  

  看route -n是否多了 eth0:1的路由
  

  ==============================配置后端web服务器=============================
  在192.168.0.39和192.168.0.40上分别建立如下脚本
  vi /sbin/realdr.sh
  #!/bin/bash
  VIP=192.168.0.100
  /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
  /sbin/route add -host $VIP dev lo:0
  echo "1">/proc/sys/net/ipv4/conf/default/arp_ignore
  echo "2">/proc/sys/net/ipv4/conf/default/arp_announce
  echo "1">/proc/sys/net/ipv4/conf/all/arp_ignore
  echo "2">/proc/sys/net/ipv4/conf/all/arp_announce
  sysctl -p
  

  chmod 755 /sbin/realdr.sh
  在两台web服务器上分别执行其指命。
  /sbin/realdr.sh start
  # /sbin/realdr.sh start
  

  

  vi /etc/rc.local //里面添加
  /etc/init.d/keepalived restart
  /sbin/lvsdr.sh start
  




页: [1]
查看完整版本: lvs快速安装