hx0011yy 发表于 2018-12-30 10:38:23

Keepalived现实Web双机热备(高可用)

Keepalived现实Web双机热备(高可用)
      通过在两台主、备调度器上实现Keepalived高可用解决调度器单点失败问题
      主、备调度器上配置LVS,正常情况下主调度器工作
      主调度器异常时,Keepalived启用备用调度器,保证了调度器的高可用
      调度器保证了后台服务的高可用
      Keepalived机制把同一个IP一直分配在同一个Web服务器
  如下实现web服务器的高可用:
  web1 :192.168.10.20   主
  web2:   192.168.10.22   备
  虚拟IP:192.168.10.100
  client :192.168.10.40
  一、在两台web服务器上安装keepalived
  # yuminstall -ygccgcc-c++ kernel-developenssl-develpopt-devel
  # tarxvzf keepalived-1.2.7.tar.gz-C/usr/src/
  # cd/usr/src/keepalived-1.2.7/
  # uname -r
  2.6.32-358.el6.x86_64
  #./configure--sysconf=/etc --with-kernel-dir=/usr/src/kernels/2.6.32-358.el6.x86_64/&& make&& make install
  注:
  --sysconf// keepalived的主配置文件存放位置/etc/keepalived/keepalived.conf
  --with-kernel-dir    //指定本服务器正在使用的内核文件的存放位置
  #ln-s /usr/local/sbin/keepalived/sbin/
  # chkconfigkeepalived on
  

  二、Keepalived配置说明
  web1服务器:
  vim/etc/keepalived/keepalived.conf
  设置报警邮件
  global_defs {
  notification_email {
  root@localhost   //发件人邮箱
  }
  notification_email_fromroot@192.168.10.40    //收件人邮箱 ,此处设置成发给自己
  smtp_server192.168.10.40    //给谁发邮件
  smtp_connect_timeout 30
  router_id LVS_devel
  }
  VRRP实例设置
  vrrp_instanceVI_1 {
  state MASTER    //主服务器就写MASTER,辅助备份就写SLAVE
  interface eth0
  virtual_router_id 51
  priority 100    //主服务器优先级要比备份的高例子:主是100那么备用就是60
  advert_int 1   //主备服务器多长时间互相检测这里是1秒
  authentication {
  auth_type pass
  auth_pass redhat   //主辅服务器密码必须一致
  }
  virtual_ipaddress { 192.168.10.100}    //指定调度器上的VIP虚拟IP
  }
  注:只要以上内容,其它的都删除。
  web2服务器:备
  vim/etc/keepalived/keepalived.conf
  设置报警邮件
  global_defs {
  notification_email {
  root@localhost   //发件人邮箱
  }
  notification_email_fromroot@192.168.10.40    //收件人邮箱 ,此处设置成发给自己
  smtp_server192.168.10.40    //给谁发邮件
  smtp_connect_timeout 30
  router_id LVS_devel
  }
  VRRP实例设置
  vrrp_instanceVI_1 {
  stateSLAVE    //主服务器就写MASTER,辅助备份就写SLAVE
  interface eth0
  virtual_router_id 51
  priority 80    //主服务器优先级要比备份的高例子:主是100那么备用就是60
  advert_int 1   //主备服务器多长时间互相检测这里是1秒
  authentication {
  auth_type pass
  auth_pass redhat   //主辅服务器密码必须一致
  }
  virtual_ipaddress { 192.168.10.100}    //指定调度器上的VIP虚拟IP
  }
  三、在两台web服务器上启动keepalived服务
# service keepalived start
  四、在两台web服务器上分别查看ip
# ip addr show eth0
web1上能看到虚拟IP 192.168.10.100
web2上不能看到虚拟IP
  五、客户端访问
http://192.168.10.100   此时能访问到web1上的内容
  六、测试其高可用性
  将web1 关闭;再看到web1和web2上的IP
web2上能看到虚拟IP 192.168.10.100
web1上不能看到虚拟IP
  客户端刷新页面:此时能访问到web2上的内容。
  说明备份服务器web2起作用了。
  可用:# tail-f/var/log/messages   实时查看



页: [1]
查看完整版本: Keepalived现实Web双机热备(高可用)