云盘算实训11——web服务器的搭建、nfs服务器的搭建、备份静态文件、基于li ...

铁佛  论坛元老 | 2024-7-26 01:37:27 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 1018|帖子 1018|积分 3054

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
一、搭建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
  1. [nginx-stable]
  2. name=nginx stable repo
  3. baseurl=http://nginx.org/packages/amzn2/$releasever/$basearch/
  4. gpgcheck=1
  5. enabled=1
  6. gpgkey=https://nginx.org/keys/nginx_signing.key
  7. module_hotfixes=true
  8. 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 root@192.168.1.60
scp -P22 2.mp4 root@192.168.1.60
  
检查文件是否已经存在
    [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
 
  2.安装nfs和rpc
   [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

5.启动rpcbind服务
[root@nfs ~]# systemctl start rpcbind.service 
6.启动nfs服务
[root@nfs ~]# systemctl start nfs
7.检察端口占用

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 
  

  仍然能够访问到下面页面
  

  检察static目次下的内容
[root@web-server ~]# ls /usr/share/nginx/html/static/
111.png  2.mp4  paswd
  在nfs服务器上写入内容

再回到web服务器,检察更新环境

发现a.txt的文件已经同步到static的目次下了
检察就可以看到写入的内容了

在欣赏器利用新的路径访问,得到以下页面

此时发现我们的文字是看不见的,这是由于字符集的缘故因由,只需要,设置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/ root@192.168.1.70:/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.
root@192.168.1.70'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

到bak-server主机上检察,发现文件已经成功备份到bakup目次下了

四、基于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

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服务器上的共享资源

连接到bak-server 服务器上的名为 smb_share 的共享文件夹

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.在控制面板打开下面的页面

2.打开这里的功能

3.然后在windows的我的电脑里面添加一个新的映射网络驱动器

4.然后点击完成,此时需要输入前面设置的用户名和密码

5.然后点击确定,就能够看到共享的文件了

也可以在它的上一级目次看到我们创建的文件共享

至此基于windows的文件共享就完成了





免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

铁佛

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表