1. 源码包下载及安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
root@iZ23tsilmb7Z:/usr/local/src# apt-get -y install make gcc
root@iZ23tsilmb7Z:/usr/local/src# wget http://fossies.org/linux/misc/haproxy-1.6.6.tar.gz
--2016-07-03 20:28:35--  http://fossies.org/linux/misc/haproxy-1.6.6.tar.gz
Resolving fossies.org (fossies.org)... 138.201.17.217
Connecting to fossies.org (fossies.org)|138.201.17.217|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1565046 (1.5M) [application/x-gzip]
Saving to: ‘haproxy-1.6.6.tar.gz’
 
100%[==============================================================>] 1,565,046    210KB/s   in 8.1s   
 
2016-07-03 20:28:44 (190 KB/s) - ‘haproxy-1.6.6.tar.gz’ saved [1565046/1565046]
 
root@iZ23tsilmb7Z:/usr/local/src# tar -zxvf haproxy-1.6.6.tar.gz
root@iZ23tsilmb7Z:/usr/local/src# cd haproxy-1.6.6
root@iZ23tsilmb7Z:/usr/local/src/haproxy-1.6.6# make TARGET=linux2628 PREFIX=/usr/local/haproxy
root@iZ23tsilmb7Z:/usr/local/src/haproxy-1.6.6# make install PREFIX=/usr/local/haproxy
 
//参数说明
TARGET=linux26
#使用uname -r查看内核,如:2.6.18-371.el5,此时该参数就为linux26
#kernel 大于2.6.28的用:TARGET=linux2628
PREFIX=/usr/local/haprpxy   #/usr/local/haprpxy为haprpxy安装路径

 2.配置启动脚本

1
2
 3
cp /usr/local/src/haproxy-1.6.3/examples/haproxy.init /etc/init.d/haproxy
chmod +x /etc/init.d/haproxy
useradd -r haproxy -s /sbin/nologin

如果是ubuntu系统需要/etc/init.d/functions为/lib/lsb/init-functins

注释/etc/sysconfig/network   [ ${NETWORKING} = "no" ] && exit 0

同时去除start 里面damon

 3.配置环境变量

1
2
echo 'PATH="/usr/local/haproxy/sbin:$PATH"' >> /etc/profile
source /etc/profile

 4.haproxy配置文件

1
2
3
4
mkdir /etc/haproxy
mkdir /var/lib/haproxy
cd /etc/haproxy/
vim haproxy.cfg

 5.启动脚本更改

1
2
vim /etc/init.d/haproxy
 35 BIN=/usr/sbin/$BASENAME   # 替换BIN=/usr/local/haproxy/sbin/$BASENAME

 6.配置haproxy日志

1
2
3
4
5
6
7
[root@localhost haproxy-1.6.3]# vim /etc/rsyslog.conf     #17,18是关于tcp行注释取消,#最后增加一行
 16 # Provides TCP syslog reception
 17 $ModLoad imtcp
 18 $InputTCPServerRun 514
  
local3.* /var/log/haproxy.log
[root@localhost haproxy-1.6.3]# /etc/init.d/rsyslog restart

7.haproxy.cfg配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# 全局配置,日志,运行安装路径,
global
        log 127.0.0.1 local3 info  # 日志存储到127.0.0.1,端口是514,
 
        chroot /var/lib/haproxy
        pidfile /var/run/haproxy.pid        #配置haproxy的sock文件,权限是600,等级是admin权限,超时2分钟
        stats socket /var/lib/haproxy/haproxy.sock mode 660 level admin
        stats timeout 2m
        user haproxy
        group haproxy
        daemon
 
# 默认配置
defaults
        log global
        mode http
        #option httplog         # 访问日志关闭
        option dontlognull      # 不记录空链接,如监控链接
        timeout connect 5000
        timeout client 50000
        timeout server 50000
        timeout check 10000
        maxconn 3000
 
# 状态监控页面
listen haproxy_status
        # 绑定地址,每5s自动刷新,隐藏版本,状态访问页面,认证账号,密码,条件满足进入管理界面
        bind 172.16.1.14:8888
        stats enable
        stats refresh 100s
        stats hide-version
        stats uri /haproxy-status
        stats realm "HAProxy/ static"
        stats auth admin:admin123
        stats admin if TRUE
        # 允许的网段,允许,拒绝
        #acl allow src 192.168.12.0/24
        #tcp-request content accept if allow
        #tcp-request content reject
 
# 1.匹配到www.pinhui001.com域名,跳转到www_backend
frontend ph_web
        bind 172.16.1.14:80
        acl www hdr_end(host) pinhui001.com        #ACL规则定义的方式有hdr_reg(host)、hdr_dom(host)、hdr_beg(host)、url_sub、url_dir、path_beg、path_end等,-i表示不匹配大小写
        acl www hdr_end(host) www.pinhui001.com
        use_backend www_backend if www
 
# 2.匹配到目录static,images及jpg,png结尾的跳转到
frontend ph_static
        bind 172.16.1.14:1802
        acl url_static path_beg -i /static /images /stylesheets
        #acl url_static path_end -i .jpg .gif .png .css .js
        acl static_reg url_reg /*.(css|jpg|js|jpeg|gif)$
        use_backend static_backend if url_static
 
# test
frontend test_web
        bind 172.16.1.14:8899
        acl test hdr_beg(host) -i test.pinhui001.cc
        use_backend test_backend if test
 
backend test_backend
        mode http
        balance roundrobin
        option forwardfor header X-REAL-IP
        option httpchk GET /iisstart.htm HTTP/1.1\r\nHost:172.16.1.25:80
        server web-node1 172.16.1.25:80 check inter 2000 rise 3 fall 3 weight 1
 
# 1.
backend www_backend
        # 随机,2秒检测,2次成功认为服务可用,3次失败认为服务不可用,权重为1
        # option httpchk GET /index.html
        balance roundrobin
        option forwardfor header X-REAL-IP
        server web-node1 172.16.1.25:18201 check inter 2000 rise 3 fall 3 weight 1
        server web-node3 192.168.2.16:80 check inter 2000 rise 3 fall 3 weight 1
 
# 2.
backend static_backend
        balance roundrobin
        option forwardfor header X-REAL-IP
        # cookie中插入srv字串防止登录信息丢失
        cookie srv insert nocache
        server static01 172.16.1.110:80 check inter 2000 rise 2 fall 3 weight 1
        server static02 172.16.1.111:80 check inter 2000 rise 2 fall 3 weight 1

 8.动态管理haproxy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 配置文件全局加入2行
vim /etc/haproxy/haproxy.cfg
global
   stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin
   stats timeout 2m
 
# 安装socker
yum list | grep socat
yum install -y socat
 
# 查看支持的命令
[root@ha-node01 haproxy]# echo "help" | socat stdio /var/lib/haproxy/haproxy.sock
[root@ha-node01 haproxy]# echo "show info" | socat stdio /var/lib/haproxy/haproxy.sock  # 查看状态信息
 
# 关闭某台主机,开启
cho "disable server test_backend/web-node1" | socat stdio /var/lib/haproxy/haproxy.sock
echo "enable server test_backend/web-node1" | socat stdio /var/lib/haproxy/haproxy.sock

 9.haproxy性能调优

1
2
3
4
5
6
[root@ha-node01 haproxy]# cat /proc/sys/net/ipv4/ip_local_port_range  # 端口范围调大
32768   61000  
[root@ha-node01 haproxy]# cat /proc/sys/net/ipv4/tcp_tw_reuse         # 设置1
1             
[root@ha-node01 haproxy]# cat /proc/sys/net/ipv4/tcp_fin_timeout      # 时间调短
30         

HAproxy-1.6.X 安装部署的更多相关文章

  1. redis cluster安装部署(测试环境)

    redis 应用于web前端,做缓存和数据存取的速度是挺可观的,最近看了一些资料,手痒了,就弄了一个测试环境,两台方案,试用一下. ##Redis 集群部署## 一,方案调研: 参考博客: http: ...

  2. CentOS7.4下安装部署HAProxy高可用群集

    目录第一部分 实验环境第二部分 搭建配置web服务器第三部分 安装配置haproxy服务器第四部分 测试验证第五部分 haproxy配置相关详细解释 第一部分 实验环境1.一台harpoxy调度服务器 ...

  3. openstack pike 集群高可用 安装 部署 目录汇总

    # openstack pike 集群高可用 安装部署#安装环境 centos 7 史上最详细的openstack pike版 部署文档欢迎经验分享,欢迎笔记分享欢迎留言,或加QQ群663105353 ...

  4. Mariadb Galera Cluster 群集 安装部署

    #Mariadb Galera Cluster 群集 安装部署 openstack pike 部署  目录汇总 http://www.cnblogs.com/elvi/p/7613861.html # ...

  5. Haproxy+Keepalived高可用环境部署梳理(主主和主从模式)

    Nginx.LVS.HAProxy 是目前使用最广泛的三种负载均衡软件,本人都在多个项目中实施过,通常会结合Keepalive做健康检查,实现故障转移的高可用功能. 1)在四层(tcp)实现负载均衡的 ...

  6. kubernetes 1.9 安装部署

    参考地址:https://github.com/gjmzj/kubeasz 引言 提供快速部署高可用k8s集群的工具,基于二进制方式部署和利用ansible-playbook实现自动化,既提供一键安装 ...

  7. 基于Containerd安装部署高可用Kubernetes集群

    转载自:https://blog.weiyigeek.top/2021/7-30-623.html 简述 Kubernetes(后续简称k8s)是 Google(2014年6月) 开源的一个容器编排引 ...

  8. Oracle安装部署,版本升级,应用补丁快速参考

    一.Oracle安装部署 1.1 单机环境 1.2 Oracle RAC环境 1.3 Oracle DataGuard环境 1.4 主机双机 1.5 客户端部署 二.Oracle版本升级 2.1 单机 ...

  9. KVM安装部署

    KVM安装部署 公司开始部署KVM,KVM的全称是kernel base virtual machine,对KVM虚拟化技术研究了一段时间, KVM是基于硬件的完全虚拟化,跟vmware.xen.hy ...

  10. Linux平台oracle 11g单实例 + ASM存储 安装部署 快速参考

    操作环境:Citrix虚拟化环境中申请一个Linux6.4主机(模板)目标:创建单机11g + ASM存储 数据库 1. 主机准备 2. 创建ORACLE 用户和组成员 3. 创建以下目录并赋予对应权 ...

随机推荐

  1. python 笔记 2017

    26.反斜杠用处,断言一些字符包含特殊字符的 if "<h3 class=\"entH 22222setH\">刷新成功</h3>" i ...

  2. 【Gearman学习笔记】分布式处理入门

    1.首先,确保你已经安装了gearmand环境并且语言绑定(language binding)已经生效. 2.涉及到的各个部分: ServerThe server, gearmand, will co ...

  3. oracle 用函数返回对象集合

    1.先要声明全局type:并且,字段变量类型要为object,不能为record: (1)CREATE OR REPLACE TYPE "DDD_BY_DEPT_STATISTISC&quo ...

  4. 原生态的javascript的n种技巧(我从别人的博客中拷贝过来的,方便以后查阅)

    1.原生JavaScript实现字符串长度截取 function cutstr(str, len) { var temp; var icount = 0; var patrn = /[^\x00-\x ...

  5. Delphi7到Delphi XE2的升级历程

    1.PChar 转为PAnsiChar; 2.第三方控件的安装 SuiPack不能直接点击InStall.exe安装,需要打开DPK文件安装: SuiPack安装之后程序编译会报错,resHandle ...

  6. hive-hbase-handler方式导入hive表数据到hbase表中

    Hive与HBase的整合功能的实现是利用两者本身对外的API接口互相进行通信,相互通信主要是依靠hive-hbase-handler.jar工具类 : hive-hbase-handler.jar在 ...

  7. 那些你希望N年前就掌握的命令

    这篇文章转载自黑客志,短短的一篇文章我找到了3个对我非常有用的技巧,在信息爆炸的今天,简直就跟捡宝似的,希望这些命令对你也有帮助. 有人在Reddit上发帖询问:有没有哪条命令是你希望自己在几年前就掌 ...

  8. .CBB 文件 如何打开

    CCB Visual Basic动态按钮配置文件 用SQL server,导入时选择 access,打开后即可.

  9. PHP Token(令牌)设计 避免重复提交

    设计目标: 避免重复提交数据. 检查来路,是否是外部提交 匹配要执行的动作(如果有多个逻辑在同一个页面实现,比如新增,删除,修改放到一个PHP文件里操作) 这里所说的token是在页面显示的时候,写到 ...

  10. 1.urlencoder和urldecoder的使用

    今天传url的时候乱码了.先说情形,url中有searchText=中文的情形,后台new String(searchText.getBytes(ISO-8859-1),"gbk" ...