【转载请注明出处】:http://www.javashuo.com/article/p-uhjihkyh-do.htmlnginx
在 PCRE 官网能够找到下载地址,这里选择8.x的最高版本 pcre-8.42.tar.gz。github
zlib 直接选择官网首页最新的zlib-1.2.11.tar.gz。segmentfault
这里下载的是nginx稳定版nginx-1.14.2.tar.gz,nginx-upsync-module模块源码使用git clone https://github.com/weibocom/nginx-upsync-module.git
下载。
解压以后进入源码目录执行缓存
./configure --sbin-path=/usr/local/opt/nginx --conf-path=/usr/local/etc/nginx/nginx.conf --pid-path=/usr/local/opt/nginx/nginx.pid --prefix=/usr/local/opt/nginx --with-http_ssl_module --add-module=/work/tools/nginx-modules/nginx-upsync-module --with-openssl=/work/tools/openssl-1.0.2q --with-pcre=/work/tools/pcre-8.42 --with-zlib=/work/tools/zlib-1.2.11 make make install
查看文件auto/options
能够看到所有的参数,下面是一些经常使用配置参数的含义:app
--prefix #nginx安装目录,默认在/usr/local/nginx --pid-path #pid问件位置,默认在logs目录 --lock-path #lock问件位置,默认在logs目录 --with-http_ssl_module #开启HTTP SSL模块,以支持HTTPS请求。 --with-http_dav_module #开启WebDAV扩展动做模块,可为文件和目录指定权限 --with-http_flv_module #支持对FLV文件的拖动播放 --with-http_realip_module #支持显示真实来源IP地址 --with-http_gzip_static_module #预压缩文件传前检查,防止文件被重复压缩 --with-http_stub_status_module #取得一些nginx的运行状态 --with-mail #容许POP3/IMAP4/SMTP代理模块 --with-mail_ssl_module #容许POP3/IMAP/SMTP可使用SSL/TLS --with-pcre=../pcre-8.11 #注意是未安装的pcre路径 --with-zlib=../zlib-1.2.5 #注意是未安装的zlib路径 --with-debug #容许调试日志 --http-client-body-temp-path #客户端请求临时文件路径 --http-proxy-temp-path #设置http proxy临时文件路径 --http-fastcgi-temp-path #设置http fastcgi临时文件路径 --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi #设置uwsgi 临时文件路径 --http-scgi-temp-path=/var/tmp/nginx/scgi #设置scgi 临时文件路径:
在make的时候报错curl
ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[4]: *** [link_app.] Error 1 make[3]: *** [openssl] Error 2 make[2]: *** [build_apps] Error 1 make[1]: *** [/user/local/openssl-1.0.2q/.openssl/include/openssl/ssl.h] Error 2 make: *** [build] Error 2
这个是由于我先前装了别的版本的openssl致使的,查看Nginx源码目录文件auto/lib/openssl/conf
,能够发现代码:测试
CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include" CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h" CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a" CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
实际的openssl源码目录是没有.openssl
目录的,ssl.h
文件是在openssl源码目录的include/openssl/
目录下的,libssl.a
和libcrypto.a
是在openssl源码根目录下的。将此文件修改成:ui
CORE_INCS="$CORE_INCS $OPENSSL/include" CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h" CORE_LIBS="$CORE_LIBS $OPENSSL/libssl.a" CORE_LIBS="$CORE_LIBS $OPENSSL/libcrypto.a"
执行make clean
以后从新执行上面的./configure ....
,这时报错url
ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[1]: *** [objs/nginx] Error 1 make: *** [build] Error 2
查了一下,看到好多人的解决方式都是修改objs/Makefile
文件,找到编译openssl的地方,将./config --prefix=
改为./Configure darwin64-x86_64-cc --prefix=
,改完以后千万不要执行./configure ....
,不然会从新生成objs/Makefile
文件,最终以下
/work/tools/openssl-1.0.2q/.openssl/include/openssl/ssl.h: objs/Makefile cd /work/tools/openssl-1.0.2q \ && if [ -f Makefile ]; then $(MAKE) clean; fi \ && ./Configure darwin64-x86_64-cc --prefix=/work/tools/openssl-1.0.2q/.openssl no-shared no-threads \ && $(MAKE) \ && $(MAKE) install_sw LIBDIR=lib
再次执行
make make install
若是还报上面的错误,能够尝试手动执行下面的命令以后再执行上面的命令
./Configure darwin64-x86_64-cc --prefix=/work/tools/openssl-1.0.2q/.openssl no-shared no-threads sudo make sudo make install
有时候报相似symbol(s) not found
有多是权限不够致使的,能够尝试加sudo
执行命令。
这时启动nginx已经能够启动了。
本文以Consul做为注册中心,关于Consul的知识将再也不介绍。
进入配置文件目录建立一个目录servers
以放未来添加的配置文件,修改配置文件nginx.conf
添加include servers/*.conf;
,进入servers
建立一个空文件upsync-test-tmp.conf
做为upsync的缓存文件,再建立配置文件 test-upsync.conf
upstream testupsync { upsync 127.0.0.1:8500/v1/kv/upstreams/testupsync/ upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off; upsync_dump_path /usr/local/etc/nginx2/servers/upsync-test-tmp.conf; include /usr/local/etc/nginx2/servers/upsync-test-tmp.conf; server 127.0.0.1:11111 down ; } server { listen 8000; server_name localhost; location / { proxy_pass http://testupsync; } location = /upstream_show { upstream_show; } }
server 127.0.0.1:11111 down ;
是为了占位,防止启动nginx报错。
接下来向注册中心注册服务
curl -X PUT -d '{"weight":2, "max_fails":2, "fail_timeout":10 }' http://127.0.0.1:8500/v1/kvtreams/testupsync/127.0.0.1:8002 curl -s http://127.0.0.1:8500/v1/kv/upstreams/testupsync?recurse
接下来启动nginx,再请求服务发现已经起做用了。
再下掉这个服务看看是否生效
curl -X PUT -d '{"weight":2, "max_fails":2, "fail_timeout":10,"down":1}' http://127.0.0.1:8500/v1/kvtreams/testupsync/127.0.0.1:8002
再上线这个服务
curl -X PUT -d '{"weight":2, "max_fails":2, "fail_timeout":10,"down":0}' http://127.0.0.1:8500/v1/kvtreams/testupsync/127.0.0.1:8002
测试已经没有问题。
【转载请注明出处】:http://www.javashuo.com/article/p-uhjihkyh-do.html