参考:

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. [HTML/CSS]z-Index层重叠顺序

    目录 语法结构 如何使用? 使用案例 总结 语法结构 z-index:具体数字.如:div{z-index:100},注意,后面跟的数字并不带单位.主要应用在div,span等标签的层叠处理. 如何使 ...

  2. ER TO SQL语句

    ER TO SQL语句的转换,在数据库设计生命周期的位置如下所示. 一.转换的类别 从ER图转化得到关系数据库中的SQL表,一般可分为3类: 1)转化得到的SQL表与原始实体包含相同信息内容.该类转化 ...

  3. web及网络基础

    关于本http系列博客 本系列博客内容全部来自或参考自<图解http>,不过博客中的图示基本上为博主自己手动绘制,部分图可能来自其它地方,但都有标注. 常见协议的分类 分层 常见协议 应用 ...

  4. EasyUI datagrid 复选框可以多选但不能全选功能实现

    1.功能需求:  实现多选,但是不能够全选功能 2.js代码 //帮卖列表页面,可以多选但是不能够全选实现 $(".datagrid-header-check").children ...

  5. mysql将字符串字段转为数字排序或比大小

    SELECT * FROM Student WHERE 1 = 1 ORDER BY -ID DESC ; SELECT * FROM Student WHERE 1 = 1 ORDER BY (ID ...

  6. Hibernate3的jar包

    一.hibernate3包说明 说明: Hibernate 软件包中的Hibernate3.jar 是我们需要使用的Hibernate 工具,其他引用的 Jar 文件位于lib 子目录下,Hibern ...

  7. 用google mock模拟C++对象

    google mock是用来配合google test对C++项目做单元测试的.它依赖于googletest(参见我上篇文章<如何用googletest写单元测试>: http://blo ...

  8. 阿里云ECS主机内核调优

    #阿里云内核调优 cat /etc/sysctl.conf vm.swappiness = 0net.ipv4.neigh.default.gc_stale_time=120 # see detail ...

  9. android sdk下载SDK Platform失败记录

    在使用android sdk manager下载的时候会遇到 下载完毕后,你可能会出现如下图一样的错误,就算重复尝试多次依然无法正常安装 Downloading SDK Platform Androi ...

  10. Razor - 模板引擎 / 代码生成 - RazorEngine

    目录 Brief Authors Official Website RazorEngine 的原理 - 官方解释 安装记录 Supported Syntax (默认实现支持的语法) 测试记录 - ca ...