一:在Centos01上安装配置Apache,修改Apache网站根目录为/www/
1)将虚拟机挂载对应的光盘
[root@centos01 ~]# mount /dev/derom /mnt/
2)安装配置Apache
[root@centos01 ~]#tar zxf /mnt/httpd-2.2.17.tar.gz -C /usr/src/
[root@centos01 ~]#cd /usr/src/httpd-2.2.17/
[root@centos01 httpd-2.2.17]#./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-cgi --enable-charset-lite
[root@centos01 httpd-2.2.17]#make && make install
[root@centos01 httpd-2.2.17]#cd
[root@centos01 ~]#cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
[root@centos01 ~]#chmod +x /etc/init.d/httpd
[root@centos01 ~]#vim /etc/init.d/httpd
在/etc/init.d/httpd文件中#!/bin/sh后两行添加服务参数和服务描述信息
#chkconfig:35 80 21
#Description:Apache Server
:x保存退出后将httpd添加为系统任务并设置开机自启动
[root@centos01 ~]#chkconfig --add httpd //添加系统任务
[root@centos01 ~]#chkconfig --level 35 httpd on //设置开机自动启动
[root@centos01 ~]#ln -s /usr/local/httpd/bin/* /usr/local/bin/ //优化命令
[root@centos01 ~]#systemctl start httpd //启动服务
[root@centos01 ~]#netstat -anptu | grep httpd //监听服务
3)配置网卡添加DNS指向DNS服务器
[root@centos01 ~]#vim /etc/sysconfig/network-scripts/ifcfg-ens32
TYPE=Ethernet
BOOTPROTO=static
NAME=ens32
DEVICE=ens32
ONBOOT=yes
IPADDR=192.168.100.10
NETMASK=255.255.255.0
4)创建网站根目录/www,网页显示www.123.com
[root@centos01 ~]#mkdir /www
[root@centos01 ~]#echo "www.123.com" > /www/index.html
5)配置Apache主配置文件
[root@centos01 ~]#vim /usr/local/httpd/conf/httpd.conf
97 ServerName www.123.com:80
105 DocumentRoot "/www"
141 <Directory "/www">
:x保存退出后检查主配置文件
[root@centos01 ~]#httpd -t
[root@centos01 ~]#systemctl restart httpd //重新启动apache配置文件加载配置
二:在Centos02安装DNS服务器
1)挂载系统光盘安装DNS服务
[root@centos02 ~]#mount /dev/cdrom /mnt
[root@centos02 ~]#rpm -ivh /mnt/Packages/bind-9.9.4-50.e17.x86_64.rpm
[root@centos02 ~]#rpm -ivh /mnt/Packages/bind-chroot-9.9.4.50.e17.x86_64.rpm
[root@centos02 ~]#systemctl enable named //设置服务开机自动启动
2)修改DNS主配置文件和区域配置文件
[root@centos02 ~]#cp /etc/named.conf /etc/named.conf.bak //备份配置文件
[root@centos02 ~]#echo "" > /etc/named.conf //清空配置文件
[root@centos02 ~]#vim /etc/named.conf
options {
listen to port 53 { any; };
directory "/var/named";
};
zone "123.com" IN {
type master;
file "/var/named/123.com.zone";
};
:x退出后检查主配置文件是否错误
[root@centos02 ~]#named-checkconf /etc/named.conf
[root@centos02 ~]#vim /var/named.123.com.zone //进入区域配置文件
$TTL 86400
@ SOA 123.com. root.123.com. (
2024030810
1H
15M
1W
1D
)
@ NS centos02.123.com.
centos02 A 192.168.100.20
www A 192.168.100.10
:x退出后检查区域配置文件是否错误
[root@centos02 ~]#named-checkzone 123.com /var/named/123.com.zone
3)启动DNS服务查看服务运行状态
[root@centos02 ~]#systemctl start named
[root@centos02 ~]#netstat -anptu | grep named
三:Windows配置与Linux相同网卡,配置IP地址和DNS服务器访问网站