多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# CentOS7环境 ## rpm安装 ## 源码编译安装 ## 一键脚本安装 ## 自定义打包 # Debian8环境 ## apt-get 安装 ``` apt-get update apt-get install haproxy dpkg -L haproxy ``` ## 源码编译安装 ``` #创建软件目录 mkdir -p /root/tools/ha #进入目录下载软件 cd /root/tools/ha && wget http://www.haproxy.org/download/1.5/src/haproxy-1.5.18.tar.gz #设置内核转发 echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf sysctl -p #创建用户 useradd haproxy -s /sbin/nologin -M #安装依赖 apt-get update apt-get install -y gcc make libpcre3 libpcre3-dev libssl-dev #解压编译安装 cd /root/tools/ha && tar zxf haproxy-1.5.18.tar.gz cd haproxy-1.5.18 make TARGET=linux26 ARCH=x86_64 USE_OPENSSL=1 ADDLIB=-lz PREFIX=/usr/local/haproxy install #创建命令软链接 ln -s /usr/local/haproxy/sbin/haproxy /usr/sbin/ #创建配置目录 mkdir -p /usr/local/haproxy/{run,conf,logs,conf} #创建启动文件 cat /etc/init.d/haproxy #!/bin/bash # # chkconfig: 35 85 15 # description: haproxy server control file set -e PROGDIR=/usr/local/haproxy PROGNAME=haproxy DAEMON=$PROGDIR/sbin/$PROGNAME CONFIG=$PROGDIR/conf/$PROGNAME.conf PIDFILE=$PROGDIR/run/$PROGNAME.pid DESC="HAProxy daemon" SCRIPTNAME=/etc/init.d/$PROGNAME E_NO_PERM=65 # Gracefully exit if the package has been removed. test -x $DAEMON || exit $E_NO_PERM start() { echo -n "Starting $DESC:$PROGNAME" $DAEMON -f $CONFIG echo "." } stop() { echo -n "Stopping $DESC:$PROGNAME" haproxy_pid=$(cat $PIDFILE) kill $haproxy_pid echo "." } restart() { echo -n "Restarting $DESC: $PROGNAME" $DAEMON -f $CONFIG -p $PIDFILE -st $(cat $PIDFILE) echo "." } case "$1" in start) start ;; stop) stop ;; restart) restart ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2 exit 1 esac #赋予启动脚本执行权限 chmod +x /etc/init.d/haproxy #创建简单的配置文件 cat /usr/local/haproxy/conf/haproxy.conf global maxconn 100000 #chroot /var/lib/haproxy user haproxy group haproxy daemon nbproc 1 pidfile /usr/local/haproxy/run/haproxy.pid log 127.0.0.1 local3 info defaults option http-keep-alive maxconn 100000 mode http timeout connect 5000ms timeout client 50000ms timeout server 50000ms listen stats mode http bind 0.0.0.0:8888 stats enable stats uri /haproxy-status stats auth haproxy:haproxy #打开日志记录功能 #配置日志的位置 cat /etc/rsyslog.d/haproxy.conf $ModLoad imudp $UDPServerRun 514 local0.* /usr/local/haproxy/logs/haproxy.log &~ #重启rsyslog service rsyslog restart #启动测试 /etc/init.d/haproxy start #查看进程 ps -ef|grep haproxy ``` ## 一键脚本安装 ## 自定义打包