环境:CentOS 6.5 64bit
httpd版本:2.2.15
PHP版本:5.3.3
在搭建stalker server后,用机顶盒访问stalker server,request 某一个URL失败。
nginx反向代理,错误log如下:
- [nginx 1.12.2 error log]
- 2018/01/30 15:20:23 [error] 5753#0: *456 upstream prematurely closed connection while reading response header from upstream, client: 10.209.177.39, server: localhost, request: "GET /stalker_portal/server/load.php?type=stb&action=get_profile&stb_type=MAG250&sn=0000000000000&ver=ImageDescription%3A%200.2.16-250%3B%20ImageDate%3A%2018%20Mar%202013%2019%3A56%3A53%20GMT%2B0200%3B%20PORTAL%20version%3A%204.9.9%3B%20API%20Version%3A%20JS%20API%20version%3A%20328%3B%20STB%20API%20version%3A%20134%3B%20Player%20Engine%20version%3A%200x566¬_valid_token=1&auth_second_step=0&hd=1&num_banks=1&image_version=216&hw_version=1.7-BD-00 HTTP/1.1", upstream: "http://127.0.0.1:88/stalker_portal/server/load.php?type=stb&action=get_profile&stb_type=MAG250&sn=0000000000000&ver=ImageDescription%3A%200.2.16-250%3B%20ImageDate%3A%2018%20Mar%202013%2019%3A56%3A53%20GMT%2B0200%3B%20PORTAL%20version%3A%204.9.9%3B%20API%20Version%3A%20JS%20API%20version%3A%20328%3B%20STB%20API%20version%3A%20134%3B%20Player%20Engine%20version%3A%200x566¬_valid_token=1&auth_second_step=0&hd=1&num_banks=1&image_version=216&hw_version=1.7-BD-00", host: "10.209.177.82"
一开始网上搜索错误"upstream prematurely closed connection while reading response header from upstream"的解决方案,基本上都是说明nginx和Apache配置中,关于KeepAlive或者Timeout设定有误,或者是说nginx接收到HTTP/1.1请求转发给Apache变更为HTTP/1.0,等等导致的错误,这些double check后,还是有此问题。于是就想着看看Apache这边有没有错误log,结果一查,Apache这边还真有个错误。
Apache错误log如下:
- [Apache(httpd 2.2.15) error log]
- [Tue Jan 30 15:20:24 2018] [notice] child pid 13990 exit signal Segmentation fault (11)
从上述两个错误log综合分析,问题应该是Apache错误log导致。
于是网上搜索错误log "[notice] child pid 13990 exit signalSegmentation fault (11)" ,没有找到适合我的解法。
看到如下文章介绍通过GDB调试问题点。
http://blog.youkuaiyun.com/greatchina01/article/details/12832717
http://blog.youkuaiyun.com/greatchina01/article/details/11613305
具体GDB debug流程如下:
- [root@localhost ~]# service httpd stop
- Stopping httpd: [ OK ]
- [root@localhost ~]# gdb httpd
- GNU gdb (GDB) Red Hat Enterprise Linux (7.2-92.el6)
- Copyright (C) 2010 Free Software Foundation, Inc.
- License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
- This is free software: you are free to change and redistribute it.
- There is NO WARRANTY, to the extent permitted by law. Type "show copying"
- and "show warranty" for details.
- This GDB was configured as "x86_64-redhat-linux-gnu".
- For bug reporting instructions, please see:
- <http://www.gnu.org/software/gdb/bugs/>...
- Reading symbols from /usr/sbin/httpd...(no debugging symbols found)...done.
- Missing separate debuginfos, use: debuginfo-install httpd-2.2.15-60.el6.centos.6.x86_64
- (gdb) run -X
- Starting program: /usr/sbin/httpd -X
- [Thread debugging using libthread_db enabled]
- Detaching after fork from child process 6564.
- Program received signal SIGSEGV, Segmentation fault.
- 0x00007fffe34f9911 in GeoIP_id_by_name_gl () from /usr/lib64/libGeoIP.so.1
从上述信息可以看到程序被中断在库函数 GeoIP_id_by_name_gl()中
使用gdb backtrace命令可以查看当前函数栈的所有信息。
- (gdb) backtrace
- #0 0x00007fffe34f9911 in GeoIP_id_by_name_gl () from /usr/lib64/libGeoIP.so.1
- #1 0x00007fffe34f9a19 in GeoIP_country_code_by_name_gl () from /usr/lib64/libGeoIP.so.1
- #2 0x00007fffe34fb8dc in GeoIP_country_code_by_name () from /usr/lib64/libGeoIP.so.1
- #3 0x00007fffe3728a12 in zif_geoip_country_code_by_name () from /usr/lib64/php/modules/geoip.so
- #4 0x00007fffe48106f1 in ?? () from /usr/lib64/php/modules/ioncube_loader_lin_5.3.so
- #5 0x00007fffe480ba95 in ?? () from /usr/lib64/php/modules/ioncube_loader_lin_5.3.so
- #6 0x00007fffe480be2b in ?? () from /usr/lib64/php/modules/ioncube_loader_lin_5.3.so
- #7 0x00007fffecc65535 in zend_call_function () from /etc/httpd/modules/libphp5.so
- #8 0x00007fffecbbcce3 in ?? () from /etc/httpd/modules/libphp5.so
- #9 0x00007fffe48106f1 in ?? () from /usr/lib64/php/modules/ioncube_loader_lin_5.3.so
- #10 0x00007fffe480ba95 in ?? () from /usr/lib64/php/modules/ioncube_loader_lin_5.3.so
- #11 0x00007fffe480be2b in ?? () from /usr/lib64/php/modules/ioncube_loader_lin_5.3.so
- #12 0x00007fffeccbd5d6 in ?? () from /etc/httpd/modules/libphp5.so
- #13 0x00007fffecc94c00 in execute () from /etc/httpd/modules/libphp5.so
- #14 0x00007fffe480bd7b in ?? () from /usr/lib64/php/modules/ioncube_loader_lin_5.3.so
- #15 0x00007fffecc6eded in zend_execute_scripts () from /etc/httpd/modules/libphp5.so
- #16 0x00007fffecc1cd58 in php_execute_script () from /etc/httpd/modules/libphp5.so
- #17 0x00007fffeccf8475 in ?? () from /etc/httpd/modules/libphp5.so
- #18 0x00007ffff7fd6650 in ap_run_handler ()
- #19 0x00007ffff7fd9f0e in ap_invoke_handler ()
- #20 0x00007ffff7fe5660 in ap_process_request ()
- #21 0x00007ffff7fe24a8 in ?? ()
- #22 0x00007ffff7fde178 in ap_run_process_connection ()
- #23 0x00007ffff7fea897 in ?? ()
- #24 0x00007ffff7feab66 in ?? ()
- #25 0x00007ffff7feb1c3 in ap_mpm_run ()
- #26 0x00007ffff7fc0d10 in main ()
安装GeoIP-debuginfo
- [root@localhost logs]# yum list | grep GeoIP
- GeoIP.x86_64 1.6.5-1.el6 @epel
- GeoIP-GeoLite-data.noarch 2017.07-1.el6 @epel
- GeoIP-GeoLite-data-extra.noarch 2017.07-1.el6 @epel
- GeoIP.i686 1.6.5-1.el6 epel
- GeoIP-debuginfo.i686 1.6.5-1.el6 epel-debuginfo
- GeoIP-debuginfo.x86_64 1.6.5-1.el6 epel-debuginfo
- GeoIP-devel.i686 1.6.5-1.el6 epel
- GeoIP-devel.x86_64 1.6.5-1.el6 epel
- python-GeoIP.x86_64 1.2.5-0.2.20090931cvs.el6 epel
- python-GeoIP-debuginfo.x86_64 1.2.5-0.2.20090931cvs.el6 epel-debuginfo
- [root@localhost logs]# yum install GeoIP-debuginfo
- [root@localhost logs]# rpm -qi GeoIP-debuginfo
- Name : GeoIP-debuginfo Relocations: (not relocatable)
- Version : 1.6.5 Vendor: Fedora Project
- Release : 1.el6 Build Date: Tue 14 Apr 2015 03:28:46 PM CST
- Install Date: Tue 30 Jan 2018 04:39:22 PM CST Build Host: buildvm-09.phx2.fedoraproject.org
- Group : Development/Debug Source RPM: GeoIP-1.6.5-1.el6.src.rpm
- Size : 962184 License: LGPLv2+
- Signature : RSA/8, Tue 14 Apr 2015 11:16:42 PM CST, Key ID 3b49df2a0608b895
- Packager : Fedora Project
- URL : http://www.maxmind.com/app/c
- Summary : Debug information for package GeoIP
- Description :
- This package provides debug information for package GeoIP.
- Debug information is useful when developing applications that use this
- package or when debugging this package.
- [root@localhost logs]# rpm -ql GeoIP-debuginfo
- /usr/lib/debug
- /usr/lib/debug/.build-id
- /usr/lib/debug/.build-id/3e
- /usr/lib/debug/.build-id/3e/9ad91a18eac417cd8ee4cad6387c3607899f89
- /usr/lib/debug/.build-id/3e/9ad91a18eac417cd8ee4cad6387c3607899f89.debug
- /usr/lib/debug/.build-id/df
- /usr/lib/debug/.build-id/df/716da35dc61049b5f5dab030631cff52b0d053
- /usr/lib/debug/.build-id/df/716da35dc61049b5f5dab030631cff52b0d053.debug
- /usr/lib/debug/.build-id/f2
- /usr/lib/debug/.build-id/f2/2a2618440310415d7dd3feadcf9896fad82a66
- /usr/lib/debug/.build-id/f2/2a2618440310415d7dd3feadcf9896fad82a66.debug
- /usr/lib/debug/usr
- /usr/lib/debug/usr/bin
- /usr/lib/debug/usr/bin/geoiplookup.debug
- /usr/lib/debug/usr/bin/geoiplookup6.debug
- /usr/lib/debug/usr/lib64
- /usr/lib/debug/usr/lib64/libGeoIP.so.1.6.5.debug
- /usr/lib/debug/usr/lib64/libGeoIP.so.1.debug
- /usr/lib/debug/usr/lib64/libGeoIP.so.debug
- /usr/src/debug/GeoIP-1.6.5
- /usr/src/debug/GeoIP-1.6.5/apps
- /usr/src/debug/GeoIP-1.6.5/apps/geoiplookup.c
- /usr/src/debug/GeoIP-1.6.5/apps/geoiplookup6.c
- /usr/src/debug/GeoIP-1.6.5/libGeoIP
- /usr/src/debug/GeoIP-1.6.5/libGeoIP/GeoIP.c
- /usr/src/debug/GeoIP-1.6.5/libGeoIP/GeoIP.h
- /usr/src/debug/GeoIP-1.6.5/libGeoIP/GeoIPCity.c
- /usr/src/debug/GeoIP-1.6.5/libGeoIP/GeoIPCity.h
- /usr/src/debug/GeoIP-1.6.5/libGeoIP/GeoIP_deprecated.c
- /usr/src/debug/GeoIP-1.6.5/libGeoIP/regionName.c
- /usr/src/debug/GeoIP-1.6.5/libGeoIP/timeZone.c
GeoIP-debuginfo安装完成后,把原来Release版本的动态库删除,建立软连接到Debug版本的动态库。
- [root@localhost logs]# ln -s /usr/lib/debug/usr/lib64/libGeoIP.so.1.6.5.debug /usr/lib64/libGeoIP.so.1
- [root@localhost logs]# ll /usr/lib64/libGeoIP.so.1
- lrwxrwxrwx 1 root root 48 Jan 30 16:47 /usr/lib64/libGeoIP.so.1 -> /usr/lib/debug/usr/lib64/libGeoIP.so.1.6.5.debug
- [root@localhost logs]# ll /usr/lib/debug/usr/lib64/libGeoIP.so.1.6.5.debug
- -r--r--r-- 1 root root 463792 Apr 14 2015 /usr/lib/debug/usr/lib64/libGeoIP.so.1.6.5.debug
- [root@localhost logs]# service httpd stop
- Stopping httpd: [ OK ]
- [root@localhost logs]# gdb httpd
- GNU gdb (GDB) Red Hat Enterprise Linux (7.2-92.el6)
- Copyright (C) 2010 Free Software Foundation, Inc.
- License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
- This is free software: you are free to change and redistribute it.
- There is NO WARRANTY, to the extent permitted by law. Type "show copying"
- and "show warranty" for details.
- This GDB was configured as "x86_64-redhat-linux-gnu".
- For bug reporting instructions, please see:
- <http://www.gnu.org/software/gdb/bugs/>...
- Reading symbols from /usr/sbin/httpd...(no debugging symbols found)...done.
- Missing separate debuginfos, use: debuginfo-install httpd-2.2.15-60.el6.centos.6.x86_64
- (gdb) run -X
- Starting program: /usr/sbin/httpd -X
- [Thread debugging using libthread_db enabled]
- Program received signal SIGSEGV, Segmentation fault.
- _dl_relocate_object (scope=0x7ffff83a5678, reloc_mode=<value optimized out>, consider_profiling=0) at dl-reloc.c:242
- 242 const char *strtab = (const void *) D_PTR (l, l_info[DT_STRTAB]);
- (gdb) backtrace
- #0 _dl_relocate_object (scope=0x7ffff83a5678, reloc_mode=<value optimized out>, consider_profiling=0) at dl-reloc.c:242
- #1 0x00007ffff7d99b8a in dl_open_worker (a=0x7fffffffe080) at dl-open.c:349
- #2 0x00007ffff7d951b6 in _dl_catch_error (objname=0x7fffffffe0d0, errstring=0x7fffffffe0c8, mallocedp=0x7fffffffe0df, operate=0x7ffff7d99920 <dl_open_worker>, args=0x7fffffffe080) at dl-error.c:178
- #3 0x00007ffff7d994fa in _dl_open (file=0x7ffff7ed90d0 "/usr/lib64/php/modules/geoip.so", mode=-2147483382, caller_dlopen=0x7fffecbc2037, nsid=-2, argc=2, argv=<value optimized out>, env=0x7fffffffe690)
- at dl-open.c:569
- #4 0x00007ffff62dff66 in dlopen_doit (a=0x7fffffffe2a0) at dlopen.c:67
- #5 0x00007ffff7d951b6 in _dl_catch_error (objname=0x7ffff824d310, errstring=0x7ffff824d318, mallocedp=0x7ffff824d308, operate=0x7ffff62dff00 <dlopen_doit>, args=0x7fffffffe2a0) at dl-error.c:178
- #6 0x00007ffff62e029c in _dlerror_run (operate=0x7ffff62dff00 <dlopen_doit>, args=0x7fffffffe2a0) at dlerror.c:164
- #7 0x00007ffff62dfee1 in __dlopen (file=<value optimized out>, mode=<value optimized out>) at dlopen.c:88
- #8 0x00007fffecbc2037 in php_load_extension () from /etc/httpd/modules/libphp5.so
- #9 0x00007fffecc6672e in zend_llist_apply () from /etc/httpd/modules/libphp5.so
- #10 0x00007fffecc2589a in ?? () from /etc/httpd/modules/libphp5.so
- #11 0x00007fffecc1e8a9 in php_module_startup () from /etc/httpd/modules/libphp5.so
- #12 0x00007fffeccf7995 in ?? () from /etc/httpd/modules/libphp5.so
- #13 0x00007fffeccf8570 in ?? () from /etc/httpd/modules/libphp5.so
- #14 0x00007ffff7fd6489 in ap_run_post_config ()
- #15 0x00007ffff7fc0ce7 in main ()
- (gdb) up 0
- #0 _dl_relocate_object (scope=0x7ffff83a5678, reloc_mode=<value optimized out>, consider_profiling=
- 0) at dl-reloc.c:242
- 242 const char *strtab = (const void *) D_PTR (l, l_info[DT_STRTAB]);
- (gdb) up
- #1 0x00007ffff7d99b8a in dl_open_worker (a=0x7fffffffe080) at dl-open.c:349
- 349 _dl_relocate_object (l, l->l_scope, reloc_mode, 0);
- (gdb) up
- #2 0x00007ffff7d951b6 in _dl_catch_error (objname=0x7fffffffe0d0, errstring=0x7fffffffe0c8, mallocedp=0x7fffffffe0df, operate=0x7ffff7d99920 <dl_open_worker>, args=0x7fffffffe080) at dl-error.c:178
- 178 (*operate) (args);
- (gdb) down
- #1 0x00007ffff7d99b8a in dl_open_worker (a=0x7fffffffe080) at dl-open.c:349
- 349 _dl_relocate_object (l, l->l_scope, reloc_mode, 0);
- (gdb) down
- #0 _dl_relocate_object (scope=0x7ffff83a5678, reloc_mode=<value optimized out>, consider_profiling=0) at dl-reloc.c:242
- 242 const char *strtab = (const void *) D_PTR (l, l_info[DT_STRTAB]);
- (gdb) up
- #1 0x00007ffff7d99b8a in dl_open_worker (a=0x7fffffffe080) at dl-open.c:349
- 349 _dl_relocate_object (l, l->l_scope, reloc_mode, 0);
- (gdb) up
- #2 0x00007ffff7d951b6 in _dl_catch_error (objname=0x7fffffffe0d0, errstring=0x7fffffffe0c8, mallocedp=0x7fffffffe0df, operate=0x7ffff7d99920 <dl_open_worker>, args=0x7fffffffe080) at dl-error.c:178
- 178 (*operate) (args);
- (gdb) up
- #3 0x00007ffff7d994fa in _dl_open (file=0x7ffff7ed90d0 "/usr/lib64/php/modules/geoip.so", mode=-2147483382, caller_dlopen=0x7fffecbc2037, nsid=-2, argc=2, argv=<value optimized out>, env=0x7fffffffe690)
- at dl-open.c:569
- 569 int errcode = _dl_catch_error (&objname, &errstring, &malloced,
- (gdb) up
- #4 0x00007ffff62dff66 in dlopen_doit (a=0x7fffffffe2a0) at dlopen.c:67
- 67 args->new = GLRO(dl_open) (args->file ?: "", args->mode | __RTLD_DLOPEN,
- (gdb) up
- #5 0x00007ffff7d951b6 in _dl_catch_error (objname=0x7ffff824d310, errstring=0x7ffff824d318, mallocedp=0x7ffff824d308, operate=0x7ffff62dff00 <dlopen_doit>, args=0x7fffffffe2a0) at dl-error.c:178
- 178 (*operate) (args);
- (gdb) up
- #6 0x00007ffff62e029c in _dlerror_run (operate=0x7ffff62dff00 <dlopen_doit>, args=0x7fffffffe2a0) at dlerror.c:164
- 164 result->errcode = GLRO(dl_catch_error) (&result->objname, &result->errstring,
- (gdb) up
- #7 0x00007ffff62dfee1 in __dlopen (file=<value optimized out>, mode=<value optimized out>) at dlopen.c:88
- 88 return _dlerror_run (dlopen_doit, &args) ? NULL : args.new;
- (gdb) up
- #8 0x00007fffecbc2037 in php_load_extension () from /etc/httpd/modules/libphp5.so
- (gdb) up
- #9 0x00007fffecc6672e in zend_llist_apply () from /etc/httpd/modules/libphp5.so
- (gdb) up
- #10 0x00007fffecc2589a in ?? () from /etc/httpd/modules/libphp5.so
- (gdb) up
- #11 0x00007fffecc1e8a9 in php_module_startup () from /etc/httpd/modules/libphp5.so
- (gdb) up
- #12 0x00007fffeccf7995 in ?? () from /etc/httpd/modules/libphp5.so
- (gdb)
这样采用debug版本的库,就可以看到详细的代码行的错误点了。不过看到这里就蒙住了,猜测不可能是dl使用的问题,会不会是php-geoip扩展库的版本问题,由于stalker官网建议安装的OS是:Ubuntu Server LTS 14.04,所以就确认了Ubuntu Server LTS 14.04下安装的php-geoip扩展库的版本是:1.0.8。而我在CentOS 6.5下安装的是1.1.1(源码安装),所以就替换为1.0.8(yum epel 安装的php-pecl-geoip),同样还是fail。再次更换为源码安装1.0.8看会不会OK,结果还是fail。
此时毫无头绪了,GDB tacktrace也看不出来问题点。突然看到GDB tacktrace #2中有一处:errstring=0x7fffffffe0c8
#2 0x00007ffff7d951b6 in _dl_catch_error (objname=0x7fffffffe0d0, errstring=0x7fffffffe0c8, mallocedp=0x7fffffffe0df, operate=0x7ffff7d99920 <dl_open_worker>, args=0x7fffffffe080) at dl-error.c:178
#3 0x00007ffff7d994fa in _dl_open (file=0x7ffff7ed90d0 "/usr/lib64/php/modules/geoip.so", mode=-2147483382, caller_dlopen=0x7fffecbc2037, nsid=-2, argc=2, argv=<value optimized out>, env=0x7fffffffe690)
at dl-open.c:569
猜测是不是库中函数定义或者使用的问题。
Program received signal SIGSEGV, Segmentation fault.
0x00007fffe34f9911 in GeoIP_id_by_name_gl () from /usr/lib64/libGeoIP.so.1
(gdb) backtrace
#0 0x00007fffe34f9911 in GeoIP_id_by_name_gl () from /usr/lib64/libGeoIP.so.1
#1 0x00007fffe34f9a19 in GeoIP_country_code_by_name_gl () from /usr/lib64/libGeoIP.so.1
#2 0x00007fffe34fb8dc in GeoIP_country_code_by_name () from /usr/lib64/libGeoIP.so.1
#3 0x00007fffe3728a12 in zif_geoip_country_code_by_name () from /usr/lib64/php/modules/geoip.so
#4 0x00007fffe48106f1 in ?? () from /usr/lib64/php/modules/ioncube_loader_lin_5.3.so
#5 0x00007fffe480ba95 in ?? () from /usr/lib64/php/modules/ioncube_loader_lin_5.3.so
#6 0x00007fffe480be2b in ?? () from /usr/lib64/php/modules/ioncube_loader_lin_5.3.so
#7 0x00007fffecc65535 in zend_call_function () from /etc/httpd/modules/libphp5.so
于是就顺着这个思路,想看看是不是函数GeoIP_country_code_by_name没有在库中定义或者使用错误了,不过grep搜索发现库中有函数定义,那就看看是不是使用出错了,但是stalker server中间件代码这部分的php代码是被concube_loader加密了,无法查看debug。
那我就自己写个php测试代码。在php测试代码中,调用函数GeoIP_country_code_by_name,进行测试,发现Apache error log有个错误,和本文标题同一个问题:[notice] child pid 13990 exit signalSegmentation fault (11) 。
到现在,初步可以确定是库函数使用出错了。
于是,查找php geoip中的函数说明:http://php.net/manual/en/ref.geoip.php
- geoip_asnum_by_name — Get the Autonomous System Numbers (ASN)
- geoip_continent_code_by_name — Get the two letter continent code
- geoip_country_code_by_name — Get the two letter country code
- geoip_country_code3_by_name — Get the three letter country code
- geoip_country_name_by_name — Get the full country name
- geoip_database_info — Get GeoIP Database information
- geoip_db_avail — Determine if GeoIP Database is available
- geoip_db_filename — Returns the filename of the corresponding GeoIP Database
- geoip_db_get_all_info — Returns detailed information about all GeoIP database types
- geoip_domain_by_name — Get the second level domain name
- geoip_id_by_name — Get the Internet connection type
- geoip_isp_by_name — Get the Internet Service Provider (ISP) name
- geoip_netspeedcell_by_name — Get the Internet connection speed
- geoip_org_by_name — Get the organization name
- geoip_record_by_name — Returns the detailed City information found in the GeoIP Database
- geoip_region_by_name — Get the country code and region
- geoip_region_name_by_code — Returns the region name for some country and region code combo
- geoip_setup_custom_directory — Set a custom directory for the GeoIP database
- geoip_time_zone_by_country_and_region — Returns the time zone for some country and region code combo
函数列表中有geoip_country_code_by_name,没有GeoIP_country_code_by_name,不过PHP对于函数名的大小写是不敏感的,当然也有在php测试代码中再测试了一遍调用geoip_country_code_by_name,也还是有问题。不过,在php测试代码中,调用geoip_record_by_name测试却OK。难道我下载安装的库中没有函数geoip_country_code_by_name?
于是就从php geoip扩展官网查询(http://php.net/manual/en/geoip.setup.php),看到有提到:If the data files under /usr/share/GeoIP/ are not readable by apache, apache's process will crash with a segfault on calls to geoip functions.
恍然大悟啊,到此已经很有把握确定是我之前安装的geoip的数据库是city级别的,并没有安装country的数据库,导致的原因。于是就下载安装country数据库。
下载geoip国家数据库如下:
- [root@localhost Downloads]# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
- [root@localhost Downloads]# gzip -d GeoIP.dat.gz
- [root@localhost Downloads]# mv GeoIP.dat /var/lib/GeoIP/GeoIP.dat
安装成功后,从新进行php测试代码:
<?php
$record = geoip_record_by_name('www.baidu.com');
if ($record) {
print_r($record);
}
echo '<br>';
$country = geoip_country_code_by_name('www.baidu.com');
if ($country) {
echo 'This host is located in: ' . $country;
}
echo '<br>';
$country = GeoIP_country_code_by_name('www.baidu.com');
if ($country) {
echo 'This host is located in: ' . $country;
}
echo '<br>';
$country = geoip_country_name_by_name('www.baidu.com');
if ($country) {
echo 'This host is located in: ' . $country;
}
echo '<br>';
$continent = geoip_continent_code_by_name('www.baidu.com');
if ($continent) {
echo 'This host is located in: ' . $continent;
}
// Required database not available at /var/lib/GeoIP/GeoIPOrg.dat
//$org = geoip_org_by_name('www.baidu.com');
//if ($org) {
// echo 'This host is located in: ' . $org;
//}
// Required database not available at /var/lib/GeoIP/GeoIPNetSpeed.dat
//$id = geoip_id_by_name('www.baidu.com');
//if ($id) {
// echo 'This host is located in: ' . $id;
//}
// Required database not available at /var/lib/GeoIP/GeoIPRegion.dat
//$region = geoip_region_by_name('www.baidu.com');
//if ($region) {
// echo 'This host is located in: ' . $region;
//}
?>
本文开头提到的请求stalker server的URL,也正常!
至于nginx error log错误:"upstream prematurely closed connection while reading response header from upstream"也没有了,本文状况下,上游服务器过早断开连接,是因为geoip数据库使用错误,从而导致Apache进程被关闭了。