HAproxy指南之haproxy编译安装(安装篇)
2017-03-06 14:24
399 查看
一.
Linux编译安装haproxy
部署前说明:
(1)系统版本: centos 6.6(64位)
(2)相关中间件信息
haproxy版本信息: haproxy-1.5.15
编译安装haproxy
1.1
到haproxy官网下载haproxy源码包如下
1.2
创建haproxy运行用户
1.3
编译安装haproxy:
注意:TARGET=Linux26
是通过uname -a 来查看Linux内核版本的
1.4
创建haproxy主配置文件:
代码内容如下
1.4
创建haproxy系统服务启动脚本:
vim
/etc/init.d/haproxy
代码内容如下
给该脚本授予可以执行的权限并启动haproxy服务:
如果想开机自启动,也可以执行以下命令加入到到开机自启动:
1.5. haproxy服务启动状态查看
当haproxy服务启动后,我们可以通过netstat
-ntlp | grep hapoxy 就可以查看到启动状态
看到以上信息说明haproxy服务已经成功了!
总结:linxu编译安装haproxy有时需要手动编写启动脚本,在centos环境下可以利用自带的RPM来安装haproxy(默认1.5.4版本),而且有自带的配置文件和服务脚本。
Linux编译安装haproxy
部署前说明:
(1)系统版本: centos 6.6(64位)
(2)相关中间件信息
haproxy版本信息: haproxy-1.5.15
编译安装haproxy
1.1
到haproxy官网下载haproxy源码包如下
cd ~ wget http://www.haproxy.org/download/1.5/src/haproxy-1.5.15.tar.gz
1.2
创建haproxy运行用户
groupadd -r haproxy useradd -g haproxy -M -s /sbin/nologin haproxy
1.3
编译安装haproxy:
cd ~ tar zxvf haproxy-1.5.15.tar.gz -C /usr/local/src cd /usr/local/src/haproxy-1.5.15 make TARGET=linux26 ARCH=X86_64 PREFIX=/usr/local/haproxy make install PREFIX=/usr/local/haproxy
注意:TARGET=Linux26
是通过uname -a 来查看Linux内核版本的
1.4
创建haproxy主配置文件:
mkdir /etc/haproxy/ vim /etc/haproxyhaproxy.cfg
代码内容如下
global log 127.0.0.1 local2 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 user haproxy group haproxy daemon stats socket /var/lib/haproxy/stats defaults mode http log global option httplog option dontlognull option http-server-close option forwardfor except 127.0.0.0/8 option redispatch retries 3 timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 10s timeout check 10s maxconn 3000 frontend main *:5000 acl url_static path_beg -i /static /images /javascript /stylesheets acl url_static path_end -i .jpg .gif .png .css .js use_backend static if url_static default_backend app backend static balance roundrobin server static 127.0.0.1:4331 check backend app balance roundrobin server app1 127.0.0.1:5001 check server app2 127.0.0.1:5002 check server app3 127.0.0.1:5003 check server app4 127.0.0.1:5004 check
1.4
创建haproxy系统服务启动脚本:
vim
/etc/init.d/haproxy
代码内容如下
#!/bin/sh # # haproxy # # chkconfig: - 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/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 exec="/usr/local/haproxy/sbin/haproxy" prog=$(basename $exec) [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog cfgfile=/etc/haproxy/haproxy.cfg pidfile=/var/run/haproxy.pid lockfile=/var/lock/subsys/haproxy check() { $exec -c -V -f $cfgfile $OPTIONS } start() { $exec -c -q -f $cfgfile $OPTIONS 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 $cfgfile -p $pidfile $OPTIONS 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 $cfgfile $OPTIONS if [ $? -ne 0 ]; then echo "Errors in configuration file, check with $prog check." return 1 fi stop start } reload() { $exec -c -q -f $cfgfile $OPTIONS if [ $? -ne 0 ]; then echo "Errors in configuration file, check with $prog check." return 1 fi echo -n $"Reloading $prog: " $exec -D -f $cfgfile -p $pidfile $OPTIONS -sf $(cat $pidfile) retval=$? echo return $retval } force_reload() { restart } fdr_status() { status $prog } case "$1" in start|stop|restart|reload) $1 ;; force-reload) force_reload ;; check) check ;; status) fdr_status ;; condrestart|try-restart) [ ! -f $lockfile ] || restart ;; *) echo $"Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}" exit 2 esac
给该脚本授予可以执行的权限并启动haproxy服务:
chmod 777 /etc/init.d/hapoxy service haproxy start
如果想开机自启动,也可以执行以下命令加入到到开机自启动:
chkconfig --add haproxy chkconfig --level 2345 haproxy on
1.5. haproxy服务启动状态查看
当haproxy服务启动后,我们可以通过netstat
-ntlp | grep hapoxy 就可以查看到启动状态
[root@svn haproxy-1.5.15]# netstat -ntlp | grep haproxy tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN 23086/haproxy [root@svn haproxy-1.5.15]#
看到以上信息说明haproxy服务已经成功了!
总结:linxu编译安装haproxy有时需要手动编写启动脚本,在centos环境下可以利用自带的RPM来安装haproxy(默认1.5.4版本),而且有自带的配置文件和服务脚本。
相关文章推荐
- HAproxy指南之haproxy编译安装(安装篇)
- Boost下载安装编译配置使用指南(含Windows和Linux)
- Boost下载安装编译配置使用指南(含Windows和Linux)
- Ubuntu 12.04 64-bit下安装android 2.3.x编译环境指南
- Boost下载安装编译配置使用指南
- Boost下载安装编译配置使用指南(含Windows和Linux)
- Boost下载安装编译配置使用指南(含Windows和Linux)
- Boost下载安装编译配置使用指南
- CentOS安装Haproxy源码编译安装
- Percona-XtraDB-Cluster+haproxy+keepalived 编译安装 推荐
- HAproxy编译安装
- Nginx+Php-fpm+MySQL+Redis源代码编译安装指南
- python+apache+mod_python+django 编译安装指南[转]
- ubuntu 16.04 libQGLViewer编译安装指南
- 【LEDE】树莓派上玩LEDE终极指南-1-LEDE的编译和安装
- boost下载安装编译指南(windows 和 linux)
- Boost下载安装编译配置使用指南
- Boost下载安装编译配置使用指南
- CentOS 6.3 编译安装HAproxy 1.4.22
- HAProxy的编译安装配置