HAProxy+Keepalived的配置(二)(及重要问题说明)

HAProxy 报错(Starting proxy stats: cannot bind socket [0....:7777] )解决办法 1、报错提示 [root@Tang ~]# systemctl start haproxy [root@Tang ~]# systemctl status haproxy ● haproxy.service - HAProxy Load Balancer Loaded: loaded (/usr/lib/systemd/system/haproxy.service; disabled; vendor preset: disabled) Active: failed (Result: exit-c... 阅读详情
HAProxy+Keepalived的配置(二)(及重要问题说明)
在搭建HAProxy+Keepalived之前先单独测试HAProxy
一 HAProxy配置测试
   
   (注测试:HAProxy只设内网网卡,Client同样位于内网)
   1.测试web提前配置
  1. yum install httpd -y #安装httpd
  2. echo 192.168.1.188 >/var/www/html/index.html #输入网站显示各自IP
  3. systemctl restart httpd
  4. firewall-cmd --permanent --add-port=80/tcp #开启防火墙80端口
  5. firewall-cmd --reload
  6. #测试,浏览器登录IP查看,是否正常启动。
   2.HAProxy配置/etc/haproxy/haproxy.cfg(yum install haproxy -y)
  1. global
  2. #全区日志配置 使用rsyslog的local3设备
  3. log 127.0.0.1 local3 info
  4. #工作目录(安全)
  5. chroot /var/lib/haproxy
  6. #pid文件存储目录
  7. pidfile /var/run/haproxy.pid
  8. #后台进程数量
  9. nbproc 1
  10. #每个进程最大并发数
  11. maxconn 40000
  12. user haproxy
  13. group haproxy
  14. #后台程序模式工作
  15. daemon
  16. defaults
  17. mode http
  18. #后端连接重试次数,超出标识不可用
  19. retries 3
  20. #连接服务器最长等待时间
  21. timeout connect 10s
  22. #客户端发送请求最长等待时间
  23. timeout client 30s
  24. #服务器会复客户端最长等待时间
  25. timeout server 30s
  26. #对后端服务器的检测超时时间
  27. timeout check 10s
  28. #定义HAProxy监控页面
  29. listen admin_stats
  30. bind 0.0.0.0:9188
  31. mode http
  32. log 127.0.0.1 local3 err
  33. #HAProxy监控页面统计自动刷新时间。
  34. stats refresh 30s
  35. #设置监控页面URL路径。 http://IP:9188/haproxy-status可查看
  36. stats uri /haproxy-status
  37. #统计页面密码框提示信息
  38. stats realm welcome login\ Haproxy
  39. #登录统计页面用户和密码
  40. stats auth admin:123456
  41. #隐藏HAProxy版本信息
  42. stats hide-version
  43. #设置TURE后可在监控页面手工启动关闭后端真实服务器
  44. stats admin if TRUE
  45. #定义前端虚拟节点
  46. frontend www
  47. #监听端口
  48. bind *:80
  49. mode http
  50. #启用日志记录HTTP请求。
  51. option httplog
  52. #启用后后端服务器可以获得客户端IP
  53. option forwardfor
  54. #客户端和服务器完成一次连接请求后,HAProxy主动关闭TCP链接(优化选项)
  55. option httpclose
  56. #使用全局日志配置
  57. log global
  58. #指定后端服务池(backend定义htmpool)
  59. default_backend htmpool
  60. #定义后端真实服务器
  61. backend htmpool
  62. mode http
  63. #用于cookie保持环境。(如后端服务器故障,客户端cookie不会刷新,用此来把用户请求强制定向到正常服务器)
  64. option redispatch
  65. #负载均衡很高时,自动结束当前队列处理时间长的连接
  66. option abortonclose
  67. #负载均衡算法
  68. balance roundrobin
  69. #允许向cookie插入SERVERID.下面server可以使用cookie定义
  70. cookie SERVERID
  71. #启用HTTP服务状态检测功能 (后端服务器一定要存在此文件,不然haproxy认为其故障)
  72. option httpchk GET /index.html
  73. #后端服务设置
  74. server web1 192.168.1.186:80 cookie server1 weight 6 check inter 2000 rise 2 fall 3
  75. server web2 192.168.1.188:80 cookie server2 weight 6 check inter 2000 rise 2 fall 3
    开启日志(日志如果在主机性能较弱的情况下,最好关闭)
  1. vim /etc/rsyslog.d/haproxy.conf
  2. $ModLoad imudp
  3. $UDPServerRun 514
  4. local3.* /var/log/haproxy
  5. systemctl restart rsyslog
    开启防火墙和安全策略
  1. firewall-cmd --permanent --add-port=80/tcp
  2. firewall-cmd --permanent --add-port=9188/tcp
  3. firewall-cmd --reload
  4. setsebool -P haproxy_connect_any=on
  5. #getsebool -a | grep haproxy 查看
   启动HAProxy服务
  1. systemctl start haproxy
    测试均衡能力
  1. [root@test2 ~]# curl http://192.168.1.166
  2. 192.168.1.188
  3. [root@test2 ~]# curl http://192.168.1.166
  4. 192.168.1.186
  5. [root@test2 ~]# curl http://192.168.1.166
  6. 192.168.1.188
  7. [root@test2 ~]# curl http://192.168.1.166
  8. 192.168.1.186
    测试HAProxy监控页面是否正常(http://IP:9188/haproxy-status)

二 HAProxy+Keepalived配置 

   HAProxy配置
   (HAProxy两台Proxy主机配置相同,如上HAProxy的配置即可)
   Keepalived配置(/etc/keepalived/keepalived.conf)(yum install keepalived -y)
  1. ! Configuration File for keepalived
  2. global_defs {
  3. #设置报警通知邮件地址,可以设置多个
  4. notification_email {
  5. msun1996@163.com
  6. }
  7. #设置邮件的发送地址
  8. notification_email_from keepalived@msun.com
  9. #设置smtp server的地址,该地址必须是存在的
  10. smtp_server 127.0.0.1
  11. #设置连接smtp server的超时时间
  12. smtp_connect_timeout 30
  13. #运行Keepalived服务器的标识,发邮件时显示在邮件标题中的信息
  14. router_id HAProxy_msun
  15. }
  16. # 检测haproxy脚本
  17. vrrp_script chk_haproxy {
  18. script "/etc/keepalived/check_haproxy.sh"
  19. interval 2
  20. #下面方法相对更优
  21. #script "killall -0 haproxy" #killall (安装 yum install psmisc -y)
  22. #interval 2
  23. #weghit 2 #权值脚本成功时(0)等于priority+weghit #否则为priority
  24. }
  25. #定义VRRP实例,实例名自定义
  26. vrrp_instance haproxy_msun {
  27. #指定Keepalived的角色,MASTER为主服务器,BACKUP为备用服务器
  28. state MASTER #从设置为BACKUP
  29. #指定HA监测的接口
  30. interface eno16777736
  31. #虚拟路由标识,这个标识是一个数字(1-255),在一个VRRP实例中主备服务器ID必须一样
  32. virtual_router_id 68
  33. #优先级,数字越大优先级越高,在一个实例中主服务>器优先级要高于备服务器
  34. priority 100 #从设置为99
  35. #设置主备之间同步检查的时间间隔单位秒
  36. advert_int 1
  37. #设置验证类型和密码
  38. authentication {
  39. #验证类型有两种{PASS|HA}
  40. auth_type PASS
  41. #设置验证密码,在一个实例中主备密码保持一样
  42. auth_pass 1689
  43. }
  44. track_script {
  45. chk_haproxy # 执行监控的服务
  46. }
  47. #定义虚拟IP地址,可以有多个,每行一个
  48. virtual_ipaddress {
  49. 192.168.1.160
  50. }
  51. }
   添加HAProxy检测脚本到vim /etc/keepalived/check_haproxy.sh(执行权限)(这一步必须关闭SElinux,不然vrrp script 脚本是不可以执行的。下面会介绍开启selinux下的解决方法)
  1. #!/bin/bash
  2. #判断haproxy是否已经启动
  3. if [ `ps -C haproxy --no-header |wc -l` -eq 0 ] ; then
  4. #如果没有启动,则启动haproxy程序
  5. systemctl start haproxy
  6. #睡眠3秒钟以等待haproxy完全启动
  7. sleep 3
  8. if [ `ps -C haproxy --no-header |wc -l` -eq 0 ] ; then
  9. systemctl stop keepalived
  10. #如果haproxy还是没有启动,则将keepalived停掉,这样VIP会自动漂移到另外一台haproxy
  11. fi
  12. fi
   启动keepalived
  1. systemctl start keepalived
   防火墙允许(开放vrrp组播)(不然会导致脑裂)
  1. firewall-cmd --permanent --add-rich='rule family="ipv4" destination address="224.0.0.18" protocol value="vrrp" accept'
  2. firewall-cmd --reload
   测试
  1. [root@test5 ~]# curl 192.168.1.160
  2. 192.168.1.186
  3. [root@test5 ~]# curl 192.168.1.160
  4. 192.168.1.188
  5. [root@test5 ~]# curl 192.168.1.160
  6. 192.168.1.186
  7. [root@test5 ~]# curl 192.168.1.160
  8. 192.168.1.188
   通过观察ip a输出VIP来判断是否存在脑裂,和主备故障时是否能正常切换。

三 部署HAProxy遇到的重点问题与解决
   1.部署单独的Haproxy时遇到问题
   配置完配置文件后,使用systemctl start haproxy,haproxy无法正常启动。(启动后查看状态没有对应进程显示)
  (防火墙80端口和9188端口已正常开启。所以不可能是防火墙问题,再说防火墙也不可能影响启动啊)
  /var/log/message有以下报错信息
  1. [root@test5 ~]# tail /var/log/messages
  2. Mar 12 14:59:29 test5 systemd: Starting HAProxy Load Balancer...
  3. Mar 12 14:59:29 test5 haproxy-systemd-wrapper: [ALERT] 070/145929 (3131) : Starting proxy admin_stats: cannot bind socket [0.0.0.0:9188]
  4. Mar 12 14:59:29 test5 haproxy-systemd-wrapper: haproxy-systemd-wrapper: exit, haproxy RC=1
  5. Mar 12 14:59:29 test5 systemd: haproxy.service: main process exited, code=exited, status=1/FAILURE
  6. Mar 12 14:59:29 test5 systemd: Unit haproxy.service entered failed state.
  7. Mar 12 14:59:29 test5 systemd: haproxy.service failed.
   查看haproxy相关selinux政策,发现haproxy默认不允许连接
  1. [root@test5 ~]# getsebool -a | grep haproxy
  2. haproxy_connect_any --> off
   重新设置selinux政策后正常启动
  1. [root@test5 ~]# setsebool -P haproxy_connect_any=on
  2. [root@test5 ~]# systemctl start haproxy
  3. [root@test5 ~]# netstat -tlunp
  4. Active Internet connections (only servers)
  5. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  6. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3171/haproxy
  7. tcp 0 0 0.0.0.0:9188 0.0.0.0:* LISTEN 3171/haproxy
   2.搭建HAProxy+Keepalived遇到的问题
       1.服务器搭建完成后,出现脑裂现象。主备机多有VIP。
         解决:防火墙允许(开放vrrp组播)
  1. firewall-cmd --permanent --add-rich='rule family="ipv4" destination address="224.0.0.18" protocol value="vrrp" accept'
       2.关于Keepalived中的vrrp script 设置的脚本不执行。
       因为检测HAproxy状态的脚本不能运行,导致就算主机HAProxy挂掉,但因为Keepalived还正常运行,VIP没有正常从主机正常漂移到从机,导致整个服务垮掉。
       直接快速解决方法:关闭SElinux.
       
       SElinux安全策略运行时解决

       1)尝试SElinux允许解决(解决失败)
       开启SElinux时的错误提示:
  1. [root@test1 ~]# tail -f /var/log/messages
  2. type=AVC msg=audit(1489338470.513:714): avc: denied { getattr } for pid=5174 comm="check_haproxy.s" path="/usr/bin/systemctl" dev="dm-0" ino=33947874 scontext=system_u:system_r:keepalived_t:s0 tcontext=system_u:object_r:systemd_systemctl_exec_t:s0 tclass=file
  3. type=SYSCALL msg=audit(1489338470.513:714): arch=c000003e syscall=4 success=no exit=-13 a0=f72c00 a1=7ffd88bca560 a2=7ffd88bca560 a3=3 items=0 ppid=5173 pid=5174 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="check_haproxy.s" exe="/usr/bin/bash" subj=system_u:system_r:keepalived_t:s0 key=(null)
       安装selinux管理工具(根据报错显示可能解决方案)
  1. yum install setroubleshoot -y
       查看settoubleshoot给出的解决方案  
  1. [root@test1 ~]# tail -f /var/log/messages
  2. Mar 13 02:30:27 test1 setroubleshoot: SELinux is preventing /usr/bin/bash from getattr access on the file /usr/bin/systemctl. For complete SELinux messages. run sealert -l 54416ee0-01c3-40e8-8198-675f6f86a7f7
  3. Mar 13 02:30:27 test1 python: SELinux is preventing /usr/bin/bash from getattr access on the file /usr/bin/systemctl.#012#012***** Plugin catchall (100. confidence) suggests **************************#012#012If you believe that bash should be allowed getattr access on the systemctl file by default.#012Then you should report this as a bug.#012You can generate a local policy module to allow this access.#012Do#012allow this access for now by executing:#012# ausearch -c 'check_haproxy.s' --raw | audit2allow -M my-checkhaproxys#012# semodule -i my-checkhaproxys.pp#012
       尝试解决:
  1. [root@test1 ~]# sealert -l 54416ee0-01c3-40e8-8198-675f6f86a7f7
  2. SELinux is preventing /usr/bin/bash from getattr access on the file /usr/bin/systemctl.
  3. ***** Plugin catchall (100. confidence) suggests **************************
  4. If 确定应默认允许 bash getattr 访问 systemctl file。
  5. Then 应该将这个情况作为 bug 报告。
  6. 可以生成本地策略模块以允许此访问。
  7. Do
  8. allow this access for now by executing:
  9. # ausearch -c 'check_haproxy.s' --raw | audit2allow -M my-checkhaproxys
  10. # semodule -i my-checkhaproxys.pp        
  1. [root@test1 ~]# sealert -l 54416ee0-01c3-40e8-8198-675f6f86a7f7
  2. [root@test1 ~]# ausearch -c 'check_haproxy.s' --raw | audit2allow -M my-checkhaproxys
  3. [root@test1 ~]# semodule -i my-checkhaproxys.pp
        尝试后日志提示:
  1. [root@test1 ~]# tail -f /var/log/messages
  2. Mar 13 02:36:08 test1 setroubleshoot: SELinux is preventing /usr/bin/bash from open access on the file /usr/bin/systemctl. For complete SELinux messages. run sealert -l 487ebbb3-fefe-4018-8c4c-5be6a185e64b
  3. Mar 13 02:36:08 test1 python: SELinux is preventing /usr/bin/bash from open access on the file /usr/bin/systemctl.#012#012***** Plugin catchall (100. confidence) suggests **************************#012#012If you believe that bash should be allowed open access on the systemctl file by default.#012Then you should report this as a bug.#012You can generate a local policy module to allow this access.#012Do#012allow this access for now by executing:#012# ausearch -c 'check_haproxy.s' --raw | audit2allow -M my-checkhaproxys#012# semodule -i my-checkhaproxys.pp#012

  1. [root@test1 ~]# tail -f /var/log/audit/audit.log
  2. type=AVC msg=audit(1489352184.678:549): avc: denied { open } for pid=3990 comm="check_haproxy.s" path="/usr/bin/systemctl" dev="dm-0" ino=33724848 scontext=system_u:system_r:keepalived_t:s0 tcontext=system_u:object_r:systemd_systemctl_exec_t:s0 tclass=file
  3. type=SYSCALL msg=audit(1489352184.678:549): arch=c000003e syscall=2 success=no exit=-13 a0=14bec50 a1=0 a2=43 a3=7ffe13e19190 items=0 ppid=3986 pid=3990 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="check_haproxy.s" exe="/usr/bin/bash" subj=system_u:system_r:keepalived_t:s0 key=(null)
        继续按提示输入
  1. [root@test1 ~]# sealert -l 487ebbb3-fefe-4018-8c4c-
  2. [root@test1 ~]# ausearch -c 'check_haproxy.s' --raw | audit2allow -M my-checkhaproxys
  3. [root@test1 ~]# semodule -i my-checkhaproxys.pp
        尝试后日志提示:
  1. [root@test1 ~]# tail -f /var/log/messages
  2. Mar 13 05:02:35 test1 setroubleshoot: SELinux is preventing /usr/bin/bash from execute_no_trans access on the file /usr/bin/systemctl. For complete SELinux messages. run sealert -l a3a942ad-2b0e-4b4b-bf1f-b521256f4405
  3. Mar 13 05:02:35 test1 python: SELinux is preventing /usr/bin/bash from execute_no_trans access on the file /usr/bin/systemctl.#012#012***** Plugin catchall (100. confidence) suggests **************************#012#012If you believe that bash should be allowed execute_no_trans access on the systemctl file by default.#012Then you should report this as a bug.#012You can generate a local policy module to allow this access.#012Do#012allow this access for now by executing:#012# ausearch -c 'check_haproxy.s' --raw | audit2allow -M my-checkhaproxys#012# semodule -i my-checkhaproxys.pp#012

  1. [root@test1 ~]# tail -f /var/log/audit/audit.log
  2. type=AVC msg=audit(1489352298.756:764): avc: denied { execute_no_trans } for pid=5507 comm="check_haproxy.s" path="/usr/bin/systemctl" dev="dm-0" ino=33724848 scontext=system_u:system_r:keepalived_t:s0 tcontext=system_u:object_r:systemd_systemctl_exec_t:s0 tclass=file
  3. type=SYSCALL msg=audit(1489352298.756:764): arch=c000003e syscall=59 success=no exit=-13 a0=162cc50 a1=162ccc0 a2=162d360 a3=7ffddf4d6190 items=0 ppid=5503 pid=5507 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="check_haproxy.s" exe="/usr/bin/bash" subj=system_u:system_r:keepalived_t:s0 key=(null)
        继续按提示输入
  1. [root@test1 ~]# sealert -l a3a942ad-2b0e-4b4b-bf1f-b521256f4405
  2. [root@test1 ~]# ausearch -c 'check_haproxy.s' --raw | audit2allow -M my-checkhaproxys
  3. [root@test1 ~]# semodule -i my-checkhaproxys.pp
        尝试后日志提示:
  1. [root@test1 ~]# tail -f /var/log/messages
  2. Mar 13 05:06:42 test1 setroubleshoot: failed to retrieve rpm info for /run/dbus/system_bus_socket
  3. Mar 13 05:06:42 test1 setroubleshoot: SELinux is preventing /usr/bin/systemctl from connectto access on the unix_stream_socket /run/dbus/system_bus_socket. For complete SELinux messages. run sealert -l e1afcda9-a674-4d76-8aa0-7787404c515e
  4. Mar 13 05:06:42 test1 python: SELinux is preventing /usr/bin/systemctl from connectto access on the unix_stream_socket /run/dbus/system_bus_socket.#012#012***** Plugin catchall (100. confidence) suggests **************************#012#012If you believe that systemctl should be allowed connectto access on the system_bus_socket unix_stream_socket by default.#012Then you should report this as a bug.#012You can generate a local policy module to allow this access.#012Do#012allow this access for now by executing:#012# ausearch -c 'systemctl' --raw | audit2allow -M my-systemctl#012# semodule -i my-systemctl.pp#012

  1. [root@test1 ~]# tail -f /var/log/audit/audit.log
  2. type=AVC msg=audit(1489352885.238:1505): avc: denied { connectto } for pid=11711 comm="systemctl" path="/run/dbus/system_bus_socket" scontext=system_u:system_r:keepalived_t:s0 tcontext=system_u:system_r:system_dbusd_t:s0-s0:c0.c1023 tclass=unix_stream_socket
  3. type=SYSCALL msg=audit(1489352885.238:1505): arch=c000003e syscall=42 success=no exit=-13 a0=3 a1=7f42bfa16918 a2=21 a3=7ffe723af2b0 items=0 ppid=11707 pid=11711 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="systemctl" exe="/usr/bin/systemctl" subj=system_u:system_r:keepalived_t:s0 key=(null)
        继续按提示输入
  1. [root@test1 ~]# sealert -l e1afcda9-a674-4d76-8aa0-7787404c515e
  2. [root@test1 ~]# ausearch -c 'systemctl' --raw | audit2allow -M my-systemctl
  3. [root@test1 ~]# semodule -i my-systemctl.pp
        尝试后日志:(最后没解决  ~。。~)
  1. [root@test1 ~]# tail -f /var/log/messages
  2. Mar 13 05:12:09 test1 Keepalived_vrrp[3090]: Process [14395] didn't respond to SIGTERM

  1. [root@test1 ~]# tail -f /var/log/audit/audit.log
  2. type=USER_AVC msg=audit(1489353197.502:2058): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='avc: denied { start } for auid=n/a uid=0 gid=0 path="/usr/lib/systemd/system/haproxy.service" cmdline="systemctl start haproxy" scontext=system_u:system_r:keepalived_t:s0 tcontext=system_u:object_r:haproxy_unit_file_t:s0 tclass=service exe="/usr/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
  3. type=USER_AVC msg=audit(1489353198.557:2059): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='avc: denied { stop } for auid=n/a uid=0 gid=0 path="/usr/lib/systemd/system/keepalived.service" cmdline="systemctl stop keepalived" scontext=system_u:system_r:keepalived_t:s0 tcontext=system_u:object_r:keepalived_unit_file_t:s0 tclass=service exe="/usr/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
  4. type=USER_AVC msg=audit(1489353198.557:2060): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='avc: denied { status } for auid=n/a uid=0 gid=0 path="/usr/lib/systemd/system/keepalived.service" cmdline="systemctl stop keepalived" scontext=system_u:system_r:keepalived_t:s0 tcontext=system_u:object_r:keepalived_unit_file_t:s0 tclass=service exe="/usr/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'

  1. type=AVC msg=audit(1489354986.919:1591): avc: denied { getattr } for pid=7566 comm="check_haproxy.s" path="/usr/sbin/haproxy" dev="dm-0" ino=68172487 scontext=system_u:system_r:keepalived_t:s0 tcontext=system_u:object_r:haproxy_exec_t:s0 tclass=file
  2. type=SYSCALL msg=audit(1489354986.919:1591): arch=c000003e syscall=4 success=no exit=-13 a0=19cbd50 a1=7ffde08b8720 a2=7ffde08b8720 a3=11 items=0 ppid=7565 pid=7566 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="check_haproxy.s" exe="/usr/bin/bash" subj=system_u:system_r:keepalived_t:s0 key=(null)
       观察:systemctl 相关命令还是因为selinux运行不了
       
       2)根据1)决定对vrrp script脚本修改如下
  1. #!/bin/bash
  2. #判断haproxy是否已经启动,去除haproxy试图启动部分
  3. if [ `ps -C haproxy --no-header |wc -l` -eq 0 ] ; then
  4. #如果haproxy还是没有启动,则将keepalived停掉,这样VIP会自动漂移到另外一台haproxy
  5. pkill keepalived
  6. fi
       (启动顺序必须是haproxy先启动,负责keepalived如果先启动会自杀)
       也可设置自启
  1. systemctl enable haproxy
  2. systemctl enable keepalived
   
      3)使用文件中注释的信息完成 vrrp_script (下面的脚本对主从服务器的priority差值有严格要求)(最优方法)
  1. # 检测haproxy脚本
  2. vrrp_script chk_haproxy{
  3.    script "killall -0 haproxy" #killall (安装 yum install psmisc -y)
  4.    interval 2
  5.    weghit 2 #权值脚本成功时(0)等于priority+weghit #否则为priority
  6. }
HAproxy的负载均衡与keepalive+haproxy实现高可用 【代码】HAproxy的负载均衡与keepalive+haproxy实现高可用。 阅读详情

相关推荐

Keepalived+Haproxy 安装配置

确认并搭建CentOS + Keepalived + Haproxy架构,采用双活模式CentOS使用防火墙,仅开通必要端口,限制非法访问和病毒传播现每组负载均衡设置8个虚拟VIP,每个节点4个VIP,实现秒级切换每个VIP对应一组AP Server,Haproxy自动检测每个AP Server节点状态实现重启单独的HA节点和AP Server节点都能秒级自动切换手动维护每组AP Server时,不影响用户正常使用。

qq_18248817的博客 2390

haproxy admin_stats端口启动错误解决

/var/log/message里的错误消息大概如下: Feb 13 09:32:50 cluster-node2 haproxy-systemd-wrapper: [ALERT] 043/093250 (6538) : Starting proxy rabbitmq-cluster-management: cannot bind socket [192.168.22.30:15673] Fe...

weixin_30879833的博客 981

Linux 基于HAProxy+KeepAlived实现

高可用(HA-High Avaialbility) 广义上理解,可以认为高可用是系统设计的目标,而容灾是达到高可用这一目标的手段。 高可用HA(High Availability)是分布式系统架构设计中必须考虑的因素之一,它通常是指,通过设计减少系统不能提供服务的时间。 负载均衡(LB-Load Balance) 负载均衡用于解决系统流量分发问题。客户端的流量首先会到达负载均衡服务器,由负载均衡服务器通过一定的调度算法将流量分发到不同的应用服务器上面,同时负载均衡服务器也会对应用服务器做周期性的健康检查,

李姓门徒 1600

haproxy 无法启动,需要添加内核参数

安装好haproxy后,配置正确无法启动,看日志: Feb 13 09:32:50 cluster-node2 systemd: Started HAProxy Load Balancer. Feb 13 09:32:50 cluster-node2 haproxy-systemd-wrapper: [ALERT] 043/093250 (6538) : Starting proxy mysql-...

weixin_34279061的博客 2624

HAProxy + Keepalived 配置架构解析

离职后的交接是一件有意思的事,被交接的时候有多头大,交接给别人的时候就有多爽,哈哈哈哈哈,不多说了,接手工作的同事要来打我了(手动狗头保命.jpg)。 不过话说回来,交接工作本身真的是学习和提升的好机会,在之前一次次接手同事工作的时候,自己也得到了快速的成长,虽然比较痛苦,但也学到了很多之前没怎么接触过的技能;而当自己辞职把工作交接给同事,也是回顾总结,反省自我和共同提升的好机会。 回想工作的 5 年里,一个人前前后后接下了系统的后端代码、架构、部署,从对后端一知半解到能够独立设计开发功能

盛夏温暖流年 2733

HaProxy+keepalived+mycat集群高可用配置

部署图 集群部署图的理解: 1、keepalived和haproxy必须装在同一台机器上(如172.17.210.210.83机器上,keepalived和haproxy都要安装),keepalived负责为该服务器抢占vip(虚拟ip),抢占到vip后,对该主机的访问可以通过原来的ip(172.17.210.210.83)访问,也可以直接通过vip(172.17.210.210.103)

wdw1206的专栏 1万+

haproxy,nginx,keepalived综合运用

haproxy,nginx,keepalived综合运用

Drw_Dcm的博客 4754

K8S、keepalived、haproxy 高可用集群实战

K8S、keepalived、haproxy 高可用集群实战 环境:Centos7.6、2个CPU、8G内存以上配置 Master1:172.20.26.24 Master2:172.20.26.86 Master3:172.20.26.89 Node1: 172.20.26.104 VIP :172.20.26.201

lqcbj的博客 2807

HAproxy+keepalived实现高可用

timeout为前缀的关键字指定了一些关于请求、连接、响应的最大超时时间,单位默认为毫秒,也可以加入后缀s(秒),m(分钟),h(小时),d(天)来指定。option redispatch关键字表示当使用了cookie时,HAProxy将会将其请求的后端服务器信息插入到cookie中,以保证会话的持久性,如果后端的服务器服务不可用,但客户端的cookie是不会刷新的,设置此参数会将客户的请求强制定向到另外一个后端服务器上,以保证服务的正常。backend后端代理配置段定义一组后端服务器,同时设置代理名称。

weixin_67274256的博客 1895

5分钟快速搭建:使用ros1_bridge实现ROS2容器与ROS1主机的无缝通信

本文详细介绍了如何在5分钟内快速搭建基于ros1_bridge的通信方案,实现运行在Docker容器中的ROS2节点与宿主机ROS1系统的无缝数据交换。通过环境隔离、Docker容器化部署及选择性桥接配置,该方案能有效整合新旧系统,避免大规模代码重构,是机器人项目渐进式升级的实用策略。

weixin_29268637的博客 181

深空探测处理软件USGS-ISIS的下载安装

深空探测处理软件USGS-ISIS下载安装教程

qq_31721595的博客 3313

Keepalived 原理及配置(高可用)

本文详细讲解了keepalived的工作原理,日常的配置,每个模式的详细配置及验证。还结合lvs和haproxy实现高可用集群的搭建,每个实验都有详细的流程及结果测试。

a_2373179473的博客 4770

ZYNQ新手必看:5分钟搞定SD卡与QSPI Flash双启动模式配置(附常见问题排查)

本文为ZYNQ开发者提供了SD卡与QSPI Flash双启动模式的完整配置指南与深度排错方法。详细解析了从BootROM、FSBL到BOOT.bin的启动链条,并分步讲解了在Vivado/Vitis中的硬件配置、软件工程创建及BOOT.bin文件生成流程。针对SD卡格式化、文件放置以及QSPI Flash烧录中的常见陷阱(如版本差异、时钟配置)给出了具体解决方案和排查清单,帮助开发者快速实现可靠的产品启动与程序固化。

ll5678的博客 935

Keepalived和Haproxy

调度器的高可用vip地址主备之间的切换,主在工作时,vip地址值在主上,主停止工作,vip飘移到备服务器在主备的优先级不变的情况下,主恢复工作,vip会飘回到主服务器1、配优先级2、配vip地址和真实服务器3、主备的id要一致4、主备的id要区分keepalive是专门为lvs打造的,但是不是为lvs专门服务的keepalive也可以使用nginx,haproxy2、keepalive+nginx实现高可用实验客户端 192.168.100.13。

2401_84592402的博客 1653

当vCenter的证书过期、Root密码过期、Root密码遗忘同时发生时的解决方法与步骤

vCenter,强制修改root密码,修改SSO User密码,修复证书过期问题

OCTSJimmy的专栏 5563

Matlab实现POD本征正交分解数据降维模型

近年来,随着大数据时代的到来,各种复杂的工程问题产生了海量的高维数据,如何有效降维、提取数据中的关键信息成为了众多领域中的重要问题。在传统的数据降维方法中,PCTFA(主成分分析)是一种典型的统计方法,然而对于流体动力学等非线性问题,PCTFA在处理时可能失去部分物理意义,难以捕捉到系统的复杂性。在降维过程中,POD提取的主要特征通常是一组复杂的正交基函数,如何将这些结果有效地转化为直观且易于理解的物理意义,特别是在实际应用中,对该特征的理解和分析,依然是一个重要的课题。本项目的扩展性也得到了有效体现。

优质创作者: 人工智能技术领域 对于有一定基础的 MATLAB和Python带具体需求都可以详谈 MATLAB和Python可以提供代码调试服务加油 谢谢 你的鼓励是我前行的动力 谢谢支持 加油 谢谢 1217

haproxy+keepalived

负载均衡+高可用

weixin_44216558的博客 1334

使用cartographer纯定位替换amcl定位

经过实际使用,发现cartographer定位对于重定位的表现比amcl好。如果机器人的起始位置离原点较远,amcl很难自行重定位到正确的位置,只能手动修改初始位置。然而cartographer定位的表现则很好,在行驶一段距离或原地旋转一段时间后能够正确重定位。

XJ_75的博客 8313

keepalived原理(主从配置+haproxy)及配置文件详解

此文上接博文:http://blog.youkuaiyun.com/tantexian/article/details/50056199 下图描述了使用keepalived+Haproxy主从配置来达到能够针对前段流量进行负载均衡到多台后端web1、web2、web3、img1、img2.但是由于haproxy会存在单点故障问题,因此使用keepalived来实现对Haproxy单点问题的高可用

Better Me的博客 3万+

C# 上位机内存泄漏排查指南:3 个工具 + 4 个技巧,从 GC 频繁到稳定运行 720 小时

C# 上位机内存泄漏排查的核心是「先定位泄漏存在,再追溯引用根源,最后修复验证通过「Visual Studio 诊断工具(快速定位)+ dotMemory(深度分析)+ PerfView(生产监控)」三个工具的配合,结合「复现场景、排查静态成员+事件、检查非托管资源、GC 日志验证」四个技巧,可高效解决绝大多数泄漏问题。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 739

RK356x U-Boot研究所(命令篇)3.10 bidram与sysmem相关命令的作用

RK356x U-Boot研究所(命令篇)3.10 bidram与sysmem相关命令的作用

Systemcall名屋 624

Haproxy+keepalived负载均衡配置

Haproxy本文主要介绍Haproxy负载均衡的安装配置以及结合keepalived保证高可用,概要如下: -安装haproxy -配置haporxy -单台haproxy负载均衡配置 -安装keepalived -配置keepalived -haproxy主从配置 -haproxy主从切换测试 -haproxy配置文件详解Haproxy

doublexi 1万+

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

HAProxy + Keepalived 高可用集群

本文系统阐述了 HAProxy 与 Keepalived 构建高可用负载均衡集群的核心技术。HAProxy 通过七层流量管理(URL 路由、请求头过滤)和健康检查机制实现智能负载均衡,Keepalived 基于 VRRP 协议实现虚拟 IP(VIP)秒级漂移,确保服务连续性。通过主备架构配置,实现单点故障消除、流量均衡分配和服务自愈能力。

a_2373179473的博客 2216

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

配置keepalived+haproxy+nginx架构

配置keepalived+haproxy+nginx架构

qq_44659804的博客 2050

linux中,mycat+haproxy+keepalived

HAProxy是法国开发者威利塔罗(Willy Tarreau)在2000年使用C语言开发的一个开源软件,是一款具备高并发(一万以上)、高性能的TCP和HTTP负载均衡器,支持基于cookie的持久性,自动故障切换,支持正则表达式及web状态统计,目前最新TLS版本为2.2。haproxy配置完成,我们的需求是两个,所以要在配一个,过程省略,一样的步骤,配置好之后就要开始配置keepalived,继续看我们的效果图。进入页面时,登录,账号密码都是我们设置的admin,具体都在haproxy的配置里。

Cao_XinYang的博客 1356
上一篇: Kafka分区机制与代码示例
下一篇: 负载均衡之Haproxy配置详解(及httpd配置)
王树民
博客等级 码龄10年 912粉丝 560原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值