1.安装必要的环境(root)
sudo yum install -y gcc gcc-c++ autoconf automake
2.安装所需要的组件
A pcre 正则表达式库
下载地址:https://ftp.pcre.org/pub/pcre/
wget "https://ftp.pcre.org/pub/pcre/pcre-8.00.tar.gz"
3.下载tengine安装包
wget "http://tengine.taobao.org/download/tengine-2.3.2.tar.gz"
解压之后进入文件夹 cd tengine-2.3.2,执行
./configure --prefix=/data/packages --with-pcre=../pcre-8.00 --add-module=./modules/ngx_http_upstream_check_module/
ps: --with-pcre 设置为自己安装的pcre路径
make && make install
4.配置tengine
cd ../
mkdir -p {run,tmp,cache}
vim conf/nginx.conf
修改worker_processes为CPU核心数
在http模块下添加配置: include /data/packages/vhosts/*.conf;
mkdir vhosts
cd vhosts
vim test.conf
文件内容:
upstream api {
server ip1:port1;
server ip2:port2;
}
server {
listen 8080;
location / {
proxy_pass http://api;
proxy_next_upstream error timeout http_500 http_502 http_503 http_504;
}
}
此时基本的配置就完成了,可以先启动看一下配置有没有问题
./sbin/nginx -c ./conf/nginx.conf
5.配置tengine的健康检查模块
http://tengine.taobao.org/document_cn/http_upstream_check_cn.html
更改test.conf
upstream api {
server ip1:port1;
server ip2:port2;
check interval=3000 rise=2 fall=5 timeout=10000 type=http;
check_keepalive_requests 100;
check_http_send "GET /hello HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}
server {
listen 8080;
location / {
proxy_pass http://api;
proxy_next_upstream error timeout http_500 http_502 http_503 http_504;
}
}
启动nginx: ./sbin/nginx -c ./conf/nginx.conf
健康检查接口:GET /hello