铁佛 发表于 2024-7-26 01:37:27

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

一、搭建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

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
欣赏器访问,出现下面页面
https://i-blog.csdnimg.cn/direct/add3110233884e67999ce87b7bd9074c.png
此时,我们的web服务器搭建完成!

5.远程访问
向web页面中添加图片和视频
上传图片和视频 到/usr/share/nginx/html/中 
vim /usr/share/nginx/html/index.html
https://i-blog.csdnimg.cn/direct/9a910534354f4c2fa24a62065c57a5cc.png
在本地物理主机上利用scp上传
   scp -P22 111.png root@192.168.1.60
scp -P22 2.mp4 root@192.168.1.60

检查文件是否已经存在
    # ls
111.png  2.mp4  50x.html  index.html
欣赏器输入地址访问,可以看到我们上传的图片和视频
https://i-blog.csdnimg.cn/direct/9b54720e0557454884d313b6b9376b1c.png
但是,视频却是播放不了的
https://i-blog.csdnimg.cn/direct/242ee630201846189ee8554ac181b451.png
为此,我们只需要在访问时加上视频的名称,再去刷新,我们就能看到视频了!
https://i-blog.csdnimg.cn/direct/e7eb11f5ab3b42e09c0208712c01948e.png
二、搭建nfs服务器


1.起首做跟web服务器上雷同的根本操作
   下载阿里云镜像
# yum -y install wget
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# yum clean all
# yum makecache
关闭防火墙,关闭selinux
# systemctl stop firewalld
# setenforce 0
 
2.安装nfs和rpc
   # yum -y install nfs-utils.x86_64 rpcbind.x86_64 
检察nfs和rpc是否安装
# rpm -aq | grep nfs
# rpm -aq | grep rpc
3.同步webf服务器的内容到nfs服务器上
创建目次及文件
   创建一个share目次
# mkdir /share
在share目次下创建一个名为paswd的文件
# touch /share/paswd
下载tree
   # yum -y install tree
利用tree检察各级目次
   # tree /share/
/share/
└── paswd
0 directories, 1 file
将web机器上的图片111.png上传到nfs机器上
https://i-blog.csdnimg.cn/direct/a674522657154c7d8d5a5c88909b97f6.png
检察上传环境
https://i-blog.csdnimg.cn/direct/e2489fa95c84420097aa953bddb1edbc.png
同样的操作,再将web机器上的图片2.mp4上传到nfs机器上并检察
https://i-blog.csdnimg.cn/direct/9e7709cc01574885b2ad02de4cd31485.png
至此,成功实现了web服务器上的内容同步给nfs服务器
4.编辑配置文件
# vim /etc/exports
https://i-blog.csdnimg.cn/direct/8bc19d6071b6417583237739cb0ae1fe.png
5.启动rpcbind服务
# systemctl start rpcbind.service 
6.启动nfs服务
# systemctl start nfs
7.检察端口占用
https://i-blog.csdnimg.cn/direct/f598b74a464d409684803c6bd777e26d.png
8.文件的测试,读文件
web服务器操作:
创建一个挂载nfs服务器的数据的目次
   # mkdir /usr/share/nginx/html/static
# ls /usr/share/nginx/html/
111.png  2.mp4  50x.html  index.html  static
下载nfs服务
   # yum -y install nfs-utils.x86_64 .pki/

挂载nfs服务器的文件
   # mount -t nfs 192.168.1.50:/share /usr/share/nginx/html/static/
检察挂载目次
   # ls /usr/share/nginx/html/static/
111.png  2.mp4  paswd
 
修改配置文件,将路径改为上面我们所创建的static目次
   # vim /usr/share/nginx/html/index.html 
https://i-blog.csdnimg.cn/direct/4832543c157046b58259faa1e451d266.png
仍然能够访问到下面页面
https://i-blog.csdnimg.cn/direct/2fccfe9c39784b27a5700dbf5680fbc7.png
检察static目次下的内容
# 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

   # systemctl stop firewalld
# setenforce 0
2..安装下载阿里云镜像

   安装wget
# yum -y install wget
下载镜像
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
清除缓存
# yum clean all
创建缓存
# yum makecache
 
3.安装rsync

   # yum -y install rsync
nfs主机也需要安装rsync
4.在nfs服务器上操作

安装epel

   # yum -y install epel-release.noarch 
安装监听软件

   # yum -y install inotify-tools
同步一份文件到bak-server上

   # 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)
此时,需要我们输入密码举行验证
由于太过贫苦,我们对它做一个免密操作
5.免密操作

生成密钥
https://i-blog.csdnimg.cn/direct/d0b726e3b3cb4c37b812b3c3bd0384ff.png
将上面生成的密钥通报给bak-server
https://i-blog.csdnimg.cn/direct/02177bf05e51497ea2a5bd6ac0622f0b.png
此时我们再去同步数据时就不需要输入密码了
https://i-blog.csdnimg.cn/direct/40869e1086c94006a1b1d4cec6a66465.png
6.创建备份目次

在备份主机上创建一个备份目次
# mkdir /bakup
7.回到nfs上编辑脚本


# vim rn.sh
# #添加x权限
# chmod +x rn.sh
# nohup ./rn.sh&
# touch /share/aaa.aaa
# touch /share/bbb.bbb
8.检察日记文件

# 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
   # yum -y install samba
编辑/etc/smb.conf配置文件,实现samba共享
   
# vim /etc/samba/smb.conf

设置用户user01 ,samba认证密码1
# useradd user01
https://i-blog.csdnimg.cn/direct/a4c7629378ff4de8a0df711d50b5495c.png
window要访问bakup中的文件,利用uer01 1
启动名称管理
    # systemctl start nmb
# systemctl start smb
(一)基于linux实现文件共享

1.为共享文件添加写权限
   #  setfacl -m u:user01:rwx /bakup/
2.回到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
   # yum -y install cifs-utils
4.创建aaa目次
# mkdir aaa
5.共享挂载
共享挂载到本地文件系统的aaa目次上
   # mount.cifs -o user=user01,pass=1 //192.168.1.70/smb_share ~/aaa/
检察验证
   # ls aaa
111.png  2.mp4  aaa.aaa  abc.txt  a.txt  bbb.bbb  paswd
可以看到文件已经被同步到aaa目次了
检察aaa目次下的详细信息
   # 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的文件共享就完成了





免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 云盘算实训11——web服务器的搭建、nfs服务器的搭建、备份静态文件、基于li