首页 > 其他分享 >搭建nfs服务器

搭建nfs服务器

时间:2022-12-22 20:23:18浏览次数:45  
标签:0.0 upload liu nfs shared 服务器 root 搭建

搭建nfs服务器

在服务端中安装nfs,并启动

[root@liu ~]# yum -y install nfs-utils
Last metadata expiration check: 0:13:16 ago on Thu 22 Dec 2022 07:16:32 PM CST.
Dependencies resolved.
=====================================================================================================================
 Package                           Architecture           Version                         Repository            Size
===================================================================================================================
... 
Complete!

创建共享目录和文件

[root@liu ~]# mkdir -p /nfs/shared
[root@liu ~]# mkdir -p /nfs/upload
[root@liu ~]# cd /nfs/
[root@liu nfs]# ls
shared  upload
[root@liu nfs]# 
[root@liu shared]# touch read.txt
[root@liu shared]# echo 'Can only see' >> read.txt
[root@liu shared]# cat read.txt 
Can only see

关闭防火墙

[root@liu shared]# systemctl stop firewalld
[root@liu shared]# setenforce 0

配置nfs共享设置为只读,非root用户访问为匿名

[root@liu shared]# vi /etc/exports
[root@liu shared]# cat /etc/exports
/nfs/shared *(ro,all_squash)
[root@liu shared]# 

启动nfs服务和rpcbind

[root@liu shared]# systemctl start nfs-server rpcbind
[root@liu shared]# ss -antl
State        Recv-Q       Send-Q             Local Address:Port                Peer Address:Port       Process       
LISTEN       0            64                       0.0.0.0:2049                     0.0.0.0:*                        
LISTEN       0            128                      0.0.0.0:111                      0.0.0.0:*                        
LISTEN       0            128                      0.0.0.0:20048                    0.0.0.0:*                        
LISTEN       0            128                      0.0.0.0:22                       0.0.0.0:*                        
LISTEN       0            128                      0.0.0.0:58775                    0.0.0.0:*                        
LISTEN       0            64                       0.0.0.0:36477                    0.0.0.0:*                        
LISTEN       0            64                          [::]:2049                        [::]:*                        
LISTEN       0            128                         [::]:40449                       [::]:*                        
LISTEN       0            128                         [::]:111                         [::]:*                        
LISTEN       0            128                         [::]:20048                       [::]:*                        
LISTEN       0            64                          [::]:44977                       [::]:*                        
LISTEN       0            128                         [::]:22                          [::]:*                        
[root@liu shared]# 

挂载

[root@liu ~]# mount -t nfs 192.168.29.128:/nfs/shared /opt 
[root@liu ~]# df -h|grep nfs 
192.168.29.128:/nfs/shared     17G  1.8G   16G  11% /opt 

开放/nfs/upload目录为172.16.12.0/24网段的数据上传目录,并将所有用户及所属的用户组都映射为nfs-upload,其UID与GID均为300

[root@liu ~]# groupadd  -g 300 nfs-upload
[root@liu ~]# useradd -u 300 -g 300 nfs-upload
[root@liu ~]# id nfs-upload
uid=300(nfs-upload) gid=300(nfs-upload) groups=300(nfs-upload)
[root@liu ~]# 

将upload目录更贵属组主为nfs-upload

[root@liu ~]# chown -R 'nfs-upload'.'nfs-upload' /nfs/upload/
[root@liu ~]# chmod g+s /nfs/upload/
[root@liu ~]#

指定所有用户访问都为匿名用户且uid,gid均为300,exportfs重新加载exports文件

[root@liu ~]# vi /etc/exports
[root@liu ~]# cat /etc/exports
/nfs/shared *(ro,all_squash)
/nfs/upload 192.168.29.0/24(rw,all_squash,root_squash,anonuid=300,anongid=300)
[root@liu ~]# exportfs -r

查看导出

[root@liu ~]# showmount -e 192.168.29.128
Export list for 192.168.29.128:
[root@liu ~]# 

创建目录xixi,将nfs 192.168.85.132:/nfs/upload挂载到xixi目录上

[root@liu ~]# mkdir /xixi
[root@liu ~]# mount -t nfs 192.168.29.128:/nfs/upload /xixi/
[root@localhost ~]# df -h|grep nfs
192.168.29.128:/nfs/shared     17G  1.8G   16G  11% /opt
192.168.29.128:/nfs/upload     17G  1.8G   16G  11% /xixi

验证

[root@liu xixi]# touch a
[root@liu xixi]# ll
total 0
-rw-r--r--. 1 300 300 0 Dec 22 19:04 a
[root@liu xixi]# ll /nfs/upload/
total 0
-rw-r--r--. 1 nfs-upload nfs-upload 0 Dec 22 19:04 a

openssh免密登录配置

创建秘钥

#使用 ssh-keygen 创建公钥-私钥对
[root@liuquanyu ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:i5HlNt3h3xfxx9aHcQzw8asRxXpwvVzxFe8hbqv5BPc root@liuquanyu
The key's randomart image is:
+---[RSA 3072]----+
|            ..++=|
|             o.B*|
|        .   .oBoO|
|       + . o.ooX*|
|      o S ..o=ooO|
|       + o  +.=o+|
|      . .    +.Eo|
|            +   .|
|           o..   |
+----[SHA256]-----+
[root@liuquanyu ~]# 

查看私钥和公钥

[root@liuquanyu ~]# ls .ssh/
id_rsa  id_rsa.pub
[root@liuquanyu ~]# 
[root@liuquanyu ~]# ll .ssh/
total 8
-rw------- 1 root root 2602 Dec 22 18:54 id_rsa
-rw-r--r-- 1 root root  568 Dec 22 18:54 id_rsa.pub

将公钥传给对方

[root@liuquanyu ~]# ssh-copy-id [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.29.128 (192.168.29.128)' can't be established.
ECDSA key fingerprint is SHA256:uMJSO1Y7uU6221le2HQsW9zZGIFwK2FN1SR+leQSiqs.
Are you sure you want to continue connecting (yes/no/[fingerprint])? y
Please type 'yes', 'no' or the fingerprint: y
Please type 'yes', 'no' or the fingerprint: yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.


开始免密登录

[root@liu ~]# ssh 192.168.29.128
Last login: Thu Dec 22 19:06:50 2022 from 192.168.29.1

标签:0.0,upload,liu,nfs,shared,服务器,root,搭建
From: https://www.cnblogs.com/lqy0917/p/16999508.html

相关文章

  • 恒创科技:选择香港服务器配置要注意什么?
    ​服务器的配置一般是包括CPU、内存、硬盘、带宽、IP、操作系统等方面,我们在选择的时候,最好是根据网站的实际需求和使用情况来选择合适的大小,下面就跟大家简单介绍一下......
  • 国产化直播系统的搭建
        国产化直播系统建设方案​     目录前言...2一、     建设内容...4二、     建设方案...52.1NMB01媒体播控系统...62.2NM......
  • typescript_01搭建环境
    typescript是什么?以JavaScript为基础构建的语言,可以在任何支持JavaScript的平台中执行,ts不能被js解析器直接执行需要先编译成js文件,ts是一个js的超集,拓展了js并添加了类型......
  • 项目搭建失败
         ......
  • react 高效高质量搭建后台系统 系列 —— 脚手架搭建
    其他章节请看:react高效高质量搭建后台系统系列脚手架搭建本篇主要创建新项目myspug,以及准备好环境(例如:安装spug中用到的包、本地开发和部署、自定义配置react-a......
  • react 高效高质量搭建后台系统 系列
    react高效高质量搭建后台系统前言目标:用react高效高质量搭建后台系统如何实现:搞定一个优秀的、通用的、有一定复杂度的react的后台系统。类似项目就可以依葫芦画瓢快......
  • 搭建DNS服务器
    安装部署快速构建DNS服务器的基本过程:安装bind、bind-chroot包建立主配置文件/etc/named.conf建立地址库文件/var/named/....启动named服务配置及使用DNS客......
  • Cassandra集群搭建
    一、准备:192.168.159.150 ---cassandra1192.168.159.151  ---cassandra2192.168.159.152  ---cassandra3[hadoop@dataxbin]$java-versionjavaversion"1.8.0......
  • Vite + Vue 3 + electron 环境搭建
    第1步,建立一个新的vite项目yarncreatevite第2步,安装项目依赖yarnadd-Dconcurrentlycross-envelectronelectron-builderwait-on第3部,修改package.json......
  • Node.js复制/删除服务器端文件到指定目录文件夹下,并且预判是否存在该目录,如果没有,则递
      注意,前情提示:本代码基于《Node.js(nodejs)对本地JSON文件进行增、删、改、查操作(轻车熟路)》 在/api/demo/文件夹下面创建copyFileOrFolder.js和deleteFileOrFolder.jsc......