云计算实训11——web服务器的搭建、nfs服务器的搭建、备份静态文件、基于linux和windows实现文件共享

一、搭建web服务器

1.关闭firewall和selinux

关闭防火墙

systemctl stop firewalld

systemctl disable firewalld

停用selinux

setenforce 0

配置文件中让sellinux不再启动

vim /etc/selinux/config

SELINUX=permissive

2.编辑dns配置文件

vim /etc/resolv.conf

nameserver 114.114.114.114

3.下载安装阿里云镜像

安装wget

yum -y install wget

下载镜像

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

编辑yum配置文件

vim /etc/yum.repos.d/nginx.repo

复制代码
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/amzn2/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
priority=9

清除缓存

yum clean all

建立缓存

yum makecache

4.安装nginx

下载nginx

yum -y install nginx

找到nginx的资源文件,查看是否安装

rpm -qa|grep nginx

yum list installed |grep nginx

查看资源文件

rpm -ql nginx

直接启动

nginx

检查服务是否启动

netstat -lnput|grep nginx

ps -aux|grep nginx

浏览器访问,出现下面页面

此时,我们的web服务器搭建完成!

5.远程访问

向web页面中添加图片和视频

上传图片和视频 到/usr/share/nginx/html/中

vim /usr/share/nginx/html/index.html

在本地物理主机上使用scp上传

scp -P22 111.png [email protected]

scp -P22 2.mp4 [email protected]

检查文件是否已经存在

root@web-server html\]# ls 111.png 2.mp4 50x.html index.html

浏览器输入地址访问,可以看到我们上传的图片和视频

但是,视频却是播放不了的

为此,我们只需要在访问时加上视频的名称,再去刷新,我们就能看到视频了!

二、搭建nfs服务器

1.首先做跟web服务器上相同的基本操作

下载阿里云镜像

root@nfs \~\]# yum -y install wget wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo \[root@nfs \~\]# yum clean all \[root@nfs \~\]# yum makecache 关闭防火墙,关闭selinux \[root@nfs \~\]# systemctl stop firewalld \[root@nfs \~\]# setenforce 0

root@nfs \~\]# yum -y install nfs-utils.x86_64 rpcbind.x86_64 查看nfs和rpc是否安装 \[root@nfs \~\]# rpm -aq \| grep nfs \[root@nfs \~\]# rpm -aq \| grep rpc

3.同步webf服务器的内容到nfs服务器上

创建目录及文件

创建一个share目录

root@nfs \~\]# mkdir /share 在share目录下创建一个名为paswd的文件 \[root@nfs \~\]# touch /share/paswd

下载tree

root@nfs \~\]# yum -y install tree

使用tree查看各级目录

root@nfs \~\]# tree /share/ /share/ └── paswd 0 directories, 1 file

将web机器上的图片111.png上传到nfs机器上

查看上传情况

同样的操作,再将web机器上的图片2.mp4上传到nfs机器上并查看

至此,成功实现了web服务器上的内容同步给nfs服务器

4.编辑配置文件

root@nfs \~\]# vim /etc/exports ![](https://i-blog.csdnimg.cn/direct/8bc19d6071b6417583237739cb0ae1fe.png) 5.启动rpcbind服务 \[root@nfs \~\]# systemctl start rpcbind.service 6.启动nfs服务 \[root@nfs \~\]# systemctl start nfs 7.查看端口占用 ![](https://i-blog.csdnimg.cn/direct/f598b74a464d409684803c6bd777e26d.png) 8.文件的测试,读文件 web服务器操作: 创建一个挂载nfs服务器的数据的目录 > \[root@web-server \~\]# mkdir /usr/share/nginx/html/static > > \[root@web-server \~\]# ls /usr/share/nginx/html/ > > 111.png 2.mp4 50x.html index.html static 下载nfs服务 > \[root@web-server \~\]# yum -y install nfs-utils.x86_64 .pki/ 挂载nfs服务器的文件 > \[root@web-server \~\]# mount -t nfs 192.168.1.50:/share /usr/share/nginx/html/static/ 查看挂载目录 > \[root@web-server \~\]# ls /usr/share/nginx/html/static/ > > 111.png 2.mp4 paswd > 修改配置文件,将路径改为上面我们所创建的static目录 > \[root@web-server \~\]# vim /usr/share/nginx/html/index.html > > ![](https://i-blog.csdnimg.cn/direct/4832543c157046b58259faa1e451d266.png) > > 仍然能够访问到下面页面 > > ![](https://i-blog.csdnimg.cn/direct/2fccfe9c39784b27a5700dbf5680fbc7.png) > > 查看static目录下的内容 > > \[root@web-server \~\]# ls /usr/share/nginx/html/static/ > > 111.png 2.mp4 paswd 在nfs服务器上写入内容 ![](https://i-blog.csdnimg.cn/direct/24181f364fb849239b7c5a77fd9b3064.png) 再回到web服务器,查看更新情况 ![](https://i-blog.csdnimg.cn/direct/cc3c6e3f0e874c78b7dccee7b3df483a.png) 发现a.txt的文件已经同步到static的目录下了 查看就可以看到写入的内容了 ![](https://i-blog.csdnimg.cn/direct/5ae74ce00eb1413eb039eace451ebe62.png) 在浏览器使用新的路径访问,得到以下页面 ![](https://i-blog.csdnimg.cn/direct/5c82919f96d94c45a1372ed2dc911c06.png) 此时发现我们的文字是看不见的,这是因为字符集的原因,只需要,设置utf-8就OK了 ### 三、备份静态文件 #### 1.关闭防火墙和selinux > \[root@bak-server \~\]# systemctl stop firewalld > > \[root@bak-server \~\]# setenforce 0 #### 2..安装下载阿里云镜像 > 安装wget > > \[root@bak-server \~\]# yum -y install wget > > 下载镜像 > > wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo > > 清除缓存 > > \[root@bak-server \~\]# yum clean all > > 建立缓存 > > \[root@bak-server \~\]# yum makecache > #### 3.安装rsync > \[root@bak-server \~\]# yum -y install rsync > > nfs主机也需要安装rsync #### 4.在nfs服务器上操作 ##### 安装epel > \[root@nfs \~\]# yum -y install epel-release.noarch ##### 安装监听软件 > \[root@nfs \~\]# yum -y install inotify-tools ##### 同步一份文件到bak-server上 > \[root@nfs \~\]# rsync -av /share/ [email protected]:/tmp/ > > The authenticity of host '192.168.1.70 (192.168.1.70)' can't be established. > > ECDSA key fingerprint is SHA256:f+o+Dk/cHGUOfJEUO6MRBUmq5O8YG9NEYM4qmoxGbvU. > > ECDSA key fingerprint is MD5:43:42:63:7e:67:d1:ee:eb:2b:7c:92:4c:1f:69:d6:b4. > > Are you sure you want to continue connecting (yes/no)? yes > > Warning: Permanently added '192.168.1.70' (ECDSA) to the list of known hosts. > > [email protected]'s password: > > rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(638) \[sender=3.1.2

此时,需要我们输入密码进行验证

由于太过麻烦,我们对它做一个免密操作

5.免密操作

生成密钥

将上面生成的密钥传递给bak-server

此时我们再去同步数据时就不需要输入密码了

6.创建备份目录

在备份主机上创建一个备份目录

root@bak-server \~\]# mkdir /bakup #### 7.回到nfs上编辑脚本 \[root@nfs \~\]# vim rn.sh \[root@nfs \~\]# #添加x权限 \[root@nfs \~\]# chmod +x rn.sh \[root@nfs \~\]# nohup ./rn.sh\& \[root@nfs \~\]# touch /share/aaa.aaa \[root@nfs \~\]# touch /share/bbb.bbb #### 8.查看日志文件 \[root@nfs \~\]# cat nohup.out ![](https://i-blog.csdnimg.cn/direct/0757c858b7514984971d46fbd6ed333c.png) 到bak-server主机上查看,发现文件已经成功备份到bakup目录下了 ![](https://i-blog.csdnimg.cn/direct/477275a1f75246a99b0bc96067d8d444.png) ### 四、基于linux和windows实现文件共享 在bak-server主机上安装samba > \[root@bak-server \~\]# yum -y install samba 编辑/etc/smb.conf配置文件,实现samba共享 > > > \[root@bak-server \~\]# vim /etc/samba/smb.conf > > > 设置用户user01 ,samba认证密码1 > > \[root@bak-server \~\]# useradd user01 > ![](https://i-blog.csdnimg.cn/direct/a4c7629378ff4de8a0df711d50b5495c.png) > > window要访问bakup中的文件,使用uer01 1 > > 启动名称管理 > \[root@bak-server \~\]# systemctl start nmb > > \[root@bak-server \~\]# systemctl start smb #### (一)基于linux实现文件共享 1.为共享文件添加写权限 > \[root@bak-server \~\]# setfacl -m u:user01:rwx /bakup/ 2.回到web-server主机上操作 安装客户端 > \[root@web-server \~\]# yum -y install samba-client 列出smb服务器上的共享资源 ![](https://i-blog.csdnimg.cn/direct/2365b9d554434947982ed4b32168d07c.png) 连接到bak-server 服务器上的名为 smb_share 的共享文件夹 ![](https://i-blog.csdnimg.cn/direct/d6cad921335744a4b0e9bcc64637d1c0.png) 3.安装cifs > \[root@web-server \~\]# yum -y install cifs-utils 4.创建aaa目录 \[root@web-server \~\]# mkdir aaa 5.共享挂载 共享挂载到本地文件系统的aaa目录上 > \[root@web-server \~\]# mount.cifs -o user=user01,pass=1 //192.168.1.70/smb_share \~/aaa/ 查看验证 > \[root@web-server \~\]# ls aaa > > 111.png 2.mp4 aaa.aaa abc.txt a.txt bbb.bbb paswd 可以看到文件已经被同步到aaa目录了 查看aaa目录下的详细信息 > \[root@web-server \~\]# ls -l aaa > > 总用量 6060 > > -rw-r--r--. 1 root root 24054 7月 22 11:41 111.png > > -rw-r--r--. 1 root root 6175659 7月 22 11:42 2.mp4 > > -rw-r--r--. 1 root root 0 7月 22 16:27 aaa.aaa > > -rw-r--r--. 1 root root 0 7月 22 16:25 abc.txt > > -rw-r--r--. 1 root root 31 7月 22 14:59 a.txt > > -rw-r--r--. 1 root root 0 7月 22 16:29 bbb.bbb > > -rw-r--r--. 1 root root 0 7月 22 11:40 paswd 至此基于linux的文件共享就完成了 #### (二)基于windows实现文件共享 1.在控制面板打开下面的页面 ![](https://i-blog.csdnimg.cn/direct/01fdc9aa08fe461988d6d07c6293462a.png) 2.打开这里的功能 ![](https://i-blog.csdnimg.cn/direct/8771f072c6834c0a9c5817d8a541fa3c.png) 3.然后在windows的我的电脑里面添加一个新的映射网络驱动器 ![](https://i-blog.csdnimg.cn/direct/c0f6f141525a4141b6e51e2580aca489.png) 4.然后点击完成,此时需要输入前面设置的用户名和密码 ![](https://i-blog.csdnimg.cn/direct/2de23ebf92e146099c8d82bec1e151d2.png) 5.然后点击确定,就能够看到共享的文件了 ![](https://i-blog.csdnimg.cn/direct/c691488da452471c9a54c811b18963ed.png) 也可以在它的上一级目录看到我们创建的文件共享 ![](https://i-blog.csdnimg.cn/direct/1fce9ffef2284d36bd9d4901b5a73b07.png) 至此基于windows的文件共享就完成了

相关推荐
hello_ejb328 分钟前
聊聊Spring AI Alibaba的PdfTablesParser
windows·python·spring
Vodka~1 小时前
深度学习——数据处理脚本(基于detectron2框架)
人工智能·windows·深度学习
长流小哥1 小时前
Linux网络编程实战:从字节序到UDP协议栈的深度解析与开发指南
linux·c语言·开发语言·网络·udp
极小狐2 小时前
极狐GitLab 功能标志详解
linux·运维·服务器·elasticsearch·gitlab·极狐gitlab
lixy5792 小时前
深度学习之自动微分
人工智能·python·深度学习
jinan8862 小时前
加密软件的发展:从古典密码到量子安全
大数据·运维·服务器·网络·安全·web安全
雾原3 小时前
Red Hat Enterprise Linux (RHEL)系统部署
linux
您8133 小时前
二十、FTP云盘
linux·服务器·网络
用户3409704691153 小时前
ROS2-Jazzy编译功能包报错
linux
264玫瑰资源库3 小时前
2025年七星棋牌跨平台完整源码解析(200+地方子游戏+APP+H5+小程序支持,附服务器镜像导入思路)
服务器·游戏·小程序