• Linux安装haproxy


    一、安装Haproxy

    1、卸载Haproxy

    1. # 卸载
    2. yum remove haproxy
    3. # 查找残留haproxy配置
    4. find / -name "haproxy"
    5. # 删除残留配置
    6. rm -rf /var/lib/haproxy
    7. rm -rf /etc/haproxy

    2、安装Haproxy

    1. yum install haproxy
    2. haproxy -v
    3. HA-Proxy version 1.5.18 2016/05/10
    4. Copyright 2000-2016 Willy Tarreau
    5.   
    6. systemctl start haproxy
    7. ● haproxy.service - HAProxy Load Balancer
    8. Loaded: loaded (/usr/lib/systemd/system/haproxy.service; disabled; vendor preset: disabled)
    9. Active: active (running) since Wed 2022-10-19 17:53:35 CST; 5s ago
    10. Main PID: 29537 (haproxy-systemd)
    11. Tasks: 3
    12. Memory: 2.6M
    13. CGroup: /system.slice/haproxy.service
    14. ├─29537 /usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
    15. ├─29538 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
    16. └─29539 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
    17. Oct 19 17:53:35 aswtechlabpoc92 systemd[1]: Started HAProxy Load Balancer.
    18. Oct 19 17:53:35 aswtechlabpoc92 haproxy-systemd-wrapper[29537]: haproxy-systemd-wrapper: executing /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg...id -Ds
    19. Hint: Some lines were ellipsized, use -l to show in full.
    20. ps -ef | grep haproxy | grep -v grep
    21. root 29537 1 0 17:53 ? 00:00:00 /usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
    22. haproxy 29538 29537 0 17:53 ? 00:00:00 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
    23. haproxy 29539 29538 0 17:53 ? 00:00:00 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds

    二、开启Haproxy后端管理界面

    1. [root@aswtechlabpoc92 haproxy]# cat haproxy.cfg
    2. #---------------------------------------------------------------------
    3. # Example configuration for a possible web application. See the
    4. # full configuration options online.
    5. #
    6. # http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
    7. #
    8. #---------------------------------------------------------------------
    9. #---------------------------------------------------------------------
    10. # Global settings
    11. #---------------------------------------------------------------------
    12. global
    13. # to have these messages end up in /var/log/haproxy.log you will
    14. # need to:
    15. #
    16. # 1) configure syslog to accept network log events. This is done
    17. # by adding the '-r' option to the SYSLOGD_OPTIONS in
    18. # /etc/sysconfig/syslog
    19. #
    20. # 2) configure local2 events to go to the /var/log/haproxy.log
    21. # file. A line like the following can be added to
    22. # /etc/sysconfig/syslog
    23. #
    24. # local2.* /var/log/haproxy.log
    25. #
    26. log 127.0.0.1 local2
    27. chroot /var/lib/haproxy
    28. pidfile /var/run/haproxy.pid
    29. maxconn 4000
    30. user haproxy
    31. group haproxy
    32. daemon
    33. # turn on stats unix socket
    34. stats socket /var/lib/haproxy/stats
    35. #---------------------------------------------------------------------
    36. # common defaults that all the 'listen' and 'backend' sections will
    37. # use if not designated in their block
    38. #---------------------------------------------------------------------
    39. defaults
    40. mode http
    41. log global
    42. option httplog
    43. option dontlognull
    44. option http-server-close
    45. option forwardfor except 127.0.0.0/8
    46. option redispatch
    47. retries 3
    48. timeout http-request 10s
    49. timeout queue 1m
    50. timeout connect 10s
    51. timeout client 1m
    52. timeout server 1m
    53. timeout http-keep-alive 10s
    54. timeout check 10s
    55. maxconn 3000
    56. #---------------------------------------------------------------------
    57. # main frontend which proxys to the backends
    58. #---------------------------------------------------------------------
    59. frontend main *:5000
    60. acl url_static path_beg -i /static /images /javascript /stylesheets
    61. acl url_static path_end -i .jpg .gif .png .css .js
    62. use_backend static if url_static
    63. default_backend app
    64. #---------------------------------------------------------------------
    65. # static backend for serving up images, stylesheets and such
    66. #---------------------------------------------------------------------
    67. backend static
    68. balance roundrobin
    69. server static 127.0.0.1:4331 check
    70. #---------------------------------------------------------------------
    71. # round robin balancing between the various backends
    72. #---------------------------------------------------------------------
    73. backend app
    74. balance roundrobin
    75. server app1 127.0.0.1:5001 check
    76. server app2 127.0.0.1:5002 check
    77. server app3 127.0.0.1:5003 check
    78. server app4 127.0.0.1:5004 check
    79. # 追加-后台管理的配置
    80. frontend admin_stats
    81. #后台管理端口7777
    82. bind :7777
    83. mode http
    84. stats enable
    85. option httplog
    86. maxconn 10
    87. stats refresh 30s
    88. #地址ip:端口/admin
    89. stats uri /admin
    90. #用户名:admin 密码:123456
    91. stats auth admin:123456
    92. stats hide-version
    93. stats admin if TRUE

     访问:http://10.95.35.92:7777/admin

    三、配置代理

    1、MySQL代理

    1. listen cc_mysql_18066
    2. maxconn 8000
    3. mode tcp
    4. bind 0.0.0.0:18066
    5. server s1 10.95.35.187:3306 check port 3306 rise 3 fall 5

    2、配置DBLE代理

    1. listen mysql_dble
    2. balance static-rr
    3. maxconn 12000
    4. bind 0.0.0.0:18066
    5. mode tcp
    6. server 37_8066 10.95.34.37:8066 check port 8066 rise 3 fall 5
    7. server 38_8066 10.95.34.38:8066 check port 8066 rise 3 fall 5
    8. server 39_8066 10.95.34.39:8066 check port 8066 rise 3 fall 5
    9. listen mysql_dble_admin
    10. balance static-rr
    11. maxconn 6000
    12. bind 0.0.0.0:19066
    13. mode tcp
    14. server 37_9066 10.95.34.37:9066 check port 9066 rise 3 fall 5
    15. server 38_9066 10.95.34.38:9066 check port 9066 rise 3 fall 5
    16. server 39_9066 10.95.34.39:9066 check port 9066 rise 3 fall 5

    3、观测

     

  • 相关阅读:
    C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.5 数组和指针的其他区别
    阿里云——OpenAPI使用——短信服务
    Java集合01:Collection集合,List子集合,ArrayList实现类和LinkedList实现类
    故障分析 | MySQL锁等待超时一例分析
    02-SpringBoot基础
    报告解读:云原生落地传统行业的必然性
    建议使用includes()代替indexOf()
    AJAX的使用,搭建web服务器,AJAX响应消息类型,JSON
    leetcode做题笔记200. 岛屿数量
    第3章 Linux网络编程 01. 网络结构模式
  • 原文地址:https://blog.csdn.net/summer_fish/article/details/127413054