部署nginx+部署nfs+挂载nfs+共享文件samba

安装nginx

配置一个本地的nginx仓库

yum -y install --downloadonly --downloaddir=./soft/

yum -y install --downloadonly --downloaddir=./soft/ nginxtree ./soft/

只下载不安装 yum -y install --downloadonly -- downloaddir=./soft/

创建本地仓库,安装createrepo

yum -y install createrepo

yum -y install createrepo

安装完成createrepo,用于创建本地仓库

使用createrepo生成仓库文件

soft目录中生成一个repodata目录

createrepo ./soft/

检测soft目录中是不是保存是了一个repo

repodata

文件夹

tree ./soft/

在/etc/yum.repos.d新建一个repo文件,文件名就叫nginx

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

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

建立缓存

yum clean allyum makecache

yum clean all yum makecache

安装nginx

安装nginx

[root@y ~]# yum -y install nginx

查看是否安装

[root@y ~]# rpm -qa|grep nginx

nginx-1.20.1-10.el7.x86_64

[root@y ~]# yum list installed |grep nginx

确定安装了nginxnginx-filesystem-1.20.1-10.el7.noarch

您在 /var/spool/mail/root 中有新邮件

查看资源文件

[root@y ~]# rpm -ql nginx

目前不用修改nginx

只需要发布一个简单的项目

[root@y ~]# tree /usr/share/nginx/html/

[root@y ~]# which nginx
/usr/sbin/nginx

[root@y ~]# ls -l /usr/bin/nginx-upgrade

-rwxr-xr-x. 1 root root 560 11月 11 2022 /usr/bin/nginx-upgrade

[root@y ~]# ls -l /usr/sbin/nginx

-rwxr-xr-x. 1 root root 1270744 11月 11 2022 /usr/sbin/nginx

查看防火墙是不是开了

[root@y ~]# systemctl status firewalld

检查服务是否启动

[root@y ~]# netstat -lnput|grep nginx

[root@y ~]# ps -aux|grep nginx

root 1926 0.0 0.0 112720 968 pts/0 S+ 10:06 0:00 grep --color=auto nginx

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

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

[root@y ~]# cp -r 205c3c94bf4444f02f9da15cc7a69cd.jpg /usr/share/nginx/html/

[root@y ~]# cp -r ppt.mp4 /usr/share/nginx/html/

检查文件是否已经存在

[root@y ~]# ls /usr/share/nginx/html/

205c3c94bf4444f02f9da15cc7a69cd.jpg

en-US i

ndex.html

404.html

icons

nginx-logo.png

50x.html

img

poweredby.png

ppt.mp4

[root@y ~]# cd /usr/share/nginx/html/
您在 /var/spool/mail/root 中有新邮件

[root@y html]# mv 205c3c94bf4444f02f9da15cc7a69cd.jpg 2.jpg

[root@y html]# ls

2.jpg

50x.html

icons

index.html

poweredby.png404.html

en-US

img

nginx-logo.png

ppt.mp4

[root@y html]# vim /usr/share/nginx/html/index.html

<img src="2.jpg" /><!--插入图片-->

154 <!--插入视频-->

155 <video>

156      <source src="ppt.mp4" />

157 </video>

[root@y html]# systemctl restart nginx[root@y html]# systemctl stop firewalld[root@y html]# setenforce 0

用浏览器访问IP:192.168.2.8

在web服务器中也要安装nfs服务

[root@y ~]# yum -y install nfs-utils.x86_64 rpcbind.x86_64

安装nfs

1.安装应用 rpcbind nfs-utils

2.停用防火墙和selinux

3.配置文件 /etc/exports

4../share *(rw,sync)

5.启动rpcbind服务

[root@nfsserver ~]# systemctl start rpcbind.service

6.启动nfs服务

[root@nfsserver ~]# systemctl start nfs

启动成功以后,就可以在webserver中测试了

rpc的端口号是111

搭建web服务

1.创建一个目录,/usr/share/nginx/html/static/,用来挂在nfs服务器的数据

[root@y ~]# mkdir /usr/share/nginx/html/static

[root@y ~]# ls -l /usr/share/nginx/html/

总用量 604

-rw-r--r--. 1 root root 230153 7月 22 10:45 2.jpg

-rw-r--r--. 1 root root 3650 11月 11 2022 404.html

-rw-r--r--. 1 root root 3693 11月 11 2022 50x.html

lrwxrwxrwx. 1 root root 20 7月 22 09:42 en-US -> ../../doc/HTML/en-US

drwxr-xr-x. 2 root root 27 7月 22 09:42 icons

lrwxrwxrwx. 1 root root 18 7月 22 09:42 img -> ../../doc/HTML/img

lrwxrwxrwx. 1 root root 25 7月 22 09:42 index.html -> ../../doc/HTML/index.html

-rw-r--r--. 1 root root 368 11月 11 2022 nginx-logo.png

lrwxrwxrwx. 1 root root 14 7月 22 09:42 poweredby.png -> nginx-logo.png

-rw-r--r--. 1 root root 368684 7月 22 12:56 ppt.mp4

drwxr-xr-x. 2 root root 6 7月 22 14:19 static

2.挂载nfsserver的文件

[root@y ~]# mount -t nfs 192.168.2.10:/share /usr/share/nginx/html/static/

rsync同步,将文件复制一份

nfs拿到了一个文件的链接(会将nfs服务器中的数据同步到web服务器中)

[root@y ~]# ls /usr/share/nginx/html/static/2.jpg passwd ppt.mp4

rsync+inotify

nfs用于局域网

挂载nfs服务

回到web服务器中。修改index.html,在nginx下的html目录中创建一个挂载目录 static,[root@y ~]# mkdir /usr/share/nginx/html/static,从static目录中引用图片和视频,vim /usr/share/nginx/html/index.html,然后在webserver上挂载nfs服务,然后进行文件测试(在static中的图片也能被访问到)。也可以在nfs服务器中的/share/目录下创建文件,再去webserver主机中查看数据是否更新。

1.创建了2个虚拟主机

2.nfsserver配置静态文件共享

(1)停用防火墙和selinux

systemctl stop firewalld

setenforce 0

(2)安装两个应用

rpcbind

nfs-utils

(3)配置/etc/exports

/share *(rw,sync|async)

sync--同步

async--异步

(4).启动服务

systemctl start rpmbind

systemctl start nfs

(5).查看端口占用

netstat -lntup | grep 111

(6).确定nfs服务正常启动

3.webserver 发布web项目

(1).停用防火墙和selinux

systemctl stop firewalld

setenforce 0

(2).安装nginx

[root@y ~]# yum -y install nginx

(3).修改nginx默认的index.html,添加图片和视频

[root@y ~]# vim /usr/share/nginx/html/index.html

<img src="static/2.jpg">
 <video>
  <source src="static/ppt.mp4" />
 </video>

[root@y ~]# systemctl restart nginx

4.在nginx下的html目录中创建一个挂载目录 static

[root@y ~]# mkdir /usr/share/nginx/html/static

5.挂载nfs服务

[root@y ~]#mount -t nfs 192.168.2.10:/share /usr/share/nginx/html/static/

[root@y ~]# ls /usr/share/nginx/html/static/2.jpg passwd ppt.mp4

[root@y ~]# systemctl restart nginx

6.查看挂载目录,在webserver中看到nfs服务共享的数据,这个数据是链接,不是真实文件,和rsync的数据不同

7.文件测试

8.用浏览器访问IP:192.168.2.8

rpc服务的端口号是111

rpc服务的端口号是111

9.向nfs服务器中的share目录中添加数据

在nfs服务器中的/share/目录中创建a.txt

[root@nfsserver ~]# touch /share/a.txt[root@nfsserver ~]# echo "我是秦始皇" > /share/a.txt

10.再去webserver主机中查看数据是否更新:

会同步到nginx的/usr/share/nginx/html/static/ 目录下

[root@y ~]# ls /usr/share/nginx/html/static/2.jpg a.txt passwd ppt.mp4

11.通过浏览器访问IP:192.168.2.8/static/a.txt

备份静态文件

备份是复制一份文件,共享是获取文件链接

1.克隆一个备份主机 bakuphost

2.停用selinux和firewalld

systemctl stop firewalld

setenforce 0

3.支持rsync备份同步 安装rsync,bakuphost nfsserver两台主机上都应安装

[root@bakup ~]# yum -y install rsync

[root@nfsserver ~]# yum -y install rsync

4.在nfs主机上安装inotify-tools监听/share目录

[root@nfsserver ~]# yum -y install inotify-tools

5.先同步一份一份到bakuphost主机的tmp目录下

[root@nfsserver ~]# rsync -av /share/ root@192.168.2.21:/tmp/

6.需要输入密码才会同步过去,为了自动化,设置免密

免密:

(1).ssh-keygen

[root@nfsserver ~]# ls ./.ssh/

authorized_keys id_rsa id_rsa.pub known_hosts

[root@nfsserver ~]# ssh-copy-id root@192.168.2.21

<1>.将公钥字符串添加到对方家目录中的authorized_keys文件中

<2>.也可以使用scp将id_rsa.pub文件上传到bakserver主机,手工将文件中的字符串复制到authorized_keys文件中

(2).ssh -copy-id root@ip

(3)测试

[root@nfsserver ~]# rsync -av /share/ root@192.168.2.21:/tmp/

sending incremental file list

./2.jpg

a.txt

passwd

ppt.mp4

sent 599,293 bytes received 95 bytes 52,120.70 bytes/sectotal size is 598,853 speedup is 1.00

7.bakuphost主机上去创建/bakup

8.nfsserver上创建一个脚本rn.sh

当nfs的share目录中的文件发生改变的时候,备份到bak_server主机中的/bakup/目录中。

9.脚本代码

#!/bin/bash
inotifywait /share -mrq -e
modify,create,delete,attrs,move|while read events
do
  rsync -av --delete /share/ root@192.168.2.21:/bakup/
   #也可以输出日志
   done

10.给添加x权限,执行脚本

在nfs服务器上修改配置文件:

[root@nfsserver ~]# vim rn.sh

[root@nfsserver ~]# chmod +x rn.sh

[root@nfsserver ~]# nohup ./rn.sh&

11.在nfs主机中的/share/下新增文件,就会同步到bakup主机下的/bakup目录下

[root@nfsserver ~]# touch /share/aaa.aaa

[root@nfsserver ~]# touch /share/bbb.bbb

[root@nfsserver ~]# touch /share/ccc.ccc

[root@nfsserver ~]# touch /share/llll.lll

12.在bakup主机中创建/bakup目录

[root@bak_server ~]# mkdir /bakup/

13.查看文件是否同步成功:

查看/bakup目录,就可以看到已经将nfs主机中在/share/中创建的文件,同步到文件/bakup中了

[root@bak_server ~]# ls /bakup/2.jpg a.txt ccc.ccc llll.lll passwd uuu.oooaaa.aaa bbb.bbb hahaa.h ooo.uuu ppt.mp4 yyy.yyy

SAMBA文件共享

1.下载samba软件

[root@bak_server ~]# yum -y install samba

[root@bak_server ~]# ls /etc/samba/lmhosts smb.conf smb.conf.example

2.修改samba的配置文件

[root@bak_server ~]# vim /etc/samba/smb.conf

[smb_share]

comment = samba service

path = /samba/share

guest ok = no

writable = yes

3.设置用户user01,samba认证123密码

[root@bak_server ~]# useradd user01[

root@bak_server ~]# smbpasswd -a user01

New SMB password:

Retype new SMB password:

Added user user01.

4.启动名称管理

[root@bak_server ~]# systemctl start nmb.service

[root@bak_server ~]# systemctl start smb.service

5.基于Windows或Linux实现⽂件共享

第九步:基于linux和linux实现文件共享

[root@webserver ~]# yum -y install samba-client

[root@webserver ~]# smbclient -L 192.168.2.21 -U user01
Enter SAMBA\user01's password: 

    Sharename       Type      Comment
    ---------       ----      -------
    print$          Disk      Printer Drivers
    smb_share       Disk      samba service
    IPC$            IPC       IPC Service (Samba 4.10.16)
    user01          Disk      Home Directories
Reconnecting with SMB1 for workgroup listing.

    Server               Comment
    ---------            -------

    Workgroup            Master
    ---------            -------
    SAMBA                BAK_SERVER
使用smbclient查看目录信息

[root@webserver ~]# smbclient //192.168.2.21/smb_share -U user01
Enter SAMBA\user01's password: 
Try "help" to get a list of possible commands.
smb: \> ls
  .                                   D        0  Mon Jul 22 16:42:01 2024
  ..                                  D        0  Mon Jul 22 16:23:12 2024
  2.jpg                               N   230153  Mon Jul 22 11:43:45 2024
  a.txt                               N       16  Mon Jul 22 15:04:12 2024
  aaa.aaa                             N        0  Mon Jul 22 16:29:22 2024
  bbb.bbb                             N        0  Mon Jul 22 16:29:46 2024
  ccc.ccc                             N        0  Mon Jul 22 16:30:54 2024
  hahaa.h                             N        0  Mon Jul 22 16:42:01 2024
  llll.lll                            N        0  Mon Jul 22 16:33:44 2024
  ooo.uuu                             N        0  Mon Jul 22 16:40:02 2024
  passwd                              N        0  Mon Jul 22 11:39:25 2024
  ppt.mp4                             N   368684  Mon Jul 22 13:01:37 2024
  uuu.ooo                             N        0  Mon Jul 22 16:38:13 2024
  yyy.yyy                             N        0  Mon Jul 22 16:36:29 2024

        17811456 blocks of size 1024. 13650856 blocks available

smb: \> mkdir aa.aa
smb: \> ls
  .                                   D        0  Mon Jul 22 17:42:41 2024
  ..                                  D        0  Mon Jul 22 16:23:12 2024
  2.jpg                               N   230153  Mon Jul 22 11:43:45 2024
  a.txt                               N       16  Mon Jul 22 15:04:12 2024
  aaa.aaa                             N        0  Mon Jul 22 16:29:22 2024
  bbb.bbb                             N        0  Mon Jul 22 16:29:46 2024
  ccc.ccc                             N        0  Mon Jul 22 16:30:54 2024
  hahaa.h                             N        0  Mon Jul 22 16:42:01 2024
  llll.lll                            N        0  Mon Jul 22 16:33:44 2024
  ooo.uuu                             N        0  Mon Jul 22 16:40:02 2024
  passwd                              N        0  Mon Jul 22 11:39:25 2024
  ppt.mp4                             N   368684  Mon Jul 22 13:01:37 2024
  uuu.ooo                             N        0  Mon Jul 22 16:38:13 2024
  yyy.yyy                             N        0  Mon Jul 22 16:36:29 2024
  aa.aa                               D        0  Mon Jul 22 17:42:41 2024

        17811456 blocks of size 1024. 13650820 blocks available

把SAMBA挂载到Linux系统(类似NFS)

[root@webserver ~]# yum -y install cifs-utils
[root@webserver ~]# mkdir aaa
[root@webserver ~]# mount.cifs -o user=user01,pass=123 //192.168.2.21/smb_share ~/aaa/
[root@webserver ~]# ls aaa/
2.jpg  aaa.aaa  bbb.bbb  hahaa.h   ooo.uuu  ppt.mp4  yyy.yyy
aa.aa  a.txt    ccc.ccc  llll.lll  passwd   uuu.ooo
[root@webserver ~]# ls -l aaa/
总用量 596
-rw-r--r--. 1 root root 230153 7月  22 11:43 2.jpg
drwxr-xr-x. 2 1002 1002      0 7月  22 17:42 aa.aa
-rw-r--r--. 1 root root      0 7月  22 16:29 aaa.aaa
-rw-r--r--. 1 root root     16 7月  22 15:04 a.txt
-rw-r--r--. 1 root root      0 7月  22 16:29 bbb.bbb
-rw-r--r--. 1 root root      0 7月  22 16:30 ccc.ccc
-rw-r--r--. 1 root root      0 7月  22 16:42 hahaa.h
-rw-r--r--. 1 root root      0 7月  22 16:33 llll.lll
-rw-r--r--. 1 root root      0 7月  22 16:40 ooo.uuu
-rw-r--r--. 1 root root      0 7月  22 11:39 passwd
-rw-r--r--. 1 root root 368684 7月  22 13:01 ppt.mp4
-rw-r--r--. 1 root root      0 7月  22 16:38 uuu.ooo
-rw-r--r--. 1 root root      0 7月  22 16:36 yyy.yyy

 

  • 16
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值