tengine安装,haproxy访问不同路径对接不同集群

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tengine安装,haproxy访问不同路径对接不同集群相关的知识,希望对你有一定的参考价值。

tengine安装

下载包:在官网 http://tengine.taobao.org/download_cn.html下载各种版本的tengine包

./configure
make
make install

将tengine设置为service服务

cd /usr/lib/systemd/system
vi nginx.service
[Unit]
Description=nginx performance web server
Documentation=http://tengine.taobao.org/documentation_cn.html
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

修改/usr/local/nginx/conf/nginx.conf文件
添加:

pid /var/run/nginx.pid;

systemctl enable nginx
systemctl start nginx
systemctl status nginx

实现api.x.com代理9001端口

192.168.115.128机器修改nginx.conf

 server {
        listen       80;
        server_name  api.x.com;

        location / {
            root   html;
            proxy_pass http://192.168.115.129:9001; #另外一台的nginx监听9001端口
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

haproxy实现7层代理,访问不同路径对应不同集群

haproxy.conf配置文件修改


frontend  main *:5000
    acl url_static1       path_beg       -i /static /images /javascript /stylesheets /a   #不同的访问路径
    acl url_static       path_end       -i .jpg .gif .png .css .js

    use_backend static1          if url_static1   #a集群

    acl url_static2      path_beg       -i /static /images /javascript /stylesheets /b   #不同的访问路径
    use_backend static2          if url_static2   #b集群
    default_backend             app

#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
    balance     roundrobin
    server      static 127.0.0.1:4331 check

#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
    balance     roundrobin
    server  app1 192.168.115.128:80 check
    server  app2 192.168.115.129:80 check

backend static1    #a集群
    balance     roundrobin
    server static1 192.168.115.128:80 check

backend static2   #b集群
    balance     roundrobin
    server static2 192.168.115.129:80 check

访问a集群:
技术图片

访问b集群:
技术图片

以上是关于tengine安装,haproxy访问不同路径对接不同集群的主要内容,如果未能解决你的问题,请参考以下文章

haproxy实现7层代理

tengine-2.3.2负载均衡和haproxy七层代理

ansible安装nginx (tengine)

tengine 默认安装在啥路径

tengine安装问题

Centos 6.5 Tengine 安装流程