首页 > 其他 > 详细

CentOS 7.2 编译安装Haproxy-1.7.4

时间:2017-04-12 05:07:10      阅读:272      评论:0      收藏:0      [点我收藏+]


  1. 环境设置

    yum groupinstall -y  "Development tools"

  2. 解压haproxy1.7.4

    tar -zxf haproxy-1.7.4.tar.gz -C /usr/local/

  3. 编译安装haproxy

    cd haproxy-1.7.4

    make TARGET=linux26  ARCH=X86_64 PREFIX=/usr/local/haproxy

    make install PREFIX=/usr/local/haproxy

  4. 创建haproxy启动脚本

    vi /etc/init.d/haproxy

       


            #!/bin/sh

            #

            # chkconfig: - 85 15

            # description: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited \

            #              for high availability environments.

            # processname: haproxy

            # config: /etc/haproxy/haproxy.cfg

            # pidfile: /var/run/haproxy.pid

            # Script Author: Simon Matter <simon.matter@invoca.ch>

            # Version: 2004060600

            # Source function library.

            if [ -f /etc/init.d/functions ]; then

              . /etc/init.d/functions

            elif [ -f /etc/rc.d/init.d/functions ] ; then

              . /etc/rc.d/init.d/functions

            else

              exit 0

            fi

            # Source networking configuration.

            . /etc/sysconfig/network

            # Check that networking is up.

            [ "${NETWORKING}" = "no" ] && exit 0

            # This is our service name

            BASENAME=`basename $0`

            if [ -L $0 ]; then

              BASENAME=`find $0 -name $BASENAME -printf %l`

              BASENAME=`basename $BASENAME`

            fi

            BIN=/usr/local/haproxy/sbin/haproxy

            CFG=/usr/local/haproxy/haproxy.cfg

            [ -f $CFG ] || exit 1

            PIDFILE=/var/run/$BASENAME.pid

            LOCKFILE=/var/lock/subsys/$BASENAME

            RETVAL=0

            start() {

              quiet_check

              if [ $? -ne 0 ]; then

                echo "Errors found in configuration file, check it with ‘$BASENAME check‘."

                return 1

              fi

              echo -n "Starting $BASENAME: "

              daemon $BIN -D -f $CFG -p $PIDFILE

              RETVAL=$?

              echo

              [ $RETVAL -eq 0 ] && touch $LOCKFILE

              return $RETVAL

            }

            stop() {

              echo -n "Shutting down $BASENAME: "

              killproc $BASENAME -USR1

              RETVAL=$?

              echo

              [ $RETVAL -eq 0 ] && rm -f $LOCKFILE

              [ $RETVAL -eq 0 ] && rm -f $PIDFILE

              return $RETVAL

            }

            restart() {

              quiet_check

              if [ $? -ne 0 ]; then

                echo "Errors found in configuration file, check it with ‘$BASENAME check‘."

                return 1

              fi

5. 创建haproxy配置文件

    vi /usr/local/haproxy/haproxy.cfg

            

                        #

                        # demo config for Proxy mode

                        #

                        global

                            log 127.0.0.1 local0 info #[err warning info debug]

                            maxconn 4096

                            daemon

                            nbproc 1

                        defaults

                            mode http

                            option httplog

                            retries 3

                            option redispatch

                            option abortonclose

                            maxconn 4096

                            contimeout 5000

                            clitimeout 30000

                            srvtimeout 30000

                            timeout check 2000

                        frontend httpfrontend

                             bind 0.0.0.0:80

                                option httplog

                                log 127.0.0.1 local2 info


        chkconfig --add haproxy

        chkconfig --level 2345 haproxy on


6. chmod 755 /etc/init.d/haproxy

    systemctl start haproxy

7. 检查80,10050的端口是否打开

    ss -tnl


CentOS 7.2 编译安装Haproxy-1.7.4

原文:http://zhengqizhq.blog.51cto.com/690602/1914983

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!