前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HAproxy+Keepalived高可用负载均衡部署

HAproxy+Keepalived高可用负载均衡部署

作者头像
星哥玩云
发布2022-06-29 18:51:04
7500
发布2022-06-29 18:51:04
举报
文章被收录于专栏:开源部署

HAproxy+Keepalived高可用负载均衡部署

一、安装haproxy软件 wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.22.tar.gz tar zxvf haproxy-1.4.22.tar.gz cd haproxy-1.4.22 make TARGET=linux26 PREFIX=/usr/local/haproxy make install PREFIX=/usr/local/haproxy cd /usr/local/haproxy mkdir conf cd conf

二、在/usr/local/haproxy/conf/目录下创建配置文件(haproxy.cfg) global         maxconn 20480         chroot /usr/local/haproxy         uid 99         gid 99         daemon         quiet         nbproc 1         stats socket /usr/local/haproxy/haproxy.stat mode 666         log    127.0.0.1 local3         pidfile  /usr/local/haproxy/haproxy.pid         ulimit-n 65535 defaults         log    global         mode    http         maxconn 20480         #option  httplog clf         option  httplog         option  dontlognull         option httpclose         option abortonclose         option redispatch         retries 3       monitor-uri /site_status          contimeout      5000         clitimeout      50000         srvtimeout      50000 frontend WEB-BANMA-cluster          bind *:80          default_backend web_pool backend web_pool          balance source #      balance leastconn            cookie  SERVERID         option forwardfor         option  httpchk GET /check.html         server  app1_1 192.168.10.15:80  cookie app1inst1 check inter 2000 rise 2 fall 5 weight 3         server  app1_2 192.168.10.16:80  cookie app1inst2 check inter 2000 rise 2 fall 5 weight 6         stats refresh 5s         stats uri /status         stats realm Haproxy\ statistics         stats auth admin:admin123         stats admin if TRUE

三、如何给haproxy添加日志记录 ①、如果是CentOS6.0以下版本配置 一、 vi /etc/syslog.conf local3.*    /var/log/haproxy.log 二、vi /etc/sysconfig/syslog SYSLOGD_OPTIONS="-m 0" 改成 SYSLOGD_OPTIONS="-r -m 0" #enables logging from remote machines 三、重启动 /etc/init.d/syslog restart

②、Centos6.0或centos6.0以上版本

一、配置日志 vi /etc/rsyslog.conf(去掉下面两行前的注释,一定要去掉,否则不记录日志) ModLoad imudp.so UDPServerRun 514 ##添加日志记录 local3.*        /var/log/haproxy.log(添加haproxy日志记录文件)

二、重启动服务 /etc/init.d/rsyslog restart

四、启动haproxy,进行检查,并查看日志 /usr/local/haproxy/sbin/haporxy -f /usr/local/haproxy/conf/haproxy.cfg

####################################################################################### 一、keepalived安装(主备机器安装方法一样) wget http://rpm5.org/files/popt/popt-1.16.tar.gz tar zxvf popt-1.16.tar.gz cd popt-1.16 ./configure make && make install wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz tar zxvf keepalived-1.2.7.tar.gz cd keepalived-1.2.7 ./configure --prefix=/usr/local/keepalived make && make install

二、初始化脚本 cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/keepalived  cp /usr/local/keepalived/sbin/keepalived /usr/sbin/  cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/  mkdir -p /etc/keepalived/  ln -s  /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf  chmod +x /etc/init.d/keepalived

三、主机器配置文件(vi /etc/keepalived/keepalived.conf ),备机器只要(修改有注释地方即可) ! Configuration File for keepalived global_defs { router_id LVS_DEVEL } vrrp_script chk_http_port { script "/usr/local/keepalived/check_haproxy.sh" interval 2 weight 2 } vrrp_instance VI_1 {         state MASTER  (备机,改MASTER为BACKUP)         interface eth0         virtual_router_id 51         priority 150  (备机,改150为149)         advert_int 1         authentication {         auth_type PASS         auth_pass 1111         }         track_script {                 chk_http_port         }         virtual_ipaddress {         10.1.1.60         } }

四、检测haproxy状态的文件 status=$(ps aux|grep haproxy | grep -v grep | grep -v bash | wc -l) if [ "${status}" = "0" ]; then   /etc/init.d/haproxy start   status2=$(ps aux|grep haproxy | grep -v grep | grep -v bash |wc -l)   if [ "${status2}" = "0"  ]; then       /etc/init.d/keepalived stop   fi fi

五、启动keepalived /etc/init.d/keepalived start

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
负载均衡
负载均衡(Cloud Load Balancer,CLB)提供安全快捷的四七层流量分发服务,访问流量经由 CLB 可以自动分配到多台后端服务器上,扩展系统的服务能力并消除单点故障。轻松应对大流量访问场景。 网关负载均衡(Gateway Load Balancer,GWLB)是运行在网络层的负载均衡。通过 GWLB 可以帮助客户部署、扩展和管理第三方虚拟设备,操作简单,安全性强。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档