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的博客 2399

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

HAProxy + Keepalived 配置架构解析

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

盛夏温暖流年 2735

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+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万+

组合导航、惯导、GNSS、INS、IMU的区别

‌:惯性导航系统(INS)是一种利用安装在运载体上的陀螺仪和加速度计来测定运载体位置的系统。它通过测量物体的加速度和角速度,结合算法计算出物体的位置、速度和姿态‌12。‌。

wynn1123的博客 8125

haproxy,nginx,keepalived综合运用

haproxy,nginx,keepalived综合运用

Drw_Dcm的博客 4756

基于STM32的RS485土壤氮磷钾与PH传感器数据采集与OLED显示实战(附完整代码)

本文详细介绍了基于STM32单片机通过RS485协议采集土壤氮磷钾与PH传感器数据的实战项目。涵盖硬件选型、连接方法、Modbus-RTU通信协议解析、STM32程序实现及OLED显示,提供完整代码和调试技巧,适用于农业物联网环境监测系统。

kotlin6android的博客 352

Linux 基于HAProxy+KeepAlived实现

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

李姓门徒 1600

EMS案例:BMS传导发射超标整改案例

BMS作为新能源汽车的关键部件,其EMC性能直接影响整车的安全性和可靠性。本文通过一个实际的传导发射整改案例,详细展示了从问题定位、分析到解决方案实施的全过程。希望这些经验能够为从事类似产品设计的工程师提供有价值的参考,在未来的产品开发中避免类似问题,设计出更加可靠、稳定的BMS产品。EMC设计是一门结合理论与实践的艺术,只有通过不断积累经验、深入理解电磁场理论,并紧密结合实际应用场景,才能在复杂的电磁环境中设计出鲁棒性强的电子产品。

m0_56451176的博客 282

【libnice】meson + vs2022,生成win32工程

libnice

突围 958

HAproxy+keepalived实现高可用

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

weixin_67274256的博客 1898

RK3588与FocalTech触摸屏代码适配全解析:从原理到实战

摘要:本文详细介绍了瑞芯微RK3588处理器与FocalTech触摸屏的适配过程,包括硬件特性、驱动加载、设备树配置和常见问题解决方案。RK3588作为8nm工艺的高性能处理器,具备强大的计算能力和丰富的接口资源;FocalTech触摸屏则采用电容式技术,支持I2C/SPI接口。适配关键步骤包括驱动程序加载、硬件连接检查、设备树配置和内核版本兼容性处理,并提供了代码示例和问题排查方法。随着嵌入式设备智能化发展,该适配技术将持续优化,为智能交互提供更优解决方案。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 284

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的博客 2809

Android 13.0 双屏时触摸失效问题排查与修复

摘要:本文记录了RK3588 Android12开发板上主屏触摸失效问题的排查与解决过程。通过分析发现,USB触摸设备被错误关联到辅屏(displayId=3)而非主屏(displayId=0)。解决方案是修改TouchInputMapper.cpp,强制触摸设备使用INTERNAL viewport(主屏),并保持设备在viewport不活跃时仍启用。该修改涉及约40行代码,有效解决了多显示器环境下触摸设备错误映射的问题,同时提供了详细的调试方法和注意事项。

ip0417的博客 362

数字电路逻辑与设计实验一 门电路逻辑功能及测试

(1)选二输入四异或门电路 74LS86,按图 1-8 接线,输入端 1、2、4、5 接逻辑开 关(S1~S4),输出端 A、B、Y 接电平显示发光二极管.用六反相器(非门)按图 1-11 接线,输入 80KHz 连续脉冲,用双踪示波器测输入, 输出相位差,计算每个门的平均传输延迟时间的 tpd 值。测试不同的输入组合:对门电路进行全面的测试,尝试不同的输入组合,包括各种可能的逻辑状态。检查门电路的输入:确认门电路的输入是否正确,并且输入信号的电平符合门电路的规格要求。确保输入信号的稳定性和准确性。

欢迎交流学习心得 2万+

Keepalived 原理及配置(高可用)

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

a_2373179473的博客 4945

UI渲染顺序:合批为何被拆碎?

在 Hierarchy 中,避免出现:Image(列表1) → Text(列表1) → 特效 → Image(列表2) → Text(列表2)…若可行,在逻辑上把布局组织成“同类元素集中”:例如:列表行中,Image 集中、Text 集中;或者接受 Text 本身就拆出一批,关键是不要在 Text 中间再插入别的材质。现实中不一定能做到完美的“所有 Image 连在一起”,但你会有一个意识:同一 Canvas 内,如果你把不同材质的元素交错穿插,

本博客聚焦游戏开发技巧、创业实战心得及大学热门课程干货。这里既有技术深度,也有思维广度,无论你是开发者、创业者还是高校学子,都能在这里找到适合自己的成长之路! 92

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的博客 1655

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

haproxy+keepalived

负载均衡+高可用

weixin_44216558的博客 1335

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)及配置文件详解

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

Better Me的博客 3万+

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Haproxy+keepalived负载均衡配置

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

doublexi 1万+

HAProxy + Keepalived 高可用集群

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

a_2373179473的博客 2226

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

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址