参考:

https://www.centos.bz/2012/09/bind-with-mysql-support/

http://blog.51niux.com/?id=125

http://4709096.blog.51cto.com/4699096/1599424

这些编译安装的东西没必要深究,没任何意义.简单方便为好.

1. bind物理机安装

  • 需求: 找一个有api的dns.可以直接增加mysql记录不用重启dns即可动态更新,于是动手搞一套mysqlbackend+bind.

    后来发现有 powerdns dj-dns也可以实现这些功能,没必要自己搞.

  • 思路: 先搞清楚物理机怎么编译bind-->容器化mysql--> 容器化mysql+supervisor-->容器化mysql+supervisor+bind

  • 目前最新的bind集合mysql不需要改bind源代码了,改起来很烦的.

  • bind和mysql本来不想安装在一台机器上,无奈编译bind需要依赖mysql的lib库(期间我尝试按照mysql-devel还是没能解决),这里已经解决了. 我用debian:jessie为基础

apt-get install -y g++ libboost-all-dev libtool make pkg-config libmysqlclient-dev libssl-dev

然后编译安装bind9.11就可以了.见文末

  • 1.1二进制安装 mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
yum -y install perl-devel
tar -xf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
ln -s mysql-5.6.30-linux-glibc2.5-x86_64 /usr/local/mysql
useradd mysql -s /sbin/nologin -M
chown -R mysql:mysql /usr/local/mysql/ cd /usr/local/mysql/support-files/
\cp my-default.cnf /etc/my.cnf ## 这个配置文件可以用第二部分my.conf改了字符集
\cp mysql.server /etc/init.d/mysqld ## 这样/etc/init.d/mysqld start 就可以启动了 /usr/local/mysql/bin/mysqladmin -u root password '123456'
vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin # 初始化-物理机这样操作,如果在容器部分,则可以将初始化好的/data目录替换mysql二进制包里的data,之后就不需要构建镜像时候初始化了.
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data # 启动
/usr/local/mysql/bin/mysqld_safe --user=mysql #前台启动
/usr/local/mysql/bin/mysqld_safe --user=mysql &
  • 1.2编译安装bind-9.11.2.tar.gz

一定要编译安装,加上with-dlz-mysql, yum安装默认是不支持mysql backend的.

echo "/usr/local/mysql/lib" >>/etc/ld.so.conf \
ldconfig yum install -y perl-devel openssl-devel cd /usr/local/src/
tar xf bind-9.11.2.tar.gz
cd bind-9.11.2/ \
&& ./configure --prefix=/usr/local/bind \
--with-dlz-mysql=/usr/local/mysql \
--enable-largefile \
--disable-openssl-version-check \
--enable-threads \
--disable-ipv6 && make && make install ./configure --prefix=/usr/local/bind \
--with-dlz-mysql \
--enable-largefile \
--disable-openssl-version-check \
--enable-threads \
--disable-ipv6
make
  • 1.3配置named
cat /usr/local/bind/etc/named.conf
logging {
channel query_log {
file "/var/log/named.log" versions 3 size 100m;
severity info;
print-time yes;
print-category yes;
print-severity yes;
};
category queries {
query_log;
};
category lame-servers {
null;
};
}; dlz "My zone" {
database "mysql
{host=172.17.92.3 dbname=dns ssl=false port=3306 user=root pass=123456}
{select zone from dns_records where zone = '$zone$'}
{select ttl, type, mx_priority, case when lower(type)='txt' then concat('\"', data, '\"')
when lower(type) = 'soa' then concat_ws(' ', data, resp_person, serial, refresh, retry, expire, minimum)
else data end from dns_records where zone = '$zone$' and host = '$record$'}";
};
  • 1.4登录数据库插入示例数据
create database dns;
use dns
CREATE TABLE dns_records(id int(11) unsigned NOT NULL auto_increment,zone varchar(255) NOT NULL,host varchar(255) NOT NULL default '@',type varchar(255) NOT NULL,data text,ttl int(11) default 600,mx_priority int(11) default NULL,refresh int(11) default NULL,retry int(11) default NULL,expire int(11) default NULL,minimum int(11) default NULL,serial bigint(20) default NULL,resp_person varchar(255) default NULL,primary_ns varchar(255),PRIMARY KEY(id));
CREATE INDEX host_index ON dns_records(host);
CREATE INDEX type_index ON dns_records(type);
CREATE INDEX zone_index ON dns_records(zone);
insert into dns_records (zone,host,type,data,refresh,retry,expire,minimum,serial,resp_person,primary_ns) values('test.com','@','SOA','ns.test.com',7200,3600,86400,3600,1000,'root.test.com.','ns.test.com.');
insert into dns_records (zone,host,type,data) values('test.com','@','NS','ns.test.com.');
insert into dns_records (zone,host,type,data) values('test.com','ns','A','1.1.1.1');
insert into dns_records (zone,host,type,data) values('test.com','www','A','127.0.0.1');
  • 1.5启动调试named
/usr/local/bind/sbin/named -c /usr/local/bind/etc/named.conf -g
/usr/local/bind/sbin/named -c /home/bind/etc/named.conf

2.mysql

  • Dockerfile

From centos:7 # Init centos
ENV TZ="PRC"
RUN ln -sf \
/usr/share/zoneinfo/Asia/Shanghai \
/etc/localtime
RUN yum install -y autoconf libaio perl-devel make gcc gcc-c++ \
&& yum clean all COPY my.conf /etc/ ADD mysql.tar.gz /usr/local/
RUN useradd mysql -s /sbin/nologin -M \
&& chown -R mysql:mysql /usr/local/mysql \
&& echo 'echo 'export PATH=$PATH:/usr/local/mysql/bin/' >> /etc/profile' \
&& source /etc/profile EXPOSE 3306
CMD ["/usr/local/mysql/bin/mysqld_safe","--user=mysql"]
  • my.conf
[mysqld]
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/
default-storage-engine = innodb
innodb_file_per_table = 1
character-set-server = utf8
collation-server = utf8_general_ci
init-connect = 'SET NAMES utf8' [mysql]
default-character-set = utf8 [mysql.server]
default-character-set = utf8 [mysqld_safe]
default-character-set = utf8 [client]
default-character-set = utf8

3.mysql-supervisor

  • Dockerfile

From centos:7 # Init centos
ENV TZ="PRC"
RUN ln -sf \
/usr/share/zoneinfo/Asia/Shanghai \
/etc/localtime RUN yum install -y autoconf libaio perl-devel make gcc gcc-c++ openssl-devel epel-release \
&& yum clean all #supervisor
RUN yum -y install supervisor && \
mkdir -p /etc/supervisor/ && \
yum clean all
COPY supervisord.conf /etc/supervisor/ COPY my.conf /etc/ ADD mysql.tar.gz /usr/local/
RUN useradd mysql -s /sbin/nologin -M \
&& chown -R mysql:mysql /usr/local/mysql \
&& echo 'export PATH=$PATH:/usr/local/mysql/bin/' >> /etc/profile \
&& source /etc/profile
COPY entry.sh /usr/local/bin/ EXPOSE 3306
ENTRYPOINT ["entry.sh"]
  • entry.sh
#!/usr/bin/env bash

## mysql初始化 设置密码

echo "-----------------------------usage------------------------------------------------------"
echo "insert into dns_records (zone,host,type,data) values('test.com','@','NS','ns.test.com.');"
echo "insert into dns_records (zone,host,type,data) values('test.com','ns','A','1.1.1.1');"
echo "insert into dns_records (zone,host,type,data) values('test.com','www','A','127.0.0.1');"
echo "-----------------------------------------------------------------------------------------"
supervisord -c /etc/supervisor/supervisord.conf
  • my.conf
[mysqld]
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/
default-storage-engine = innodb
innodb_file_per_table = 1
character-set-server = utf8
collation-server = utf8_general_ci
init-connect = 'SET NAMES utf8' [mysql]
default-character-set = utf8 [mysql.server]
default-character-set = utf8 [mysqld_safe]
default-character-set = utf8 [client]
default-character-set = utf8

4.bind-with-mysql-supervisor

CentOS-7 bind-9.11.2.tar.gz  mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
  • Dockerfile
From centos:7

# Init centos
ENV TZ="PRC"
RUN ln -sf \
/usr/share/zoneinfo/Asia/Shanghai \
/etc/localtime RUN yum install -y autoconf libaio perl-devel make gcc gcc-c++ openssl-devel epel-release \
&& yum clean all #supervisor
RUN yum -y install supervisor && \
mkdir -p /etc/supervisor/ && \
yum clean all
COPY supervisord.conf /etc/supervisor/ # mysql
ADD mysql.tar.gz /usr/local/
RUN useradd mysql -s /sbin/nologin -M \
&& chown -R mysql:mysql /usr/local/mysql \
&& echo 'export PATH=$PATH:/usr/local/mysql/bin/' >> /etc/profile \
&& source /etc/profile \
&& echo "/usr/local/mysql/lib" >>/etc/ld.so.conf \
&& ldconfig # bind
ADD bind-9.11.2.tar.gz /usr/local/src/
RUN cd /usr/local/src/bind-9.11.2/ \
&& ./configure --prefix=/usr/local/bind \
--with-dlz-mysql=/usr/local/mysql \
--enable-largefile \
--disable-openssl-version-check \
--enable-threads \
--disable-ipv6 \
--disable-linux-caps \
&& make && make install
COPY named.conf /usr/local/bind/etc COPY entry.sh /usr/local/bin/ EXPOSE 53/udp 53/tcp 3306/tcp
ENTRYPOINT ["entry.sh"]
  • entry.sh
#!/usr/bin/env bash

## mysql初始化 设置密码

echo "-----------------------------usage------------------------------------------------------"
echo "insert into dns_records (zone,host,type,data) values('test.com','@','NS','ns.test.com.');"
echo "insert into dns_records (zone,host,type,data) values('test.com','ns','A','1.1.1.1');"
echo "insert into dns_records (zone,host,type,data) values('test.com','www','A','127.0.0.1');"
echo "-----------------------------------------------------------------------------------------"
supervisord -c /etc/supervisor/supervisord.conf
echo 'sdasdfadsfda \
asdfadsfads'
  • named.conf
logging {
channel query_log {
file "/var/log/named.log" versions 3 size 100m;
severity info;
print-time yes;
print-category yes;
print-severity yes;
};
category queries {
query_log;
};
category lame-servers {
null;
};
}; dlz "My zone" {
database "mysql
{host=127.0.0.1 dbname=dns ssl=false port=3306 user=root pass=123456}
{select zone from dns_records where zone = '$zone$'}
{select ttl, type, mx_priority, case when lower(type)='txt' then concat('\"', data, '\"')
when lower(type) = 'soa' then concat_ws(' ', data, resp_person, serial, refresh, retry, expire, minimum)
else data end from dns_records where zone = '$zone$' and host = '$record$'}";
};
  • supervisor.sh
[supervisord]
nodaemon = true [program:mysqld]
command=/usr/local/mysql/bin/mysqld_safe --user=mysql
process_name=%(program_name)s
auto_start = true
autorestart = true [program:named]
command=/usr/local/bind/sbin/named -c /usr/local/bind/etc/named.conf -g
process_name=%(program_name)s
auto_start = true
autorestart = true stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
stderr_logfile = /dev/stderr
stderr_logfile_maxbytes = 0
  • my.conf
[mysqld]
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/
default-storage-engine = innodb
innodb_file_per_table = 1
character-set-server = utf8
collation-server = utf8_general_ci
init-connect = 'SET NAMES utf8' [mysql]
default-character-set = utf8 [mysql.server]
default-character-set = utf8 [mysqld_safe]
default-character-set = utf8 [client]
default-character-set = utf8

至此一切编译顺利,

期间遇到dockerfile COPY目录一个小问题, COPY mysql /user/local/ 拷贝不进去,拷贝文件没问题, 最终解决: COPY mysql /user/local/mysql即可.

更新: 从debian:jessie,实现bind和mysql分离

  • Dockerfile
FROM debian:jessie

#http://mirrors.aliyun.com/help/debian
COPY sources.list /etc/apt/sources.list RUN apt-get update \
&& apt-get install -y g++ libboost-all-dev libtool make pkg-config libmysqlclient-dev libssl-dev \
&& apt-get clean # bind
ADD bind-9.11.2.tar.gz /usr/local/src/
RUN cd /usr/local/src/bind-9.11.2/ \
&& ./configure --prefix=/usr/local/bind \
--with-dlz-mysql \
--enable-largefile \
--disable-openssl-version-check \
--enable-threads \
--disable-ipv6 \
--disable-linux-caps \
&& make && make install
COPY named.conf /usr/local/bind/etc
COPY entry.sh /usr/local/bin/
ENV TZ="PRC"
RUN ln -sf \
/usr/share/zoneinfo/Asia/Shanghai \
/etc/localtime EXPOSE 53/udp 53/tcp
ENTRYPOINT ["entry.sh"]
  • entry.sh
#!/usr/bin/env bash
echo
echo "--------------------------------请初始化你的bind的mysqlbackend库-----------------------"
echo "
create database dns;
use dns
CREATE TABLE dns_records(id int(11) unsigned NOT NULL auto_increment,zone varchar(255) NOT NULL,host varchar(255) NOT NULL default '@',type varchar(255) NOT NULL,data text,ttl int(11) default 600,mx_priority int(11) default NULL,refresh int(11) default NULL,retry int(11) default NULL,expire int(11) default NULL,minimum int(11) default NULL,serial bigint(20) default NULL,resp_person varchar(255) default NULL,primary_ns varchar(255),PRIMARY KEY(id));
CREATE INDEX host_index ON dns_records(host);
CREATE INDEX type_index ON dns_records(type);
CREATE INDEX zone_index ON dns_records(zone);
insert into dns_records (zone,host,type,data,refresh,retry,expire,minimum,serial,resp_person,primary_ns) values('test.com','@','SOA','ns.test.com',7200,3600,86400,3600,1000,'root.test.com.','ns.test.com.');
insert into dns_records (zone,host,type,data) values('test.com','@','NS','ns.test.com.');
insert into dns_records (zone,host,type,data) values('test.com','ns','A','1.1.1.1');
insert into dns_records (zone,host,type,data) values('test.com','www','A','127.0.0.1');
"
echo "----------------------------------------------be happy---------------------------------------------------"
echo if [ ! -n "$1" ] ;then
echo "dokcer run -p 53:53/udp -p 53:53/tcp bind-with-nomysql your_mysqlserver_ip"
exit 0;
fi mysqlserver_ip=$1
sed -i "s#127.0.0.1#${mysqlserver_ip}#g" /usr/local/bind/etc/named.conf /usr/local/bind/sbin/named -c /usr/local/bind/etc/named.conf -g
  • named.conf
options{
forwarders { 192.168.6.6; };
}; logging {
channel query_log {
file "/var/log/named.log" versions 3 size 100m;
severity info;
print-time yes;
print-category yes;
print-severity yes;
};
category queries {
query_log;
};
category lame-servers {
null;
};
}; dlz "My zone" {
database "mysql
{host=127.0.0.1 dbname=dns ssl=false port=3306 user=root pass=123456}
{select zone from dns_records where zone = '$zone$'}
{select ttl, type, mx_priority, case when lower(type)='txt' then concat('\"', data, '\"')
when lower(type) = 'soa' then concat_ws(' ', data, resp_person, serial, refresh, retry, expire, minimum)
else data end from dns_records where zone = '$zone$' and host = '$record$'}";
};
  • sources.list
deb http://mirrors.aliyun.com/debian/ jessie main non-free contrib
deb http://mirrors.aliyun.com/debian/ jessie-proposed-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ jessie main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ jessie-proposed-updates main non-free contrib

[docker]bind9.11-with-mysql5.6 docker容器化实战的更多相关文章

  1. Asp.NetCore轻松学-使用Docker进行容器化托管

    前言 没有 docker 部署的程序是不完整的,在写了 IIS/Centos/Supervisor 3篇托管介绍文章后,终于来到了容器化部署,博客园里面有关于 docker 部署的文章比比皆是,作为硬 ...

  2. 【docker】【mysql】docker安装mysql,阿里云docker镜像加速器,docker搜索查看远程仓库上的镜像,docker拉取镜像,查看本地所有镜像,查看容器的运行状况,查看容器的详细信息

    在docker上安装mysql有两种方式 1.通过Dockerfile构建 2.直接在docker hub上拉取镜像安装 =================本篇采用方法2=============== ...

  3. Docker多台物理主机之间的容器互联

    Docker 默认的桥接网卡是 docker0.它只会在本机桥接所有的容器网卡,举例来说容器的虚拟网卡在主机上看一般叫做 veth* 而 Docker 只是把所有这些网卡桥接在一起,如下: [root ...

  4. docker学习-lnmp+redis之搭建lnp容器服务

    nginx+php7.0容器服务 本来想用单独的容器(nginx和php分开),但是因为是初学,php容器安装扩展的时候一直失败,所以就把centos+nginx+php放一起搭建了,优点是扩展简单, ...

  5. docker学习-lnmp+redis之搭建mysql容器服务

    一. 前期准备工作,创建配置文件目录,log文件目录,数据库DATA和WEB站点目录[root@T1 ~]# mkdir -p /lnmp/conf/{mysql,nginx,php} /lnmp/l ...

  6. 容器化-Docker实战

    导读:本文系统性介绍Docker安装.Docker组件.Docker命令.Dockerfile语法和Docker应用,通过上述介绍使我们已经对docker基本操作有一定了解. 一.前言 本文将系统性的 ...

  7. AspNetCore容器化(Docker)部署(三) —— Docker Compose容器编排

    一.前言 上一篇部署了一个最基础的helloworld应用,创建了两个容器和一个network,还算应付得过来. 如果该应用继续引入mysql.redis.job等若干服务,到时候发布一次得工作量之大 ...

  8. AspNetCore容器化(Docker)部署(四) —— Jenkins自动化部署

    一.前言 (Jenkins.Docker.Git/Svn组建一套简单的自动化发布流程) 文章中用到的相关服务器角色 角色 环境 功能 开发机 Win10.Docker(Linux OS) 编码.调试 ...

  9. docker系列(三):docker容器

    1 引言 在前面博文中,我们介绍了镜像.如果说镜像犹如面向对象中的类,本节要说的容器就是由类实例化出来的对象了,有了类才可以创建容器. 先从拉取一个官方提供的ubuntu最新镜像: $ docker ...

随机推荐

  1. iOS- dispatch_semaphore和NSOperationQueue并发

    并发:同一个时间内运行多个任务.又叫共行性,是指处理多个同时性活动的能力. 并行:是指两个并发的任务同时发生. 并发不一定并行,并发不一定要同时发生. 举个例子: 有两个快递分别要送到目的地,有以下两 ...

  2. Android获取apk的版本及包名等信息

    import android.app.Activity; import android.content.Context; import android.content.pm.ApplicationIn ...

  3. 小程序把图片转换成base64

    1.首先需要到upng.js,然后upng.js需要pako.js,先一并下载了 2.然后就可以直接用了,具体代码如下: <!--pages/base/base.wxml--> <c ...

  4. IOS开发错误

    After modifying system headers, please delete the module cache at '/Users/XXX/Library/Developer/Xcod ...

  5. Windows DiskPart工具使用

    启动工具 diskpart 列出磁盘列表 list disk 选择磁盘 select disk 1 转换为GPT分区 convert gpt 列出分区 list partition 清除所有分区 cl ...

  6. 利用PMKID破解PSK的实际测试与影响评估

    在2018年8月4日,一位研究员在hashcat论坛中发布了一篇帖子,表示他研究WPA3协议密码破解方法的过程中,发现了一个针对WPA/WPA2协议密码破解的新方法,使用PMKID(the Pairw ...

  7. Java笔记11:JSP连接Oracle数据库

    1 建立Web项目 在D:\tomcat\webapps\中建立basicSyntax项目,在该项目中添加WEB-INF,WEB-INF\classes\,WEB-INF\lib\和WEB-INF\w ...

  8. BS中保存参数

    开发中经常需要将值存起来,当点击某一项时以便知道点击了哪一项. 一:应用JS页面跳转(牛腩中讲到) HTML: <td class="txt c"><a href ...

  9. spinner自定义,效果如腾讯QQ账号选择时候的下拉列表

         下拉列表在android中自带spinner的有时候不太适合我们的界面,我们希望有自己的一种显示方法,那怎么办?自定义Spinner.效果如QQ账号选择一样.如图所以. 这种效果,如果你喜欢 ...

  10. Hadoop 伪分布式上安装 Hive

    下载地址:点此链接(P.S.下载带bin的安装包) 下载hive后放到虚拟机文件夹内,打开: -bin.tar.gz -C /home/software/ 修改并保存环境配置: gedit /etc/ ...