以ubuntu20.04為例
倉庫地址:
https://github.com/PowerDNS/pdns
按上面教程可以編譯直接使用,但不能實現分省分線路解析,需要自行編譯,還得改文件
先到打開https://dev.maxmind.com/geoip/geoip2/geolite2/
分省解析需要下載:GeoLite2-City.mmdb 這個數據庫
分線路線解析需要下載: GeoLite2-ISP.mmdb (收費的,$24,如果你不需要更新,買一次就可以了)
下載好放到/etc/geoip
然後開始操作了:
先安裝依賴
apt install libcurl4-openssl-dev luajit lua-yaml-dev libyaml-cpp-dev libtolua-dev lua5.3 autoconf automake ragel bison flex g++ libboost-all-dev libtool make pkg-config libssl-dev lua-yaml-dev libyaml-cpp-dev libluajit-5.1-dev libcurl4 gawk libsqlite3-dev python3-venv
apt install libsodium-dev
apt install default-libmysqlclient-dev
apt install libpq-dev
apt install libsystemd0 libsystemd-dev
apt install libmaxminddb-dev libmaxminddb0 libgeoip1 libgeoip-dev
apt install lua*
再克隆倉庫
git clone https://github.com/PowerDNS/pdns.git
把我附件修改過的代碼覆蓋到 modules/geoipbackend
執行編譯
./configure --prefix=/usr/local/powerdns --enable-verbose-logging --enable-static-binaries --enable-pdns_server --enable-nedmalloc --with-libcurl --with-maxminddb-includedir --with-maxminddb-libdir --with-lua --with-modules='gmysql geoip lua2 bind'
make
make install
建立數據庫,把附件的數據導入執行(注意:這個庫和官方的有改動,我把表放到內存中運行了,所以重啟數據庫記錄會消失,我是多臺服務器做主從了,不怕丟失)
停止系統默認DNS解析器,防止53端口占用
#停止 DNSStubListener
systemctl stop systemd-resolved
echo "nameserver 8.8.8.8" > /etc/resolv.conf
cat > /usr/local/powerdns/etc/pdns.conf<<EOF
[Unit]
enable-lua-records=yes
gmysql-host=127.0.0.1
#mysql帳號
gmysql-user=root
#mysql密碼
gmysql-password=123456
#mysql數據庫
gmysql-dbname=pdns
local-address=0.0.0.0:53
api=yes
api-key=rthqnglamaorrivu
# IP Address of web server to listen on
webserver-address=0.0.0.0
# Port of web server to listen on
webserver-port=62888
# Web server access is only allowed from these subnets
webserver-allow-from=0.0.0.0/0,::/0
# Needed before 4.1.0
webserver=yes
launch=gmysql,geoip
#以下三個參數為調試使用
log-dns-details=yes
log-dns-queries=yes
loglevel=6
#是否放到後臺運行
#daemon=yes
geoip-database-files=/etc/geoip/GeoIP2-ISP.mmdb
EOF
ln -s /usr/local/powerdns/sbin/pdns_server /usr/sbin/pdns_server
運行
/usr/sbin/pdns_server --socket-dir=/run/pdns --guardian=no --daemon=no --disable-syslog --log-timestamp=no --write-pid=no
如果沒意外服務端就好了
LUA數據庫插件安裝:
$ wget http://luarocks.org/releases/luarocks-2.2.1.tar.gz
$ tar zxpf luarocks-2.2.1.tar.gz
$ cd luarocks-2.2.1
$ ./configure; sudo make bootstrap
$ sudo luarocks install luasql-mysql
$ lua
Lua 5.3.0 Copyright (C) 1994-2015 Lua.org, PUC-Rio
> require "socket"
Lua 5.3.0 Copyright (C) 1994-2015 Lua.org, PUC-Rio
WEB 端下載
https://www.poweradmin.org/ 直接安裝就行了
安裝完後替換
inc/toolkit.inc.php 和 inc/dns.inc.php 增加LUA
然後登陸 點上方的Add master zone添加域名
點List zones 管理域名解析
使用LUA增加分線路解析示示例
LOC 發不了代碼來張圖片吧
5和10的取值於geoipinterface.hh:
enum GeoIPQueryAttribute
{
ASn, #0
City, #1
Continent, #2
Country, #3
Country2, #4
Name, #5
Region,
Location,
autonomousSystemNumber,
autonomousSystemOrganization,
isp, #10
organization
};
LUA 參考:https://doc.powerdns.com/authoritative/lua-records/
API 參考(就是62888那個API端口): https://doc.powerdns.com/md/httpapi/README/
|