网站流量功能更怎么做,硬件开发语言,网站项目方案,在线网站建设诚信经营1、背景介绍
目前公司使用PowerDNS进行DNS管理#xff0c;但由于采用的是单节点架构#xff0c;存在不可用的风险。为提升系统的稳定性和可靠性#xff0c;我们计划对现有架构进行重构。通过引入高可用性设计#xff0c;我们将优化系统架构#xff0c;使其能够在故障情况…1、背景介绍
目前公司使用PowerDNS进行DNS管理但由于采用的是单节点架构存在不可用的风险。为提升系统的稳定性和可靠性我们计划对现有架构进行重构。通过引入高可用性设计我们将优化系统架构使其能够在故障情况下依然保持服务的连续性和高效性从而提升整体的业务稳定性。
2、环境介绍
系统Cnetos7 软件 pdns-4.1.8-1.el7.MIND.x86_64 pdns-recursor-4.1.11-1.el7.MIND.x86_64 相关信息已经脱敏
名称ip组件matser172.17.20.20nginxmysqlPowerDNS Authoritative PowerDNS Recursor 主slave172.17.20.21nginxmysqlPowerDNS Authoritative PowerDNS Recursor (备)
nginx53作为upstream 代理 53 端口
mysql3306作为PowerDNS的后端存储
PowerDNS Authoritative5300用于管理企业私有域名
PowerDNS Recursor5301 用于DNS解析转发、缓存 3、组件介绍
PowerDNS全家桶中包含PowerDNS Authoritative、Recursor、DNSList暂不使用三个组件。
PowerDNS AuthoritativeDNS权威服务器用于提供企业私有域名的管理和解析PowerDNS RecursorDNS递归服务器用于接受客户端DNS查询请求并根据目标域转发配置转发到不同的上游DNS服务器进行解析并对DNS解析记录进行缓存PowerDNS-AdminDNS权威服务器的Web管理页面PowerDNS-Monitor使用Grafana提供权威服务器和递归服务器的监控页面
PowerDNS权威服务器支持多种复制模式本架构采用MySQL作为后端存储并通过MySQL复制实现主备数据同步。
PowerDNSPDNS成立于20世纪90年代末是开源DNS软件、服务和支持的主要供应商它们提供的权威认证DNS服务器和递归认证DNS服务器都是100%开源的软件同时也和红帽等开源方案提供商一样提供了付费的技术支持版本。同时官方表示为了避免和软件使用者出现竞争他们只提供服务支持而不提供DNS托管服务。
熟悉DNS工作原理的同学可以大致地将DNS记录的查询分为两种查询本地缓存和向上递归查询。和其他的如BIND、dnsmasq等将这些功能集成到一起的DNS软件不同PowerDNS将其一分为二分为了PowerDNS Authoritative Server和PowerDNS Recursor分别对应这两种主要的需求而我们常说的pdns指的就是PowerDNS Authoritative Server (后面简称PDNS Auth)主要用途就是作为权威域名服务器当然也可以作为普通的DNS服务器提供DNS查询功能。
对于PowerDNS-RecursorPowerDNS官网介绍其是一个内置脚本能力的高性能的DNS递归查询服务器并且已经为一亿五千万个互联网连接提供支持。
4、MySQL安装
可参照博客安装 https://blog.csdn.net/heian_99/article/details/106644755
MySQL主从同步
master创建账号
grant replication slave on *.* to repl172.17.20.% identified by 123;
flush privileges;
show master status; #查询master的状态 进行同步slave库同步
注意主从库的server_id 不能设置一样auto.cnf 设置也不能一样不满会出现mysql主从同步失败的
mysql change master to master_host172.17.20.20′,master_userrepl,master_password123,master_log_filemysql-bin.000006′,master_log_pos407;CHANGE MASTER TO
MASTER_HOST172.17.20.20,
MASTER_PORT3306,
MASTER_USERrepl,
MASTER_PASSWORD123,
MASTER_LOG_FILEmysql-bin.000006,
MASTER_LOG_POS407;mysql start slave;mysql show slave status\G创建powerdns数据库
需要在主从配置完成后创建
在主库执行以下命令
mysql -uroot -p
CREATE DATABASE powerdns;
GRANT ALL ON powerdns.* TO powerdnslocalhost IDENTIFIED BY VMware1!;
FLUSH PRIVILEGES;导入PowerDNS 的数据库
CREATE TABLE domains (id INT AUTO_INCREMENT,name VARCHAR(255) NOT NULL,master VARCHAR(128) DEFAULT NULL,last_check INT DEFAULT NULL,type VARCHAR(6) NOT NULL,notified_serial INT DEFAULT NULL,account VARCHAR(40) CHARACTER SET utf8 DEFAULT NULL,PRIMARY KEY (id)
) EngineInnoDB CHARACTER SET latin1;CREATE UNIQUE INDEX name_index ON domains(name);CREATE TABLE records (id BIGINT AUTO_INCREMENT,domain_id INT DEFAULT NULL,name VARCHAR(255) DEFAULT NULL,type VARCHAR(10) DEFAULT NULL,content VARCHAR(64000) DEFAULT NULL,ttl INT DEFAULT NULL,prio INT DEFAULT NULL,change_date INT DEFAULT NULL,disabled TINYINT(1) DEFAULT 0,ordername VARCHAR(255) BINARY DEFAULT NULL,auth TINYINT(1) DEFAULT 1,PRIMARY KEY (id)
) EngineInnoDB CHARACTER SET latin1;CREATE INDEX nametype_index ON records(name,type);
CREATE INDEX domain_id ON records(domain_id);
CREATE INDEX ordername ON records (ordername);CREATE TABLE supermasters (ip VARCHAR(64) NOT NULL,nameserver VARCHAR(255) NOT NULL,account VARCHAR(40) CHARACTER SET utf8 NOT NULL,PRIMARY KEY (ip, nameserver)
) EngineInnoDB CHARACTER SET latin1;CREATE TABLE comments (id INT AUTO_INCREMENT,domain_id INT NOT NULL,name VARCHAR(255) NOT NULL,type VARCHAR(10) NOT NULL,modified_at INT NOT NULL,account VARCHAR(40) CHARACTER SET utf8 DEFAULT NULL,comment TEXT CHARACTER SET utf8 NOT NULL,PRIMARY KEY (id)
) EngineInnoDB CHARACTER SET latin1;CREATE INDEX comments_name_type_idx ON comments (name, type);
CREATE INDEX comments_order_idx ON comments (domain_id, modified_at);CREATE TABLE domainmetadata (id INT AUTO_INCREMENT,domain_id INT NOT NULL,kind VARCHAR(32),content TEXT,PRIMARY KEY (id)
) EngineInnoDB CHARACTER SET latin1;CREATE INDEX domainmetadata_idx ON domainmetadata (domain_id, kind);CREATE TABLE cryptokeys (id INT AUTO_INCREMENT,domain_id INT NOT NULL,flags INT NOT NULL,active BOOL,content TEXT,PRIMARY KEY(id)
) EngineInnoDB CHARACTER SET latin1;CREATE INDEX domainidindex ON cryptokeys(domain_id);CREATE TABLE tsigkeys (id INT AUTO_INCREMENT,name VARCHAR(255),algorithm VARCHAR(50),secret VARCHAR(255),PRIMARY KEY (id)
) EngineInnoDB CHARACTER SET latin1;CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm);
创建文件导入数据库
touch /opt/schema.mysql.sql
把mysql的内容写到这个文件里面
mysql use powerdns
Database changed
mysql source /opt/schema.mysql.sql
Query OK, 0 rows affected (0.01 sec)5、PowerDNS Authoritative Server安装
参考官网文档https://doc.powerdns.com/authorit文章来源(Source)https://www.dqzboy.comative/installation.htmlPowerDNS已经集成到epel源中所以我们首先需要安装elel源
[rootlocalhost ~]# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm[rootlocalhost ~]# rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm[rootlocalhost ~]# yum clean all
[rootlocalhost ~]# yum makecache
[rootlocalhost ~]# yum install -y pdns pdns-backend-mysql修改配置文件
/etc/pdns/pdns.conf
[rootmaster ~]# cp /etc/pdns/pdns.conf /etc/pdns/pdns.conf_date %Y_%m_%d
[rootmaster ~]# tree /etc/pdns/
/etc/pdns/
└── pdns.conf0 directories, 1 file[rootmaster ~]# cat /etc/pdns/pdns.conf | grep -Ev ^#|^$
launchbind
setgidpdns
setuidpdns添加配置 生产环境如下###############cache-ttl60
config-dir/etc/pdns
disable-axfryes
distributor-threads3
#数据库的连接信息
gmysql-dbnamepowerdns
gmysql-host127.0.0.1
gmysql-passwordVMware1!
gmysql-userpowerdns
guardianno
launchgmysql
## pdns config 本地地址和启动端口
local-address127.0.0.1
local-port5300
log-dns-detailsno
disable-syslogno
negquery-cache-ttl60
query-cache-ttl60
query-loggingno
receiver-threads12
cache-ttl0
setuidpdns
setgidpdns
## pdns API 激活 API 服务
api-key3jEkItlrSHfuqJbr
apiyes
#web页面也信息
webserver-address0.0.0.0
webserver-passwordbdata.pdns
# webserver-allow-from指定允许访问webserver和API的IP白名单多个IP可以使用英文逗号隔开
webserver-allow-from0.0.0.0/0
webserver-port8281
webserveryes
loglevel9
启动Pdns服务
[rootmaster pdns]# systemctl enable pdns
Created symlink from /etc/systemd/system/multi-user.target.wants/pdns.service to /usr/lib/systemd/system/pdns.service.[rootmaster pdns]# systemctl start pdns.service
[rootmaster pdns]# systemctl status pdns.service6、PowerDNS Recursor安装
[rootmaster pdns]# yum install pdns-recursor -y修改配置文件
/etc/pdns-recursor/recursor.conf
[rootmaster pdns]# tree /etc/pdns-recursor/
/etc/pdns-recursor/
└── recursor.conf[rootmaster pdns]# cp /etc/pdns-recursor/recursor.conf /etc/pdns-recursor/recursor.conf_date %Y_%m_%d[rootmaster pdns]# cat /etc/pdns-recursor/recursor.conf | grep -Ev ^#|^$
security-poll-suffix
setgidpdns-recursor
setuidpdns-recursor添加配置 生产环境如下################允许所有用户端请求
allow-from0.0.0.0/0,::/0
## pdns-re API 激活 API 服务
api-key3jEkItlrSHfuqJbrdisable-packetcacheno
export-etc-hostsyes
#用户解析的自定义配置文件 与forward-zones相同从文件中解析
forward-zones-file/etc/pdns-recursor/forward
#/etc/hosts 文件的路径或等效文件。该文件可用于使用export-etc-hosts权威地提供数据。
etc-hosts-file/etc/pdns-recursor/hosts
#本地监听地址
local-address0.0.0.0
local-port5301
max-cache-entries1000000
max-cache-ttl60
max-mthreads1024
max-packetcache-entries500000
packetcache-servfail-ttl0
packetcache-ttl0
quietyes
setgidpdns-recursor
setuidpdns-recursor
threads6
#web页面也信息
webserver-address0.0.0.0
webserver-passwordbdata.pdns
webserver-port8282
webserver-allow-from172.17.0.0/16
webserveryes
loglevel9
创建forward 和hosts 文件
1. Forward 配置
forward 配置用于指定 PowerDNS 在无法解析某个 DNS 请求时将请求转发给其他上游 DNS 服务器进行解析。这在多种情况下都很有用比如公司内部网络中的 DNS 服务器需要解析外部互联网域名时。
主要用途
外部解析如果本地 DNS 服务器没有相应的记录可以通过 forward 配置将请求转发给公共 DNS 服务器如 Google DNS8.8.8.8。负载均衡和冗余可以配置多个上游 DNS 服务器提高解析请求的成功率和响应速度。
配置示例
forward-zones.8.8.8.8;8.8.4.4上面的示例表示将所有. 代表所有域名未解析的请求转发给 Google 的 DNS 服务器。
2. Hosts 文件
hosts 文件是一个静态的 DNS 记录文件用于手动定义特定域名的 IP 地址。这类似于传统的 /etc/hosts 文件用于快速、本地化地解析一些常用或特定的域名而无需通过外部 DNS 服务器。
主要用途
本地解析快速解析常用域名避免每次都去查询外部 DNS。自定义解析为本地网络设备或特定服务自定义域名解析记录。简化开发和测试开发和测试环境中直接在 hosts 文件中添加记录方便快捷。
配置示例
假设 hosts 文件内容如下
192.168.1.1 server1.local
192.168.1.2 server2.local这表示将 server1.local 解析为 192.168.1.1将 server2.local 解析为 192.168.1.2。
总结
Forward 配置用于指定 PowerDNS 在无法解析请求时将请求转发给其他上游 DNS 服务器确保解析的成功率和速度。Hosts 文件用于手动定义特定域名的 IP 地址实现本地化、静态的 DNS 解析。
通过合理配置和使用 forward 和 hosts 文件可以大大提升 PowerDNS 系统的灵活性和解析效率满足各种不同的网络需求。
touch {forward,hosts}借鉴配置
[rootprometheus-server pdns-recursor]# cat forward
fjf.com127.0.0.1:5300
sit.com127.0.0.1:5300
fjf127.0.0.1:5300
cloudcs.fjf172.31.0.10
168.192.in-addr.arpa127.0.0.1:5300
30.172.in-addr.arpa172.31.0.10
31.172.in-addr.arpa172.31.0.10
.223.5.5.5,223.6.6.6,119.29.29.29[rootprometheus-server pdns-recursor]# cat hosts
192.168.82.22 mvn.test.com
192.168.84.47 gitlab.test.com
192.168.81.11 mirrors.test.cn
192.168.82.22 img.test.cn
192.168.82.22 test.xxx.com启动Pdns-recursor
[rootmaster pdns-recursor]# systemctl enable pdns-recursor.service
Created symlink from /etc/systemd/system/multi-user.target.wants/pdns-recursor.service to /usr/lib/systemd/system/pdns-recursor.service.[rootmaster pdns-recursor]# systemctl start pdns-recursor
[rootmaster pdns-recursor]# systemctl status pdns-recursor.service 7、PowerAdmin安装
wget https://nchc.dl.sourceforge.net/project/poweradmin/poweradmin-2.1.7.tgz
yum -y install php56u php56u-fpm php56u-fpm tengine php56u-mcrypt php56u-pdo php56u-soap php56u-mysqlnd
https://linux.cn/article-5623-2.html #跟随此连接安装即可安装步骤
打开浏览器 打开页面
http://172.17.20.20:90/install/需要移除从PowerAdmin的根目录中移除“install”文件夹这一点很重要。使用以下命令
添加主域名
添加子域名 8、成功测试
[rootmaster pdns-recursor]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 172.17.20.20
[rootmaster pdns-recursor]# nslookup www.fjf.com
Server: 172.17.20.20
Address: 172.17.20.20#53Non-authoritative answer:
Name: www.fjf.com
Address: 172.17.20.21[rootmaster pdns-recursor]# nslookup test.fjf.com
Server: 172.17.20.20
Address: 172.17.20.20#53Non-authoritative answer:
Name: test.fjf.com
Address: 172.17.20.21[rootmaster pdns-recursor]# nslookup 112.efoxconn.com
Server: 172.17.20.20
Address: 172.17.20.20#53Non-authoritative answer:
Name: 112.efoxconn.com
Address: 10.134.192.1169、备服务器同上步骤
备份服务器 按照上面配置可以进行安装 和配置文件scp
yum install -y pdns pdns-backend-mysqlyum install pdns-recursor -y[rootmaster pdns-recursor]# scp -r /etc/pdns/* 172.17.20.21:/etc/pdns/
[rootmaster pdns-recursor]# scp -r /etc/pdns-recursor/* 172.17.20.21:/etc/pdns-recursor/[rootslave pdns]# systemctl start pdns systemctl status pdns
[rootslave pdns]# systemctl start pdns-recursor systemctl status pdns-recursor.service [rootslave pdns]# systemctl enable pdns systemctl enable pdns-recursor10、nginx负载均衡
安装nginx
yum install -y nginx把这个配置加入 nginx.conf 后面 stream {# 添加socket转发的代理upstream dns {server 172.17.20.21:5301 max_fails3 fail_timeout3s;server 172.17.20.21:5301 max_fails3 fail_timeout3s;}# 提供转发的服务即访问localhost:30001会跳转至代理bss_num_socket指定的转发地址server {listen 53 udp;proxy_pass dns;proxy_timeout 3s;proxy_connect_timeout 3s;}
} [rootmaster ~]# netstat -ltunp |grep 53
tcp 0 0 127.0.0.1:5300 0.0.0.0:* LISTEN 39851/pdns_server
tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN 41809/nginx: master
tcp 0 0 0.0.0.0:5301 0.0.0.0:* LISTEN 40930/pdns_recursor
tcp6 0 0 :::5300 :::* LISTEN 39851/pdns_server
udp 0 0 127.0.0.1:5300 0.0.0.0:* 39851/pdns_server
udp 0 0 0.0.0.0:5301 0.0.0.0:* 40930/pdns_recursor
udp 0 0 0.0.0.0:53 0.0.0.0:* 41809/nginx: master
udp6 0 0 :::5300 :::* 39851/pdns_server 备份服务器的nginx也如上配置即可