haproxy introduction
# ----------------------------------------------- ---------------------- #, Ltd. Free Join Settings # ------------------------ --------------------------------------------- , Ltd. Free Join # global log configuration, use the log keyword, specify 127. the 0.0 syslog service on the .1 in local0日志设备, logging level for the info log log 127.0 . 0.1 local3 # software working directory chroot / var / lib / HAProxy # of HAProxy pid storage path, the user starts the process must have permission to access this document the PidFile / usr / local / HAProxy / haproxy.pid # maximum number of connections, default 4000 maxconn 30000 # belongs to user user haproxy # Belonging group Group HAProxy # running as a daemon HAProxy daemon # Turn ON stats UNIX Socket # stats Socket / var / lib / HAProxy / stats Socket Path # # ---------------- -------------------------------------------------- --- # Defaults that the Common at The All ' the listen ' and ' backend ' Sections by Will # use IF not Designated in Their Block # ----------------------- ---------------------------------------------- Defaults the MODE HTTP # the default mode mode {tcp | HTTP | Health}, tcp 4 layers, http seven layers, health will only return the OK log , Ltd. Free Join # using logs globally defined to enable logging of HTTP requests option httplog #, haproxy default logging is not recorded HTTP request logs option dontlognull # log does not record the health check option http -server- after each finished close # http request to close the active channel # If the back-end server need to get real client ip parameters need to be configured, you can get the client ip from Http Header in option the except forwardfor 127.0 . 0.0 / 8 the Option redispatch # serverId corresponding server hang after forced directed to other healthy server retries 3 # 3 times the connection fails considers service is not available, can also be set back by timeout HTTP -request 10s # http request time a timeout queue 1m # request queue timeout period timeout connect 10s # connection timeout timeout client 1m # client connection timeout timeout server 1m # of the server timeout HTTP timeout -keep-Alive # 10s-Keep-set HTTP Alive timeout detection timeout timeout check 10s # The maxconn 3000 # maximum connection number # ------------------------------------- -------------------------------- # Which proxys to main frontend at The backends # --------- -------------------------------------------------- ---------- # front-end configuration frontend main *: 80 acl url_static path_beg -i /static /images /javascript /stylesheets acl url_static path_end -i .jpg .gif .png .css .js use_backend static if url_static default_backend servers #--------------------------------------------------------------------- # static backend for serving up images, stylesheets and such #--------------------------------------------------------------------- # 后台静态文件服务配置 backend static balance roundrobin server static1 192.168 . 6.100 : 10001 the Check Inter 2000 Fall 3 weight 50 Server static2 192.168 . 6.110 : 10001 the Check Inter 2000 Fall 3 weight 50 # ----------------------- ---------------------------------------------- # round Robin Balancing Various at The backends the BETWEEN # --------------------------------------------- ------------------------ # background service configuration backend Servers Balance the RoundRobin # add cookie configuration, you will be directed to a client before their post-served end server, and that is a back-end server to keep in touch, to prevent the login authentication failure INSERT nocache app_cook the cookie Server app1 192.168 . 6.100 : 10001 the Check Inter 2000 Fall 3 weight 50 the cookie server1 Server app2 192.168 . 6.110 : 10001 the Check Inter 2000 Fall 3 weight 50 the cookie server2 # HAProxy status monitoring service configuration the listen stats # Bind port the bind * : 8080 the MODE HTTP # stats enable # access address: 192.168 . 6.100 : 8080/ web and 192.168 . 6.110: 8080 / Web stats uri / Web stats realm, Ltd. Free Join \ statistics # administrator account stats auth hapadmin: 1qazse $ # 2
global
daemon
nbproc 1
pidfile /var/run/haproxy.pid
defaults
mode tcp #默认的模式mode { tcp|http|health },tcp是4层,http是7层,health只会返回OK
retries 3 #两次连接失败就认为是服务器不可用,也可以通过后面设置
option redispatch #当serverId对应的服务器挂掉后,强制定向到其他健康的服务器
option abortonclose #当服务器负载很高的时候,自动结束掉当前队列处理比较久的链接
maxconn 4096 #默认的最大连接数 timeout connect 5000ms #连接超时 timeout client 30000ms #客户端超时 timeout server 30000ms #服务器超时 timeout check 2000 #=心跳检测超时 log global listen mysql_cluster bind 10.10.91.71:3306 mode tcp maxconn 4086 server node2 10.10.91.72:3306 server node3 10.10.91.75:3306
Introduction keepalived
# Master provisioning content: ! The Configuration File for keepalived global_defs { notification_email { [email protected] # incoming mail people can define multiple } notification_email_from [email protected] # sender, can disguise smtp_server 127.0 . 0.1 # E-mail server address smtp_connect_timeout 30 # connection time no_email_faults the router_id of the the WebMaster vrrp_skip_check_adv_addr vrrp_strict vrrp_garp_interval 0 vrrp_gna_interval 0 } vrrp_script chk_haproxy {# HAProxy monitoring service scripts script '/etc/keepalived/check_haproxy.sh ' interval The 2 weight 2 } vrrp_instance VI_1 {# vrrp_instance each virtual router is to define a state MASTER # is converted by the master state is the initial state of the state interface card NIC # Name name, such as eth0, according to their without modification virtual_router_id 100 ID # virtual route number, generally not greater than 255 priority 100 # priority, the larger the number, the higher the priority, than the second largest main advert_int . 1 Newsletter # initialization authentication {# authentication mechanism AUTH_TYPE the PASS AUTH_PASS 666 # password, make changes, to standby consistent } track_script { chk_haproxy } virtual ip address virtual_ipaddress {# Web services: vip, alternate virtual IP mentioned earlier. # <The IPADDR> / <the MASK> brd <the IPADDR> dev <STRING> scope <SCOPT> label <the LABEL> # 192.168 . 200.18 / 24 dev eth2 eth2 label: . 1 192.168 . 6.111 } notify_master ' /etc/keepalived/clean_arp.sh 192.168.6.111 ' }