Docker制作镜像并部署bind9(yum安装bind)--use

news/2024/11/29 4:34:17/

镜像制作

1.1 下载镜像

docker pull centos:centos7.9.2009

1.2 运行容器

[root@localhost ~]# docker run -d \
--privileged \
--name=bind9 \
--restart=always \
-p 53:53/udp \
-p 53:53/tcp \
-v /data/bind9:/etc/bind \
-v /sys/fs/cgroup:/sys/fs/cgroup \
centos:centos7.9.2009 /usr/sbin/init# 查看容器日志
[root@localhost ~]# docker logs bind9# 进入容器查看
[root@localhost ~]# docker exec -it bind9 bash# 步骤七: 查看容器运行情况
root@ubuntu-vm1:/data/bind9# docker ps
CONTAINER ID   IMAGE                   COMMAND            CREATED          STATUS          PORTS                                                                  NAMES
3e12e7dd4439   centos:centos7.9.2009   "/usr/sbin/init"   42 seconds ago   Up 41 seconds   0.0.0.0:53->53/tcp, 0.0.0.0:53->53/udp, :::53->53/tcp, :::53->53/udp   bind9

1.3 部署named服务

# 1. 进入容器查看
[root@localhost ~]# docker exec -it bind9 bash# 2. 关闭SELinux与防火墙
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl stop firewalld# 永久关闭
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
[root@localhost ~]# systemctl disable firewalld# 3. yum 安装DNS服务
[root@localhost ~]# yum install -y bind* vim*# 查看bind是否完成
[root@localhost yum.repos.d]# rpm -aq |grep bind# 状态管理
systemctl enable named --now
systemctl status named
systemctl stop named
systemctl start named
systemctl restart named

1.4 配置文件

1.4.1 named.conf

# 在docker容器中执行
$. cp /etc/named.conf /etc/named.conf-bak
$. vi /etc/named.conf
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
// See the BIND Administrator's Reference Manual (ARM) for details about the
// configuration located in /usr/share/doc/bind-{version}/Bv9ARM.htmloptions {// listen-on port 53 { 127.0.0.1; };listen-on port 53 { any; };listen-on-v6 port 53 { ::1; };directory       "/var/named";dump-file       "/var/named/data/cache_dump.db";statistics-file "/var/named/data/named_stats.txt";memstatistics-file "/var/named/data/named_mem_stats.txt";recursing-file  "/var/named/data/named.recursing";secroots-file   "/var/named/data/named.secroots";//allow-query     { localhost; };allow-query     { any; };/*- If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.- If you are building a RECURSIVE (caching) DNS server, you need to enablerecursion.- If your recursive DNS server has a public IP address, you MUST enable accesscontrol to limit queries to your legitimate users. Failing to do so willcause your server to become part of large scale DNS amplificationattacks. Implementing BCP38 within your network would greatlyreduce such attack surface*/recursion yes;forward first;forwarders { 8.8.8.8; };dnssec-enable no;dnssec-validation no;/* Path to ISC DLV key */bindkeys-file "/etc/named.root.key";managed-keys-directory "/var/named/dynamic";pid-file "/run/named/named.pid";session-keyfile "/run/named/session.key";
};logging {channel default_debug {file "data/named.run";severity dynamic;};
};zone "." IN {type hint;file "named.ca";
};include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";// mine
include "/etc/bind/named.zones";

1.4.2 named.zones

# 宿主机中
[root@localhost ~]# cd /data/bind9
[root@localhost ~]# vi named.zones
// named.zones文件内容如下:
zone "lpf-test.com" IN {type master;file "/etc/bind/lpf-test.com.hosts";
};zone "31.168.192.in-addr.arpa" IN {type master;file "/etc/bind/lpf-test.com.back";
};

1.4.3 lpf-test.com.hosts, lpf-test.com.back

[root@localhost ~]# cd /data/bind9/zones
[root@localhost ~]# vi lpf-test.com.hosts
$TTL 1D
@       IN SOA  @ root.lpf-test.com. (0       ; serial1D      ; refresh1H      ; retry1W      ; expire3H )    ; minimum@               NS      dns.lpf-test.com.
@               IN A    192.168.31.85
*               IN A    192.168.31.85[root@localhost ~]# vi lpf-test.com.back
$TTL 1D
@       IN SOA  @ root.lpf-test.com. (0       ; serial1D      ; refresh1H      ; retry1W      ; expire3H )    ; minimum
@       IN      NS      dns.lpf-test.com.
100     IN      PTR     dns.lpf-test.com
101     IN      PTR     www.lpf-test.com
102     IN      PTR     smb.lpf-test.com
103     IN      PTR     ftp.lpf-test.com 

1.4.4 步骤四:检查

root@my-ubuntu-vm1:~# docker exec -it bind9 bash# 查看状态
root@8d4b47ea885c:/# service named status
root@8d4b47ea885c:/# service named restart
root@8d4b47ea885c:/# service named status$. named-checkconf -z "$NAMEDCONF"
$. named-checkconf /etc/named.conf# 检查主配置文件: 
[root@localhost ~]# named-checkconf# named-checkzone yourDNS域名和路径
# 检查正向解析文件
[root@localhost ~]# named-checkzone lpf-test.com \
/etc/bind/lpf-test.com.hostszone lpf-test.com/IN: loaded serial 0OK# 检查反向解析文件:
[root@localhost ~]# named-checkzone \
31.168.192.in-addr.arpa \
/etc/bind/lpf-test.com.backzone 10.168.192.in-addr.arpa/IN: loaded serial 0OK# 问题排查
journalctl -xefu named
journalctl -xefu docker
journalctl -u named

1.4.5 开机启动执行

# 容器中执行如下命令
chmod +x /etc/rc.d/rc.local
vi /etc/rc.d/rc.local
# 添加如下内容  
mkdir -p /etc/bind
cp -p /opt/* /etc/bind

1.5 打包镜像

# 打包镜像
docker commit -p \
-a "langpf" \
-m "centos7.9.2009, bind-9.11.4" \
d46d528d2f97 centos/bind9:9.11.4-26 # 推送到本地仓库
1) 
docker tag centos/bind9:9.11.4-26 \
k8s-harbor.com/my-project/centos-bind9:9.11.4-262) 
docker login \
https://k8s-harbor.com/harbor/projects \
-u admin -p Harbor123453) 
docker push k8s-harbor.com/my-project/centos-bind9:9.11.4-26

问题处理

问题:在docker中启动服务报错:New main PID 547 does not belong to service, and PID file is not owned by root. Refusing.解决:挂载宿主机 cgroup目录,启动时加上 -v /sys/fs/cgroup:/sys/fs/cgroup完整启动命令如下:docker run -itd --name=ldap --privileged=true \-v /sys/fs/cgroup:/sys/fs/cgroup \ -p 80:80 -p 389:389 centos:7 /usr/sbin/init

http://www.ppmy.cn/news/1129292.html

相关文章

【Verilog 教程】 6.1Verilog函数

关键词:函数,大小端转换,数码管译码 在 Verilog 中,可以利用任务(关键字为 task)或函数(关键字为 function),将重复性的行为级设计进行提取,并在多个地方调用…

【红日靶场】vulnstack2-完整渗透过程

文章目录 一、网络拓扑二、描述配置环境渗透开始信息收集开始攻击干掉杀软cs上线权限提升 内网探测横向移动再次横向rdp连接痕迹清除 总结: 一、网络拓扑 网络配置: 二、描述 红队实战系列,主要以真实企业环境为实例搭建一系列靶场&#x…

SpringMVC 学习(八)整合SSM

10. 整合 SSM (1) 新建数据库 CREATE DATABASE SSM;USE SSM;DROP TABLE IF EXISTS BOOKS;CREATE TABLE BOOKS (BOOK_ID INT(10) NOT NULL AUTO_INCREMENT COMMENT 书ID,BOOK_NAME VARCHAR(100) NOT NULL COMMENT 书名,BOOK_COUNTS INT(11) NOT NULL COMMENT 数量,DETAIL VARCH…

Python的单选框、复选框、下拉框、消息提示框、文件对话框

优秀教程:https://zhuanlan.zhihu.com/p/569960987?utm_id0 单行文本框 - Entry textvariable:单行文本框变量,String类型,可以使用变量的set和get可以获取或设置值show:单行文本框内文字显示方式,如密码…

docker系列(9) - docker-compose

文章目录 9. compose编排9.1 介绍9.2 安装9.3 compose常用命令9.4 编排微服务9.4.1 准备docker-compose.yml9.4.2 启动服务9.4.3 测试验证 9. compose编排 9.1 介绍 多服务部署工具,通过一个docker-compose.yml模板文件,定义一组关联的应用容器为一个项…

13.(开发工具篇github)如何在GitHub上上传本地项目

一:创建GitHub账户并安装Git 二:创建一个新的仓库(repository) 三、拉取代码 git clone https://github.com/ainier-max/myboot.git git clone git@github.com:ainier-max/myboot.git四、拷贝代码到拉取后的工程 五、上传代码 (1)添加所有文件到暂存

java 根据身份证号码判断性别

在Java中,您可以根据身份证号码的规则来判断性别。中国的身份证号码通常采用的是以下规则: 第17位数字代表性别,奇数表示男性,偶数表示女性。 通常,男性的出生日期的第15、16位数字是01,女性是02。 请注意&…

深入props --React进阶指南笔记

一次render的过程&#xff1a; 调用React.createElement形成新的element过程&#xff0c;新的element上就会有新的props属性&#xff08;即重新渲染视图的关键&#xff09;。 来看一个demo&#xff1a; /* children 组件 */ function ChidrenComponent(){return <div> I…