自学内容网 自学内容网

nfs配置静态文件共享、web发布web项目、samba文件共享(基于Windows/linux的文件共享),

nfs配置静态文件共享

1.停用防火墙和selinux

​ 2.安装2个应用rpcbind、nfs-utils

​ 3.配置/etc/exports

​ 4.启动服务

​ 5.查看端口占用(111)

web发布web项目

1.停用防火墙和selinux

2.安装nginx

[root@web ~]# systemctl stop firewalld
[root@web ~]# setenforce 0
[root@web ~]# systemctl disable firewalld
[root@web ~]# vim /etc/selinux/config 
[root@web ~]# yum -y install --downloadonly --downloaddir=./soft/ nginx
[root@web ~]# yum -y install nginx
[root@web ~]# tree /usr/share/nginx/html/
/usr/share/nginx/html/
├── 404.html
├── 50x.html
├── css
│?? └── app.16b1c3fc.css
├── en-US -> ../../doc/HTML/en-US
├── favicon.ico
├── icons
│?? └── poweredby.png -> ../../../pixmaps/poweredby.png
├── img -> ../../doc/HTML/img
├── index.html -> ../../doc/HTML/index.html
├── js
│?? ├── about.bfdc2607.js
│?? ├── about.bfdc2607.js.map
│?? ├── app.3758bade.js
│?? ├── app.3758bade.js.map
│?? ├── chunk-vendors.622eb712.js
│?? └── chunk-vendors.622eb712.js.map
├── nginx-logo.png
└── poweredby.png -> nginx-logo.png
​
5 directories, 14 files
[root@web ~]# which nginx
/usr/sbin/nginx
[root@web ~]# ls -l /usr/sbin/nginx 
-rwxr-xr-x. 1 root root 1270744 11月 11 2022 /usr/sbin/nginx
[root@web ~]# systemctl stop firewalld
[root@web ~]# nginx
[root@web ~]# netstat -lnput|grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1949/nginx: master  
tcp6       0      0 :::80                   :::*                    LISTEN      1949/nginx: master  
[root@web ~]# 

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

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

修改/usr/bin/nginx/html/index.html

在本地物理机使用scp上传

物理机:

​
C:\Users\Shi si>scp D:\lll\aaa.png root@192.168.2.15:/usr/share/nginx/html
root@192.168.2.15's password:
aaa.png                                                                               100%  290KB  42.1MB/s   00:00
​
C:\Users\Shi si>scp D:\lll\cc8b23eec3ac306667b4f7e554622aec.mp4 root@192.168.2.15:/usr/share/nginx/html
root@192.168.2.15's password:
cc8b23eec3ac306667b4f7e554622aec.mp4                                                  100% 4201KB  62.8MB/s   00:00
​
C:\Users\Shi si>

web虚拟机:

[root@web ~]# scp -p22 aaa.png root@192.168.2.15^C
[root@web ~]# ls /usr/share/nginx/html/
404.html  aaa.png  en-US        icons  index.html  nginx-logo.png
50x.html  css      favicon.ico  img    js          poweredby.png
[root@web ~]# vim /usr/share/nginx/html/index.html 
<img src="aaa.png" /><!--插入图片-->
 <!--插入视频-->
 <video>
         <source src="cc8b23eec3ac306667b4f7e554622aec.mp4" />
 </video>
</body>
</html>

​
[root@web ~]# 

真机访问192.168.2.15:

​ 2.安装2个应用rpcbind、nfs-utils

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

14主机:​ 安装2个应用rpcbind、nfs-utils

[root@14 ~]# yum -y install nfs-utils.x86_64 
[root@14 ~]# mkdir /share
[root@14 ~]# touch /share/passwd
[root@14 ~]# tree /share/
/share/
└── passwd
​
0 directories, 1 file
[root@14 ~]# scp root@192.168.2.15:/usr/share/nginx/html/aaa.png /share/
The authenticity of host '192.168.2.15 (192.168.2.15)' can't be established.
ECDSA key fingerprint is SHA256:DFQPeJuLPiA/K0OYrrZoRt1BhKyxWLVaHvJH0afkFjc.
ECDSA key fingerprint is MD5:98:77:aa:0a:39:d6:ef:64:31:f9:c4:59:ab:13:59:12.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.2.15' (ECDSA) to the list of known hosts.
root@192.168.2.15's password: 
aaa.png                                    100%  290KB  38.4MB/s   00:00    
[root@14 ~]# scp root@192.168.2.15:/usr/share/nginx/html/cc8b23eec3ac306667b4f7e554622aec.mp4 /share/
root@192.168.2.15's password: 
cc8b23eec3ac306667b4f7e554622aec.mp4       100% 4201KB  35.8MB/s   00:00    
[root@14 ~]# 

写文件:

        3.配置/etc/exports

[root@14 ~]# tree /share/
/share/
├── aaa.png
├── cc8b23eec3ac306667b4f7e554622aec.mp4
└── passwd
​
0 directories, 3 files
[root@14 ~]# vim /etc/exports
​
/share *(rw,sync)
​

4.启动服务 /重启服务:

[root@14 ~]# systemctl start rpcbind
[root@14 ~]# systemctl start nfs-utils.service 
[root@14 ~]# systemctl start nfs
[root@14 ~]# 

5.查看端口:

rpc服务端口号:111

回到web主机(实现共享):

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

5.挂载nfs服务

创建目录/usr/share/nginx/html/static/用来挂载nfs服务器数据

挂载

[root@web ~]# mkdir /usr/share/nginx/html/static
[root@web ~]# mount -t nfs 192.168.2.14:/share /usr/share/nginx/html/static/
[root@web ~]# ls /usr/share/nginx/html/static/
aaa.png  cc8b23eec3ac306667b4f7e554622aec.mp4  passwd
[root@web ~]#  

更改配置文件:

<img src="static/aaa.png" /><!--插入图片-->
 <!--插入视频-->
 <video>
         <source src="static/cc8b23eec3ac306667b4f7e554622aec.mp4" />
 </video>
​
</body>
</html>
​

在14 nfs主机添加:

[root@14 ~]# echo "你好世界" > /share/a.txt

在web主机:

[root@web ~]# ls /usr/share/nginx/html/static/
aaa.png  a.txt  cc8b23eec3ac306667b4f7e554622aec.mp4  passwd
[root@web ~]# 

在static目录中添加文件,看看nfs服务器中的文件是否会更新:(无法创建)

[root@web ~]# touch /usr/share/nginx/html/static/b.txt
touch: 无法创建"/usr/share/nginx/html/static/b.txt": 权限不够
[root@web ~]# 

备份:

当nfs的static目录中的文件发生改变时,备份到bakerver

克隆新的主机kl,14 nfs主机和 kl主机安装rsync:

systemctl stop firewalld.service setenforce 0 yum -y install rsync

nfs主机安装监听软件:

[root@14 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@14 ~]# yum -y install epel-release.noarch 
[root@14 ~]# yum -y install inotify-tools

同步文件到kl主机:(设置免密)

[root@14 ~]# ssh-keygen
[root@14 ~]# ssh-copy-id root@192.168.2.12
[root@14 ~]# rsync -av /share/ root@192.168.2.12:/tmp/

kl主机创建目录:

mkdir bak

14 nfs主机加脚本:

[root@14 ~]# vim inotify.sh 
​
#!/bin/bash
​
/usr/bin/inotifywait -mrq -e modify,delete,create,attrib,move  |while read events
do
    rsync -av /share/ root@192.168.2.12:/root/bak
        echo "`date +%F\ %T`出现事件$events" >> /var/log/rsync.log 2>&1
done
[root@14 ~]# chmod 700 inotify.sh 
[root@14 ~]# nohup ./inotify.sh &
[1] 21508
[root@14 ~]# nohup: 忽略输入并把输出追加到"nohup.out"
​
[root@14 ~]# nohup ./inotify.sh &
[root@14 ~]# touch /share/ll.txt
[root@14 ~]# cat nohup.out

kl主机:

[root@kl ~]# ls bak/
aaa.png  abc.abc  cc8b23eec3ac306667b4f7e554622aec.mp4  passwd
ab.abc   a.txt    ll.txt
[root@kl ~]# 

samba文件共享:(linux文件共享给Windows)

[root@kl ~]# yum -y install samba
[root@kl ~]# vim /etc/samba/smb.conf
[yulan]
        comment = samba service
        path = /root/bak
        guest ok = no
        writable = yes

设置用户01,samba认证密码123

[root@kl ~]# useradd 01
[root@kl ~]# smbpasswd -a 01
New SMB password:
Retype new SMB password:
Added user 01.
[root@kl ~]# 

启动名称管理:

[root@kl ~]# systemctl start nmb.service 
[root@kl ~]# systemctl start smb.service

基于windows真机实现文件共享:

 基于Linux或Linux实现⽂件共享:

yum -y install samba-client

使⽤smbclient查看⽬录信息:

[root@web ~]# smbclient //192.168.2.12/yulan -U 01

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

[root@web ~]# yum -y install cifs-utils
[root@web ~]# mkdir /01
[root@web ~]# mount.cifs -o user=01,pass=123 //192.168.2.12/yulan /01

[root@web ~]# smbclient //192.168.2.12/yulan -U 01


原文地址:https://blog.csdn.net/m0_72244574/article/details/140616791

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!