参考:

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. svn: None of the environment variables SVN_EDITOR...问题解决

    转:http://blog.163.com/lgh_2002/blog/static/44017526201046111856208/ 问题1: svn: Could not use external ...

  2. C语言中的位域、字节序、比特序、大小端

    转:http://www.360doc.com/content/13/0624/10/496343_295125641.shtml 1.比特序 / 位序 /  bit numbering / bit  ...

  3. 【shiro】使用shiro搭建的项目,页面引用js,报错:Uncaught SyntaxError: Unexpected token <

    使用shiro搭建项目过程中,总是出现登录页面 登录第一次有效果,登陆第二次出现302状态码,第三次又有效果,第四次又没有效果的局面. 因此,采用ajax提交页面登录的用户名和密码,但是在引用js的过 ...

  4. Netty游戏服务器二

    上节我们写个server主类,那么发现什么事情都干不了,是的,我们还没有做任何的业务处理. 接着我们开始写处理客户端连接,发送接收数据的类ServerHandler. public class Ser ...

  5. WebLogic Operator初试

    时隔几个月,重拾WebLogic 为什么是WebLogic 简单说一句就是,因为WebLogic在中间件里面够复杂. Server不同的角色 AdminServer和Managed Server之间的 ...

  6. jquery中remove()与detach()的区别

    说到删除节点,马上就会想到remove,不过原来还有一个detach,而且它们还是有区别的,就是detach保留了jquery的数据,而remove就会完全删除干净.所以如果在删除一个dom节点后还想 ...

  7. 浏览器下载附件Content-Disposition

    Content-disposition是MIME(Multipurpose Internet Mail Extensions,多用途互联网邮件扩展类型)协议的扩展,MIME协议指示MIME用户代理如何 ...

  8. [转载]《Delphi 版 everything、光速搜索代码》 关于获取文件全路径 GetFullFileName 函数的优化

    Delphi 版 everything.光速搜索代码>,文章中关于获取文件全路径的函数:GetFullFileName,有一个地方值得优化. 就是有多个文件,它们可能属于同一个目录. 譬如 Sy ...

  9. 模拟源码深入理解Vue数据驱动原理(1)

    Vue有一核心就是数据驱动(Data Driven),允许我们采用简洁的模板语法来声明式的将数据渲染进DOM,且数据与DOM是绑定在一起的,这样当我们改变Vue实例的数据时,对应的DOM元素也就会改变 ...

  10. python灰帽子学习感想

    Gray Hat Python Python Programming for hackers and reverse engineers Python灰帽子:黑客与逆向project师的Python编 ...