首页 > 其他分享 >使用ansible部署缓存服务器

使用ansible部署缓存服务器

时间:2023-01-20 16:00:15浏览次数:43  
标签:www 缓存 unbound name ansible dns 服务器 com shifen

DNS缓存服务器是一种不负责域名数据维护的DNS服务器。简单来说,缓存服务器就是把用户经常使用到的域名与IP地址的解析记录保存在主机本地,从而提升下次解析的效率,这次使用unbound这款软件部署缓存服务器

一、 准备工作

1、 实验拓扑

::: hljs-center

image-20230120151411613.png

:::

节点 IP地址 说明
DNS-server 192.168.0.100 缓存服务器
centos2 192.168.0.101 客户端

2、 unbound软件介绍

Unbound是红帽公司(RedHat)默认使用的的DNS服务包,Unbound是一个安全性高、功能强大、配置简单。

3、 使用参数说明

参数 说明
interface 监听ip
interface-automatic 如果部署在非默认端口上,例如80/443,则需要禁用此选项
access-control 允许网段
forward-zone 允许域名,从哪里缓存

二、 ansible文件

1、 目录结构

[root@mmx_ansible dns_automating_unbound]# ls
ansible.cfg  inventory.yml  server.conf.j2  unbound.conf  unbound.yml

2、 配置文件

ansible.cfg

[defaults]
inventory=./inventory.yml
remote_user=root

3、主机清单文件

inventory.yml

home:
	caching_dns:
      ansible_host: 192.168.0.100
      ansible_ssh_password: "密码"
      ansible_user: "用户名"

4、 模板文件

server.conf.j2

{# 通过列举出所有的ipv4地址,来写 #}
server:
{% for ip in ansible_facts['all_ipv4_addresses'] %}
    interface: {{ ip }}
{% endfor %}

    interface-automatic: no
    access-control: {{ access_control }}
    domain-insecure: {{ domain_insecure }}

forward-zone:
    name: "{{ forward_zone_name }}"
    forward-addr: {{ forward_addr }}

5、 playbook

unbound.yml

---
- name: ubound is deployed on caching nameservers
  hosts: caching_dns
  become: yes
  vars:
    forward_addr: "114.114.114.114"
    access_control: "0.0.0.0/0 allow"
    domain_insecure: "*"
    forward_zone_name: "."

  tasks:
    - name: unbound is installed(安装软件包)
      yum:
        name: unbound
        state: present

    - name: unbound configuration is correct(配置unbound文件,当修改该文件时,重启服务)
      template:
        src: server.conf.j2
        dest: /etc/unbound/conf.d/server.conf
        owner: root
        group: unbound
        mode: '0644'
        setype: named_conf_t
      notify:
        - restart unbound
    
    - name: unbound is started and enabled(开启&&开机启动unbound服务)
      service:
        name: unbound
        state: started
        enabled: yes
    
    - name: unbound is started and enabled(开启&&开机启动unbound服务)
      service:
        name: firewalld
        state: started
        enabled: yes
    
    - name: dns is enabled on the firewalld(放行unbound服务)
      ansible.posix.firewalld:
        service: dns
        state: enabled
        permanent: yes
        immediate: yes
  
  handlers:
      # 重启unbound服务
    - name: restart unbound
      service:
        name: unbound
        state: restarted

6、 执行playbook

ansible-playbook unbound.yml

[root@mmx_ansible dns_automating_unbound]# ansible-playbook unbound.yml 

PLAY [ubound is deployed on caching nameservers] *************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************************************************************************************************
ok: [caching_dns]

TASK [unbound is installed(安装软件包)] **********************************************************************************************************************************************************************************************************
ok: [caching_dns]

TASK [unbound configuration is correct(配置unbound文件,当修改该文件时,重启服务)] ***************************************************************************************************************************************************************
ok: [caching_dns]

TASK [unbound is started and enabled(开启&&开机启动unbound服务)] *********************************************************************************************************************************************************************************
ok: [caching_dns]

TASK [unbound is started and enabled(开启&&开机启动unbound服务)] *********************************************************************************************************************************************************************************
ok: [caching_dns]

TASK [dns is enabled on the firewalld(放行unbound服务)] ******************************************************************************************************************************************************************************************
ok: [caching_dns]

PLAY RECAP ***************************************************************************************************************************************************************************************************************************************
caching_dns                : ok=6    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

三、测试

1、 客户端

1) 临时修改客户端DNS地址

[root@dns_client ~]# vim /etc/resolv.conf
nameserver 192.168.0.100

2) nslookup访问百度

[root@dns_client ~]# nslookup www.baidu.com
Server:         192.168.0.100
Address:        192.168.0.100#53

Non-authoritative answer:
www.baidu.com   canonical name = www.a.shifen.com.
Name:   www.a.shifen.com
Address: 182.61.200.7
Name:   www.a.shifen.com
Address: 182.61.200.6

2、 缓存服务器

1 ) 查看修改的配置文件

[root@DNS-Server_ubound ~]# cat /etc/unbound/conf.d/server.conf
server:
    interface: 192.168.0.100

    interface-automatic: no
    access-control: 0.0.0.0/0 allow
    domain-insecure: *

forward-zone:
    name: "."
    forward-addr: 114.114.114.114

2)查看缓存

unbound-control dump_cache

[root@DNS-Server_ubound ~]# unbound-control dump_cache
START_RRSET_CACHE
;rrset 155 1 0 2 3
a.shifen.com.   155     IN      SOA     ns1.a.shifen.com. baidu_dns_master.baidu.com. 2301200016 5 5 2592000 3600
;rrset 125 2 0 5 3
www.a.shifen.com.       125     IN      A       182.61.200.6
www.a.shifen.com.       125     IN      A       182.61.200.7
;rrset 545 1 0 5 3
www.baidu.com.  545     IN      CNAME   www.a.shifen.com.
END_RRSET_CACHE
START_MSG_CACHE
msg www.a.shifen.com. IN AAAA 33152 1 155 3 0 1 0
a.shifen.com. IN SOA 4
msg www.baidu.com. IN A 33152 1 125 3 2 0 0
www.baidu.com. IN CNAME 0
www.a.shifen.com. IN A 0
msg www.a.shifen.com. IN A 33152 1 125 0 1 0 0
www.a.shifen.com. IN A 0
END_MSG_CACHE
EOF

标签:www,缓存,unbound,name,ansible,dns,服务器,com,shifen
From: https://blog.51cto.com/mmx123/6020722

相关文章

  • Nginx配置将二级域名解析到Linux服务器指定端口
    最近几天用Python写了个接口后台服务,把它部在了服务器的300端口上。之后,我又要把一个二级域名解析到该服务器的300端口上,此时就要用到NGINX了。因为之前对NGINX的使用并不......
  • IBM免费服务器试用
    IBM公司的免费资源,仅需一个邮箱就可以注册申请,注册可以有60天试用期。1、注册点击注册进入IBM教育资源官网进行注册,注册时仅需要一个有效邮箱,QQ,Gmail,outlook均可。......
  • MESI协议:如何让多核CPU的高速缓存保持一致?
    你平时用的电脑,应该都是多核的CPU。多核CPU有很多好处,其中最重要的一个就是,它使得我们在不能提升CPU的主频之后,找到了另一种提升CPU吞吐率的办法。不知道......
  • 一台服务器最大能支持多少条TCP连接 转载
    一、一台服务器最大能打开的文件数1、限制参数我们知道在Linux中一切皆文件,那么一台服务器最大能打开多少个文件呢?Linux上能打开的最大文件数量受三个参数影响,分别是:fs......
  • 在Ubuntu下搭建泰拉瑞亚TShock服务器
    下载TShock从官方仓库下载TShock(选择对应的CPU架构下载)本文以TShock-5.1.3和x64为例,所以命令就是:wgethttps://github.com/Pryaxis/TShock/releases/download/v5.1.3/TS......
  • dart 服务器返回video
    HttpServerhttpServer=awaitHttpServer.bind("localhost",45678);Filefile=File("C:/Users/19519/Desktop/videos/bg2.mp4");awaitfor(HttpRequesthttpReques......
  • 手把手教你阿里云服务器的购买及环境搭建
    1.服务器相关程序员都需要一个自己的服务器!用于发布自己的网站和项目!用于操作系统的练习!将自己的远程仓库、远程数据库、远程tomcat.....搭建在服务器上!用于Linu......
  • mysql主(云服务器centos7)从(本地win10)搭建失败记录【reggie_take_out】
    mysql集群结构主库(云服务器centos7)配置[Err]1055-Expression#1ofORDERBYclauseisnotinGROUPBYclauseandcontainsnonaggregatedcolumn'informat......
  • Tomcat服务器 设置 不同端口、域名、网站
    serve.xml(新)<?xmlversion="1.0"encoding="UTF-8"?><Serverport="8005"shutdown="SHUTDOWN"><ListenerclassName="org.apache.catalina.startup.V......
  • 浅谈Spring如何利用三个缓存Map解决循环依赖
    写在最前面,在写这篇文章之前,我也参考了很多别人对于Spring循环依赖的讲解,大部分人都是按照先使用二级缓存,再使用三级缓存的思路去讲解。在阅读了Spring源码中关于循环依赖的......