DHCP,DNS,APACHE,NGINX,TOMCAT
五项服务实验汇总
检验学习进度
1.搭建dhcp服务器及其中继;
2.搭建dns服务器;
3.配置apache服务;
4.配置nginx服务;
5.配置tomcat服务; 客户端通过中继获取ip地址并访问各项服务
从拓扑中能读出以下信息,这将是本次实验的结果展现内容
dhcp | 192.168.100.253 | 静态 |
---|---|---|
dns | 192.168.100.252 | 静态 |
Relay | 192.168.100.254(GATEWAY1) | 静态 |
192.168.200.254(GATEWAY2) | 静态 | |
client1 | 192.168.100.* | dhcp分配 |
client2 | 192.168.200.* | dhcp分配 |
三合一服务器 | 192.168.100.251 | dhcp分配,固定 |
三合一服务器 | ||
apache | nginx | tomcat |
www.apache.com | www.nginx.com | www.tomcat.com |
/web/apache | /web/nginx | /web/tomcat |
80 | 81 | 8080 |
为了便于叙述,我将对六台虚拟机进行编号
1 | DHCP服务器 |
---|---|
2 | DNS服务器 |
3 | DHCP中继服务器 |
4 | web服务器 |
5 | 客户一号机 |
6 | 客户二号机 |
1、2、4、5 | 使用网卡一 |
---|---|
6 | 使用网卡二 |
3 | 使用两个网卡,一和二 |
对1、2、3、4号机
配置yum源
关闭防火墙、网络图形化工具及SElinux
对1、2、3号机
配置静态IP,3号机需要对两个网卡都进行配置
编号 | 网卡配置 |
---|---|
1 | TYPE=Ethernet BOOTPROTO=static NAME=ens33 DEVICE=ens33 ONBOOT=yes IPADDR=192.168.100.253 PREFIX=24 GATEWAY=192.168.100.254 DNS=192.168.100.252 |
2 | TYPE=Ethernet BOOTPROTO=static NAME=ens33 DEVICE=ens33 ONBOOT=yes IPADDR=192.168.100.252 PREFIX=24 DNS=192.168.100.252 GATEWAY=192.168.100.254 |
3-1 | TYPE=Ethernet BOOTPROTO=static NAME=ens33 DEVICE=ens33 ONBOOT=yes IPADDR=192.168.100.254 PREFIX=24 GATEWAY=192.168.100.254 DNS=192.168.100.252 |
3-2 | TYPE=Ethernet BOOTPROTO=static NAME=ens37 DEVICE=ens37 ONBOOT=yes IPADDR=192.168.200.254 PREFIX=24 DNS=192.168.100.252 GATEWAY=192.168.200.254 |
安装DHCP软件包
yum install -y dhcp
核心配置文件
进入dhcp配置文件存储目录
cd /etc/dhcp
查看dhcpd.conf
找到模板文件,并复制到当前目录下
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
配置DHCP分配的地址池–subnet
vim /etc/dhcp/dhcpd.conf
前三段subnet注释掉
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.2 192.168.100.250;
option domain-name-servers 192.168.100.252;
option domain-name "internal.example.org";
option routers 192.168.100.254;
option broadcast-address 192.168.100.255;
default-lease-time 600;
max-lease-time 7200;
}
subnet 192.168.200.0 netmask 255.255.255.0 {
range 192.168.200.2 192.168.200.250;
option domain-name-servers 192.168.100.252;
option domain-name "internal.example.org";
option routers 192.168.200.254;
option broadcast-address 192.168.200.255;
default-lease-time 600;
max-lease-time 7200;
}
固定IP地址–host
指定分配给对应的MAC地址的主机(web服务器)
host fantasia {
hardware ethernet 00:0c:29:39:77:b4;
fixed-address 192.168.100.251;
}
配置完成后重启dhcp服务
systemctl start dhcpd
开启路由转发功能
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
载入sysctl配置文件
sysctl -p
提供中继DHCP请求
dhcrelay 192.168.100.253
dhcrelay DHCP服务器IP
5、6号机连通网络后查看是否已经获取到ip
安装DNS软件包
yum install -y bind
配置DNS服务的运行状态
vim /etc/named.conf
options
项
listen-on port 53 { 192.168.100.252; };
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 { any; };
配置区域文件的名称
zone
//zhengxiangjiexi
zone "com" IN {
type master;
file "com.zones";
};
//nixiangjiexi
zone "100.168.192.in-addr.arpa" IN {
type master;
file "192.168.100.zones";
};
注释掉
include
//include "/etc/named.rfc1912.zones";
进入区域文件配置目录
cd /var/named
创建正向和反向解析文件
cp -p named.empty com.zones
cp -p named.empty 192.168.100.zones
配置正向解析文件
vim com.zones
$TTL 3H
@ IN SOA com. root.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns1.com.
dns1 A 192.168.100.252
dhcp A 192.168.100.253
relay A 192.168.100.254
301 A 192.168.100.251
www.apache A 192.168.100.251
www.nginx A 192.168.100.251
www.tomcat A 192.168.100.251
配置反向解析文件
vim 192.168.100.zones
$TTL 3H
@ IN SOA com. root.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.com.
254 PTR luyou.com.
253 PTR dhcp.com.
252 PTR dns.com.
251 PTR web.com.
启动DNS服务
systemctl start named
使用nslookup
命令进行验证:查询是否能够解析域名/IP地址
安装httpd软件包
yum install -y httpd
创建目录,并将模板文件移入目录内
mkdir /etc/httpd/extra
cp /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf /etc/httpd/extra
修改主配置文件
vim /etc/httpd/conf/httpd.conf
#Listen 80
IncludeOptional extra/*.conf
修改为
修改虚拟主机头配置文件
vim /etc/httpd/extra/httpd-vhosts.conf
Listen 80
<VirtualHost 192.168.100.251:80>
ServerAdmin root
DocumentRoot "/web/apache/"
ServerName www.apache.com
ServerAlias www.dummy-host.example.com
ErrorLog "/var/log/httpd/www.apache.com-error_log"
CustomLog "/var/log/httpd/www.apache.com-access_log" common
</VirtualHost>
重启服务
systemctl restart httpd
rpm -ivh nginx
vim /etc/nginx/conf.d/default.conf
server {
listen 81;
server_name www.nginx.com;
#access_log /var/log/nginx/host.access.log main;
location / {
root /web/nginx/;
index index.html index.htm;
}
systemctl restart nginx
解压归档包后,即可直接使用
tar xf apache-tomcat-8.5.16.tar.gz
mv apache-tomcat-8.5.16 /usr/local/tomcat
命令优化
ln -s /usr/local/tomcat/bin/startup.sh /usr/local/bin/btomcat
ln -s /usr/local/tomcat/bin/shutdown.sh /usr/local/bin/stomcat
vim /usr/local/tomcat/conf/server.xml
Engine name=“Catalina” defaultHost=“www.tomcat.com”
Host name=“www.tomcat.com” appBase=“/web/tomcat/”
btomcat
通过5、6号机器对各项服务进行验证
5、6号机连通网络后查看ip,查看是否自动获取到ip以及能够ping通其他服务器
通过查漏补缺,我们可以找出自己在学习中存在的问题和不足之处,完善知识结构,提高学习的效果和质量。