zoukankan      html  css  js  c++  java
  • HAProxy-1.8.x版本源码编译

     源码编译HAProxy:  

     官网下载HAProxy包,并解压包,切换到haproxy包目录下

    [root@centos17haproxy-1.8.20]#tar xvf haproxy-1.8.20.tar.gz && cd haproxy-1.8.20
    

     安装相关依赖包

    [root@centos17haproxy-1.8.20]#yum install gcc gcc-c++ glibc glibc-devel pcrepcre-devel openssl openssl-devel systemd-devel net-tools vim iotopbczip unzip zlib-devellrzsztree screen lsof tcpdump wget ntpdate
    

      开始编译

    [root@centos17haproxy-1.8.20]#make ARCH=x86_64 TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 USE_CPU_AFFINITY=1 PREFIX=/usr/local/haproxy
    

      指定安装路径

    [root@centos17haproxy-1.8.20]#make install PREFIX=/usr/local/haproxy
    

      将可执行程序haproxy复制/usr/sbin/目录下

    [root@centos17haproxy-1.8.20]#cp haproxy  /usr/sbin/
    

     创建haproxy启动脚本 vim  /usr/lib/systemd/system/haproxy.service

    [Unit]
    Description=HAProxy Load Balancer
    After=syslog.target network.target
    
    [Service]
    ExecStartPre=/usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg   -c -q
    ExecStart=/usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg   -p /run/haproxy.pid
    ExecReload=/bin/kill -USR2 $MAINPID
    
    [Install]
    WantedBy=multi-user.target
    

     创建启动脚本目录

    [root@centos_17haproxy]#mkdir /etc/haproxy

    创建haproxy服务启动目录及基本的配置文件

    [root@centos_17haproxy]#vim /etc/haproxy/haproxy.cfg 
    global
    maxconn 100000
    chroot /usr/local/haproxy
    #stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin
    user haproxy
    group haproxy
    daemon
    nbproc 2   绑定两个cpu就开启下面两个,绑定四个就开启四个
    cpu-map 1 0
    cpu-map 2 1
    #cpu-map 3 2
    #cpu-map 4 3
    pidfile /usr/local/haproxy/run/haproxy.pid
    log 127.0.0.1 local3 info
    
    defaults
    option http-keep-alive
    option  forwardfor
    maxconn 100000
    mode http
    timeout connect 300000ms
    timeout client  300000ms
    timeout server  300000ms
    
    listen stats
     mode http
     bind 0.0.0.0:9999
     stats enable
     log global
     stats uri     /haproxy-status
     stats auth    haadmin:q1w2e3r4ys
    
    listen  web_port
     bind 0.0.0.0:80
     mode http
     log global
     server web1  127.0.0.1:8080  check inter 3000 fall 2 rise 5
    

     创建一个haproxy用户,并设置为系统不能登录的shell类型

    [root@centos_17haproxy]#useradd -s /sbin/nologin haproxy

     启动haproxy服务

    [root@centos_17haproxy]#systemctl start haproxy
    

     查看haproxy启动的线程数

    [root@centos_17haproxy]#ps -ef |grep haproxy  可以看到此时用户名是nobody启动双线程,并都属于一个父进程
    root 13270 1 0 21:59 ? 00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
    haproxy 13272 13270 0 21:59 ? 00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
    haproxy 13273 13270 0 21:59 ? 00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
    root 13278 12621 0 21:59 pts/0 00:00:00 grep --color=auto haproxy
  • 相关阅读:
    java监控Linux磁盘空间的使用情况
    报道篇
    标签详解
    selectors模块
    [Python 多线程] RLock可重入锁
    Mysql中索引的 创建,查看,删除,修改
    openpyxl模块的使用
    Oracle中row_number()、rank()、dense_rank() 的区别
    python面试题
    sql 用Group by分组后,取每组的前几条记录
  • 原文地址:https://www.cnblogs.com/struggle-1216/p/12078430.html
Copyright © 2011-2022 走看看