coredns mysql 扩展使用+readyset 试用

基于db 进行dns 记录的管理还是比较有用的,尤其在一些开发环境中,以下是一个使用
同时也会尝试集成readyset(但是木有成功,应该是mysql 编码兼容的问题)

添加&构建插件

方法比较简单,官方有比较完整的文档说明,主要就是修改plugin.cfg 文件,同时通过go get 获取插件,然后就是
go generate 以及 go build,为了方便我构建了一个容器镜像,可以直接使用dalongrong/coredns

环境准备

  • docker-compose 文件
 
version: '3'
services:
  coredns:
    image: dalongrong/coredns
    command: -conf=/opt/Corefile
    volumes:
      - ./Corefile:/opt/Corefile
    ports:
      - 53:53
      - 53:53/udp
  mysql:
    image: mysql:8.0.32
    command: --default-authentication-plugin=mysql_native_password --log-bin --binlog-format=ROW --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    environment:
      - MYSQL_ROOT_PASSWORD=dalong
      - MYSQL_DATABASE=coredns
    ports:
      - 3306:3306
  # 包含了readyset 但是目前似乎是兼容问题没成功
  readyset:
    image: public.ecr.aws/readyset/readyset:beta-2023-01-18
    command: --standalone --deployment=quickstart-mysql --database-type=mysql -upstream-db-url=mysql://root:dalong@mysql:3306/coredns --address=0.0.0.0:5433   --password=dalong --query-caching=explicit --db-dir=/state --allow-unauthenticated-connections
    environment:
      - DEPLOYMENT_ENV=quickstart_docker
      - RS_API_KEY
    ports:
      - 5433:5433
    volumes:
      - ./readyset:/state

Corefile 配置文件

.:53 {
   mysql {
    dsn root:dalong@tcp(mysql:3306)/coredns?tls=skip-verify&autocommit=true
    ttl 20
  }
}

运行&准备

  • 启动环境
docker-compose up -d
  • 初始化数据表
CREATE TABLE `coredns_records` (
    `id` INT NOT NULL AUTO_INCREMENT,
  `zone` VARCHAR(255) NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  `ttl` INT DEFAULT NULL,
  `content` TEXT,
  `record_type` VARCHAR(255) NOT NULL,
  PRIMARY KEY (`id`)
)
 
INSERT INTO coredns_records (zone, name, ttl, content, record_type) VALUES
('example.org.', 'foo', 30, '{"ip": "1.1.1.1"}', 'A'),
('example.org.', 'foo', '60', '{"ip": "1.1.1.0"}', 'A'),
('example.org.', 'foo', 30, '{"text": "hello"}', 'TXT'),
('example.org.', 'foo', 30, '{"host" : "foo.example.org.","priority" : 10}', 'MX');
  • 查询效果
dig @127.0.0.1 A MX foo.example.org 

 

 

说明

本来是想测试readyset的,但是碰到了兼容问题,基本就是没成功,错误信息如下,应该是编码兼容问题,readyset 的想法是很不错的,目前兼容性问题还是不少的,可能pg 协议会好点,后边尝试下

 

 

参考资料

https://docs.readyset.io/guides/quickstart/
https://github.com/readysettech/readyset
https://github.com/cloud66-oss/coredns_mysql
https://github.com/coredns/coredns
https://coredns.io/2017/07/25/compile-time-enabling-or-disabling-plugins/

posted on 2023-01-23 19:19  荣锋亮  阅读(199)  评论(0编辑  收藏  举报

导航