openresty+health_check+consul安装
2016-08-05 本文已影响0人
allanYan
项目中经常要搭建nginx环境,记录下安装脚本,备忘;
-
安装依赖:
yum install readline-devel pcre-devel openssl-devel gcc
-
下载依赖包:
git clone https://github.com/xiaokai-wang/nginx_upstream_check_module.git wget --secure-protocol=TLSv1 --no-check-certificate https://openresty.org/download/openresty-1.11.2.5.tar.gz git clone https://github.com/weibocom/nginx-upsync-module.git git clone https://github.com/sumory/orange.git git clone https://github.com/sumory/lor.git
-
准备nginx_upstream_check_module模块,需要先对nginx打patch:
tar -xvf openresty-1.11.2.5.tar.gz -C /data/exec/ cd /data/exec/openresty-1.11.2.5/bundle/nginx-1.11.2
patch -p0 < /data/exec/nginx_upstream_check_module/check_1.11.1+.patch
```
-
修改nginx-upsync-module模块ngx_http_upsync_module.c的1688行:
node = cJSON_GetObjectItem(server_next, "Node")
改为:
```
node = cJSON_GetObjectItem(server_next, "Service")
```
-
安装openresty:
./configure --prefix=/data/exec/openresty --with-http_stub_status_module --add-module=/data/exec/nginx_upstream_check_module --add-module=/data/exec/nginx-upsync-module
make & make install
```
- 安装Lor,默认安装到/usr/local目录:
cd lor
make install
- 安装orange
cd orange
make install
-
修改orange的配置文件,增加upstream:
upstream xiu-relation-server { upsync 10.221.83.98:8500/v1/health/service/xiu-relation-server upsync_timeout=6m upsync_interval=500ms upsync_type=consul_health strong_dependency=on; upsync_dump_path /usr/local/openresty/nginx/conf/servers/servers_xiu_relation_server.conf; include /usr/local/openresty/nginx/conf/servers/servers_xiu_relation_server.conf; check interval=1000 rise=2 fall=2 timeout=3000 type=tcp default_down=false; #check_http_send "HEAD / HTTP/1.0\r\n\r\n"; #check_http_expect_alive http_2xx http_3xx; }
location = /upstream_show {
upstream_show;
}
location = /upstream_status {
check_status;
access_log off;
}
-
修改oragne的配置文件orange.conf,主要配置mysql的地址;
-
建立nginx的软链接:
ln -s /data/exec/openresty/nginx/sbin/nginx /usr/local/bin/nginx
- 通过orange start/stop/restart管理应用,假设服务器ip为10.1.1.2,upstream相关指令放在80端口
- 管理界面:http://10.1.1.2:9999/
- 查看upstream配置:http://10.1.1.2/upstream_status
- 查看upstream状态:http://10.1.1.2/upstream_show