Shared Resource Library System

Shared Resource Library System

1. Case analysis

1. Planning the node

IP CPU name node
192.168.235.128 FTP FTP server, NFS client
192.168.235.129 NFS NFS server

2. Basic preparation

  • Use CentOS 7 image

3. Case requirements

  • Create six FTP virtual users
  • The permission is set to only download permission, no upload permission, and the maximum bandwidth is 60KB
  • New disk mounted on NFS shared directory, the nightly incremental backups of shared data, into the /backup/weekbackupdirectory

2. FTP service

1. What is FTP

FTP (File Transfer Protocol) file transfer protocol for reliable network file sharing.

2. FTP principle

  • FTP is a C/S architecture service, with a server and a client

  • The bottom layer uses TCP protocol as the transfer protocol, so it is a reliable file transfer protocol

  • FTP provides two ports: 20 and 21: Port
    20 is a data port, which provides transmission between data. Port
    21 is a command port, which provides transmission between commands.

  • The active mode of the connection between the FTP server and the client:
    ① The FTP client randomly opens a port N greater than 1024 to send the password and user name to port 21 of the server and opens the N+1 port to monitor the server instructions, and the server confirms the user name Whether the password is correct;
    ② If it is correct, the client uses port N+1 to send a PORT N+1 command to port 21 of the server, telling the server that the client uses the active mode and opens the port.
    ③ After receiving the PORT command, the server opens port 20 to send data to the client's N+1 port for data transmission.

  • The passive mode in which the FTP server is connected to the client:
    ① The FTP client randomly opens a port N greater than 1024 to send the password and user name to port 21 of the server, and open N+1 port again to listen to the server instructions, and the server confirms the user Whether the name and password are correct;
    ② If it is correct, the client uses port N+1 to send a PASV command to port 21 of the server to tell the server that the client uses the passive mode.
    ③ After the server receives the command, it will open a port P greater than 1024 for monitoring, and then use the PORT P command to notify the client that its data port is P.
    ④ After receiving the command, the client will connect to port P through port N+1, and then realize data transmission.

3. FTP status code

1) 1xx-positive preliminary answer.

​ These status codes indicate that an operation has started successfully, but the client wants to get another response before proceeding with the new command.

  • 110 Restart marking reply.

  • 120 The service is ready and will start in nnn minutes.

  • 125 The data connection has been opened and the transfer is being started.

  • 150 The file is in normal state, ready to open the data connection.

2) 2xx-affirmative completion reply

An operation has been successfully completed. The client can execute new commands.

  • The 200 command is confirmed.
  • 202 Command not executed, too many commands on the site.
  • 211 System status, or system help reply.
  • 212 Directory status.
  • 213 File status.
  • 214 Help message.
  • 215 NAME system type, where NAME is the official system name listed in the Assigned Numbers document.
  • 220 The service is ready to execute the request of the new user.
  • 221 The service closed the control connection. If appropriate, please log out.
  • 225 The data connection is open and there is no transmission in progress.
  • 226 Close the data connection. The requested file operation was successful (for example, transferring a file or abandoning a file).
  • 227 Enter passive mode (h1, h2, h3, h4, p1, p2).
  • 230 user has logged in, continue.
  • 250 The requested file operation is correct and has been completed.
  • 257 "PATHNAME" has been created.

3) 3xx-positive intermediate reply

The command was successful, but the server needs more information from the client to complete the processing of the request.

  • 331 The user name is correct and a password is required.
  • 332 A login account is required.
  • 350 The requested file operation is waiting for further information.

4) 4xx-transient negative completion response

The command was unsuccessful, but the error was temporary. If the client retries the command, it may execute successfully.

  • 421 The service is unavailable, and the control connection is being closed. If the service determines that it must be shut down, it will send this response to any command.
  • 425 Unable to open data connection.
  • 426 Connection closed; transfer aborted.
  • 450 The requested file operation was not performed. The file is unavailable (for example, the file is busy).
  • 451 The requested operation terminated abnormally: a local error is being processed.
  • 452 The requested operation was not performed. The system storage space is insufficient.

5) 5xx-Permanently negative completion response

The command was unsuccessful and the error is permanent. If the client retries the command, the same error will occur again.

  • 500 Syntax error, the command cannot be recognized. This may include errors such as the command line is too long.
  • 501 There is a syntax error in the parameter.
  • 502 The command was not executed.
  • 503 Bad command sequence.
  • 504 The parameter command was not executed.
  • 530 Not logged in.
  • 532 An account is required to store files.
  • 550 The requested operation was not performed. The file is unavailable (for example, the file was not found, and there is no access permission).
  • 551 The requested operation terminated abnormally: unknown page type.
  • 552 The requested file operation terminated abnormally: storage allocation exceeded (for the current directory or data set).
  • 553 The requested operation was not performed. File name not allowed.

6) Common FTP status codes and their reasons

  • 150-FTP uses two ports: 21 for sending commands and 20 for sending data. The status code 150 means that the server is ready to open a new connection on port 20 and send some data.
  • 226-Command opens a data connection on port 20 to perform operations such as transferring files. The operation completed successfully and the data connection was closed.
  • 230-After the client sends the correct password, the status code is displayed. It indicates that the user has successfully logged in.
  • 331-After the client sends the user name, the status code is displayed. This status code will be displayed regardless of whether the username provided is a valid account in the system.
  • 426-Command to open a data connection to perform an operation, but the operation has been cancelled and the data connection has been closed.
  • 530-This status code indicates that the user cannot log in because the username and password combination is invalid. If you log in with a user account, you may type the wrong user name or password, or you may choose to allow only anonymous access. If you log in with an anonymous account, the IIS configuration may deny anonymous access.
  • 550-The command was not executed because the specified file is not available. For example, the file to be GET does not exist, or you are trying to PUT the file to a directory where you do not have write permission.

4. FTP client

1) Deployment and installation of vsftpd

  • Install vsftp via yum source:

    # yum install vsftpd tenet
    # systemctl start vsftpd    //启动服务
    # netstat -lntp | grep 21   //查看端口是否监听
    # systemctl stop firewalld
    # setenforce 0
    

2) Configure the global configuration file

# cd /etc/vstpd
# cp vstpd.conf vstpd.conf_bak
# egrep -v '^#|^$' vsftpd.conf_bak  //忽略井号和$符并且输出
# egrep -v '^#|^$' vstpd.conf_bak > vsftpd.conf   //将大约号前的内容完全重定向到 conf 

3) Description of global configuration items:

	`listen=YES`:是否以独立的运行方式监听服务

listen_address=IP: Set up listening address

listen_port=21: Set up listening port number of the FTP service

write_enable=YES: Enable write permission

download_enable=YES: Allow Download file

userlist_enable=YES: Whether to enable user_list list of files, the user name is unavailable user_list

userlist_deny=YES: Whether to disable the user user_list

max_clients=0: Limit concurrent client connections

max_per_ip=0: Limiting the same ip address number of concurrent connections

guest_enable=YESEnable Virtual User

use_config_dir=/etc/vsftpd/vsftpd_user_conf: Virtual user profile directory

allow_writeable_chroot=YES: Allow writing to the user's home directory

anonymous_enable=YES: Enable anonymous access

anon_umask=022: Anonymous users to upload files permission mask, ie 777-022 = 755

anon_root=/var/ftp: Anonymous FTP user's root directory

anon_upload_enable=YES: Allowed to upload files

anon_mkdir_write_enable=YES: Allow creation of directories

anon_other_write_enable=YES: Open Other write permissions

anon_max_rate=0: Limit the maximum transmission rate (bytes / sec)

4) Commonly used local user FTP configuration items:

ocal_enable=YES: Whether to enable the local system users

local_umask=022Permission mask local user to upload a file:

local_root=/var/ftp: Local user FTP root directory : whether detained in the user's home directory
chroot_local_user=YES

5) Virtual user configuration

  • Create account data The
    vsftpd service uses a database file in Berkeley DB format to store virtual user accounts. The establishment of this database file requires db_load. The basic format is as follows:
    -fused to specify the data source file.
    -TAllow non-Berkeley DB files to be converted to DB data files.
    -t hashUsed to specify the basic method of reading data files.

    # vim /etc/vsftpd/users.conf   //创建文本格式的用户名秘密列表,奇数行为用户名,偶数行是密码
    [写入如下]
    zhangsan
    1
    [精致的结尾]
    # db_load -T -t hash -f /etc/vsftpd/users.conf /etc/vsftpd/users.db
    # chmod 600 users.db  //保证账号文件的安全性
    
  • Create FTP root directory and virtual user mapping system user
    ------ this account does not need to set a password and login shell

    # useradd  vsftpd -s /sbin/nologin -d /home/vsftpd
    # mkdir -p /home/vsftpd/xmcsxy
    # chmod -R 755 /home/vsftpd
    
  • Establishing a PAM authentication file supporting virtual users After
    creating a virtual user account data file, you also need to adjust the configuration of the vsftpd service to identify and read new user information.
    In the vsftpd server, user authentication is achieved through the PAM (Pluggable Authentication Module, pluggable authentication module) mechanism, which includes flexible selection of authentication methods. The default PAM authentication file of the Vsftpd service is located in /etc/pam.d/vsftpd, which is suitable for authentication with the system user account of the Linux host. To read the account data file of a virtual user, you need to create a new PAM authentication configuration.

    # vi /etc/pam.d/vsftpd
    [在第三行添加如下]
    auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/users
    account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/users
    [精致的结尾]
    
  • Add virtual user support

    # vim /etc/vsftpd/vsftpd.conf    //在主配置文件配置虚拟用户支持
    [配置内容如下]
    anonymous_enable=NO   //禁止匿名用户登录,增加下面的参数
    chroot_local_user=YES  //禁止用户访问除主目录以外的目录
    guest_enable=YES     //启用虚拟用户
    allow_writeable_chroot=YES  //允许写入用户主目录
    user_config_dir=/etc/vsftpd/vsftpd_user_conf  //虚拟用户使用的配置文件目录
    [精致的结尾]
    # mkdir -p /etc/vsftpd/vsftpd_user_conf
    # cd !$
    # vim zhangsan  //各个用户的配置文件
    [配置内容如下]
    local_root=/home/vsftpd/xmcsxy //当本地用户登录时,将被更改到定义的目录下,默认是 /var/ftp/
    anon_upload_enable=YES	//是否允许登陆用户有上传权限
    write_enable=YES 			//是否允许登陆用户有写权限
    
  • Restart the service and test

    # systemctl restart vsftpd
    # systemctl enable vsftpd  //出现以下内容为成功
    Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
    # 关闭防火墙和selinux
    # cd /home/vsftpd/xmcsxy/
    # touch a.txt
    nfs# yum -y install lftp
    nfs# lftp [email protected]
    Password: 
    lftp [email protected]:~> ls       
    ls: Login failed: 530 Login incorrect. //不行就重装,还可以查看 /var/log/secure 的错误日志
    

    LFTP internal commands:

    • ls display remote file list
    • cd switch directory
    • get download remote file
    • mget download remote file
    • pget uses multiple threads to download remote files
    • mirror download/upload (mirror -R)/synchronize the entire directory
    • put upload file
    • mput uploads multiple files, supports wildcards
    • mv move remote file
    • rm delete remote file
    • mrm deletes multiple remote files, supports wildcards
    • mkdir creates a remote directory
    • rmdir delete remote directory
    • pwd displays the current remote directory (lpwd displays the local directory)
    • du calculates the size of the remote directory
    • ! Execute local shell commands (because lftp does not have lls, so use !ls instead)
    • lcd switch local directory
    • lpwd display local directory
    • alias defines an alias
    • bookmark Set bookmark
    • exit exit ftp

Three, NFS service

1. What is NFS

  • Share files of different operating systems over the network.
  • The NFS server can mount the shared directory to the local file system, which looks like its own local system on the local side
  • NFS is transmitted over the network, and the port of the NFS server is opened above 2049, but due to the complexity of the file system, other NFS programs need to open additional random ports. The client uses the Remote Procedure Call (Remote Procedure Call) to know it. Those extra ports.

2. How RPC and NFS communicate

  • RPC is used to uniformly manage the services of the NFS port, and the unified external port is 111. RPC will record the information of the NFS port.

  • Communication steps:

    1. First, start the RPC service on the server side and open port 111;
    2. The server starts the NFS service and registers port information with RPC;
    3. The client starts RPC (portmap service), and requests the server's NFS port from the server's RPC (portmap) service;
    4. The RPC (portmap) service of the server feeds back the NFS port information to the client;
    5. The client establishes an NFS connection with the server and transmits data through the obtained NFS port.

3. NFS deployment

Check the environment and configure the environment required for NFS

# uname -a  // 查看是不是 centos 7
# hostnamectl set-hostname nfs
# systemctl stop firewalld   
# systemctl disable firewalld
# setenforce  0

# yum -y install nfs-utils rpcbind  // 安装所需要的依赖包,两台都要
# id nfsnobody //查看 nsfnobody 用户是否存在,有内容输出即为存在,两台都要

# systemctl start rpcbind  //启动服务,两台都要
# systemctl enable rpcbind  //启动服务,两台都要
# netstat -tnulp|grep rpc  //查看端口
# rpcinfo -p localhost(注:这里nfs服务没启动,看不到nfs端口的映射情况)

# systemctl start nfs   启动 nfs 服务 ,两台都要
# systemctl enable nfs
# netstat -ntplu |grep rpc
# rpcinfo -p localhost

NFS configuration

1) Create a shared directory
# mkdir /data
# mkdir /data/public
# mkdir /data/test
# mkdir /data/linux
2) Shared directory permissions
# chown -R nfsnobody.nfsnobody /data
# chmod 755 -R /data
3) Edit the configuration file
# vi /etc/exports
[配置内容如下]
/tmp            *(rw,no_root_squash)
/data/public    192.168.100.0/24(rw) 
/data/test      192.168.100.11(rw)
/data/linux     *.xmcsxy.com(rw,all_squash,anonuid=40,anongid=40)
[精致的结尾]
4) nfs configuration file /etc/exportsformat:
NFS 共享目录	NFS 客户端地址(参1,参2,....)
NFS 共享目录2	NFS 客户端地址2(参1,参2,....)
.......
  • Common parameters of NFS sharing:
    roread-only access

    rwRead and write access
    syncAll data is written to the share when requested. Async NFS can request
    secureNFS to send
    insecurethrough a secure TCP/IP port below 1024 before writing the data. NFS is sent through a port above 1024.
    subtree_checkIf you share a child such as /usr/bin For directories, force NFS to check the permissions of the parent directory (default)
    no_subtree_checkand relative to the above, do not check the permissions of the parent directory
    all_squash. The UID and GID of the shared file are mapped to anonymous users, suitable for public directories.
    no_all_squashKeep the UID and GID of the shared file (default)
    root_squashAll requests of the root user are mapped to the same permissions as the anonymous user (default) The
    no_root_squashroot user has full administrative access to the root directory
    anonuid=xxxSpecify the UID of the anonymous user in the /etc/passwd file of the NFS server

5) Effective configuration and inspection test
------- 重新加载 nfs 服务生效配置的方法------
# systemctl restart nfs   //方法 1
# exportfs -rv    //方法 2
# showmount -e localhsot   //检查权限挂载服务器能否挂载,输出内容如下:
/tmp         *
/data/linux  *.xmcsxy.com
/data/public 192.168.100.0/24
/data/test   192.168.100.11
  • exportfs command operation of the particular file as input parameters without directly modifying the / etc / exports file:
    -aAll mount /etc/exportsis set within the file
    -rremounting exportsis set, in addition synchronization update exportsand /var/lib/nfs/xtabthe contents of
    -uunloading a directory
    -vin exporta shared directory on the screen
  • The parameters of the showmount command are as follows:
    -a or -all Display the client host name and mount point directory in the format host:dir
    -d or -directories display only the directory name mounted by the client
    -e or -exports display the NFS server Output list.

Fourth, regular schedule and backup

1. Introduction to crond service

  • Crond is a daemon process used to periodically perform certain tasks or wait for certain events under linux, similar to scheduled tasks under windows.

  • Task scheduling under Linux is divided into two categories:
    ① System task scheduling: tasks to be performed by the system periodically, such as writing cached data to the hard disk, log cleaning, etc. In the /etc/crontab file, this is the configuration file for system task scheduling.

    ② User task scheduling: tasks that users need to perform regularly, such as user data backup, regular email reminders, etc. Users can use the crontab tool to customize their own scheduled tasks. In the crontab file created by the user, each line represents a task, and each field of each line represents a setting. Its format is divided into six fields. The first five sections are the time setting section, and the sixth section is The command segment to be executed , the format is as follows: the meaning of each field:
    minute hour day month week command

    • minute: indicates the minute, which can be any integer from 0 to 59.
    • hour: indicates the hour, which can be any integer from 0 to 23.
    • day: indicates the date, which can be any integer from 1 to 31.
    • month: Represents the month, which can be any integer from 1 to 12.
    • week: indicates the day of the week, which can be any integer from 0 to 7, where 0 or 7 represents Sunday.
    • command: The command to be executed, which can be a system command or a script file written by yourself.
    • In each of the above fields, the following special characters can also be used:
    • Asterisk (*): Represents all possible values. For example, if the day field is an asterisk, it means that the command operation will be executed every day after meeting the constraints of other fields.
    • Comma (,): You can specify a list range with comma-separated values, for example, "1,2,5,7,8,9"
    • Middle bar (-): A middle bar between integers can be used to represent a range of integers, for example, "3-6" means "3,4,5,6"
    • Forward slash (/): You can use forward slashes to specify the interval frequency of the time. For example, "0-23/2" in the hour field means that it will be executed every two hours. At the same time, the forward slash can be used with an asterisk, such as */10. If it is used in the minute field, it means that it is executed every ten minutes.

2. Use contab

  • Install contab

    # yum install -y crontabs
    # systemctl status crond
    # systemctl start crond
    
    • Common options and functions of the crontab command:
      -uused to set a user's crontab service, such as "-u demo" means the device demo user's contab service, this option is generally executed by the root user to
      -eedit the content of a user's crontab file. If no user is specified, the
      -lcontent of a user's crontab file will be displayed for root . By default, a user's crontab file is
      -rdeleted from /var/spool/cron by default. By default, the current user
      -iwill be prompted for confirmation when deleting a user's crontab file.

      -------例如--------
      # crontab -e  //进入编辑页面
      [配置如下内容]
      */5 * * * echo "11" >> /opt/test  //每隔 5 分钟向 test 文件里面写入一行 11
      # crontab -l  //列出 crontab 文件
      
      • Notes for writing crontab timing tasks
        1. None of the 6 options can be empty and must be filled in. If you are not sure, use "*" to represent any time.
        2. The date and week are best not to appear in a scheduled task, because they are all in days, which is very easy to confuse the administrator.
        3. In timed tasks, whether you write commands directly or in scripts, it is best to use absolute paths .

3. Backup script

  • The backup software uses rsync, a tool that can realize incremental backup and remote transmission. The basic options are as follows:

    -vDisplay the backup process
    -PDisplay the progress information of the file transfer

    -n Test transmission

    -a Archive transmission, recursive transmission keeps file attributes

    -r Recurse into the directory

    -t Keep the mtime attribute and add it at any time

    -o Keep the owner attribute

    -g Keep group attributes

    -p Maintain permissions, but do not include special permissions

    -D Copy device files and special files

    -l Copy the soft connection itself

    -z Compression during transmission improves efficiency

# vi /usr/local/sbin/backup.sh
[配置如下内容]
a=`date '+%Y%m%d'`
b=/backup/weekbackup
c=/var/log/backup.log
pname=$(rpm -qa | grep rsync)
#判断rsync是否存在
if [ $? -eq 0 ]
then
        echo "软件包rsync已经安装。"
else
        echo "软件包rsync没有安装"
        yum -y install rsync >> /dev/null
        if [ $? -eq 0 ];then
                echo "安装rsync完成。"
        else
                echo "安装rsync失败。"
        fi
fi
#判断备份目录是否存在,并增量备份。
if [ ! -d "$b" ];then
        mkdir -p $b
        echo "$a Backup File missing!" >> /var/log/backup.log
        rsync -rvz /data/* $b/$a
else
        rsync -rvz /data/* $b/$a
        if [ -d $b/$a ];then
                echo "$a Backup success." >> /var/log/backup.log
                find $b -mtime +14 | xargs rm -rf
        else
                echo "$a Backup failed." >> /var/log/backup.log
        fi
fi
[精致的结尾]
# chmod 755 /usr/local/sbin/backup.sh //脚本添加可执行权限:

# crontab -e  //添加定时任务:(每7天凌晨1点执行一次脚本)
[配置内容如下]
* 1 */7 * * sh /usr/local/sbin/backup.sh
[精致的结尾]

V. Case implementation

  • Mount a disk to the NFS node

  • Basic construction

    # hostnamectl set-hostname ftp
    # hostnamectl set-hostname nfs
    -----关闭防火墙及安全规则----------
    # systemctl stop firewalld
    # systemctl disable firewalld
    # setenforce 0
    

1. FTP deployment

1) Environment setup
# yum -y install vsftpd

------启动ftp并设置开机自启----------
# systemctl start vsftpd
# systemctl enable vsftpd
2) Create a virtual user account (zhang1-3)
# vi /etc/vsftpd/users.conf
[配置内容如下]
zhang1
1
zhang2
1
zhang3
1
[精致的结尾]
# db_load -T -t hash -f /etc/vsftpd/users.conf /etc/vsftpd/users.db    //创建 DB 库文件
# chmod 600 /etc/vsftpd/users.db
3) Configure independent files for virtual users
# cd /etc/vsftpd/vsftpd_user_conf/
# vi zhang1
[配置内容如下]
local_root=/home/vsftpd/xmcsxy/yumwei		#本地家目录路径
write_enable=YES
anon_upload_enable=NO
anon_max_rate=60000
[精致的结尾]
。。。。。zhang2 zhang3 亦是如此
4) Restart the effective configuration file
# systemctl restart vsftpd
# systemctl status vsftpd
# netstat -lntp | grep 21
tcp6       0      0 :::21   :::*  LISTEN  18750/vsftpd 

2. NFS deployment

1) Environment setup
# uname -a  //检查环境(两台都需要)

# yum -y install nfs-utils rpcbind //安装nfs依赖包(两台都需要)
# id nfsnobody  //查看nfsnobody用户在不在(两台都需要)
uid=65534(nfsnobody) gid=65534(nfsnobody) 组=65534(nfsnobody)
2) Start nfs related services (required for both)
# systemctl start rpcbind   //启动rpc服务
# systemctl enable rpcbind

# systemctl start nfs      //启动nfs服务
# systemctl enable nfs
[root@ftp ~]# netstat -lntp | grep rpc   //查看rpc端口
tcp        0      0 0.0.0.0:34875           0.0.0.0:*               LISTEN      19141/rpc.statd     
tcp        0      0 0.0.0.0:20048           0.0.0.0:*               LISTEN      19162/rpc.mountd    
tcp6       0      0 :::48860                :::*                    LISTEN      19141/rpc.statd     
tcp6       0      0 :::20048                :::*                    LISTEN      19162/rpc.mountd 
查看端口映射情况: rpcinfo -p localhost(注:这里nfs服务没启动,看不到nfs端口的映射情况)
3) Disk mounting
-------在VMware中添加一个新的磁盘并重启虚拟机---------
# fdisk /dev/sdb
命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):
将使用默认值 41943039
分区 1 已设置为 Linux 类型,大小设为 20 GiB
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
 
# mkfs.ext4 /dev/sdb1   //格式化磁盘
# rm -rf /data  //删掉原有的/data路径
# mkdir /data   //创建共享目录

[root@nfs ~]# vi /etc/fstab   //在/etc/fstab增加挂载
[增加内容如下]
/dev/sdb1       /data              ext4    defaults        0 0
[精致的结尾]
[root@nfs ~]# mount -a
[root@nfs ~]# df -h				//查看是否挂载成功
4) Configure the shared directory
vi /etc/exports
[配置内容如下]
/data   192.168.235.0/24(rw,no_root_squash,async)		#分配no_root_squash权限
[精致的结尾]
5) Effective configuration and inspection
# exportfs -rv
exporting 192.168.235.0/24:/data
# showmount -e localhost
Export list for localhost: /data 192.168.235.0/24
# showmount -e 192.168.235.129		#检测nfs共享目录创建成果
Export list for 192.168.100.12: /data 192.168.100.0/24
6) [Report an error]
1. clnt_create: RPC: Program not registered
	以此关闭nfs和rpcbind命令:
		# /etc/init.d/nfs stop
		# /etc/init.d/rpcbind stop 
	再依次启动服务,命令:(注意先启动rpc)
		# /etc/init.d/rpcbind start
		# /etc/init.d/nfs start
2. clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host) 
	原因:nfs 服务的防火墙没关
7) Debugging and inspection results
ftp# vim /etc/fstab
[配置内容如下]
192.168.100.12:/data /home/vsftpd/xmcsxy nfs defaults 0 0
[精致的结尾]
ftp# mount -a
ftp# df -h
8) Create a home directory corresponding to the FTP virtual user
ftp# mkdir yumwei
ftp# mkdir zhang2
ftp# mkdir zhang3
------------- NFS 节点查看-------------
# ls data
lost+found yumwei zhang2 zhang3 
9) Test virtual user login
# yum -y install lftp
# lftp [email protected]
password: 
lftp [email protected]:~>ls
lftp [email protected]:/>

3. Shell backup data and timing plan

[root@nfs ~]# vi /usr/local/sbin/backup.sh
a=`date '+%Y%m%d'`				#定义时间
b=/backup/weekbackup				#定义备份目录路径
c=/var/log/backup.log				#定义输出日志路径
pname=$(rpm -qa | grep rsync)		#定义rsync安装包检查	
#判断rsync是否存在
if [ $? -eq 0 ]
then
        echo "软件包rsync已经安装。"
else
        echo "软件包rsync没有安装"
        yum -y install rsync >> /dev/null
        if [ $? -eq 0 ];then
                echo "安装rsync完成。"
        else
                echo "安装rsync失败。"
        fi
fi
#判断备份目录是否存在,并增量备份。
if [ ! -d "$b" ];then
        mkdir -p $b
        echo "$a Backup File missing!" >> /var/log/backup.log
        rsync -rvz /data $b/$a
else
        rsync -rvz /data $b/$a
        if [ -d $b/$a ];then
                echo "$a Backup success." >> /var/log/backup.log
                find $b -mtime +14 | xargs rm -rf
        else
                echo "$a Backup failed." >> /var/log/backup.log
        fi
fi
---------------测试脚本执行过程结果---------
[root@nfs ~]# sh -x /usr/local/sbin/backup.sh 
定时计划:
[root@nfs ~]# crontab -e
* 21 */7 * * sh /usr/local/sbin/backup.sh			#每7天晚上21点执行一次

Guess you like

Origin blog.csdn.net/weixin_54898062/article/details/114970079