nginx和geoip2(geolite2)错误:不是二进制兼容的

时间:2017-01-21 21:03:34

标签: ubuntu nginx geoip maxmind geoip2

nginx不支持geoip2。在nginx documentation上有一个geoip2 3d party module的引用,所以我想试一试,但我猜有些东西我不知道了。

以下是我正在处理的机器的一些细节:

$ cat /etc/*release* | grep -i dist
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"

$ dpkg -l | grep -i nginx
ii  nginx   1.10.2-1~xenial  amd64  high performance web server

这是我为编译geoip2模块而采取的步骤:

$ cd /tmp
/tmp$ wget https://github.com/maxmind/libmaxminddb/releases/download/1.2.0/libmaxminddb-1.2.0.tar.gz
/tmp$ tar xvzf libmaxminddb-1.2.0.tar.gz

/tmp$ apt-get install dh-autoreconf build-essential automake
/tmp$ cd libmaxminddb*
/tmp/libmaxminddb-1.2.0$ ./configure
/tmp/libmaxminddb-1.2.0$ make check
/tmp/libmaxminddb-1.2.0$ make install
/tmp/libmaxminddb-1.2.0$ ldconfig

/tmp/libmaxminddb-1.2.0:$ cd ..
/tmp$ wget https://github.com/leev/ngx_http_geoip2_module/archive/2.0.tar.gz -O ngx_http_geoip2_module-2.0.tar.gz
/tmp$ tar xvzf ngx_http_geoip2_module*.tar.gz
/tmp$ VERSION=`dpkg -l | grep -i nginx | awk '{print $3}' | cut -d - -f 1`
/tmp$ wget https://nginx.org/download/nginx-${VERSION}.tar.gz
/tmp$ tar xvzf nginx-${VERSION}.tar.gz
/tmp$ cd nginx*
/tmp/nginx-1.10.2$ nginx -V # finding configuration flags
/tmp/nginx-1.10.2$ ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-file-aio --with-threads --with-ipv6 --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed' --add-dynamic-module=/tmp/ngx_http_geoip2_module-2.0
/tmp/nginx-1.10.2$ make
/tmp/nginx-1.10.2$ make install

这些是我在geoip2中动态加载nginx模块的步骤:

$ mv /tmp/nginx-1.10.2/objs/ngx_http_geoip2_module.so /etc/nginx/modules/
# placing a configuration
$ cat /etc/nginx/conf.d/http_geoip.conf
geoip2 /usr/share/GeoIP/GeoIP2-City.mmdb {
  $geoip2_data_city_name default=NA city names zh-CN;
  $geoip2_data_country_name default=NA country names zh-CN;
  $geoip2_data_country_code default=NA country is_code;
  $geoip2_data_status default=NA subdivisions 0 names zh-CN;
  $geoip2_data_zip default=NA postal code;
}
$ cat -n /etc/nginx/nginx.conf | grep -i load_module
     4  load_module modules/ngx_http_geoip2_module.so;

当我重新启动nginx服务时,我收到以下错误:

nginx: [emerg] module "/etc/nginx/modules/ngx_http_geoip2_module.so" is not binary compatible in /etc/nginx/nginx.conf:4

是否有人有领导?

更新 上面的所有命令都是在root用户下执行的,因此sudo命令不会显示在上面的代码段中。

更新2: 对于评论,我在执行make install之前添加了nginx二进制文件的sha1:

# openssl sha1 /usr/sbin/nginx && openssl sha1 /tmp/nginx-1.10.2/objs/nginx
SHA1(/usr/sbin/nginx)=              bef34e8fc1366cd831a3c61b0773af14c75f63d8
SHA1(/tmp/nginx-1.10.2/objs/nginx)= bd955d6b372f803c1527a8abf91f40fe9b3ffa89

,执行make install

后也是如此
# openssl sha1 /usr/sbin/nginx && openssl sha1 /tmp/nginx-1.10.2/objs/nginx
SHA1(/usr/sbin/nginx)=              bd955d6b372f803c1527a8abf91f40fe9b3ffa89
SHA1(/tmp/nginx-1.10.2/objs/nginx)= bd955d6b372f803c1527a8abf91f40fe9b3ffa89

sha摘要不同,表示不同的二进制文件。我想如果引入的某些更改和编译导致新的不同二进制文件,它应该是不同的。

我可以看到在configure目录中执行nginx命令时(如上所述),它输出它发现geoip2为动态模块。这是输出:

configuring additional dynamic modules
adding module in /tmp/ngx_http_geoip2_module-2.0
checking for MaxmindDB library ... found
 + ngx_geoip2_module was configured

任何想法?

解决: 当我在一台全新的ubuntu机器上重复这些步骤时问题得到解决。

0 个答案:

没有答案