首页 > 其他分享 >NFS日志管理和文件共享以及永久挂载文件

NFS日志管理和文件共享以及永久挂载文件

时间:2023-03-03 20:31:46浏览次数:35  
标签:www ubuntu2004 文件共享 data nfsdir1 NFS nfs 日志 root

今天分享的是NFS的网络共享,其中包括主机之间的文件公布共享和挂载其相关配置文件

网络文件实时同步和共享

实战案例:将所有服务器里的存储内容传到共享服务器里
1.硬盘插入首先要分区  2.创建文件系统 3.挂载
NFS软件介绍

软件包:

  • 红帽系统: nfs-utils: 包括服务器和客户端相关工具,CentOS8 最小化安装时默认没有安装)
  • Ubuntu: nfs-kernel-server 服各器包名,nfs-common 客户端包名

相关软件包:rpcbind(必须),tcp_wrappers

端口:2049(nfsd), 其它端口由portmap(111)分配

NFS服务主要进程:

  • rpc.nfsd 最主要的NFS进程,管理客户端是否可登录
  • rpc.mountd 挂载和卸载NFS文件系统,包括权限管理
  • rpc.lockd 非必要,管理文件锁,避免同时写出错
  • rpc.statd 非必要,检查文件一致性,可修复文件

说明:CentOS 6 开始portmap进程由rpcbind代替

日志:/var/lib/nfs/

NFS配置文件:

/etc/exports
/etc/exports.d/*.exports

范例:红帽系统安装NFS软件包

[root@centos8 ~]#yum -y install nfs-utils
[root@centos8 ~]#systemctl enable --now nfs-server.service

范例: Ubuntu 安装NFS软件包

#服务器
[root@ubuntu2004 ~]#apt install nfs-kernel-server
[root@ubuntu2004 ~]#systemctl status nfs-server

#客户端
[root@ubuntu2004 ~]#apt -y install nfs-common
服务端
1.#NFS服务器,共享/data/nfsdir文件夹
[root@ubuntu2004 ~]#mkdir /data/nfsdir{1,2} -pv
mkdir: 已创建目录 '/data'
mkdir: 已创建目录 '/data/nfsdir1'
mkdir: 已创建目录 '/data/nfsdir2'
[root@ubuntu2004 ~]#tree /data
/data
├── nfsdir1
└── nfsdir2

2directories, 0 files
2.想要共享首先要安装NFS软件
[root@ubuntu2004 ~]#apt update;apt install nfs-kernel或者安装
[root@ubuntu2004 ~]#apt update;apt install nfs-server

[root@ubuntu2004 ~]#systemctl status nfs-server
客户端
[root@ubuntu2204 ~]#apt update;apt install nfs-common -y
[root@rocky8 ~]#yum install nfs-utils -y
#查看端口号
[root@ubuntu2004 ~]#ss -ntl
[root@ubuntu2004 ~]#ss -ntlp #可以查看更详细的
[root@ubuntu2004 ~]#rpcinfo -p 端口nfs适合公司内网使用不适合互联网
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
100005 1 udp 47417 mountd
100005 1 tcp 59645 mountd
100005 2 udp 56450 mountd
100005 2 tcp 58285 mountd
100005 3 udp 32818 mountd
100005 3 tcp 55179 mountd
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100227 3 tcp 2049
100003 3 udp 2049 nfs
100227 3 udp 2049
100021 1 udp 39663 nlockmgr
100021 3 udp 39663 nlockmgr
100021 4 udp 39663 nlockmgr
100021 1 tcp 38387 nlockmgr
100021 3 tcp 38387 nlockmgr
100021 4 tcp 38387 nlockmgr
[root@ubuntu2004 ~]#ll /etc/exports
-rw-r--r-- 1 root root 389 5月 13 2021 /etc/exports
[root@ubuntu2004 ~]#cat /etc/exports
# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3: #传统用这个
# /srv/homes 权限hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check) 共享的对象
#
# Example for NFSv4: #这个比较鸡肋,不好
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
#
3.#参考文件,设置一下
[root@ubuntu2004 ~]#vim /etc/exports
加入共享的文件
/data/nfsdir1 *

#可以查看共享的资源
[root@ubuntu2004 ~]#exportfs -v
#生效不断掉的方法
[root@ubuntu2004 ~]#exportfs -r
exportfs: No options for /data/nfsdir1 *: suggest *(sync) to avoid warning
exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/nfsdir1".
Assuming default behaviour ('no_subtree_check').
NOTE: this default has changed since nfs-utils version 1.0.x
[root@ubuntu2004 ~]#exportfs -v
/data/nfsdir1 <world>(ro,wdelay,root_squash,no_subtree_check,sec=sys,ro,secure,root_squash,no_all_squash)

客户端访问的命令 能看到共享列表则共享成功,没装客户端也不会成功
[root@rocky8 ~]#showmount -e 10.0.0.100
Export list for 10.0.0.100:
/data/nfsdir1 *

因为没有东西,所以拷一个文件进去
[root@ubuntu2004 ~]#cp /etc/os-release /data/nfsdir1/a.txt
想使用需要进行文件挂载到本机 建个网站
[root@rocky8 ~]#yum -y install httpd
把远程共享的文件夹挂载到下面的文件夹,格式就是IP加路径跟上要挂载的文件,/var/www/html/需要提前创建
[root@rocky8 ~]#ls /var/www/html/
[root@rocky8 ~]#mount 10.0.0.100:/data/nfsdir1 /var/www/html/
[root@rocky8 ~]#df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 894044 0 894044 0% /dev
tmpfs 914116 0 914116 0% /dev/shm
tmpfs 914116 8908 905208 1% /run
tmpfs 914116 0 914116 0% /sys/fs/cgroup
/dev/mapper/rl-root 73364480 3135108 70229372 5% /
/dev/sda1 1038336 214868 823468 21% /boot
/dev/mapper/rl-home 133071376 960828 132110548 1% /home
tmpfs 182820 0 182820 0% /run/user/0
10.0.0.100:/data/nfsdir1 101848064 6872832 89755648 8% /var/www/html
现在web服务是httpd,现在可以访问页面了
[root@rocky8 ~]#systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@rocky8 ~]#ls /var/www/html/
a.txt
现在可以去网站上查看了
http://10.0.0.161/a.txt

NAME="Ubuntu"
VERSION="20.04.4 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.4 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
续例:让两个服务共享一个页面
换一台机子继续操作
[root@ubuntu2204 ~]#apt install apache2 -y
然后挂载一下
[root@ubuntu2204 ~]#mount 10.0.0.100:/data/nfsdir1 /var/www/html/
[root@ubuntu2204 ~]#df
文件系统 1K-块 已用 可用 已用% 挂载点
tmpfs 198828 1020 197808 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 101590008 6286172 90097208 7% /
tmpfs 994120 0 994120 0% /dev/shm
tmpfs 5120 0 5120 0% /run/lock
/dev/sda2 1992552 251960 1619352 14% /boot
tmpfs 198824 0 198824 0% /run/user/0
10.0.0.100:/data/nfsdir1 101848064 6872832 89755648 8% /var/www/html
现在可以去换另一个从网站上查看了
http://10.0.0.200/a.txt

NAME="Ubuntu"
VERSION="20.04.4 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.4 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

更改源主机数据
[root@ubuntu2004 ~]#vim /data/nfsdir1/a.txt
welcome to nfs server
网站刷新
http://10.0.0.200/a.txt

welcome to nfs server
注#该文件内容为只读的 其中root_squash为压榨,剥削,使原本root用户变成普通用户
如果想不被压榨就更改文件
[root@ubuntu2004 ~]#vim /etc/exports
/data/nfsdir1 *(rw,no_root_squash)#不压榨
#生效不断掉的方法
[root@ubuntu2004 ~]#exportfs -r
exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/nfsdir1".
Assuming default behaviour ('no_subtree_check').
NOTE: this default has changed since nfs-utils version 1.0.x
#可以查看共享的资源
[root@ubuntu2004 ~]#exportfs -v
/data/nfsdir1 <world>(rw,wdelay,no_root_squash,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
在另一个文件输入文件可以成功
[root@rocky8 ~]#cd /var/www/html/
[root@rocky8 html]#touch b.txt
[root@rocky8 html]#ll
total 4
-rw-r--r-- 1 root root 22 Nov 20 12:39 a.txt
-rw-r--r-- 1 root root 0 Nov 20 12:57 b.txt
之前挂载都是临时性的

永久挂载配置文件

[root@rocky8 ~]#cd /var/www/html/
[root@rocky8 html]#vim /etc/fstab
10.0.0.100:/data/nfsdir1 /var/www/html nfs _netdev 0 0
第一个0是设备备份周期 第二个0表示检查次序
先取消临时挂载
[root@ubuntu2204 ~]#df
文件系统 1K-块 已用 可用 已用% 挂载点
tmpfs 198828 1020 197808 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 101590008 6286176 90097204 7% /
tmpfs 994120 0 994120 0% /dev/shm
tmpfs 5120 0 5120 0% /run/lock
/dev/sda2 1992552 251960 1619352 14% /boot
tmpfs 198824 0 198824 0% /run/user/0
10.0.0.100:/data/nfsdir1 101848064 6872832 89755648 8% /var/www/html

#挂载取消不成功是应为占用根目录,直接全部返回源目录就好
[root@ubuntu2204 ~]#umount /var/www/html/

#查看
[root@ubuntu2204 ~]#cat /etc/fstab
/dev/disk/by-uuid/fd29b9ab-4943-44c7-894f-7db7a966f8e9 /boot ext4 defaults 0 1
/swap.img none swap sw 0 0
10.0.0.100:/data/nfsdir1 /var/www/html nfs _netdev 0 0
#使挂载文件生效
[root@ubuntu2204 ~]#mount -a
[root@ubuntu2204 ~]#df
文件系统 1K-块 已用 可用 已用% 挂载点
tmpfs 198828 1020 197808 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 101590008 6286180 90097200 7% /
tmpfs 994120 0 994120 0% /dev/shm
tmpfs 5120 0 5120 0% /run/lock
/dev/sda2 1992552 251960 1619352 14% /boot
tmpfs 198824 0 198824 0% /run/user/0
10.0.0.100:/data/nfsdir1 101848064 6872832 89755648 8% /var/www/html

今天的分享就到这里,谢谢大家的观看!

标签:www,ubuntu2004,文件共享,data,nfsdir1,NFS,nfs,日志,root
From: https://blog.51cto.com/chengpitang/6099112

相关文章

  • 如何查看wix安装包日志
    提问如何查看wix安装包日志回答xxx.msi-l"debug.txt"参考https://blog.walterlv.com/post/how-to-view-wix-burn-installer-logs.html......
  • 【大型软件开发】开发日志(五).net框架与C++的融合:CLR——C++调用C#的DLL
    做什么?先说一下场景,现在正在开发一个QtActiveServer,也就是用一个应用程序去向其他的组件暴露接口,以达到提供服务的目的。然后新版的框架要提供大部分功能,也就是要重做大......
  • 笨功夫------再论日志的重要性
    最近我又把日志的重要性反复提了出来。团队建设之初,这个调调一定要定好,不能跑偏了。 我突然想,写好日志下的可是笨功夫。可是又想,笨功夫有什么不好呢?首先笨功夫不会有......
  • ubuntu20.04 开启日志审计
    rsyslog50-default.conf#vim/etc/rsyslog.d/50-default.conf*.=info;*.=notice;*.=warn;\auth,authpriv.none;\cron,daemon.none;\mail,n......
  • 正点原子IMX6ULL开发板-busybox rootfs移植-Cannot open root device "nfs" or unknow
    环境VMware17.0.0Ubuntu16NXP提供的U-boot与Linux版本:u-boot:uboot-imx-rel_imx_4.1.15_2.1.0_ga.tar.bz2linux:linux-imx-rel_imx_4.1.15_2.1.0_ga.tar.bz2开发板:......
  • ffmpeg设置终端不显示日志
    在使用ffmpeg处理视频的时候,终端页面会输出大量日志,其实打印这些日志也是很耗时的,所以有时候没有显示,那么怎么关闭日志输出呢:要在使用FFmpeg时禁用日志输出,可以......
  • Kali搭建NFS踩坑
    服务端安装nfs服务包:#aptinstallnfs-kernel-server准备共享目录mkdir/mnt/sharedirchownnobody:nogroup/mnt/sharedirchmod777/mnt/sharedir配置编辑/etc......
  • kubectl查询日志命令
    防水堡bug日志定位命令:dockerlogs--tail100xxx:xxx是容器的id或者名称kubectllogs-f--tail100xxx:xxx是pod的id,如果的命名空间不一样就:kubectl-nyyylogs-f......
  • Filebeat 日志采集工具安装
    Filebeat是比较轻量的日志采集工具,对于一些简单的采集任务可以直接使用Filebeat采集,同时也支持很多的方式输出,可以输出至Kafka、Elasticsearch、Redis等,下面我们来简......
  • 14. Kubernetes - PV / PVC / NFS
    存储前面有通过hostPath或者emptyDir的方式来持久化数据,但是显然还需要更加可靠的存储来保存应用的持久化数据,这样容器在重建后,依然可以使用之前的数据。可存储资源和......