OS 7--DNS配置+Apache发布网站

环境准备

centOS 7

1.配置DNS
1.1 域名为lianxi.com
1.2 为WWW服务器、FTP服务器、NEWS服务器做域名解析

1)安装DNS

yum -y install bind bind-utils

(如果安装不上,就把磁盘在重洗挂载一下)

2)修改DNS配置文件

 vim /etc/resolv.conf

本地解析(本地dns就是虚拟机的IP地址,把现有nameserver都注释掉)

vim /etc/named.com/

在全局配置文件中添加两个any

检查配置文件/etc/named.conf有没有错误

named- checkconf /etc/named.conf

3)在区域声明文件中添加两个区域(正向区域和反向区域)

[root@ljy named]# vim /etc/named.rfc1912.zones

4)创建正向解析文件和反向解析文件

[root@ljy ~]# named-checkconf /etc/named.conf

[root@ljy ~]# cd /var/named/

[root@ljy named]# ls

abc.fx data lianxi.com.zone lianxi.zx named.empty

named.loopback abc.zx dynamic lianxi.fx named.ca named.localhost slaves

[root@ljy named]# vim named.localhost

[root@ljy named]#cp named.loopback lianxi..fx

[root@ljy named]# vim lianxi.fx

[root@ljy named]#cp named.loopback lianxi..zx

[root@ljy named]# vim lianxi.zx

修改一哈lianxi.fx地址解析协议,正向和逆向都不配套,111改66

判断文件是否写入正确

[root@ljy named]# named-checkzone www.lianxi.com /var/named/lianxi.zx

5)修改正反向解析文件的所有者和所属组

6)systemctl restart named开启

7)域名解析(nslookup)

DNS步骤

2.发布网站(要先创建了DNS服务器,才能创建网站)
网站域名网页内容网站主目录
www.lianxi.com111111111/srv/lianxi/www
news.lianxi.com222222222/srv/lianxi/news
www.lianxi.com:10080333333333/srv/lianxi/10080

知识点:

Apache 的主配置文件:/etc/httpd/conf/httpd.conf

默认站点主目录:/var/www/html/

[root@ljy log]# tail -30 messages //查看messages日志文件后30行--开启不了httpd服务报错信息

要进入/var/log/messages/这个目录下查看

1)基于主机头的虚拟主机网站搭建

[root@ljy ~]# firewall-cmd --permanent --zone=public --add-service=http
Warning: ALREADY_ENABLED: http
success
[root@ljy ~]# firewall-cmd --permanent --zone=public --add-service=https
Warning: ALREADY_ENABLED: https
success
[root@ljy ~]# firewall-cmd --reload 
success
[root@ljy ~]# systemctl start httpd.service
[root@ljy ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.66  netmask 255.255.255.0  broadcast 192.168.10.255
        inet6 fe80::16d2:eb8:3e29:e1a5  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:e8:01:3c  txqueuelen 1000  (Ethernet)
        RX packets 6232  bytes 538885 (526.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 145  bytes 19532 (19.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 36211  bytes 2951962 (2.8 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 36211  bytes 2951962 (2.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@ljy ~]# mkdir -pv /var/www/html/www
mkdir: 已创建目录 "/var/www/html/www"
[root@ljy ~]# echo 1111111 > /var/www/html/www/index.html
[root@ljy ~]# mkdir -pv /var/www/html/news
mkdir: 已创建目录 "/var/www/html/news"
[root@ljy ~]# echo 222222 > /var/www/html/news/index.html
[root@ljy ~]# vim /etc/httpd/conf.d/www.conf
[root@ljy ~]# vim /etc/httpd/conf.d/news.conf
[root@ljy ~]# vim /etc/hosts
[root@ljy ~]# systemctl restart httpd
[root@ljy ~]# curl www.lianxi.com
111111
[root@ljy ~]# curl news.lianxi.com
22222222
[root@ljy ~]#