[notice] child pid 13990 exit signalSegmentation fault (11) 解决办法

本文通过GDB调试解决了一个因GeoIP数据库缺失导致的段错误问题,最终通过正确配置数据库解决了问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境:CentOS 6.5 64bit

httpd版本:2.2.15

PHP版本:5.3.3


在搭建stalker server后,用机顶盒访问stalker server,request 某一个URL失败。

nginx反向代理,错误log如下:

[plain]  view plain  copy
  1. [nginx 1.12.2 error log]  
  2. 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如下:

[plain]  view plain  copy
  1. [Apache(httpd 2.2.15) error log]  
  2. [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流程如下:

[plain]  view plain  copy
  1. [root@localhost ~]# service httpd stop  
  2. Stopping httpd:                                            [  OK  ]  
[plain]  view plain  copy
  1. [root@localhost ~]# gdb httpd  
  2. GNU gdb (GDB) Red Hat Enterprise Linux (7.2-92.el6)  
  3. Copyright (C) 2010 Free Software Foundation, Inc.  
  4. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>  
  5. This is free software: you are free to change and redistribute it.  
  6. There is NO WARRANTY, to the extent permitted by law.  Type "show copying"  
  7. and "show warranty" for details.  
  8. This GDB was configured as "x86_64-redhat-linux-gnu".  
  9. For bug reporting instructions, please see:  
  10. <http://www.gnu.org/software/gdb/bugs/>...  
  11. Reading symbols from /usr/sbin/httpd...(no debugging symbols found)...done.  
  12. Missing separate debuginfos, use: debuginfo-install httpd-2.2.15-60.el6.centos.6.x86_64  
  13. (gdb) run -X  
  14. Starting program: /usr/sbin/httpd -X  
  15. [Thread debugging using libthread_db enabled]  
  16. Detaching after fork from child process 6564.  
此时,这里向服务器发一个连接请求。

[plain]  view plain  copy
  1. Program received signal SIGSEGV, Segmentation fault.  
  2. 0x00007fffe34f9911 in GeoIP_id_by_name_gl () from /usr/lib64/libGeoIP.so.1  

从上述信息可以看到程序被中断在库函数 GeoIP_id_by_name_gl()中

使用gdb backtrace命令可以查看当前函数栈的所有信息。


[plain]  view plain  copy
  1. (gdb) backtrace  
  2. #0  0x00007fffe34f9911 in GeoIP_id_by_name_gl () from /usr/lib64/libGeoIP.so.1  
  3. #1  0x00007fffe34f9a19 in GeoIP_country_code_by_name_gl () from /usr/lib64/libGeoIP.so.1  
  4. #2  0x00007fffe34fb8dc in GeoIP_country_code_by_name () from /usr/lib64/libGeoIP.so.1  
  5. #3  0x00007fffe3728a12 in zif_geoip_country_code_by_name () from /usr/lib64/php/modules/geoip.so  
  6. #4  0x00007fffe48106f1 in ?? () from /usr/lib64/php/modules/ioncube_loader_lin_5.3.so  
  7. #5  0x00007fffe480ba95 in ?? () from /usr/lib64/php/modules/ioncube_loader_lin_5.3.so  
  8. #6  0x00007fffe480be2b in ?? () from /usr/lib64/php/modules/ioncube_loader_lin_5.3.so  
  9. #7  0x00007fffecc65535 in zend_call_function () from /etc/httpd/modules/libphp5.so  
  10. #8  0x00007fffecbbcce3 in ?? () from /etc/httpd/modules/libphp5.so  
  11. #9  0x00007fffe48106f1 in ?? () from /usr/lib64/php/modules/ioncube_loader_lin_5.3.so  
  12. #10 0x00007fffe480ba95 in ?? () from /usr/lib64/php/modules/ioncube_loader_lin_5.3.so  
  13. #11 0x00007fffe480be2b in ?? () from /usr/lib64/php/modules/ioncube_loader_lin_5.3.so  
  14. #12 0x00007fffeccbd5d6 in ?? () from /etc/httpd/modules/libphp5.so  
  15. #13 0x00007fffecc94c00 in execute () from /etc/httpd/modules/libphp5.so  
  16. #14 0x00007fffe480bd7b in ?? () from /usr/lib64/php/modules/ioncube_loader_lin_5.3.so  
  17. #15 0x00007fffecc6eded in zend_execute_scripts () from /etc/httpd/modules/libphp5.so  
  18. #16 0x00007fffecc1cd58 in php_execute_script () from /etc/httpd/modules/libphp5.so  
  19. #17 0x00007fffeccf8475 in ?? () from /etc/httpd/modules/libphp5.so  
  20. #18 0x00007ffff7fd6650 in ap_run_handler ()  
  21. #19 0x00007ffff7fd9f0e in ap_invoke_handler ()  
  22. #20 0x00007ffff7fe5660 in ap_process_request ()  
  23. #21 0x00007ffff7fe24a8 in ?? ()  
  24. #22 0x00007ffff7fde178 in ap_run_process_connection ()  
  25. #23 0x00007ffff7fea897 in ?? ()  
  26. #24 0x00007ffff7feab66 in ?? ()  
  27. #25 0x00007ffff7feb1c3 in ap_mpm_run ()  
  28. #26 0x00007ffff7fc0d10 in main ()  


问题点在libGeoIP.so.1中的函数GeoIP_id_by_name_gl(),看不出来个所以然,于是打算安装GeoIP-debuginfo版本再来 查看详细的debug信息


安装GeoIP-debuginfo

[plain]  view plain  copy
  1. [root@localhost logs]# yum list | grep GeoIP  
  2. GeoIP.x86_64                            1.6.5-1.el6               @epel  
  3. GeoIP-GeoLite-data.noarch               2017.07-1.el6             @epel  
  4. GeoIP-GeoLite-data-extra.noarch         2017.07-1.el6             @epel  
  5. GeoIP.i686                              1.6.5-1.el6               epel  
  6. GeoIP-debuginfo.i686                    1.6.5-1.el6               epel-debuginfo  
  7. GeoIP-debuginfo.x86_64                  1.6.5-1.el6               epel-debuginfo  
  8. GeoIP-devel.i686                        1.6.5-1.el6               epel  
  9. GeoIP-devel.x86_64                      1.6.5-1.el6               epel  
  10. python-GeoIP.x86_64                     1.2.5-0.2.20090931cvs.el6 epel  
  11. python-GeoIP-debuginfo.x86_64           1.2.5-0.2.20090931cvs.el6 epel-debuginfo  
[plain]  view plain  copy
  1. [root@localhost logs]# yum install GeoIP-debuginfo  
[plain]  view plain  copy
  1. [root@localhost logs]# rpm -qi GeoIP-debuginfo  
  2. Name        : GeoIP-debuginfo              Relocations: (not relocatable)  
  3. Version     : 1.6.5                             Vendor: Fedora Project  
  4. Release     : 1.el6                         Build Date: Tue 14 Apr 2015 03:28:46 PM CST  
  5. Install Date: Tue 30 Jan 2018 04:39:22 PM CST      Build Host: buildvm-09.phx2.fedoraproject.org  
  6. Group       : Development/Debug             Source RPM: GeoIP-1.6.5-1.el6.src.rpm  
  7. Size        : 962184                           License: LGPLv2+  
  8. Signature   : RSA/8, Tue 14 Apr 2015 11:16:42 PM CST, Key ID 3b49df2a0608b895  
  9. Packager    : Fedora Project  
  10. URL         : http://www.maxmind.com/app/c  
  11. Summary     : Debug information for package GeoIP  
  12. Description :  
  13. This package provides debug information for package GeoIP.  
  14. Debug information is useful when developing applications that use this  
  15. package or when debugging this package.  
[plain]  view plain  copy
  1. [root@localhost logs]# rpm -ql GeoIP-debuginfo  
  2. /usr/lib/debug  
  3. /usr/lib/debug/.build-id  
  4. /usr/lib/debug/.build-id/3e  
  5. /usr/lib/debug/.build-id/3e/9ad91a18eac417cd8ee4cad6387c3607899f89  
  6. /usr/lib/debug/.build-id/3e/9ad91a18eac417cd8ee4cad6387c3607899f89.debug  
  7. /usr/lib/debug/.build-id/df  
  8. /usr/lib/debug/.build-id/df/716da35dc61049b5f5dab030631cff52b0d053  
  9. /usr/lib/debug/.build-id/df/716da35dc61049b5f5dab030631cff52b0d053.debug  
  10. /usr/lib/debug/.build-id/f2  
  11. /usr/lib/debug/.build-id/f2/2a2618440310415d7dd3feadcf9896fad82a66  
  12. /usr/lib/debug/.build-id/f2/2a2618440310415d7dd3feadcf9896fad82a66.debug  
  13. /usr/lib/debug/usr  
  14. /usr/lib/debug/usr/bin  
  15. /usr/lib/debug/usr/bin/geoiplookup.debug  
  16. /usr/lib/debug/usr/bin/geoiplookup6.debug  
  17. /usr/lib/debug/usr/lib64  
  18. /usr/lib/debug/usr/lib64/libGeoIP.so.1.6.5.debug  
  19. /usr/lib/debug/usr/lib64/libGeoIP.so.1.debug  
  20. /usr/lib/debug/usr/lib64/libGeoIP.so.debug  
  21. /usr/src/debug/GeoIP-1.6.5  
  22. /usr/src/debug/GeoIP-1.6.5/apps  
  23. /usr/src/debug/GeoIP-1.6.5/apps/geoiplookup.c  
  24. /usr/src/debug/GeoIP-1.6.5/apps/geoiplookup6.c  
  25. /usr/src/debug/GeoIP-1.6.5/libGeoIP  
  26. /usr/src/debug/GeoIP-1.6.5/libGeoIP/GeoIP.c  
  27. /usr/src/debug/GeoIP-1.6.5/libGeoIP/GeoIP.h  
  28. /usr/src/debug/GeoIP-1.6.5/libGeoIP/GeoIPCity.c  
  29. /usr/src/debug/GeoIP-1.6.5/libGeoIP/GeoIPCity.h  
  30. /usr/src/debug/GeoIP-1.6.5/libGeoIP/GeoIP_deprecated.c  
  31. /usr/src/debug/GeoIP-1.6.5/libGeoIP/regionName.c  
  32. /usr/src/debug/GeoIP-1.6.5/libGeoIP/timeZone.c  

GeoIP-debuginfo安装完成后,把原来Release版本的动态库删除,建立软连接到Debug版本的动态库。


[plain]  view plain  copy
  1. [root@localhost logs]# ln -s  /usr/lib/debug/usr/lib64/libGeoIP.so.1.6.5.debug /usr/lib64/libGeoIP.so.1  
  2. [root@localhost logs]# ll /usr/lib64/libGeoIP.so.1  
  3. 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  
  4. [root@localhost logs]# ll  /usr/lib/debug/usr/lib64/libGeoIP.so.1.6.5.debug  
  5. -r--r--r-- 1 root root 463792 Apr 14  2015 /usr/lib/debug/usr/lib64/libGeoIP.so.1.6.5.debug  


按照上面GDB debug流程再次进行debug。

[plain]  view plain  copy
  1. [root@localhost logs]# service httpd stop  
  2. Stopping httpd:                                            [  OK  ]  
  3. [root@localhost logs]# gdb httpd  
  4. GNU gdb (GDB) Red Hat Enterprise Linux (7.2-92.el6)  
  5. Copyright (C) 2010 Free Software Foundation, Inc.  
  6. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>  
  7. This is free software: you are free to change and redistribute it.  
  8. There is NO WARRANTY, to the extent permitted by law.  Type "show copying"  
  9. and "show warranty" for details.  
  10. This GDB was configured as "x86_64-redhat-linux-gnu".  
  11. For bug reporting instructions, please see:  
  12. <http://www.gnu.org/software/gdb/bugs/>...  
  13. Reading symbols from /usr/sbin/httpd...(no debugging symbols found)...done.  
  14. Missing separate debuginfos, use: debuginfo-install httpd-2.2.15-60.el6.centos.6.x86_64  
  15. (gdb) run -X  
  16. Starting program: /usr/sbin/httpd -X  
  17. [Thread debugging using libthread_db enabled]  
  18.   
  19. Program received signal SIGSEGV, Segmentation fault.  
  20. _dl_relocate_object (scope=0x7ffff83a5678, reloc_mode=<value optimized out>, consider_profiling=0) at dl-reloc.c:242  
  21. 242         const char *strtab = (const void *) D_PTR (l, l_info[DT_STRTAB]);  
  22. (gdb) backtrace  
  23. #0  _dl_relocate_object (scope=0x7ffff83a5678, reloc_mode=<value optimized out>, consider_profiling=0) at dl-reloc.c:242  
  24. #1  0x00007ffff7d99b8a in dl_open_worker (a=0x7fffffffe080) at dl-open.c:349  
  25. #2  0x00007ffff7d951b6 in _dl_catch_error (objname=0x7fffffffe0d0, errstring=0x7fffffffe0c8, mallocedp=0x7fffffffe0df, operate=0x7ffff7d99920 <dl_open_worker>, args=0x7fffffffe080) at dl-error.c:178  
  26. #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)  
  27.     at dl-open.c:569  
  28. #4  0x00007ffff62dff66 in dlopen_doit (a=0x7fffffffe2a0) at dlopen.c:67  
  29. #5  0x00007ffff7d951b6 in _dl_catch_error (objname=0x7ffff824d310, errstring=0x7ffff824d318, mallocedp=0x7ffff824d308, operate=0x7ffff62dff00 <dlopen_doit>, args=0x7fffffffe2a0) at dl-error.c:178  
  30. #6  0x00007ffff62e029c in _dlerror_run (operate=0x7ffff62dff00 <dlopen_doit>, args=0x7fffffffe2a0) at dlerror.c:164  
  31. #7  0x00007ffff62dfee1 in __dlopen (file=<value optimized out>, mode=<value optimized out>) at dlopen.c:88  
  32. #8  0x00007fffecbc2037 in php_load_extension () from /etc/httpd/modules/libphp5.so  
  33. #9  0x00007fffecc6672e in zend_llist_apply () from /etc/httpd/modules/libphp5.so  
  34. #10 0x00007fffecc2589a in ?? () from /etc/httpd/modules/libphp5.so  
  35. #11 0x00007fffecc1e8a9 in php_module_startup () from /etc/httpd/modules/libphp5.so  
  36. #12 0x00007fffeccf7995 in ?? () from /etc/httpd/modules/libphp5.so  
  37. #13 0x00007fffeccf8570 in ?? () from /etc/httpd/modules/libphp5.so  
  38. #14 0x00007ffff7fd6489 in ap_run_post_config ()  
  39. #15 0x00007ffff7fc0ce7 in main ()  
  40. (gdb) up 0  
  41. #0  _dl_relocate_object (scope=0x7ffff83a5678, reloc_mode=<value optimized out>, consider_profiling=  
  42. 0) at dl-reloc.c:242  
  43. 242         const char *strtab = (const void *) D_PTR (l, l_info[DT_STRTAB]);  
  44. (gdb) up  
  45. #1  0x00007ffff7d99b8a in dl_open_worker (a=0x7fffffffe080) at dl-open.c:349  
  46. 349                 _dl_relocate_object (l, l->l_scope, reloc_mode, 0);  
  47. (gdb) up  
  48. #2  0x00007ffff7d951b6 in _dl_catch_error (objname=0x7fffffffe0d0, errstring=0x7fffffffe0c8, mallocedp=0x7fffffffe0df, operate=0x7ffff7d99920 <dl_open_worker>, args=0x7fffffffe080) at dl-error.c:178  
  49. 178           (*operate) (args);  
  50. (gdb) down  
  51. #1  0x00007ffff7d99b8a in dl_open_worker (a=0x7fffffffe080) at dl-open.c:349  
  52. 349                 _dl_relocate_object (l, l->l_scope, reloc_mode, 0);  
  53. (gdb) down  
  54. #0  _dl_relocate_object (scope=0x7ffff83a5678, reloc_mode=<value optimized out>, consider_profiling=0) at dl-reloc.c:242  
  55. 242         const char *strtab = (const void *) D_PTR (l, l_info[DT_STRTAB]);  
  56. (gdb) up  
  57. #1  0x00007ffff7d99b8a in dl_open_worker (a=0x7fffffffe080) at dl-open.c:349  
  58. 349                 _dl_relocate_object (l, l->l_scope, reloc_mode, 0);  
  59. (gdb) up  
  60. #2  0x00007ffff7d951b6 in _dl_catch_error (objname=0x7fffffffe0d0, errstring=0x7fffffffe0c8, mallocedp=0x7fffffffe0df, operate=0x7ffff7d99920 <dl_open_worker>, args=0x7fffffffe080) at dl-error.c:178  
  61. 178           (*operate) (args);  
  62. (gdb) up  
  63. #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)  
  64.     at dl-open.c:569  
  65. 569       int errcode = _dl_catch_error (&objname, &errstring, &malloced,  
  66. (gdb) up  
  67. #4  0x00007ffff62dff66 in dlopen_doit (a=0x7fffffffe2a0) at dlopen.c:67  
  68. 67        args->new = GLRO(dl_open) (args->file ?: "", args->mode | __RTLD_DLOPEN,  
  69. (gdb) up  
  70. #5  0x00007ffff7d951b6 in _dl_catch_error (objname=0x7ffff824d310, errstring=0x7ffff824d318, mallocedp=0x7ffff824d308, operate=0x7ffff62dff00 <dlopen_doit>, args=0x7fffffffe2a0) at dl-error.c:178  
  71. 178           (*operate) (args);  
  72. (gdb) up  
  73. #6  0x00007ffff62e029c in _dlerror_run (operate=0x7ffff62dff00 <dlopen_doit>, args=0x7fffffffe2a0) at dlerror.c:164  
  74. 164       result->errcode = GLRO(dl_catch_error) (&result->objname, &result->errstring,  
  75. (gdb) up  
  76. #7  0x00007ffff62dfee1 in __dlopen (file=<value optimized out>, mode=<value optimized out>) at dlopen.c:88  
  77. 88        return _dlerror_run (dlopen_doit, &args) ? NULL : args.new;  
  78. (gdb) up  
  79. #8  0x00007fffecbc2037 in php_load_extension () from /etc/httpd/modules/libphp5.so  
  80. (gdb) up  
  81. #9  0x00007fffecc6672e in zend_llist_apply () from /etc/httpd/modules/libphp5.so  
  82. (gdb) up  
  83. #10 0x00007fffecc2589a in ?? () from /etc/httpd/modules/libphp5.so  
  84. (gdb) up  
  85. #11 0x00007fffecc1e8a9 in php_module_startup () from /etc/httpd/modules/libphp5.so  
  86. (gdb) up  
  87. #12 0x00007fffeccf7995 in ?? () from /etc/httpd/modules/libphp5.so  
  88. (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_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国家数据库如下:

[plain]  view plain  copy
  1. [root@localhost Downloads]# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz  
[plain]  view plain  copy
  1. [root@localhost Downloads]# gzip -d GeoIP.dat.gz  
[plain]  view plain  copy
  1. [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;
//}

?>


测试成功!Apache后台error log不再有错误:[notice] child pid 13990 exit signalSegmentation fault (11)

本文开头提到的请求stalker server的URL,也正常!


至于nginx error log错误:"upstream prematurely closed connection while reading response header from upstream"也没有了,本文状况下,上游服务器过早断开连接,是因为geoip数据库使用错误,从而导致Apache进程被关闭了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值