脚本安装haproxy:
#!/bin/bash
echo -e '\033[5;32m本脚本用来安装haproxy \033[0m'
echo -e '\033[5;32m 请把软件包放在/root/目录下\033[0m'
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i '/SELINUX=/s/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
mkdir -p /opt/haproxy/conf
mkdir -p /etc/haproxy
mkdir -p /opt/haproxy/logs
ls /root/haproxy*.tar.gz
if [ $? -eq 0 ];then
ln -s /opt/haproxy/conf/haproxy.cfg /etc/haproxy/haproxy.cfg
cd /root/
tar -zxvf haproxy-1.7.5.tar.gz
cp -r /root/haproxy-1.7.5/examples/errorfiles /opt/haproxy/errorfiles
ln -s /opt/haproxy/errorfiles /etc/haproxy/errorfiles
touch /opt/haproxy/logs/haproxy.log
ln -s /opt/haproxy/logs/haproxy.log /var/log/haproxy.log
cp /root/haproxy-1.7.5/examples/haproxy.init /etc/rc.d/init.d/haproxy
chmod +x /etc/rc.d/init.d/haproxy
chkconfig --level 2345 haproxy on
sed -i '/#$ModLoad imudp/s/#$ModLoad imudp/$ModLoad imudp/' /etc/rsyslog.conf
sed -i '/$UDPServerRun 514/s/#$UDPServerRun 514/$UDPServerRun 514/' /etc/rsyslog.conf
echo 'local0.* /var/log/haproxy.log ' >> /etc/rsyslog.conf
sed -i '/SYSLOGD_OPTIONS=/s/SYSLOGD_OPTIONS=.*/SYSLOGD_OPTIONS="-r -m 0 -c 2"/' /etc/sysconfig/rsyslog
yum -y install pcre* pcre-devel GeoIP gd libXpm ncurses-devel perl make gcc gcc-c++ ncurses-devel zlib zlib-devel openssl*
cd /root/haproxy-1.7.5/
make TARGET=linux2628 USE_STATIC_PCRE=1 USE_REGPARM=1 USE_LINUX_TPROXY=1 USE_OPENSSL=1 USE_ZLIB=1 ARCH=x86_64
ldd haproxy | grep ssl
make install PREFIX=/opt/haproxy
ln -s /opt/haproxy/sbin/haproxy /usr/sbin
fi
echo 'global
log 127.0.0.1 local0
maxconn 65535
pidfile /var/run/haproxy.pid
nbproc 1
daemon
ulimit-n 819200
tune.ssl.default-dh-param 2048
defaults
mode http
log global
option httplog
option redispatch
option dontlognull
option httpclose
option forwardfor
maxconn 65535
balance source
retries 5
timeout connect 5000
timeout client 3600000
timeout server 3600000
timeout check 10s
timeout http-request 20s
timeout queue 1m
timeout http-keep-alive 20s
listen admin_status
mode http
bind *:8080
stats uri refresh 30s
stats uri /status
stats realm status
stats auth admin:123456passwd
stats hide-version' > /opt/haproxy/conf/haproxy.cfg
systemctl start haproxy
systemctl restart rsyslog.service
ss -tnulp |grep haproxy
echo -e '\033[33m 验证haproxy是否成功安装请访问127.0.0.1:8080/status \033[0m'