本教程实验环境:
[root@localhost ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)
[root@localhost ~]#
一、首先在dns server上面配置域名解析
(1).在dns server上面创建三个域名
[root@localhost ~]# vim /etc/named.rfc1912.zones
zone "zzqa.com" IN {
type master;
file "zzqa.com";
allow-update { none; };
};
zone "zzqb.com" IN {
type master;
file "zzqb.com";
allow-update { none; };
};
zone "zzqc.com" IN {
type master;
file "zzqc.com";
allow-update { none; };
};
(2) 在网站根目录对应创建三个网站的目录,并在每个目录下创建一个人html测试页面。
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# mkdir zzqa
[root@localhost html]# mkdir zzqb
[root@localhost html]# mkdir zzqc
[root@localhost html]# ls
1.html 1.php DVWA zzqa zzqb zzqc
[root@localhost html]#
[root@localhost html]# echo "I am zzqa" > zzqa/index.html
[root@localhost html]# echo "I am zzqb" > zzqb/index.html
[root@localhost html]# echo "I am zzqc" > zzqc/index.html
[root@localhost html]#
(3)配置域名解析
- 首先在
/var/named/
目录下面拷贝3份模板分别作为解析三个站点的配置文件。
[root@localhost ~]# cd /var/named/
[root@localhost named]# cp named.localhost zzqa.com
[root@localhost named]# cp named.localhost zzqb.com
[root@localhost named]# cp named.localhost zzqc.com
- 依次编辑
zzqa.com
zzqb.com
zzqc.com
三个解析文件,编辑完成,保存并退出。
[root@localhost named]# vim zzqa.com
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
@ IN A 192.168.3.112
www IN A 192.168.3.113
game IN A 10.1.1.1
[root@localhost named]# vim zzqb.com
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
@ IN A 192.168.3.112
www IN A 192.168.3.114
game IN A 10.1.1.2
[root@localhost named]# vim zzqc.com
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
@ IN A 192.168.3.112
www IN A 192.168.3.115
game IN A 10.1.1.3
(4).到此,我们可以重启named服务,测试一下我们配置的域名解析是否成功。
[root@localhost named]# service named restart
重启服务没毛病,说明我们的dns解析配置没出错!
下面测试:
开始测试一下失败了,原因是三个目录没有给可读权限:
- 因此我们先刚给个可读权限
[root@localhost named]# ll | grep zzq
[root@localhost named]# chmod +r zzq*
[root@localhost named]# ll | grep zzq
- 加完权限一定要重启服务
[root@localhost named]# service named restart
- 然后再来测试就OK了,如下图所示
二、然后配置apache三个虚拟主机
1.在eth0上面添加3个IP地址
[root@localhost ~]# ifconfig eth0:1 192.168.3.113 netmask 255.255.255.0
[root@localhost ~]# ifconfig eth0:2 192.168.3.114 netmask 255.255.255.0
[root@localhost ~]# ifconfig eth0:3 192.168.3.115 netmask 255.255.255.0
配置完之后查看一下:
2.修改apache服务配置文件
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
- 在此文件尾部,将下图部分复制三份,中间最好有空行,避免错误也美观。
- 然后修改为如下内容:
<VirtualHost 192.168.3.113:80>
ServerAdmin www.zzqa.com
DocumentRoot /var/www/html/zzqa/
ServerName 192.168.3.113
ErrorLog logs/dummy-host.zzqa.com-error_log
CustomLog logs/dummy-host.zzqa.com-access_log common
</VirtualHost>
<VirtualHost 192.168.3.114:80>
ServerAdmin www.zzqb.com
DocumentRoot /var/www/html/zzqb/
ServerName 192.168.3.114
ErrorLog logs/dummy-host.zzqb.com-error_log
CustomLog logs/dummy-host.zzqb.com-access_log common
</VirtualHost>
<VirtualHost 192.168.3.115:80>
ServerAdmin www.zzqc.com
DocumentRoot /var/www/html/zzqc/
ServerName 192.168.3.115
ErrorLog logs/dummy-host.zzqc.com-error_log
CustomLog logs/dummy-host.zzqc.com-access_log common
</VirtualHost>
要注意图2-3里面的网站路径要和下图2-4创建的三个文件夹路径一致
- 然后保存退出
3.重启httpd服务
[root@localhost html]# service httpd restart
4.测试,在本机上面将DNS地址改为我们搭建DNS Server的地址
通过web访问三个站点,如下图所示:
没毛病,全部正常!