agladysh / lua-geoip Goto Github PK
View Code? Open in Web Editor NEWBindings for MaxMind's GeoIP library
License: Other
Bindings for MaxMind's GeoIP library
License: Other
When lua_code_cache
is off
, fd which points to error.log increases continuously for workers.
I do understand lua_code_cache off
should not be used in production. This setting exists in development environment only. However, it still annoys because nginx will no longer accept any request when fd limit is reached during testing.
$ ll /proc/{worker_pid}/fd/
l-wx------ 1 ubuntu ubuntu 64 May 8 06:43 14 -> /var/log/nginx/error.log
l-wx------ 1 ubuntu ubuntu 64 May 8 06:43 2 -> /var/log/nginx/error.log
l-wx------ 1 ubuntu ubuntu 64 May 8 06:43 28 -> /var/log/nginx/error.log
l-wx------ 1 ubuntu ubuntu 64 May 8 06:43 30 -> /var/log/nginx/error.log
l-wx------ 1 ubuntu ubuntu 64 May 8 06:43 33 -> /var/log/nginx/error.log
l-wx------ 1 ubuntu ubuntu 64 May 8 06:43 35 -> /var/log/nginx/error.log
l-wx------ 1 ubuntu ubuntu 64 May 8 06:43 37 -> /var/log/nginx/error.log
l-wx------ 1 ubuntu ubuntu 64 May 8 06:43 39 -> /var/log/nginx/error.log
l-wx------ 1 ubuntu ubuntu 64 May 8 06:43 42 -> /var/log/nginx/error.log
l-wx------ 1 ubuntu ubuntu 64 May 8 06:43 44 -> /var/log/nginx/error.log
...
After some experiments and observation, I can reproduce by the following simplified scripts:
Entry script:
#!/usr/bin/env lua
local Geo = require "MyGeo"
MyGeo.lua:
#!/usr/bin/env lua
local geoip_country = require "geoip.country"
local GeoIp = {
db_country = geoip_country.open("/usr/share/GeoIP/GeoIP.dat")
}
return GeoIp
The geoip module is
# luarocks show lua-geoip
lua-geoip 0.1.2-1 - Bindings for MaxMind's GeoIP library
License: MIT/X11
Homepage: http://github.com/agladysh/lua-geoip
Installed in: /usr/local
Modules:
geoip.country
geoip
geoip.city
The openresty version is:
./nginx -v
nginx version: openresty/1.11.2.1
It isn't explicitly stated, but this library only supports the legacy .dat format correct.. and not the new mmdb format (https://github.com/maxmind/libmaxminddb)?
luaL_optint for charset should probably use parameter 3, although WITHOUT F*CKING DOCS this is not easy to tell.
https://github.com/agladysh/lua-geoip/blob/master/src/database.c#L21
No one wants to look at the tests file for it, obviously.
push_country_info
should handle if nothing was found or GeoIP_*_by_id
returned NULL
.
I am using luarocks install lua-geoip
but I got this “Error: Could not find expected file GeoIP.h, or GeoIP.h for GEOIP ”
yum install libgeoip-dev no pakage
I cannot find where you declare constant GEOIP_SILENCE, neither does the compiler.
Please let me know how to install lua-geoip successfully.
Thanks!
see:
root@yy-luarocks-server:/# luarocks install lua-geoip
Installing http://luarocks.org/repositories/rocks/lua-geoip-0.2-1.src.rock
gcc -O2 -fPIC -I/usr/include/lua5.1 -c src/database.c -o src/database.o -Isrc/
gcc -O2 -fPIC -I/usr/include/lua5.1 -c src/country.c -o src/country.o -Isrc/
src/country.c: In function ‘lcountry_open’:
src/country.c:264:28: error: ‘GEOIP_SILENCE’ undeclared (first use in this function)
GEOIP_MEMORY_CACHE | GEOIP_SILENCE,
^
src/country.c:264:28: note: each undeclared identifier is reported only once for each function it appears in
Error: Build error: Failed compiling object src/country.o
You should make a new release on luarocks with my old fix for the file descriptor leak, and fix the naming luaL_reg -> luaL_Reg, because not all distros have LUA_COMPAT_ALL defined.
I trying get country name by Ip, but have error:
$ lua init.lua
lua: init.lua:9: attempt to call field 'COUNTRY' (a number value)
require "geoip"
local ip = "185.10.127.226"
local geoip_country = require 'geoip.country'
local geoip_country_filename = select(1, ...) or "./GeoIP.dat"
assert(io.open(geoip_country_filename, "r")):close()
do
local country = geoip.COUNTRY(ip)
end
print(country)
```lua
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.