▲单独架构的小伙伴看这里:(学习杰哥视频的作业第3-4天)
1、编译安装tengine,配置虚拟主机,实现api.x.com代理9001端口
1.1 准备源码
http://tengine.taobao.org/download.html 找到下载包并且下载(Tengine-2.2.0.tar.gz)
1.2 编译安装
# tar-xvf tengine-2.2.0.tar.gz
#./configure--prefix=/apps/tengine--user=nginx--group=nginx--with-http_ssl_module--with-http_v2_module--with-http_realip_module--with-http_stub_status_module--with-http_gzip_static_module--with-pcre--add-module=/root/echo-nginx-module
# make&&make install
1.3 配置代理
# vim /apps/tengine/conf/conf.d/9001.conf
server{
listen 9001;
server_name api.x.com;
}
2、配置haproxy,实现7层代理。/a 代理路径转发到a集群;/b 代理路径转发到b集群
2.1 编译安装haproxy
# tar xvf haproxy-1.8.20.tar.gz
# make ARCH=x86_64 TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 \ USE_CPU_AFFINITY=1 PREFIX=/apps/haproxy
# make install PREFIX=/apps/haproxy
2.2 haproxy添加代理配置
# cat /etc/haproxy/haproxy.cfg
global
maxconn 100000
chroot /apps/haproxy
user haproxy
group haproxy
daemon
nbproc 2
cpu-map 1 0
cpu-map 2 1
log 127.0.0.1 local3 info
defaults
option http-keep-alive
option forwardfor
maxconn 100000
mode http
timeout connect 300000ms
timeout client 300000ms
timeout server 300000ms
#添加haproxy代理配置
listen web_port
bind 192.168.100.101:80
mode http
acl a_path path_beg -i /a
use_backend a_path_host if a_path
acl b_path path_beg -i /b
use_backend b_path_host if b_path
backend a_path_host
mode http
server web1 192.168.100.102:80check inter 2000 fall 3 rise 5
backend b_path_host
mode http
server web1 192.168.100.103:80 check inter 2000 fall 3 rise 5