CentOS安装Haproxy源码编译安装
来源:互联网 发布:mac微信文件保存位置 编辑:程序博客网 时间:2024/05/20 12:49
下载地址:http://download.chinaunix.net/download/0013000/12508.shtml 可以在这里下载,[root@localhost ~]# yum -y install cmake gcc gcc-c++ autoconf automake zlib* libxml* \ncurses ncurses-devel libtool-ltdl-devel* make bison bison-devel libaio [root@localhost ~]# tar zxvf haproxy-1.4.25.tar.gz [root@localhost ~]# cd haproxy-1.4.25[root@localhost haproxy-1.4.25]#
开始编译安装
(MAKE 参数请参考文件中的README)
[root@localhost haproxy-1.4.25]# make TARGET=linux26 PREFIX=/usr/local/haproxy[root@localhost haproxy-1.4.25]# make install PREFIX=/usr/local/haproxy[root@localhost haproxy-1.4.25]# install -d /usr/local/sbin[root@localhost haproxy-1.4.25]# install haproxy /usr/local/sbin[root@localhost haproxy-1.4.25]# install -d /usr/local/share/man/man1[root@localhost haproxy-1.4.25]# install -m 644 doc/haproxy.1 /usr/local/share/man/man1[root@localhost haproxy-1.4.25]# install -d /usr/local/doc/haproxy[root@localhost haproxy-1.4.25]# for x in configuration architecture haproxy-en haproxy-fr; do \> install -m 644 doc/$x.txt /usr/local/doc/haproxy ; \> done[root@localhost haproxy-1.4.25]#
安装完成,
我们检测 一下是否安装成功
[root@localhost haproxy-1.4.25]# haproxy -vHA-Proxy version 1.4.25 2014/03/27Copyright 2000-2014 Willy Tarreau <w@1wt.eu>则安装成功
配置haproxy.cfg文件
这里解释一下,我用的时候 安装文件夹用 /root/haproxy-1.4.25/examples/haproxy.cfg 这个是自带的配置文件
[root@localhost examples]# vim haproxy.cfg# this config needs haproxy-1.1.28 or haproxy-1.2.1global log 127.0.0.1 local0 log 127.0.0.1 local1 notice #log loghost local0 info maxconn 4096# chroot /usr/share/haproxy chroot /usr/local/haproxy uid 99 gid 99 daemon #debug #quietdefaults log global mode http option httplog option dontlognull retries 3 #redispatch maxconn 2000 contimeout 5000 clitimeout 50000 srvtimeout 50000#============================这一段是我后面加上去了。 就是WEB代理listen web_proxy bind *:80 mode http option httpchk GET /index.html server s1 192.168.11.210:80 weight 3 check server s2 192.168.11.211:80 weight 3 check#后面的我做的注释#listen appli1-rewrite 0.0.0.0:10001# cookie SERVERID rewrite# balance roundrobin# server app1_1 192.168.34.23:8080 cookie app1inst1 check inter 2000 rise 2 fall 5# server app1_2 192.168.34.32:8080 cookie app1inst2 check inter 2000 rise 2 fall 5# server app1_3 192.168.34.27:8080 cookie app1inst3 check inter 2000 rise 2 fall 5# server app1_4 192.168.34.42:8080 cookie app1inst4 check inter 2000 rise 2 fall 5##listen appli2-insert 0.0.0.0:10002# option httpchk# balance roundrobin# cookie SERVERID insert indirect nocache# server inst1 192.168.114.56:80 cookie server01 check inter 2000 fall 3# server inst2 192.168.114.56:81 cookie server02 check inter 2000 fall 3# capture cookie vgnvisitor= len 32## option httpclose # disable keep-alive# rspidel ^Set-cookie:\ IP= # do not let this cookie tell our internal IP address# #listen appli3-relais 0.0.0.0:10003# dispatch 192.168.135.17:80##listen appli4-backup 0.0.0.0:10004# option httpchk /index.html# option persist# balance roundrobin# server inst1 192.168.114.56:80 check inter 2000 fall 3# server inst2 192.168.114.56:81 check inter 2000 fall 3 backup##listen ssl-relay 0.0.0.0:8443# option ssl-hello-chk# balance source# server inst1 192.168.110.56:443 check inter 2000 fall 3# server inst2 192.168.110.57:443 check inter 2000 fall 3# server back1 192.168.120.58:443 backup#listen appli5-backup 0.0.0.0:10005# option httpchk *# balance roundrobin# cookie SERVERID insert indirect nocache# server inst1 192.168.114.56:80 cookie server01 check inter 2000 fall 3# server inst2 192.168.114.56:81 cookie server02 check inter 2000 fall 3# server inst3 192.168.114.57:80 backup check inter 2000 fall 3# capture cookie ASPSESSION len 32# srvtimeout 20000# option httpclose # disable keep-alive# option checkcache # block response if set-cookie & cacheable# rspidel ^Set-cookie:\ IP= # do not let this cookie tell our internal IP address# errorloc 502 http://192.168.114.58/error502.html# errorfile 503 /etc/haproxy/errors/503.http
启动服务
[root@localhost examples]# haproxy -f /root/haproxy-1.4.25/examples/haproxy.cfg [WARNING] 316/220055 (2376) : parsing [/root/haproxy-1.4.25/examples/haproxy.cfg:22]: keyword 'redispatch' is deprecated, please use 'option redispatch' instead.[ALERT] 316/220055 (2376) : [haproxy.main()] Cannot chroot(/usr/local/sbin/haproxy).
出现的报错信息,下面我们来解决问题。因为上面配置文件是我改后的,应该没有什么问题。
[ALERT] 316/220055 (2376) : [haproxy.main()] Cannot chroot(/usr/local/sbin/haproxy).
是配置文件chroot的目录不对,根据我的文档安装改成 chroot /urs/local/haproxy 就可以解决了 执行 mkdir /usr/share/haproxy
[WARNING] 316/220055 (2376) : parsing [/root/haproxy-1.4.25/examples/haproxy.cfg:22]: keyword 'redispatch' is deprecated, please use 'option redispatch' instead.
这个报错信息是配置文件22行的问题, 我是做了注释掉就可以起动服务了。 注释到相对应的错误行
再次起动服务:[root@localhost examples]# haproxy -f /root/haproxy-1.4.25/examples/haproxy.cfg [root@localhost examples]#
没有任何提示,那我们检测一下是否启动成功
看一下进程信息
[root@localhost examples]# ps -ef |grep haproxynobody 3826 1 0 22:38 ? 00:00:00 haproxy -f /root/haproxy-1.4.25/examples/haproxy.cfgroot 3837 1260 0 22:38 pts/0 00:00:00 grep haproxy
进程已经在
看一下端口信息
下图就成功了80端口是我们自定义的服务。最后加的配置文件
[root@localhost examples]# netstat -anp |grep haproxytcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3826/haproxy udp 0 0 0.0.0.0:43549 0.0.0.0:* 3826/haproxy把配置文件移动到/etc目录下
[root@localhost examples]# cd /etc/[root@localhost etc]# 复制haproxy配置文件到/etc/目录下面[root@localhost etc]# cp /root/haproxy-1.4.25/examples/haproxy.cfg haproxy.cfg我们再一次查看进程 kill掉。 在用/etc/haproxy.cfg的配置文件启动看看[root@localhost etc]# ps -ef | grep haproxynobody 3826 1 0 22:38 ? 00:00:00 haproxy -f /root/haproxy-1.4.25/examples/haproxy.cfgroot 3901 1260 0 22:40 pts/0 00:00:00 grep haproxy[root@localhost etc]# kill 3826[root@localhost etc]# ps -ef | grep haproxyroot 3928 1260 0 22:41 pts/0 00:00:00 grep haproxy已经kill掉进程,进程已经没有在运行了, 我们现在用/etc/haproxy.cfg 来运行服务[root@localhost etc]# haproxy -f /etc/haproxy.cfg[root@localhost etc]# ps -ef |grep haproxy.cfgnobody 3959 1 0 22:42 ? 00:00:00 haproxy -f /etc/haproxy.cfgroot 3965 1260 0 22:43 pts/0 00:00:00 grep haproxy.cfg
我们已经看到运行成功
设置以服务形式启动
目录切换到/etc/init.d
这段是参考:http://blog.chinaunix.net/uid-24250828-id-3778032.html
[root@localhost etc]# cd /etc/init.d/[root@localhost init.d]# vi haproxy#!/bin/bash # # haproxy # # chkconfig: 35 85 15 # description: HAProxy is a free, very fast and reliable solution \ # offering high availability, load balancing, and \ # proxying for TCP and HTTP-based applications # processname: haproxy # config: /etc/haproxy.cfg # pidfile: /var/run/haproxy.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 config="/etc/haproxy.cfg" exec="/usr/local/haproxy/sbin/haproxy" prog=$(basename $exec) [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog lockfile=/var/lock/subsys/haproxy check() { $exec -c -V -f $config } start() { $exec -c -q -f $config if [ $? -ne 0 ]; then echo "Errors in configuration file, check with $prog check." return 1 fi echo -n $"Starting $prog: " # start it up here, usually something like "daemon $exec" daemon $exec -D -f $config -p /var/run/$prog.pid retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " # stop it here, often "killproc $prog" killproc $prog retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { $exec -c -q -f $config if [ $? -ne 0 ]; then echo "Errors in configuration file, check with $prog check." return 1 fi stop start } reload() { $exec -c -q -f $config if [ $? -ne 0 ]; then echo "Errors in configuration file, check with $prog check." return 1 fi echo -n $"Reloading $prog: " $exec -D -f $config -p /var/run/$prog.pid -sf $(cat /var/run/$prog.pid) retval=$? echo return $retval } force_reload() { restart } fdr_status() { status $prog } case "$1" in start|stop|restart|reload) $1 ;; force-reload) force_reload ;; checkconfig) check ;; status) fdr_status ;; condrestart|try-restart) [ ! -f $lockfile ] || restart ;; *) echo $"Usage: $0 {start|stop|status|checkconfig|restart|try-restart|reload|force-reload}" exit 2 esac重起服务haproxy
[root@localhost init.d]# service haproxy restartenv: /etc/init.d/haproxy: Permission denied这个提示。大概是权限问题。我们下面加上执行权限[root@localhost init.d]# ll haproxy -rw-r--r--. 1 root root 2588 Nov 13 23:02 haproxy[root@localhost init.d]# chmod -R 655 haproxy [root@localhost init.d]# ll haproxy -rw-r-xr-x. 1 root root 2588 Nov 13 23:02 haproxy选 看一下进程是否存在,不存在我们重起haproxy服务[root@localhost init.d]# ps -ef | grep haproxyroot 7409 1260 0 23:56 pts/0 00:00:00 grep haproxy[root@localhost init.d]# service haproxy restartStopping haproxy: [FAILED]Starting haproxy: [ OK ][root@localhost init.d]# ps -ef | grep haproxynobody 7444 1 0 23:56 ? 00:00:00 /usr/local/haproxy/sbin/haproxy -D -f /etc/haproxy.cfg -p /var/run/haproxy.pidroot 7449 1260 0 23:56 pts/0 00:00:00 grep haproxy[root@localhost init.d]# 配置上面就完成了
0 0
- CentOS源码编译安装Haproxy
- CentOS安装Haproxy源码编译安装
- haproxy的编译安装
- haproxy 源码安装
- CentOS源码编译安装Nginx
- CentOS源码编译安装boost
- CentOS 源码编译安装MySQL
- centos源码编译安装git
- centos 7 下安装haproxy
- HaProxy在CentOS 6安装
- centos6.4编译安装haproxy
- Saltstack自动化编译安装haproxy
- HAproxy指南之haproxy编译安装(安装篇)
- centos源码编译安装mysql-5.5.13
- centos 源码编译安装gcc 4.7.0
- CentOS源码编译安装Mysql5.5
- RedHat/CentOS源码编译安装MySQL5.6.12
- Centos下Cmake源码编译安装MySQL
- UVa 10140 - Prime Distance
- Dialog的几种方式
- C共用体
- 机器学习之——归一化
- 发布地图打印服务注意事项
- CentOS安装Haproxy源码编译安装
- Java利用Properties类操作属性文件
- hdu2222
- linux下tomcat7 catalina.out 文件分割
- js中获取url?后面的参数,以及其他参数的获取
- 不安装oracle客户端,plsql developer的安装教程
- 关于ImageView.setBackgroundResource()方法不显示图片
- Android数据存储五种方式总结
- C#反射学习笔记