Loading...  # **集 中 实 训 报 告 书** 报告书文档: 主线:[linux综合应用实训报告书.pdf](http://j.zmzaxg.top:8082/data/User/admin/home/My_de_D/网站图片/文章文件/Linux综合应用实训报告书/Linux综合应用实训报告书.pdf) 备用:[linux综合应用实训报告书.pdf](https://www.zmzaxg.top/usr/uploads/2023/06/543993045.pdf) ## **一、项目实训的目的** 实训是教学工作的重要环节,是课堂理论教学的检验和延续,是培养学生实践技能的重要场所。 通过实训,使学生能够完成企业Linux服务器的配置、管理与维护。通过实际操作,使学生掌握一定的操作技能,能认真、细致、准确的操作。通过实践过程,培养学生独立思考、独立工作的能力及团队协作精神。 ## **二、项目背景** B公司包括一个园区网络和一个分支机构,网络拓扑图如下图所示。在园区网络中,大约有500名员工,分支机构大约有100名员工,此外还有一些SOHO员工及出差人员。 假定你是该公司的网络管理员,现在公司的网络要进行规划和实施。现有条件如下:公司已租借了一个公网的IP地址100.100.100.10,和ISP提供的一个公网DNS服务器的IP地址100.100.100.200。该公司申请的域名为king.com。园区网络和分支机构使用192.168.0.0网络,并进行必要的子网划分。 ## **三、拓扑结构** *项目总体结构图*  *项目1 搭建VPN服务器*  *项目2 搭建邮件服务器*  *项目3 搭建Web服务器*  *项目4搭建DHCP服务器*  *项目5搭建FTP服务器*  *项目6搭建DNS服务器*  *项目7搭建Samba服务器*  *项目8搭建代理服务器*  *项目9. 搭建NAT服务器*  ## **四、实训的内容** ### And 4.0.环境 VM虚拟机: ``` 搭建CentOS7 64位、Windows XP ``` ### And 4.1.centos配置yum源 #### And 4.1.1.备份系统yum文件 备份系统自带的yum文件 ```shell ## 进入yum源路径 cd /etc/yum.repos.d/ ## mv剪切重命名备份一下 mv CentOS-Base.repo CentOS-Base.repo.backup ```  #### And 4.1.2.下载最新yum源配置文件 依上步骤,将文件下载到yum.repos.d路径下 这里用的163源,如果有缺失,可以使用阿里或者其他源试试 (163源:mirrors.163.com/.help)   复制好yum配置文件到centos的yum文件路径下使用wget下载保存 ```shell wget http://mirrors.163.com/.help/CentOS7-Base-163.repo ```  #### And 4.1.3.yum配置命令 ##### And 4.1.3.1.清除缓存 ```shell yum clean all ``` ##### And 4.1.3.2.生成缓存 ```shell yum makecache ```  ##### And 4.1.3.3.更新本地所有库 这里东西多,可能会比较久。有选项的话都选y即可,等待完成...  ##### And 4.1.3.4.关闭防火墙及SELinux ```shell ## 使用service或者systemctl关闭防火墙 [root@localhost yum.repos.d]# service firewalld stop [root@localhost yum.repos.d]# systemctl stop firewalld ## 关闭SELinux setenforce 0 ```  ##### And 4.1.3.5.安装epel源 ~~~shell yum -y install epel-release ~~~  ### And 4.2.任务1:搭建VPN服务器 #### And 4.2.1.安装ppp服务与pptpd服务 ~~~shell yum install -y ppp yum install -y pptpd ~~~   #### And 4.2.2.配置文件以和用户 ##### And 4.2.2.1.配置pptpd文件 ~~~shell vi /etc/pptpd.conf ~~~ 正常这里的文件是有内容的,如果进去没有内容,就需要使用chmod给文件权限再重新打开编辑就会有内容。 配置内容是定义虚拟网关,分配好ip给客户端使用,保持默认即可 直接定位到localip找到下图两行,将前面的“#”号去除,保存退出  ##### And 4.2.2.2.配置ppp文件 ~~~shell vi /etc/ppp/options.pptpd ~~~ 同上方一样,都是有默认内容的,如果进去没有内容就先给权限 然后定位到ms-dns两行,将前面的‘#’去掉,防止ping不通互联网,我这里将首选dns改为114  ##### And 4.2.2.3.配置sysctl文件 ~~~shell vi /etc/sysctl.conf # 在文件最后加入一行: net.ipv4.ip_forward = 1 ~~~ 让服务器允许ip转发内核  终端输入`sysctl -p`检查一下配置是否正确  ##### And 4.2.2.4.配置客户端用户 ```shell vi /etc/ppp/chap-secrets ```  创建一个用户 其中:`client==账号` `service==服务` `secret==密码` `IP addresses==分配ip` #### And 4.2.3.启动VPN服务 ```shell systemctl start pptpd systemctl enable pptpd ```  #### And 4.2.4.连接VPN服务器       提示`已连接`即可 在VPN服务器上使用ifconfig可以看到多了一个ppp0连接 --- ### And 4.3.任务2:搭建邮箱服务器 该任务配置前需要<span style='color:#ff0000'>先完善DNS服务器</span> 的配置,请定位到<span style='color:#ff0000'>And 4.7.任务6</span> #### And 4.3.1.安装sendmail服务 ```shell yum install -y sendmail ```  #### And 4.3.2.配置发信服务器 ```shell vi /etc/mail/sendmail.mc ``` 查找到下方图片这行,修改Addr为服务器的ip  查找修改下面图上的local地址为DNS服务器上配置过的域名  #### And 4.3.3.生成sendmail配置文件 这里生成配置文件将使用m4来配置生成 ```shell m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf ``` 这里出现了报错  再使用yum安装一下sendmail-cf ```shell yum install -y sendmail-cf ```  安装好后再次使用m4来生成配置就可以了:  #### And 4.3.4.启动sendmail服务 ~~~shell [root@localhost ~]# systemctl enable sendmail [root@localhost ~]# systemctl start sendmail [root@localhost ~]# systemctl status sendmail ~~~  #### And 4.3.5.创建邮箱账户 密码均为用户名  #### And 4.3.6.发信测试   其他的邮箱以及收发信服务器均依照配置的mail.zmzaxg.top填写   然后我们发送一封邮件试试看   #### And 4.3.7.安装mailx 在服务器上安装mailx查看接收的邮件 ~~~shell yum -y install mailx ~~~  安装好了之后使用命令查看接收到的邮件 ~~~shell mail -u user02 ~~~  可以看到刚刚已发送列表的两封邮件 #### And 4.3.8.安装dovecot ~~~shell yum install -y dovecot ~~~  #### And 4.3.9.修改配置文件 ##### And 4.3.9.1.修改主配置文件 ~~~shell vi /etc/dovecot/dovecot.conf ~~~ 进入编辑文件,找到下图这行,去掉前面的注释,让服务器支持pop以及imap  ##### And 4.3.9.2.修改认证文件 ~~~shell vi /etc/dovecot/conf.d/10-auth.conf ~~~ 编辑文件,找到下面图片这行,去掉注释,yes改no,配置开启认证  ##### And 4.3.9.3.修改加密配置 ~~~shell vi /etc/dovecot/conf.d/10-ssl.conf ~~~ 进入将ssl修改为no不进行加密  ##### And 4.3.9.4.修改邮箱文件配置 ~~~shell vi /etc/dovecot/conf.d/10-mail.conf ~~~ 修改下图这行路径为想要保存的位置,我这里保存默认  ##### And 4.3.9.5.创建邮箱路径 ~~~shell mkdir -p /var/mail/.imap/INBOX ~~~  #### And 4.3.10.启动dovecot ~~~shell [root@localhost mail]# systemctl start dovecot [root@localhost mail]# systemctl enable dovecot ~~~  #### And 4.3.11.测试 在xp系统使用cmd终端 ~~~shell telnet mail.zmzaxg.top 110 ~~~  --- ### And 4.4.任务3:搭建Web服务器 #### And 4.4.1.安装httpd ```shell yum install -y httpd ```  #### And 4.4.2.启动Apache服务 ```shell [root@localhost mail]# systemctl start httpd [root@localhost mail]# systemctl enable httpd ```  #### And 4.4.3.创建Web站点目录和文件 ```shell mkdir /var/www/web01 mkdir /var/www/web02 echo "内容" >> /var/www/web01/index.html ```  #### And 4.4.4.修改配置设置站点 ```shell vi /etc/httpd/conf/httpd.conf ``` 进入文件,找到`Require all denied`(拒绝所有主机访问)改为`Require all granted`(允许所有主机访问)  在后面编辑站点配置 ```shell <VirtualHost 172.168.1.7> DocumentRoot /var/www/web01 ServerName web01.zmzaxg.top </VirtualHost> <VirtualHost 172.168.1.8> DocumentRoot /var/www/web02 ServerName web02.zmzaxg.top </VirtualHost> ```  保存完成切换目录 ```shell cd /etc/httpd/conf.d ```  ```shell ## 编辑创建文件 vi virtual.conf ``` 内容与上方VirtualHost相同:  #### And 4.4.5.编辑网卡 这里使用图形化编辑,如下图:  如果编辑网卡配置文件,需要进入到`/etc/sysconfig/network-scripts/`目录内打开在用的网卡文件,配置可以参照如下:  子网`16`可以使用`255.255.0.0` 对网卡配置修改后重启一下network: ```shell service network restart ```  配置好网卡到实体主机的cmd终端ping一下两个ip,保证均可通行  再服务器上也可以使用ip address来查看:  这里如果有问题可以修改配置文件的默认选项,在后面加个“0”:  添加完重启再试试,正常是可以直接成功应用 #### And 4.4.6.重启httpd服务与测试 ```shell systemctl restart httpd ```  确保服务器的dns服务开启动,关闭防火墙 到前面的win xp系统打开  到此,Web服务器以及完善,后面我们去修改dns服务器的域名正反向解析,就可以实现域名访问: ```shell vi named.zmzaxg.top ```  ```shell vi named.172.168.1 ```  配置完成后再重新启动DNS服务器 ```shell systemctl restart named ```  在连接了DNS服务器的xp系统上就能通过域名访问:  --- ### And 4.5.任务4:搭建DHCP服务器 #### And 4.5.1.安装DHCP包 ```shell yum -y install dhcp ```  #### And 4.5.2.修改配置文件 ```shell vi /etc/dhcp/dhcpd.conf ``` 内容可以参照下方: ```shell subnet 172.168.0.0 netmask 255.255.0.0 { # 此 DHCP 服务分配的 IP 地址范围 range 172.168.1.100 172.168.1.200; # DHCP服务器IP option domain-name-servers 172.168.1.7; # 指定默认网关 option routers 172.168.1.1; # 默认租约时间 default-lease-time 600; # 指定最大租用周期 max-lease-time 7200; } ```  其中虚拟机的NAT网络配置如下:  #### And 4.5.3.启动DHCP服务与测试 启动 ~~~shell [root@localhost named]# systemctl start dhcpd [root@localhost named]# systemctl enable dhcpd ~~~  测试 到xp系统cmd查看未更新的ip  之前分配的ip是172.168.1.9,我们重新连接一下网卡,让它自带获取:  成功经DHCP服务器分配到ip,然后ping一下baidu.com看看:  --- ### And 4.6.任务5:搭建FTP服务器 #### And 4.6.1.安装vsftpd ```shell yum install -y vsftpd ```  #### And 4.6.2.创建用户和目录 上面搭建邮件服务器时候已创建过两个测试账号了,如果你需要添加可以再加入新的用户: ```shell useradd [用户名] passwd [用户名]##设置密码 ``` 创建ftp目录 ```shell [root@localhost named]# mkdir -p /data/ftp_data /data/ftp_data/anon [root@localhost named]# chmod o+w /data/ftp_data/ ```   #### And 4.6.3.修改配置文件 ```shell vi /etc/vsftpd/vsftpd.conf ``` 配置文件有大量注释行,如果很乱的话可以先用mv备份配置文件,再使用`grep -v "#" vsftpd.conf.bak > vsftpd.conf`,将注释清除。直接编辑也是可行的: ```shell [root@localhost data]# mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak [root@localhost data]# grep -v "#" /etc/vsftpd/vsftpd.conf.bak > /etc/vsftpd/vsftpd.conf ```  完成后进入编辑就不会一堆注释行了 ```shell vi /etc/vsftpd/vsftpd.conf ``` 在配置文件中加入: ```shell ###################################### anon_root=/data/ftp_data/anon anon_upload_enable=YES anon_mkdir_write_enable=YES local_root=/data/ftp_data chroot_local_user=YES allow_writeable_chroot=YES ###################################### ```  然后再到/etc/selinux/config查看SELINUX配置是否为disable,不是的话需要修改保存,重载一下文件或者重启服务器 ```shell vi /etc/selinux/config ```  #### And 4.6.4.重启和测试 ```shell [root@dns ~]# systemctl restart vsftpd [root@dns ~]# systemctl enable vsftpd ```  测试 可以到实体主机或者xp虚拟机上的文件资源管理器中的目录栏输入ftp://[服务器ip]:   --- ### And 4.7.任务6:搭建DNS服务器 #### And 4.7.1.安装bind服务 ```shell yum install -y bind ```  #### And 4.7.2.配置文件 ##### And 4.7.2.1.DNS主配置 ```shell vi /etc/named.conf ``` 进入配置文件,将下图的`listen-on`处的ip修改成服务器ip或者`any` `Allow-query`的locla修改成`any`  ##### And 4.7.2.2.域配置 ```shell # 编辑named.rfcxxx.zones文件 vi /etc/named.rfc1912.zones ``` 进入配置文件,在文件的最后方加入自定义的配置: ```shell ############################################# zone "zmzaxg.top" IN { type master; file "named.zmzaxg.top"; allow-update { none; }; }; zone "1.168.172.in-addr.arpa" IN { type master; file "named.172.168.1"; allow-update { none; }; }; ```  ##### And 4.7.2.3.配置正/反向解析 复制的文件名要与上方zones的文件相对应 ```shell ## cd进入named目录,拷贝两个新的配置文件 cd /var/named/ [root@localhost named]# cp -p named.localhost named.zmzaxg.top [root@localhost named]# cp -p named.localhost named.172.168.1 ```  ```shell ## 编辑配置文件 vi named.zmzaxg.top ```  ```shell vi named.172.168.1 ```  <span style='color:ff0000'>注!!上方图片配置中的SOA后面的“@”需要去除,属于错误配置,如果有其他错误,可以使用“vim”编辑配置可方便查找错误。</span> #### And 4.7.3.启动和测试 ##### And 4.7.3.1.启动 <span style='color:ff0000'>注!!如果你在启动命令后提示如下图,表示正反向配置文件配置内容存在问题,请检查!</span>  启动后如下:  ##### And 4.7.3.2.测试 在VM虚拟机安装好win xp,在网络属性的tcp/ip中配置dns为上面的dns服务器ip  打开xp系统的cmd终端,输入`nslookup`查看输出结果可以看到是dns服务器的dns.zmzaxg.top 然后在nslookup的“>”后面继续输入`set type=mx` `zmzaxg.top` nslookup就会在zmzaxg.top域上查找关于MX的DNS服务器解析:  使用ping命令以及浏览器访问一下百度确保正常访问即可  --- ### And 4.8.任务7:搭建samba服务器 #### And 4.8.1.安装samba ```shell yum install -y samba ```  #### And 4.8.2.启动samba服务 ```shell systemctl start smb systemctl status smb systemctl enable smb ```  #### And 4.8.3.创建目录共享 ```shell [root@mail opt]# mkdir manager market factory [root@mail opt]# touch manager/ market/ factory/ [root@mail opt]# chmod -R 777 * ```  #### And 4.8.4.创建用户组和用户 创建用户 ```shell [root@mail opt]# useradd toolll [root@mail opt]# useradd mike [root@mail opt]# useradd admin [root@mail opt]# useradd cali ``` 创建用户组 ```shell [root@mail opt]# groupadd market [root@mail opt]# groupadd factory ```  将用户分别加入到用户组: ```shell [root@mail opt]# gpasswd -a toolll market [root@mail opt]# gpasswd -a cali market [root@mail opt]# gpasswd -a mike factory [root@mail opt]# gpasswd -a admin factory ```  #### And 4.8.5.本地用户转SMB用户 ```shell [root@mail opt]# smbpasswd -a zmzaxg [root@mail opt]# smbpasswd -a toolll [root@mail opt]# smbpasswd -a mike [root@mail opt]# smbpasswd -a admin [root@mail opt]# smbpasswd -a cali ```  #### And 4.8.6.修改配置文件 ```shell [root@mail opt]# vi /etc/samba/smb.conf ``` 在配置最后加入: ```shell #################################################################################### [manager] # SMB服务器共享文件夹的名 comment = manager document # 描述 path = /opt/manager # 共享目录路径 valid users = admin,zmzaxg # 可访问用户/用户组 writable = yes # 可读写权限 [market] # SMB服务器共享文件夹的名 comment = market staff document # 描述 path = /opt/market # 共享目录路径 valid users = @market,zmzaxg,admin # 可访问用户/用户组 writable = no # 可读写权限 write list = @market,zmzaxg # 限制其用户可读写,其外用户只可读 [factory] # SMB服务器共享文件夹的名 comment = factory staff document # 描述 path = /opt/factory # 共享目录路径 valid users = @factory,admin,zmzaxg # 可访问用户/用户组 writable = no # 可读写权限 write list = @factory,admin # 限制其外用户只可读 ################################################################################### ```  编辑配置文件时要把注释去除掉,否则配置会不可用:  #### And 4.8.7.重启SMB服务与测试 ##### And 4.8.7.1.重启SMB ```shell [root@mail opt]# systemctl restart smb ```  ```shell [root@mail opt]# systemctl status smb ```  ##### And 4.8.7.2.测试 打开物理主机或者xp虚拟机的文件管理器   连接后如下图:  --- ### And 4.9.任务8:搭建代理服务器 #### And 4.9.1.安装squid ````shell [root@mail ~]# yum -y install squid ````  #### And 4.9.2.修改配置 ```shell vi /etc/squid/squid.conf ``` 进入配置文件编辑定位到`http_access deny all`,修改为:`http_access allow all`  (配置行后的注释要去除,防止出错) 在配置最后面加入: ```shell ###################################### #缓存相对的用户 cache_effective_user squid #缓存相对的组 cache_effective_group squid #缓存64M的内容 cache_mem 64 MB #禁止下载的超过10MB的文件 reply_body_max_size 10 MB #超过4MB的文件不进行缓存 maximum_object_size 4096 KB ####################################### ```  #### And 4.9.3.启动代理服务器 ```shell [root@mail ~]# squid [root@mail ~]# systemctl enable squid ``` #### And 4.9.4.配置代理客户端 这里用xp虚拟机来配置 先进入到控制面板,点开网络  选择局域网设置   打开代理服务器选项,填写好服务器配置保存即可 Ping百度看看  --- ### And 4.10.任务9:搭建NAT服务器 #### And 4.10.1.载入模块 ````shell [root@mail ~]# iptables -t filter -F [root@mail ~]# iptables -t nat -F [root@mail ~]# iptables -t mangle -F ````  #### And 4.10.2.设置Web服务器 ```shell [root@mail ~]# iptables -A FORWARD -i eth0 -p udp --dport 80 -j ACCEPT [root@mail ~]# iptables -t nat -A POSTROUTING -o eth0 -p tcp --dport 80 -j SNAT --to-source 202.112.113.112 [root@mail ~]# iptables -t nat -A POSTROUTING -o eth0 -p udp --dport 80 -j SNAT --to-source 202.112.113.112 ```  #### And 4.10.3.设置DNS服务器 ````shell [root@mail ~]# iptables -A FORWARD -i eth0 -p tcp --dport 53 -j ACCEPT [root@mail ~]# iptables -A FORWARD -i eth0 -p udp --dport 53 -j ACCEPT ````  #### And 4.10.4.设置邮件服务器 ```shell [root@mail ~]# iptables -A FORWARD -i eth0 -p tcp --dport 25 -j ACCEPT [root@mail ~]# iptables -A FORWARD -i eth0 -p udp --dport 25 -j ACCEPT [root@mail ~]# iptables -A FORWARD -i eth0 -p udp --dport 110 -j ACCEPT [root@mail ~]# iptables -A FORWARD -i eth0 -p tcp --dport 110 -j ACCEPT ```  #### And 4.10.5.设置不回应ICMP封包 ```shell [root@mail ~]# iptables -t filter -A INPUT -p icmp --icmp-type 8 -j DROP [root@mail ~]# iptables -t filter -A OUTPUT -p icmp --icmp-type 0 -j DROP [root@mail ~]# iptables -t filter -A FORWARD -p icmp --icmp-type 8 -j DROP [root@mail ~]# iptables -t filter -A FORWARD -p icmp --icmp-type 0 -j DROP ```  #### And 4.10.6.防止网络扫描 ```shell [root@mail ~]# iptables -t filter -A INPUT -p tcp --tcp-flags ALL ALL -j DROP [root@mail ~]# iptables -t filter -A FORWARD -p tcp --tcp-flags ALL ALL -j DROP [root@mail ~]# iptables -t filter -A INPUT -p tcp --tcp-flags ALL NONE -j DROP [root@mail ~]# iptables -t filter -A FORWARD -p tcp --tcp-flags ALL NONE -j DROP [root@mail ~]# iptables -t filter -A FORWARD -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP [root@mail ~]# iptables -t filter -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP [root@mail ~]# iptables -t filter -A FORWARD -p tcp --tcp-flags SYN,RST SYN,RST -j DROP ```  #### And 4.10.7.允许管理员以SSH方式连接到防火墙修改设定 ```shell [root@mail ~]# iptables -t filter -A INPUT -p tcp --dport 22 -j ACCEPT [root@mail ~]# iptables -t filter -A INPUT -p udp --dport 22 -j ACCEPT ```  #### And 4.10.8.检测是否连接成功 ```shell [root@mail ~]# ping baidu.com ``` 检查ping通外网  检查VPN服务器,邮箱服务器以及Web服务器还有SMB服务器、ftp服务器及其他应用服务器是否正常       --- ## **五、问题汇总** 1.在配置环境中会出现yum源的软件源失效或者不存在,需要切换有对应软件源的yum源重新生成缓存才能够安装。 2.搭建FTP服务器时windows登录上了账户但没有显示文件,需要修改服务器的/etc/selinux/config配置中的SELINUX=enforcing为disable,保存修改后需要重载一下配置文件重启ftp服务器才可以生效 3.DNS服务器配置需要认真详阅,是一个很容易出现配置问题的存在。 ## **六、收获和体会。** ``` 在本次的实训周中学习了 Linux 搭建服务的方法和在面对遇到各种报错都应去面对查找各种相关质料去一一解决问题成功搭建服务。 ``` ``` 在信息时代,不断学习是获得进步的动力。作为一名青年学子更应把学习作 为主要目标。 ``` ## **七、参考资料。** [zmzaxg|blog社区 - zmzaxg官方](https://www.zmzaxg.top/) [Linux环境下配置DHCP服务器_linux修改dhcp配置文件_mldl_的博客-CSDN博客](https://blog.csdn.net/mldl_/article/details/118282062) [sendmail 配置错误:Cannot open /usr/share/sendmail-cf/m4/cf.m4解决办法_lsfw的博客-CSDN博客](https://blog.csdn.net/haiyang79/article/details/6907224) 学生(签名)xxx 最后修改:2023 年 07 月 06 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 觉得文章有用,可以赞赏请我喝瓶冰露