Haproxy在centos7上的部署 |
发表者:admin分类:应用服务2023-01-07 10:33:02 阅读[410] |
一、Haproxy在centos7上的部署
1、实验环境
System OS: CentOS Linux release 7.8.2003 (Core) 内核:3.10.0-1127.el7.x86_64
[root@node4 ~]# yum provides haproxy Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile haproxy-1.5.18-9.el7.x86_64 : TCP/HTTP proxy and load balancer for high availability environments Repo : base [root@node4 ~]# yum install -y haproxy #yum部署的haproxy版本为比较旧
#https://pkgs.org/download/haproxy #下载rpm包 #部署步骤 #准备工作 mkdir /app cd /app #Download latest cheese-release rpm from #http://www.nosuchhost.net/~cheese/fedora/packages/epel-7/x86_64/cheese-release.html wget http://www.nosuchhost.net/~cheese/fedora/packages/epel-7/x86_64/cheese-release-7-1.noarch.rpm #Install cheese-release rpm: rpm -Uvh cheese-release*rpm #查看可以安装的haproxy版本 [root@node4 ~]# yum provides haproxy Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile haproxy-1.5.15-1.el7.x86_64 : HAProxy reverse proxy for high availability environments Repo : cheese haproxy-1.5.18-9.el7.x86_64 : TCP/HTTP proxy and load balancer for high availability environments Repo : base haproxy-1.7.3-2.el7.x86_64 : HAProxy reverse proxy for high availability environments Repo : cheese haproxy-1.8.12-4.el7.x86_64 : HAProxy reverse proxy for high availability environments Repo : cheese haproxy-1.8.13-1.el7.x86_64 : HAProxy reverse proxy for high availability environments Repo : cheese haproxy-1.8.14-1.el7.x86_64 : HAProxy reverse proxy for high availability environments Repo : cheese haproxy-1.8.14-1.el7.x86_64 : HAProxy reverse proxy for high availability environments Repo : @cheese #Install haproxy rpm package: yum install -y haproxy-1.8.14-1.el7.x86_64 #查看安装的版本 [root@node4 ~]# haproxy -v HA-Proxy version 1.8.14-52e4d43 2018/09/20 Copyright 2000-2018 Willy Tarreau <willy@haproxy.org>
编译安装HAProxy 2.0 LTS版本,更多源码包下载地址:http://www.haproxy.org/download/
HAProxy 支持基于lua实现功能扩展,lua是一种小巧的脚本语言,于1993年由巴西里约热内卢天主教大学 (Pontifical Catholic University of Rio de Janeiro)里的一个研究小组开发,其设计目的是为了嵌入应用程序中, 从而为应用程序提供灵活的扩展和定制功能。 Lua 应用场景 1)游戏开发 2)独立应用脚本 3)Web 应用脚本 4)扩展和数据库插件,如MySQL Proxy 5)安全系统,如入侵检测系统
由于centos自带的lua版本比较低并不符合HAProxy要求的lua最低版本(5.3)的要求,因此需要编译安装较新版本的 lua环境,然后才能编译安装HAProxy
#lua的当前版本 [root@node4 app]# lua -v Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio #源码部署5.3.5lua mkdir /app cd /app yum install -y libtermcap-devel ncurses-devel libevent-devel readline-devel gcc gcc-c++ wget http://www.lua.org/ftp/lua-5.3.5.tar.gz tar xvf lua-5.3.5.tar.gz cd lua-5.3.5 make linux test #拷贝新版本的lua命令 mv /usr/bin/lua /usr/bin/lua.bak ln -s /app/lua-5.3.5/src/lua /usr/bin/lua [root@node4 lua-5.3.5]# ll /usr/bin/lua lrwxrwxrwx 1 root root 22 Jan 6 18:58 /usr/bin/lua -> /app/lua-5.3.5/src/lua [root@node4 ~]# lua -v Lua 5.3.5 Copyright (C) 1994-2018 Lua.org, PUC-Rio
#下载haproxy2.0.4,下载地址:http://www.haproxy.org/download mkdir /app cd /app wget http://www.haproxy.org/download/2.0/src/haproxy-2.0.4.tar.gz tar xvf haproxy-2.0.4.tar.gz #安装依赖包 yum install -y gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel net-tools vim iotop bc zip unzip zlib-devel lrzsz tree screen lsof tcpdump wget ntpdate #安装编译环境 #HAProxy 1.8及1.9版本编译参数: cd haproxy-1.8.4 make ARCH=x86_64 TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 USE_CPU_AFFINITY=1 PREFIX=/usr/local/haproxy #HAProxy 2.0编译参数: cd haproxy-2.0.4 make ARCH=x86_64 TARGET=linux-glibc USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 \ USE_SYSTEMD=1 USE_CPU_AFFINITY=1 USE_LUA=1 LUA_INC=/app/lua-5.3.5/src/ \ LUA_LIB=/app/lua-5.3.5/src/ PREFIX=/usr/local/haproxy make install PREFIX=/usr/local/haproxy cp haproxy /usr/sbin/ echo 'export PATH=/usr/local/haproxy/sbin:$PATH' > /etc/profile.d/haproxy.sh source /etc/profile
查看haproxy安装版本
[root@node4 haproxy-2.0.4]# haproxy -v HA-Proxy version 2.0.4 2019/08/06 - https://haproxy.org/
#启动用户 useradd -M -s /sbin/nologin haproxy [root@node4 ~]# id haproxy uid=1000(haproxy) gid=1000(haproxy) groups=1000(haproxy) #配置文件 mkdir /etc/haproxy cd /etc/haproxy cat >> harproxy.cfg <<EOF global maxconn 100000 chroot /usr/local/haproxy stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin #启动用户的uid和gid号,有2中配置方法 uid 99 gid 99 #user haproxy #group haproxy daemon #nbproc 4 #cpu-map 1 0 #cpu-map 2 1 #cpu-map 3 2 #cpu-map 4 3 pidfile /var/lib/haproxy/haproxy.pid log转载请标明出处【Haproxy在centos7上的部署】。
《www.micoder.cc》 虚拟化云计算,系统运维,安全技术服务.
Tags: | [阅读全文...] |
网站已经关闭评论
最新评论