centos编译安装powerdns下安装配置GeoIP及分区智能dns解析
先开启一下防火墙
firewall-cmd --add-port=53/tcp --permanent
firewall-cmd --add-port=53/udp --permanent
firewall-cmd --reload
yum下安装powerdns不是最新版本,所以我们自己安装最新版本
yum update -y
yum -y install wget gcc gcc-c++ bzip2 autoconf automake make lua-devel openssl openssl-devel boost-devel
yum install libyaml libyaml-devel git libmaxminddb libmaxminddb-devel -y
安装cmake
wget https://cmake.org/files/v3.18/cmake-3.18.0.tar.gz
tar zxvf cmake-3.18.0.tar.gz
cd cmake-3.18.0
./configure
gmake&&gmake install
安装yaml-cpp
cd /root
git clone https://github.com/jbeder/yaml-cpp.git
cd yaml-cpp
mkdir build
cd build
cmake -DBUILD_SHARED_LIBS=ON ..
make&&make install
复制到pkgconfig
cp /usr/local/lib/pkgconfig/yaml-cpp.pc /usr/lib64/pkgconfig/
cp /usr/local/share/pkgconfig/yaml-cpp.pc /usr/lib64/pkgconfig/
复制到lib64
cp /usr/local/lib/libyaml-cpp.a /usr/lib64
cp /usr/local/lib64/libyaml-cpp.so.0.6 /usr/lib64
安装libcurl,因为需要启用lua-records。可以到https://curl.haxx.se/download.html下载最新版本
cd /root
wget https://curl.haxx.se/download/curl-7.73.0.tar.gz
tar zxvf curl-7.73.0.tar.gz
cd curl-7.73.0
./configure
make&&make install
下载并安装powerdns
cd /root
wget https://downloads.powerdns.com/releases/pdns-4.3.1.tar.bz2
tar jxf pdns-4.3.1.tar.bz2
cd pdns-4.3.1
chmod +x ./configure
./configure --prefix=/usr/local/powerdns --enable-verbose-logging --enable-static-binaries --enable-pdns_server --enable-nedmalloc --with-libcurl --with-modules=geoip --with-maxminddb-includedir --with-maxminddb-libdir --with-lua
make&&make install
安装设置geoip
cd /usr/local/powerdns
mkdir -p geoip
cd geoip
wget http://source.loshub.com/linux/GeoIP/GeoLite2-Country.mmdb
wget http://source.loshub.com/linux/GeoIP/GeoLite2-City.mmdb
wget http://source.loshub.com/linux/GeoIP/GeoLite2-ASN.mmdb
mkdir -p /usr/local/powerdns/etc/key
配置powerdns配置文件
创建一个pdns的用户和组,指定运行powerdns这样更加安全
groupadd pdns
useradd -m -s /sbin/nologin -g pdns pdns
把pdns.conf-dist重命名pdns.conf
cd /usr/local/powerdns/etc
mv pdns.conf-dist pdns.conf
修改/usr/local/powerdns/etc/pdns.conf里的setgid和setuid,在其下面直接加上
setgid=pdns
setuid=pdns
修改#launch=,直接在下面输入以下代码
launch=geoip
geoip-database-files=/usr/local/powerdns/geoip/GeoLite2-Country.mmdb /usr/local/powerdns/geoip/GeoLite2-City.mmdb /usr/local/powerdns/geoip/GeoLite2-ASN.mmdb
geoip-zones-file=/usr/local/powerdns/etc/zones.yaml
geoip-dnssec-keydir=/usr/local/powerdns/etc/key
给pdns目录权限让其能运行
chown -R pdns:pdns /usr/local/powerdns
配置dns记录,yaml记录,官方格式
# @see: https://doc.powerdns.com/md/authoritative/backend-geoip/
domains:
- domain: example.com
ttl: 300 # 默认 TTL 时长
records:
##### Default NS
ns1.example.com:
- a: # 你的服务器的第一个 IPv4 地址,注意是你安装powerdns的服务器ip地址主
content: 127.0.0.1
ttl: 86400
- aaaa: # 你的服务器的第一个 IPv6 地址
content: ::1
ttl: 86400
ns2.example.com: # 你的服务器的第二个 IPv4 地址(如果没有就和上面一样)备
- a:
content: 127.0.0.1
ttl: 86400
- aaaa: # 你的服务器的第二个 IPv6 地址(如果没有就和上面一样)
content: ::2
ttl: 86400
##### Root domain
example.com: # 根域名下的记录
- soa:
content: ns1.example.com. admin.example.com. 1 86400 3600 604800 10800
ttl: 300
- ns:
content: ns1.example.com.
ttl: 300
- ns:
content: ns2.example.com.
ttl: 300
##### Servers list 你的服务器列表
beijing-server.example.com: &beijing
- a: 10.0.1.1
- aaaa: ::1:1
newyork-server.example.com: &newyork
- a: 10.0.2.1
- aaaa: ::2:1
japan-server.example.com: &japan
- a: 10.0.3.1
- aaaa: ::3:1
london-server.example.com: &uk
- a: 10.0.4.1
- aaaa: ::4:1
france-server.example.com: &france
- a: 10.0.5.1
- aaaa: ::5:1
##### GEODNS 分区解析
# @see: https://php.net/manual/en/function.geoip-continent-code-by-name.php
# @see: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
# unknown also is default
# %co.%cn.geo.example.com
# 默认
unknown.unknown.geo.example.com: *newyork # 默认解析到美国
# 洲
unknown.as.geo.example.com: *japan # 亚洲解析到日本
unknown.oc.geo.example.com: *japan # 大洋洲解析到日本
unknown.eu.geo.example.com: *france # 欧洲解析到法国
unknown.af.geo.example.com: *france # 非洲解析到法国
# 国家
chn.as.geo.example.com: *beijing # 中国解析北京
gbr.eu.geo.example.com: *uk # 英国解析到英国
services:
# GEODNS
www.example.com: [ '%co.%cn.geo.example.com', 'unknown.%cn.geo.example.com', 'unknown.unknown.geo.example.com']
启动测试
启动方法
/usr/local/powerdns/sbin/pdns_server
后台运行方法
/usr/local/powerdns/sbin/pdns_server &
centos7或8加入系统启动
vi /lib/systemd/system/pdns.service
输入以下代码
[Unit]
Description=PowerDNS Authoritative Server
Documentation=man:pdns_server(1) man:pdns_control(1)
Documentation=https://doc.powerdns.com
Wants=network-online.target
After=network-online.target mysqld.service postgresql.service slapd.service mariadb.service
[Service]
Type=notify
ExecStart=/usr/local/powerdns/sbin/pdns_server --guardian=no --daemon=no --disable-syslog --log-timestamp=no --write-pid=no
Restart=on-failure
RestartSec=1
StartLimitInterval=0
PrivateTmp=true
PrivateDevices=true
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_SETGID CAP_SETUID CAP_CHOWN CAP_SYS_CHROOT
NoNewPrivileges=true
# ProtectSystem=full will disallow write access to /etc and /usr, possibly
# not being able to write slaved-zones into sqlite3 or zonefiles.
ProtectSystem=full
ProtectHome=true
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
[Install]
WantedBy=multi-user.target
保存退出
创建软连
ln -s /lib/systemd/system/pdns.service /etc/systemd/system/multi-user.target.wants/pdns
载入启动
systemctl daemon-reload
启动pdns
systemctl start pdns
停止pdns
systemctl stop pdns
加入系统启动
systemctl enable pdns
完成
版权申明
本文系作者 @天边的云 原创发布在Loshub站点。未经许可,禁止转载。
暂无评论数据