centos6.8 x64安装keepalived-1.3.5+lvs

前端之家收集整理的这篇文章主要介绍了centos6.8 x64安装keepalived-1.3.5+lvs前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


CentOS release 6.8 x64 (Final)2.6.32-642.4.2.el6.x86_64 安装keepalived-1.3.5+lvs

============

一、环境安装:

============

1.依赖安装

  1. yuminstall-yopenssl-devellibnl3-develipset-develiptables-devellibnfnetlink-develpopt*
  2.  
  3. 增加软连接
  4. ln-s/usr/src/kernels/`uname-r`/usr/src/linux

2.5台机器IP设置

LVS1: 172.16.0.100

LVS2: 172.16.0.101

VIP: 172.16.0.150

WEB: 172.16.0.102

WEB2:172.16.0.103

web3:172.16.0.104(windows客户端IIS)

3.关闭selinux

修改/etc/selinux/config文件中设置SELINUX=disabled ,然后重启服务器。

4.关闭iptables,如果不关的话,需更具情况增加开放端口。

  1. #iptables-IINPUT-ptcp--dport80-jACCEPT
  2. #iptables-IINPUT-picmp-jACCEPT
  3. #serviceiptablessave

二、安装步骤(在LVS1.LVS2上安装):

============

1)安装lvs管理工具

  1. 1.tarzxvfipvsadm-1.26.tar.gz
  2. 2.cdipvsadm-1.26
  3. 3.'make'
  4. 4.'makeinstall'
  5. 5.#ipvsadm
  6. 6.lsmod|grepip_vs

2)安装keepalived软件

  1. 1.tarzxvfkeepalived-1.3.5.tar.gz
  2. 2.cdikeepalived-1.3.5
  3. 3../configure--prefix=/usr/local/keepalived--with-init=SYSV
  4. #注:(upstart|systemd|SYSV|SUSE|openrc)
  5. #根据系统选择对应的启动方式
  6. 4.'make'
  7. 5.'makeinstall'.

6.配置keepalived文件的路径

  1. cp/usr/local/keepalived/etc/rc.d/init.d/keepalived/etc/init.d/
  2. cp/usr/local/keepalived/etc/sysconfig/keepalived/etc/sysconfig/
  3. mkdir/etc/keepalived
  4. cp/usr/local/keepalived/etc/keepalived/keepalived.conf/etc/keepalived/
  5. cp/usr/local/keepalived/sbin/keepalived/usr/sbin/

7.配置文件(vim /etc/keepalived/keepalived.conf)

#这里是全局定义部分

  1. global_defs{
  2. notification_email{
  3. root@local#设置报警邮件单个或多个地址
  4.  
  5. }
  6. notification_email_fromserver@local#邮件的发送地址
  7. smtp_server127.0.0.1#smtp地址
  8. smtp_connect_timeout30#连接smtp服务器超时的实际
  9. router_idLVS_ONE#路由ID两台机器不能相同。LVS2更改为不同
  10. vrrp_skip_check_adv_addr
  11. #vrrp_strict#严格执行VRRP协议规范,此模式不支持节点单播.
  12. #且重启keepalived服务,会自动启动iptables,原计划打算关闭iptables,
  13. #但测试发现,多次(通过命令serviceiptablesstop且chkconfigiptablesoff,)
  14. #将iptables关闭后,但启动或重启keepalived服务后,自动又启动起来iptables,#且自加了一条把VIP地址DROP掉的规则。导致VIP查不到,ping不通.默认安装时自带配置
  15. #含有此选项。所以建议禁用此选项。
  16. vrrp_garp_interval0
  17. vrrp_gna_interval0
  18.  
  19.  
  20.  
  21.  
  22. }
  23. #vrrp实例定义部分
  24. vrrp_instanceVI_1{
  25. stateMASTER#keepalived的角色MASTER表示主服务器。LVS2更改为:BACKUP
  26. interfaceeth0#指定监测网卡
  27. virtual_router_id51#虚拟路由标示,相同实例,需相同标示。
  28. priority150#优先级数字越大优先级越高MASTER的优先级高于BACKUP优先级(如master150,backup100)
  29. advert_int1#设定主备之间检查时间单位s
  30. authentication{#设定验证类型和密码
  31. auth_typePASS
  32. auth_pass1111
  33. }
  34. virtual_ipaddress{#设定虚拟IP地址可以设置多个每行一个
  35. 172.16.0.150/24brd172.16.0.255deveth0labeleth0:0
  36. }
  37. }
  38. #虚拟服务器部分
  39. virtual_server172.16.0.15080{
  40. delay_loop6#设定运行情况检查时间单位s
  41. lb_algorr#负载调度算法rr即轮叫算法
  42. lb_kindDR#设置LVS负载机制NATTUNDR三种模式可选
  43. persistence_timeout0#会话时间
  44. #会话保持在某个服务节点
  45. #用户在动态页面50s内没有任何动作,那么后面就会被分发到其他节点
  46. #用户一直动作,不受50s限制
  47. protocolTCP#使用协议
  48. #以下为real_server部分
  49. real_server172.16.0.10280{
  50. weight1#服务节点权值,数字越大,权值越高
  51. #权值的大小可以为不同性能的服务器分配不同的负载
  52. #这样才能有效合理的利用服务器资源
  53. TCP_CHECK{#状态检查部分
  54. connect_timeout3#3s无响应超时
  55. nb_get_retry3#重试次数
  56. delay_before_retry3#重试间隔
  57. connect_port80#连接端口
  58. }
  59. }
  60. real_server172.16.0.10380{
  61. weight1
  62. TCP_CHECK{
  63. connect_timeout3
  64. nb_get_retry3
  65. delay_before_retry3
  66. connect_port80
  67. }
  68. }
  69. real_server172.16.0.10480{
  70. weight1
  71. TCP_CHECK{
  72. connect_timeout3
  73. nb_get_retry3
  74. delay_before_retry3
  75. connect_port80
  76. }
  77. }
  78. }

三、客户端设置(web1,web2配置)

1.增加启动关闭脚本,并chmod执行权限

  1. #!/bin/bash
  2. #
  3. #ScripttostartLVSDRrealserver.
  4. #description:LVSDRrealserver
  5. #
  6. ./etc/rc.d/init.d/functions
  7. VIP=172.16.0.150#修改相应的VIP
  8. host=`/bin/hostname`
  9. case"$1"in
  10. start)
  11. #启动LVS-DR模式,realserveronthismachine.关闭ARP冲突检测。
  12. /sbin/ifconfiglodown
  13. /sbin/ifconfigloup
  14. echo1>/proc/sys/net/ipv4/conf/lo/arp_ignore
  15. echo2>/proc/sys/net/ipv4/conf/lo/arp_announce
  16. echo1>/proc/sys/net/ipv4/conf/all/arp_ignore
  17. echo2>/proc/sys/net/ipv4/conf/all/arp_announce
  18. /sbin/ifconfiglo:0$VIPbroadcast$VIPnetmask255.255.255.255up
  19. /sbin/routeadd-host$VIPdevlo:0
  20. ;;
  21. stop)
  22. #停止LVS-DRrealserverloopbackdevice(s).
  23. /sbin/ifconfiglo:0down
  24. echo0>/proc/sys/net/ipv4/conf/lo/arp_ignore
  25. echo0>/proc/sys/net/ipv4/conf/lo/arp_announce
  26. echo0>/proc/sys/net/ipv4/conf/all/arp_ignore
  27. echo0>/proc/sys/net/ipv4/conf/all/arp_announce
  28. ;;
  29. status)
  30. #StatusofLVS-DRrealserver.
  31. islothere=`/sbin/ifconfiglo:0|grep$VIP`
  32. isrothere=`netstat-rn|grep"lo:0"|grep$VIP`
  33. if[!"$islothere"-o!"isrothere"];then
  34. #Eithertherouteorthelo:0device
  35. #notfound.
  36. echo"LVS-DRrealserverStopped!"
  37. else
  38. echo"LVS-DRrealserverRunning..."
  39. fi
  40. ;;
  41. *)
  42. #Invalidentry.
  43. echo"$0:Usage:$0{start|status|stop}"
  44. exit1
  45. ;;
  46. esac

2.增加web http服务,使用80端口可以打开网站。

3.测试服务器相互之间是否可以PING通。

4.windows客户端增加VIP事项(web3机器):

win2003地址设置方法:控制面板->添加硬件->添加新的硬件->手动安装硬件-》网络适配器

wKiom1kugOzyUd6wAAASjw6Iehs850.png-wh_50

重命名为VIP,增加IP地址172.16.0.104,掩码255.255.255.0

打开regedit,编辑:subnetMask为255.255.255.255

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces

wKioL1kugW7ghZKQAAAkpchWWLk438.png-wh_50

Win2008地址设置方法:控制面板-硬件和打印机->新增硬件

找到新增的环回连接,重命名VIP,右键VIP连接属性,开始设置TCP/IP

172.16.0.104 255.255.255.255.255 保存

运行CMD执行:

  1. netshinterfaceipv4setinterface"VIP"weakhostreceive=enabled
  2. netshinterfaceipv4setinterface"VIP"weakhostsend=enabled
  3. netshinterfaceipv4setinterface"LAN"weakhostreceive=enabled
  4. netshinterfaceipv4setinterface"LAN"weakhostsend=enabled


四、测试检查keepalived+lvs问题

1、 查看系统日志 /var/log/messages

2、 检查负载均衡器的网络连通状况(ping命令或arping)。

3、 检查 keepalived 的运行情况。ps -aux | grep keepalived查看是否进程启动。lsmod | grep ip_vs,检查ipvs 模块是否被加载到系统的内核,vip 是否被绑定到网络接口,ipvsadm 是否有输出

4、 检查 keepalived 的配置文件书写是否正确。

5、 检查负载均衡器是否启用防火墙规则。

6、 realserver的web是否正常

推荐文档:http://www.keepalived.org/pdf/sery-lvs-cluster.pdf

猜你在找的CentOS相关文章