Haproxy脚本安装配置

25 篇文章 0 订阅
18 篇文章 0 订阅

脚本安装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'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值