Construction of NFS remote shared storage and FTP file transfer services

1. NFS remote shared storage

  1. File system level sharing (NAS storage) --------- It has been formatted and can be used directly.

  1. Because NFS has many functions, different functions require the use of different ports. So NFS cannot pin the port. So NFS cannot pin the port. RPC will record the NFS port information, so that the server and client can communicate port information through RPC.

practise

Environment preparation:

Server: Server1 IP: 192.168.56.99

Client: web1 IP: 192.168.56.110

Modify hostname:

Server: hostnamectl set-hostname server1

Client: hostnamectl set-hostname web1

At the same time, turn off the server client firewall and selinux kernel firewall:

[root@server1 ~]# systemctl stop firewalld && systemctl disable firewalld && setenforce 0
[root@web1 ~]# systemctl stop firewalld && systemctl disable firewalld && setenforce 0
  1. NFS-server operation

[root@server1 ~]# yum -y install rpcbind  #安装rpc协议的包
[root@server1 ~]# yum -y install nfs-utils  #安装nfs服务,提供文件系统
[root@server1 ~]# systemctl start nfs && systemctl start rpcbind  #开启nfs服务和rpc协议
[root@server1 ~]# mkdir /nfs   #在根下创建一个名为nfs的目录作为共享存储目录
[root@server1 ~]# echo 'holle NFS' >> /nfs/text   #在目录nfc下创建text文件并追加内容
[root@server1 ~]# vim /etc/exports        #编辑共享文件
/nfs 192.168.56.0(rw,no_root_squash,sync)

[Description of parameter value content]

rw ro The permissions shared by this directory are read-write or read-only.

sync async sync means that the data will be written to the memory and hard disk simultaneously, while async means that the data will be temporarily stored in the memory first instead of being written directly to the hard disk!

no_root_squash root_squash If the account used by the client to use the NFS file system is root, how does the system determine the identity of this account? By default, the identity of the client root will be compressed into nfsnobody by the root_squash setting, which will be more secure for the server system. But if you want to allow the client to use the root identity to operate the server's file system, then you have to turn on no_root_squash here!

all_squash Regardless of the identity of the user logging into NFS, his identity will be compressed into an anonymous user, usually nobody (nfsnobody)!

anonuid anongid anon means anonymous (anonymous) The UID setting value of the anonymous user mentioned earlier about *_squash is usually nobody (nfsnobody), but you can set the value of this UID by yourself! Of course, this UID must exist in your /etc/passwd! anonuid refers to the UID and anongid is the GID of the group.

[root@server1 ~]# systemctl restart nfs-server   #重启nfc服务
[root@server1 ~]# systemctl enable nfs-server   #制作开机启动
[root@server1 ~]#  exportfs -v                  #确认 NFS 服务器启动

Client web1 operation:

[root@web1 ~]# yum -y install rpcbind  #安装rpc协议的包
[root@web1 ~]# yum -y install nfs-utils  #安装nfs服务,提供文件系统
[root@web1 ~]# systemctl start nfs && systemctl start rpcbind  #开启nfs服务和rpc协议
[root@web1 ~]# mkdir /gyl      #创建挂载点
[root@web-1 ~]# mount -t nfs 192.168.56.110:/nfs /gyl/   #挂载
[root@web-1 ~]# df -Th                                  # 查看挂载是否成功
[root@web-1 ~]# ls /gyl/
text
[root@web-1 ~]# umount /qf  #取消挂载

Automatically mount when booting:

[root@web-1 ~]# vim /etc/fstab
192.168.56.110:/nfs     /gyl                    nfs     defaults        0 0
[root@web-1 ~]# mount -a

2. FTP file transfer service

  • File Transfer Protocol (FTP), based on this protocol, the FTP client and server can share files, upload files, and download files. FTP generates a virtual connection based on the TCP protocol. Users can upload, download, and delete files to the FTP server through the client. The FTP server can be shared by multiple people at the same time.

  • The FTP service is Client/Server (referred to as C/S) mode. The software that realizes external sharing and transmission of FTP files based on the FTP protocol is called the FTP server source. The client program is based on the FTP protocol and is called the FTP client. FTP The client can upload and download files to the FTP server.

  • FTP Server

Function: Provide file sharing services to achieve uploading and downloading

port:

On the 21st, establish the default port of tcp connection

No. 20: Transfer data

  • ftp active mode:

The client opens a port N (>1023) to establish a connection with the server's port 21, and at the same time opens a port N+1 to tell the server that I am monitoring port N+1. After the server receives the request, it uses its own 20 The port is connected to the N+1 port of the client for transmission.

Establish a connection on port 21

Port 20 transmits data

  • ftp passive mode:

The client opens two ports (1024, 1025) at the same time, one port (1024) establishes a connection with the server's port 21, and requests, brother, I am connected, you can open another port. After the server receives the request, it will randomly open a port (1027) and tell the client that I have opened port 1027. The client uses another port (1025) to connect to the server's (1027) port to transmit data.

vsftp service introduction:

  • Very Secure FTP service process (Very Secure FTP daemon, Vsftpd), Vsftpd is the most mainstream FTP server program in Unix/Linux distributions. It has the advantages of being small and light, safe and easy to use, stable and efficient, and can meet the needs of cross-department and multi-user use in enterprises. (1000 users) etc.

  • Start vsftpd configuration

Environment preparation:

Server: Server1 IP: 192.168.56.99

Client: web1 IP: 192.168.56.110

Modify hostname:

Server: hostnamectl set-hostname server1

Client: hostnamectl set-hostname web1

At the same time, turn off the server client firewall and selinux kernel firewall:

[root@server1 ~]# systemctl stop firewalld && systemctl disable firewalld && setenforce 0
[root@web1 ~]# systemctl stop firewalld && systemctl disable firewalld && setenforce 0
  • Server configuration:

[root@server-1 ~]# yum install -y vsftpd         #下载安装vsftp服务
[root@server-1 ~]# systemctl start vsftpd        #开启vsftp服务
[root@server-1 ~]# systemctl enable vsftpd     #设置开机自启动
[root@server-1 ~]# touch /var/ftp/pub/text.txt     #创建文件到共享目录
[root@server-1 ~]# cd /var/ftp/                             #切换到ftp目录下
[root@server-1 ftp]# ls
[root@server-1 ftp]# chown ftp.ftp pub/ -R            #修改ftp目录的属主与属组
[root@server-1 ftp]# vim /etc/vsftpd/vsftpd.conf          --修改配置文件找到29行将下面的注释取消
 anon_other_write_enable=YES
 anon_umask=000                                      #匿名用户上传下载目录权限掩码
[root@server-1 ftp]# systemctl restart vsftpd.service       #重启vsftp服务
[root@server-1 ftp]# systemctl status vsftpd.service        #查看vsftp服务运行状态

  • Client configuration

[root@web-1 ~]# yum -y install lftp          #安装ftp客户端
[root@web-1 ~]# lftp 192.168.56.110         #登录ftp
lftp 192.168.56.110:~> ls
drwxr-xr-x    2 14       50             22 Feb 24 11:24 pub
lftp 192.168.56.110:/> cd /pub/
lftp 192.168.56.110:/pub> ls
-rw-r--r--    1 14       50              0 Feb 24 11:24 text.txt
lftp 192.168.56.110:/pub> get text.txt        # 下载文件
lftp 192.168.56.110:/pub> exit                    # 退出ftp
[root@web-1 ~]# ls
anaconda-ks.cfg       text.txt      initial-setup-ks.cfg  
[root@web-1 ~]# lftp 192.168.56.110
lftp 192.168.56.110:/> mkdir /pub/gao            #创建目录
lftp 192.168.56.110:/> exit
[root@web-1 ~]# touch liang.txt                     #创建测试目录
[root@web-1 ~]# mkdir /text/                         #创建测试文件
[root@web-1 ~]# touch /text/liang-1              #在测试目录下创建测试文件
[root@web-1 ~]# lftp 192.168.56.110
lftp 192.168.56.110:~> cd /pub/
lftp 192.168.56.110:/pub> ls
drwxrwxrwx    2 14       50              6 Feb 24 11:39 gao
-rw-r--r--    1 14       50              0 Feb 24 11:24 text.txt
lftp 192.168.56.110:/pub> put /root/liang.txt       #上传文件
lftp 192.168.56.110:/pub> ls
drwxrwxrwx    2 14       50              6 Feb 24 11:39 gao
-rw-rw-rw-    1 14       50              0 Feb 24 11:45 liang.txt
-rw-r--r--    1 14       50              0 Feb 24 11:24 text.txt
lftp 192.168.56.110:/pub> mirror -R /text/          #上传目录以及目录中的子文件(mirror 下载目录)
Total: 1 directory, 1 file, 0 symlinks
New: 1 file, 0 symlinks
lftp 192.168.56.110:/pub> ls
drwxrwxrwx    2 14       50              6 Feb 24 11:39 gao
-rw-rw-rw-    1 14       50              0 Feb 24 11:45 liang.txt
drwxrwxrwx    2 14       50             21 Feb 24 11:46 text
-rw-r--r--    1 14       50              0 Feb 24 11:24 text.txt

  • ftp configure local user login

  • Create a test user (server operation)

Create zhangsan and set the password to "root"

[root@server-1 ~]# useradd zhangsan           # 创建zhangsan用户
[root@server-1 ~]# echo 'root' | passwd --stdin zhangsan    # 设置密码
更改用户 zhangsan 的密码 。
passwd:所有的身份验证令牌已经成功更新。
[root@server-1 ~]# vim /etc/vsftpd/vsftpd.conf  # 添加注释并修改 
 anonymous_enable=NO                       #将允许匿名登录关闭
新添加
local_root=/home/zhangsan     # 设置本地用户的FTP根目录,一般为用户的家目录(可有可无)
local_max_rate=0              # 限制最大传输速率(字节/秒)0为无限制(可有可无)
[root@server-1 ~]# systemctl restart vsftpd        # 重启服务
  • Client operations
[root@web-1 ~]# lftp 192.168.56.110 -u zhangsan           # 使用zhangsan登录ftp
口令: 
lftp [email protected]:~> ls
lftp [email protected]:~> mkdir gyl                  # 创建gyl目录
mkdir 成功, 建立 `gyl' 
lftp [email protected]:~> ls 
drwxr-xr-x    2 1000     1000            6 Aug 02 20:55 gyl
lftp [email protected]:~> put /root/test.txt      # 上传文件text.txt
lftp [email protected]:~> ls
drwxr-xr-x    2 1001     1001            6 Feb 27 02:06 gyl
-rw-r--r--    1 1001     1001            7 Feb 27 01:55 text.txt
  • Server side view
[root@server-1 ~]# cd /home/zhangsan/
[root@server-1 zhangsan]# ls
gyl  text.txt  
[root@server-1 zhangsan]# ll
总用量 4
drwxr-xr-x. 2 zhangsan zhangsan 6 2月  27 10:06 gyl
-rw-r--r--. 1 zhangsan zhangsan 7 2月  27 09:55 text.txt

Guess you like

Origin blog.csdn.net/weixin_63125636/article/details/129196758