2020-10-27
linux
00
请注意,本文编写于 1214 天前,最后修改于 1214 天前,其中某些信息可能已经过时。

目录

安装脚本

安装脚本

操作系统:Ubuntu 18.04.4 LTS 本机ip:192.168.0.221

bash
#!/bin/bash VERSION=2.2.0 VERSION_LUA=5.3.5 #编译lua apt install make gcc build-essential libssl-dev zlib1g-dev libpcre3 libpcre3-dev libsystemd-dev libreadline-dev iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev gcc openssh-server iotop unzip libreadline-dev libsystemd-dev -y cd /opt wget -P /opt http://www.lua.org/ftp/lua-${VERSION_LUA}.tar.gz tar xf lua-${VERSION_LUA}.tar.gz cd lua-$VERSION_LUA/src make linux #编译haproxy wget https://codeload.github.com/haproxy/haproxy/tar.gz/v${VERSION} tar xf v${VERSION} cd haproxy-${VERSION} make ARCH=x86_64 TARGET=linux-glibc USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 USE_CPU_AFFINITY=1 USE_LUA=1 LUA_INC=/opt/lua-${VERSION_LUA}/src LUA_LIB=/opt/lua-${VERSION_LUA}/src PREFIX=/usr/local/haproxy make install PREFIX=/usr/local/haproxy cp /usr/local/haproxy/sbin/haproxy /usr/sbin/ #准备相关文件 mkdir /var/lib/haproxy mkdir /etc/haproxy/ echo "global maxconn 100000 chroot /usr/local/haproxy stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin uid 99 gid 99 daemon #nbproc 4 #cpu-map 1 0 #cpu-map 2 1 #cpu-map 3 2 #cpu-map 4 3 pidfile /var/lib/haproxy/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:123456 listen web_port bind 192.168.0.228:80 mode http log global server 192.168.0.225 192.168.0.225:80 check inter 3000 fall 2 rise 5 server 192.168.0.226 192.168.0.226:80 check inter 3000 fall 2 rise 5 " > /etc/haproxy/haproxy.cfg #启动 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /var/lib/haproxy/haproxy.pid &

访问:http://192.168.0.221:9999/haproxy-status 账号:haadmin 密码:123456

负载均衡地址:192.168.0.228:80 node服务器地址:192.168.0.225:80 和 192.168.0.226:80

本文作者:mykernel

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!