内容简介:2、源码编译安装haproxy3、配置haproxy配置文件
Centos7 haproxy动静分离
实现的结果:
当客户端访问haproxy时,请求的是静态文件内容时,请求转交给static server,请求的是 php 内容时,请求转交给php server,请求的是jsp内容时,请求转交给tomcat server,以实现动静分离。
haproxy服务器:192.168.80.100
先部署三台web服务器:
一台httpd支持php 192.168.80.101
一台部署httpd支持静态资源 192.168.80.102
一台tomcat支持jsp 192.168.80.103
192.168.80.100:
1、安装编译环境与软件
yum install -y pcre-devel bzip2-devel gcc gcc-c++ make
2、源码编译安装haproxy
tar xzvf haproxy-1.5.15.tar.gz -C /opt
cd /opt/haproxy-1.5.15 make TARGET=linux26 PREFIX=/usr/local/haproxy //标识64为系统 make install PREFIX=/usr/local/haproxy
3、配置haproxy配置文件
mkdir /etc/haproxy
useradd -s /sbin/nologin -M haproxy
cp /opt/haproxy-1.5.15/examples/haproxy.cfg /etc/haproxy/
vi /etc/haproxy/haproxy.cfg #--------------------------------------------------------------------- # Global settings #--------------------------------------------------------------------- global log 127.0.0.1 local3 maxconn 204800 chroot /usr/local/haproxy user haproxy group haproxy daemon nbproc 1 pidfile /var/run/haproxy.pid stats socket /usr/local/haproxy/stats description haproxy server #--------------------------------------------------------------------- # common defaults that all the 'listen' and 'backend' sections will # use if not designated in their block #--------------------------------------------------------------------- defaults log global mode http maxconn 10000 option httplog option httpclose option dontlognull option forwardfor except 127.0.0.0/8 retries 3 option redispatch option abortonclose balance roundrobin timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 10s timeout check 10s #--------------------------------------------------------------------- # use listen setting the haproxy status for site #--------------------------------------------------------------------- listen admin_status #设置haproxy监控状态 bind *:8089 mode http log 127.0.0.1 local3 err stats refresh 5s stats uri /status #监控状态页面访问url stats realm www.skeryp.com stats auth admin:admin stats hide-version stats admin if TRUE #--------------------------------------------------------------------- # main listen which proxys to the backends #--------------------------------------------------------------------- listen www bind *:80 maxconn 5000 mode http log global option httplog option httpclose option forwardfor log global default_backend default #设置默认访问页面 #定义当请求的内容是静态内容时,将请求转交给static server的acl规则 acl url_static path_beg -i /static /images /img /javascript /stylesheets acl url_static path_end -i .jpg .gif .png .css .js .html acl host_static hdr_beg(host) -i img. video. download. ftp. imags. videos. #定义当请求的内容是php内容时,将请求转交给php server的acl规则 acl url_php path_end -i .php #定义当请求的内容是.jsp或.do内容时,将请求转交给tomcat server的acl规则 acl url_jsp path_end -i .jsp .do #引用acl匹配规则 use_backend static_pool if url_static or host_static use_backend php_pool if url_php use_backend tomcat_pool if url_jsp #定义后端backend server backend static_pool option httpchk GET /index.html server static1 192.168.80.101:80 cookie id1 check inter 2000 rise 2 fall 3 backend php_pool option httpchk GET /info.php server php1 192.168.80.102:80 cookie id1 check inter 2000 rise 2 fall 3 backend tomcat_pool option httpchk GET /index.jsp server tomcat1 192.168.80.103:8086 cookie id2 check inter 2000 rise 2 fall 3 #<----------------------default site for listen and frontend------------------------------------> backend default mode http option httpchk GET /index.html server default 192.168.80.104:80 cookie id1 check inter 2000 rise 2 fall 3 maxconn 5000
192.168.80.101:
1、安装php
yum install -y php
2、安装php插件
yum install -y \ php-mysql \ php-gd \ libjpeg* \ php-ldap \ php-odbc \ php-pear \ php-xml \ php-xmlrpc \ php-mbstring \ php-bcmath \ php-mhash
3、修改配置文件
vi /etc/httpd/conf/httpd.conf ServerName www.aa.com DirectoryIndex index.html index.php
vi /etc/php.ini date.timezone = PRC 日期时区=×××
4、创建一个php网页
cd /var/www/html vi index.php <?php phpinfo(); ?>
systemctl start httpd
浏览器输入:192.168.80.101
192.168.80.102:
1、安装httpd
yum install httpd -y
2、安装上传软件
yum install lrz* -y
3、修改配置文件
vi /etc/httpd/conf/httpd.conf ServerName www.aa.com
4、创建一个img目录,在给img目录里放进去一张图片,在创建一个index.html网页
cd /var/www/html mkdir img 放进入一张图片,找一张图片直接拉到Xshell cd .. vi index.html <h1>静态</h1>
systemctl start httpd
浏览器输入:192.168.80.102
192.168.80.102/img/图片名称.格式
192.168.80.103:
软件包自己去网上找
1、安装JAVA
tar xf jdk-8u144-linux-x64.tar.gz
cp -rv jdk1.8.0_144/ /usr/local/java vi /etc/profile //在文件末尾新增 export JAVA_HOME=/usr/local/java 安装路径 export JRE_HOME=/usr/local/java/jre export PATH=$PATH:/usr/local/java/bin export CLASSPATH=./:/usr/local/java/lib:/usr/local/java/jre/lib
source /etc/profile
2、安装tomcat
cp -r apache-tomcat-8.5.23 /usr/local/tomcat8 ln -s /usr/local/tomcat8/bin/startup.sh /usr/bin/tomcatup ln -s /usr/local/tomcat8/bin/shutdown.sh /usr/bin/tomcatdown tomcatup netstat -anpt | grep 8080
浏览器输入:192.168.80.103:8080
测试:浏览器中输入
192.168.80.100:8089/status 统计页面
浏览器中输入:192.168.80.100/index.php
192.168.80.100/img/图片名称.格式
192.168.80.100/index.jsp
以上所述就是小编给大家介绍的《Centos7 haproxy动静分离》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 简述动静分离
- Nginx+Tomcat动静分离
- Nginx Tomcat 动静分离提高系统性能
- Nginx Tomcat 动静分离提高系统性能
- 微服务的接入层设计与动静资源
- Nginx 动静分离与负载均衡的实现
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Introduction to the Design and Analysis of Algorithms
Anany Levitin / Addison Wesley / 2006-2-24 / USD 122.00
Based on a Based on a new classification of algorithm design techniques and a clear delineation of analysis methods, "Introduction to the Design and Analysis of Algorithms" presents the subject in a c......一起来看看 《Introduction to the Design and Analysis of Algorithms》 这本书的介绍吧!
在线进制转换器
各进制数互转换器
html转js在线工具
html转js在线工具