当前位置: 首页 > news >正文

主从DNS和Web服务器搭建过程

完整服务器搭建流程

环境说明

  • 主服务器:192.168.102.128  - DNS + Web

  • 从服务器:192.168.102.133  - 从DNS

  • 网站:www.zhangsan.com (HTTPS加密)、www.lisi.com (HTTP)

手动配置主服务器和从服务器的ip地址,dns,网关,并将网络编辑器改为nat模式

对主服务器192.168.102.128(手动配置),将dns改为自己的dns

修改网卡配置: nmcli connection modify ens160 ipv4.addresses 192.168.102.128/24 ipv4.dns 192.168.102.128 ipv4.gateway 192.168.102.2 connection.autoconnect yes ipv4.method manual

重启网卡:nmcli connection  up ens160

查看DNS端口  cat /etc/resolv.conf

                        nmcli device show | grep DNS

搭建本地仓库和网络仓库并挂载

本地: vim  /etc/yum.repos.d/rpm.repo  

挂载:mount /dev/sr0 /mnt

下载并启动httpd ,将/dev/sr0挂载到/var/www/html

dnf install httpd  -y 

systemctl   restart httpd

mount   /dev/sr0   /var/www/html,修改仓库配置

第1步:在主服务器(128)上安装软件

# 安装DNS和Web服务
dnf install bind httpd mod_ssl -y# 关闭防火墙和SELinux(测试环境)
systemctl stop firewalld
setenforce 0

第2步:配置DNS主服务器

2.1 配置主配置文件 /etc/named.conf

启动DNS服务  systemctl   restart  named

vim /etc/named.conf

options {listen-on port 53 { 192.168.102.128; };directory       "/var/named";zone "zhangsan.com" IN {type master;file "named.zhangsan";
};zone "lisi.com" IN {type master;file "named.lisi";
};

2.2 创建named.zhangsan区域文件

vim /var/named/named.zhangsan
$TTL  1d
@   IN   SOA   @   admin.zhangsan.com (20250830011111)IN  NS  ns.zhangsan.com.
ns     IN  A   192.168.102.128
www    IN  A   192.168.102.128

vim /var/named/named.lisi

$TTL  1d
@   IN   SOA   @   admin.lisi.com (2025083001
                                           1
                                           1
                                           1
                                           1)
       IN  NS  ns.lisi.com.
ns     IN  A   192.168.102.128
www    IN  A   192.168.102.128


 

2.4 启动DNS

systemctl    restart   named

systemctl  enable    named

第3步:配置Web服务器和SSL加密

3.1 创建网站目录和内容

mkdir -p /www/zhangsan
mkdir -p /www/lisiecho "zhangsan website" > /www/zhangsan/index.html
echo "lisi website" > /www/lisi/index.html

3.2 生成SSL证书(zhangsan加密)

# 生成私钥
openssl genrsa > /etc/pki/tls/private/zhangsan.key# 生成证书(按照提示输入信息,Common Name填www.zhangsan.com)
openssl req -utf8 -new -key /etc/pki/tls/private/zhangsan.key -x509 -days 100 -out /etc/pki/tls/certs/zhangsan.crt

3.3 配置Apache虚拟主机

vim /etc/httpd/conf.d/vhost.conf

apache

<Directory /www>AllowOverride NoneRequire all granted
</Directory><VirtualHost *:443>DocumentRoot /www/zhangsanServerName www.zhangsan.comSSLEngine onSSLCertificateFile /etc/pki/tls/certs/zhangsan.crtSSLCertificateKeyFile /etc/pki/tls/private/zhangsan.keyErrorLog /var/log/httpd/zhangsan_error.logCustomLog /var/log/httpd/zhangsan_access.log combined
</VirtualHost><VirtualHost *:80>DocumentRoot /www/lisiServerName www.lisi.comErrorLog /var/log/httpd/lisi_error.logCustomLog /var/log/httpd/lisi_access.log combined
</VirtualHost>

3.4 启动Web服务

systemctl start httpd
systemctl enable httpd

实验验证

在主服务器上测试

dig -t A ns.zhangsan.com

dig -t A www.zhangsan.com

curl  -k  https://www.zhangsan.com

curl  http://www.lisi.com

在从服务器192.168.102.133也是同样的道理改为nat模式

将手动改DNS为192.168.102.128

nmcli  connection  modify  ens160  ipv4.dns 192.168.102.128

nmcli  connection up ens160

curl  http://www.lisi.com

curl   -k  https://www.zhangsan.com

http://www.dtcms.com/a/357961.html

相关文章:

  • Windows系统提示“找不到文件‘javaw‘”
  • 【C语言强化训练16天】--从基础到进阶的蜕变之旅:Day16
  • Azure DevOps cherry pick
  • 基于IEC61499开放自动化PLC数据储存方案
  • Python 多线程日志错乱:logging.Handler 的并发问题
  • 42-Ansible-Inventory
  • AUTOSAR进阶图解==>AUTOSAR_TR_ClassicPlatformReleaseOverview
  • Spring Boot 日志操作全解析:从基础到实践
  • 加密软件哪个好用?加密软件-为数据共享提供安全保障
  • SQLSERVER分页存储过程
  • 【YOLO11小目标改进】多尺度前馈网络(MSFN)代码
  • 第 8 篇:量化交易之tradeUI和webserverUI 区别?
  • 学习Python中Selenium模块的基本用法(11:弹窗处理)
  • LangGraph结构化输出详解:让智能体返回格式化数据
  • Docker核心概念与镜像仓库操作指南
  • AIGC应用与实践- 实验1:采用Markdown转换成WORD文档方式
  • 基于SpringBoot的流浪动物领养系统【2026最新】
  • Java函数式编程之【流(Stream)性能优化】
  • Docker(自写)
  • Netty 心跳与链路保活机制详解:保证高并发环境下的稳定连接
  • Web 聊天室消息加解密方案详解
  • Java面试-spring boot框架
  • 音视频学习(六十):H264中的PPS
  • 【C语言】字符函数与字符串函数实战:用法原理 + 模拟实现
  • VMware 设置 Ubuntu 虚拟机桥接模式完整教程
  • 音视频学习(六十二):H264中的SEI
  • 【Qt开发】按钮类控件(一)-> QPushButton
  • Ethan独立开发新品速递 | 2025-08-30
  • 【读书笔记】《最好的告别》
  • Git 安装与国内加速(配置 SSH Key + 镜像克隆)