歡迎光臨
每天分享高質量文章

用 OpenStack Designate 構建一個 DNS 即服務(DNSaaS) | Linux 中國

學習如何安裝和配置 Designate,這是一個 OpenStack 的多租戶 DNS 即服務(DNSaaS)。

— Amjad Yaseen

 

Designate 是一個多租戶的 DNS 即服務,它包括一個用於域名和記錄管理的 REST API 和集成了 Neutron 的框架,並支持 Bind9。

DNSaaS 可以提供:

◈ 一個管理區域和記錄的乾凈利落的 REST API
◈ 自動生成記錄(集成 OpenStack)
◈ 支持多個授權名字服務器
◈ 可以托管多個專案/組織

Designate’s architecture

這篇文章解釋瞭如何在 CentOS 和 RHEL 上手動安裝和配置 Designate 的最新版本,但是同樣的配置也可以用在其它發行版上。

在 OpenStack 上安裝 Designate

在我的 GitHub 倉庫里,我已經放了 Ansible 的 bind 和 Designate 角色的示範設置。

這個設置假定 bing 服務是安裝 OpenStack 控制器節點之外(即使你可以在本地安裝 bind)。

1、在 OpenStack 控制節點上安裝 Designate 和 bind 軟體包:

  1. # yum install openstack-designate-* bind bind-utils -y

2、創建 Designate 資料庫和用戶:

  1. MariaDB [(none)]> CREATE DATABASE designate CHARACTER SET utf8 COLLATE utf8_general_ci;
  2. MariaDB [(none)]> GRANT ALL PRIVILEGES ON designate.* TO \
  3. 'designate'@'localhost' IDENTIFIED BY 'rhlab123';
  4. MariaDB [(none)]> GRANT ALL PRIVILEGES ON designate.* TO 'designate'@'%' \
  5. IDENTIFIED BY 'rhlab123';

註意:bind 包必須安裝在控制節點之外才能使遠程名字服務控制Remote Name Daemon Control(RNDC)功能正常。

配置 bind(DNS 服務器)

1、生成 RNDC 檔案:

  1. rndc-confgen -a -k designate -c /etc/rndc.key -r /dev/urandom
  2. cat <<EOF> etcrndc.conf
  3. include "/etc/rndc.key";
  4. options {
  5. default-key "designate";
  6. default-server {{ DNS_SERVER_IP }};
  7. default-port 953;
  8. };
  9. EOF

2、將下列配置添加到 named.conf

  1. include "/etc/rndc.key";
  2. controls {
  3. inet {{ DNS_SERVER_IP }} allow { localhost;{{ CONTROLLER_SERVER_IP }}; } keys { "designate"; };
  4. };

在 option 節中,添加:

  1. options {
  2. ...
  3. allow-new-zones yes;
  4. request-ixfr no;
  5. listen-on port 53 { any; };
  6. recursion no;
  7. allow-query { 127.0.0.1; {{ CONTROLLER_SERVER_IP }}; };
  8. };

添加正確的權限:

  1. chown named:named /etc/rndc.key
  2. chown named:named /etc/rndc.conf
  3. chmod 600 /etc/rndc.key
  4. chown -v root:named /etc/named.conf
  5. chmod g+w /var/named
  6. # systemctl restart named
  7. # setsebool named_write_master_zones 1

3、把 rndc.key 和 rndc.conf 推入 OpenStack 控制節點:

  1. # scp -r /etc/rndc* {{ CONTROLLER_SERVER_IP }}:/etc/

創建 OpenStack Designate 服務和端點

輸入:

  1. # openstack user create --domain default --password-prompt designate
  2. # openstack role add --project services --user designate admin
  3. # openstack service create --name designate --description "DNS" dns
  4. # openstack endpoint create --region RegionOne dns public http://{{ CONTROLLER_SERVER_IP }}:9001/
  5. # openstack endpoint create --region RegionOne dns internal http://{{ CONTROLLER_SERVER_IP }}:9001/
  6. # openstack endpoint create --region RegionOne dns admin http://{{ CONTROLLER_SERVER_IP }}:9001/

配置 Designate 服務

1、編輯 /etc/designate/designate.conf

在 [service:api] 節配置 auth_strategy

  1. [service:api]
  2. listen = 0.0.0.0:9001
  3. auth_strategy = keystone
  4. api_base_uri = http://{{ CONTROLLER_SERVER_IP }}:9001/
  5. enable_api_v2 = True
  6. enabled_extensions_v2 = quotas, reports

在 [keystone_authtoken] 節配置下列選項:

  1. [keystone_authtoken]
  2. auth_type = password
  3. username = designate
  4. password = rhlab123
  5. project_name = service
  6. project_domain_name = Default
  7. user_domain_name = Default
  8. www_authenticate_uri = http://{{ CONTROLLER_SERVER_IP }}:5000/
  9. auth_url = http://{{ CONTROLLER_SERVER_IP }}:5000/

在 [service:worker] 節,啟用 worker 模型:

  1. enabled = True
  2. notify = True

在 [storage:sqlalchemy] 節,配置資料庫訪問:

  1. [storage:sqlalchemy]
  2. connection = mysql+pymysql://designate:[email protected]{{ CONTROLLER_SERVER_IP }}/designate

填充 Designate 資料庫:

  1. # su -s /bin/sh -c "designate-manage database sync" designate

2、 創建 Designate 的 pools.yaml 檔案(包含 target 和 bind 細節):

編輯 /etc/designate/pools.yaml

  1. - name: default
  2. # The name is immutable. There will be no option to change the name after
  3. # creation and the only way will to change it will be to delete it
  4. # (and all zones associated with it) and recreate it.
  5. description: Default Pool
  6. attributes: {}
  7. # List out the NS records for zones hosted within this pool
  8. # This should be a record that is created outside of designate, that
  9. # points to the public IP of the controller node.
  10. ns_records:
  11. - hostname: {{Controller_FQDN}}. # Thisis mDNS
  12. priority: 1
  13. # List out the nameservers for this pool. These are the actual BIND servers.
  14. # We use these to verify changes have propagated to all nameservers.
  15. nameservers:
  16. - host: {{ DNS_SERVER_IP }}
  17. port: 53
  18. # List out the targets for this pool. For BIND there will be one
  19. # entry for each BIND server, as we have to run rndc command on each server
  20. targets:
  21. - type: bind9
  22. description: BIND9 Server 1
  23. # List out the designate-mdns servers from which BIND servers should
  24. # request zone transfers (AXFRs) from.
  25. # This should be the IP of the controller node.
  26. # If you have multiple controllers you can add multiple masters
  27. # by running designate-mdns on them, and adding them here.
  28. masters:
  29. - host: {{ CONTROLLER_SERVER_IP }}
  30. port: 5354
  31. # BIND Configuration options
  32. options:
  33. host: {{ DNS_SERVER_IP }}
  34. port: 53
  35. rndc_host: {{ DNS_SERVER_IP }}
  36. rndc_port: 953
  37. rndc_key_file: /etc/rndc.key
  38. rndc_config_file: /etc/rndc.conf

填充 Designate 池:

  1. su -s /bin/sh -c "designate-manage pool update" designate

3、啟動 Designate 中心和 API 服務:

  1. systemctl enable --now designate-central designate-api

4、驗證 Designate 服務運行:

  1. # openstack dns service list
  2. +--------------+--------+-------+--------------+
  3. | service_name | status | stats | capabilities |
  4. +--------------+--------+-------+--------------+
  5. | central | UP | - | - |
  6. | api | UP | - | - |
  7. | mdns | UP | - | - |
  8. | worker | UP | - | - |
  9. | producer | UP | - | - |
  10. +--------------+--------+-------+--------------+

用外部 DNS 配置 OpenStack Neutron

1、為 Designate 服務配置 iptables:

  1. # iptables -I INPUT -p tcp -m multiport --dports 9001 -m comment --comment "designate incoming" -j ACCEPT
  2. # iptables -I INPUT -p tcp -m multiport --dports 5354 -m comment --comment "Designate mdns incoming" -j ACCEPT
  3. # iptables -I INPUT -p tcp -m multiport --dports 53 -m comment --comment "bind incoming" -j ACCEPT
  4. # iptables -I INPUT -p udp -m multiport --dports 53 -m comment --comment "bind/powerdns incoming" -j ACCEPT
  5. # iptables -I INPUT -p tcp -m multiport --dports 953 -m comment --comment "rndc incoming - bind only" -j ACCEPT
  6. # service iptables save; service iptables restart
  7. # setsebool named_write_master_zones 1

2、 編輯 /etc/neutron/neutron.conf 的 [default] 節:

  1. external_dns_driver = designate

3、 在 /etc/neutron/neutron.conf 中添加 [designate] 節:

  1. [designate]
  2. url = http://{{ CONTROLLER_SERVER_IP }}:9001/v2 ## This end point of designate
  3. auth_type = password
  4. auth_url = http://{{ CONTROLLER_SERVER_IP }}:5000
  5. username = designate
  6. password = rhlab123
  7. project_name = services
  8. project_domain_name = Default
  9. user_domain_name = Default
  10. allow_reverse_dns_lookup = True
  11. ipv4_ptr_zone_prefix_size = 24
  12. ipv6_ptr_zone_prefix_size = 116

4、編輯 neutron.conf 的 dns_domain

  1. dns_domain = rhlab.dev.

重啟:

  1. # systemctl restart neutron-*

5、在 /etc/neutron/plugins/ml2/ml2_conf.ini 中的組成層 2(ML2)中添加 dns

  1. extension_drivers=port_security,qos,dns

6、在 Designate 中添加區域:

  1. # openstack zone create email=[email protected].dev rhlab.dev.

在 rhlab.dev 區域中添加記錄:

  1. # openstack recordset create --record '192.168.1.230' --type A rhlab.dev. Test

Designate 現在就安裝和配置好了。

赞(0)

分享創造快樂