14.1 NFS介绍 14.2 NFS服务端安装配置 14.3 NFS配置选项 14.4 exportfs命令 14.5 NFS客户端问题 15.1 FTP介绍 15.2/15.3 使用vsftpd搭建ftp 15.4 xshell使用xftp传输文件 15.5 使用pure-ftpd搭建ftp服务 扩展 vsftp使用mysql存放虚拟用户并验证 http://www.aminglinux.com/bbs/thread-342-1-1.html ftp的主动和被动模式 http://www.aminglinux.com/bbs/thread-961-1-1.html
用两台机器做实验,一台作为服务端(linux-001 192.168.141.128),一台作为客户端(linux-02 192.168.141.129)
[root@linux-001 ~]# yum install -y nfs-utils rpcbind
已加载插件:fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 7.0 kB 00:00:00
* base: mirrors.aliyun.com
* epel: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/3): extras/7/x86_64/primary_db | 200 kB 00:00:00
(2/3): epel/x86_64/primary_db | 6.7 MB 00:00:04
epel/x86_64/updateinfo FAILED
http://ftp.riken.jp/Linux/fedora/epel/7/x86_64/repodata/63e651af768aaf626aec9f32f0a7e4e354152e96316aed7f1c0e2513e5cf4328-updateinfo.xml.bz2: [Errno 12] Timeout on http://ftp.riken.jp/Linux/fedora/epel/7/x86_64/repodata/63e651af768aaf626aec9f32f0a7e4e354152e96316aed7f1c0e2513e5cf4328-updateinfo.xml.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。
(3/3): epel/x86_64/updateinfo | 1.0 MB 00:00:02
正在解决依赖关系
--> 正在检查事务
---> 软件包 nfs-utils.x86_64.1.1.3.0-0.61.el7 将被 安装
--> 正在处理依赖关系 libtirpc >= 0.2.4-0.7,它被软件包 1:nfs-utils-1.3.0-0.61.el7.x86_64 需要
--> 正在处理依赖关系 gssproxy >= 0.7.0-3,它被软件包 1:nfs-utils-1.3.0-0.61.el7.x86_64 需要
--> 正在处理依赖关系 quota,它被软件包 1:nfs-utils-1.3.0-0.61.el7.x86_64 需要
--> 正在处理依赖关系 libnfsidmap,它被软件包 1:nfs-utils-1.3.0-0.61.el7.x86_64 需要
--> 正在处理依赖关系 libevent,它被软件包 1:nfs-utils-1.3.0-0.61.el7.x86_64 需要
--> 正在处理依赖关系 keyutils,它被软件包 1:nfs-utils-1.3.0-0.61.el7.x86_64 需要
--> 正在处理依赖关系 libtirpc.so.1()(64bit),它被软件包 1:nfs-utils-1.3.0-0.61.el7.x86_64 需要
--> 正在处理依赖关系 libnfsidmap.so.0()(64bit),它被软件包 1:nfs-utils-1.3.0-0.61.el7.x86_64 需要
--> 正在处理依赖关系 libevent-2.0.so.5()(64bit),它被软件包 1:nfs-utils-1.3.0-0.61.el7.x86_64 需要
---> 软件包 rpcbind.x86_64.0.0.2.0-47.el7 将被 安装
--> 正在检查事务
---> 软件包 gssproxy.x86_64.0.0.7.0-21.el7 将被 安装
--> 正在处理依赖关系 libini_config >= 1.3.1-31,它被软件包 gssproxy-0.7.0-21.el7.x86_64 需要
--> 正在处理依赖关系 libverto-module-base,它被软件包 gssproxy-0.7.0-21.el7.x86_64 需要
--> 正在处理依赖关系 libref_array.so.1(REF_ARRAY_0.1.1)(64bit),它被软件包 gssproxy-0.7.0-21.el7.x86_64 需要
--> 正在处理依赖关系 libini_config.so.3(INI_CONFIG_1.2.0)(64bit),它被软件包 gssproxy-0.7.0-21.el7.x86_64 需要
--> 正在处理依赖关系 libini_config.so.3(INI_CONFIG_1.1.0)(64bit),它被软件包 gssproxy-0.7.0-21.el7.x86_64 需要
--> 正在处理依赖关系 libref_array.so.1()(64bit),它被软件包 gssproxy-0.7.0-21.el7.x86_64 需要
--> 正在处理依赖关系 libini_config.so.3()(64bit),它被软件包 gssproxy-0.7.0-21.el7.x86_64 需要
--> 正在处理依赖关系 libcollection.so.2()(64bit),它被软件包 gssproxy-0.7.0-21.el7.x86_64 需要
--> 正在处理依赖关系 libbasicobjects.so.0()(64bit),它被软件包 gssproxy-0.7.0-21.el7.x86_64 需要
---> 软件包 keyutils.x86_64.0.1.5.8-3.el7 将被 安装
---> 软件包 libevent.x86_64.0.2.0.21-4.el7 将被 安装
---> 软件包 libnfsidmap.x86_64.0.0.25-19.el7 将被 安装
---> 软件包 libtirpc.x86_64.0.0.2.4-0.15.el7 将被 安装
---> 软件包 quota.x86_64.1.4.01-17.el7 将被 安装
--> 正在处理依赖关系 quota-nls = 1:4.01-17.el7,它被软件包 1:quota-4.01-17.el7.x86_64 需要
--> 正在处理依赖关系 tcp_wrappers,它被软件包 1:quota-4.01-17.el7.x86_64 需要
--> 正在检查事务
---> 软件包 libbasicobjects.x86_64.0.0.1.1-32.el7 将被 安装
---> 软件包 libcollection.x86_64.0.0.7.0-32.el7 将被 安装
---> 软件包 libini_config.x86_64.0.1.3.1-32.el7 将被 安装
--> 正在处理依赖关系 libpath_utils.so.1(PATH_UTILS_0.2.1)(64bit),它被软件包 libini_config-1.3.1-32.el7.x86_64 需要
--> 正在处理依赖关系 libpath_utils.so.1()(64bit),它被软件包 libini_config-1.3.1-32.el7.x86_64 需要
---> 软件包 libref_array.x86_64.0.0.1.5-32.el7 将被 安装
---> 软件包 libverto-libevent.x86_64.0.0.2.5-4.el7 将被 安装
---> 软件包 quota-nls.noarch.1.4.01-17.el7 将被 安装
---> 软件包 tcp_wrappers.x86_64.0.7.6-77.el7 将被 安装
--> 正在检查事务
---> 软件包 libpath_utils.x86_64.0.0.2.1-32.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=====================================================================================================================================
Package 架构 版本 源 大小
=====================================================================================================================================
正在安装:
nfs-utils x86_64 1:1.3.0-0.61.el7 base 410 k
rpcbind x86_64 0.2.0-47.el7 base 60 k
为依赖而安装:
gssproxy x86_64 0.7.0-21.el7 base 109 k
keyutils x86_64 1.5.8-3.el7 base 54 k
libbasicobjects x86_64 0.1.1-32.el7 base 26 k
libcollection x86_64 0.7.0-32.el7 base 42 k
libevent x86_64 2.0.21-4.el7 base 214 k
libini_config x86_64 1.3.1-32.el7 base 64 k
libnfsidmap x86_64 0.25-19.el7 base 50 k
libpath_utils x86_64 0.2.1-32.el7 base 28 k
libref_array x86_64 0.1.5-32.el7 base 27 k
libtirpc x86_64 0.2.4-0.15.el7 base 89 k
libverto-libevent x86_64 0.2.5-4.el7 base 8.9 k
quota x86_64 1:4.01-17.el7 base 179 k
quota-nls noarch 1:4.01-17.el7 base 90 k
tcp_wrappers x86_64 7.6-77.el7 base 78 k
事务概要
=====================================================================================================================================
安装 2 软件包 (+14 依赖软件包)
总下载量:1.5 M
安装大小:4.2 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/16): libcollection-0.7.0-32.el7.x86_64.rpm | 42 kB 00:00:00
(2/16): libbasicobjects-0.1.1-32.el7.x86_64.rpm | 26 kB 00:00:00
(3/16): libini_config-1.3.1-32.el7.x86_64.rpm | 64 kB 00:00:00
(4/16): libevent-2.0.21-4.el7.x86_64.rpm | 214 kB 00:00:00
(5/16): libpath_utils-0.2.1-32.el7.x86_64.rpm | 28 kB 00:00:00
(6/16): libnfsidmap-0.25-19.el7.x86_64.rpm | 50 kB 00:00:00
(7/16): libtirpc-0.2.4-0.15.el7.x86_64.rpm | 89 kB 00:00:00
(8/16): libref_array-0.1.5-32.el7.x86_64.rpm | 27 kB 00:00:00
(9/16): libverto-libevent-0.2.5-4.el7.x86_64.rpm | 8.9 kB 00:00:00
(10/16): nfs-utils-1.3.0-0.61.el7.x86_64.rpm | 410 kB 00:00:00
(11/16): quota-4.01-17.el7.x86_64.rpm | 179 kB 00:00:00
(12/16): quota-nls-4.01-17.el7.noarch.rpm | 90 kB 00:00:00
(13/16): tcp_wrappers-7.6-77.el7.x86_64.rpm | 78 kB 00:00:00
(14/16): rpcbind-0.2.0-47.el7.x86_64.rpm | 60 kB 00:00:00
(15/16): keyutils-1.5.8-3.el7.x86_64.rpm | 54 kB 00:00:01
(16/16): gssproxy-0.7.0-21.el7.x86_64.rpm | 109 kB 00:00:05
-------------------------------------------------------------------------------------------------------------------------------------
总计 251 kB/s | 1.5 MB 00:00:06
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : libtirpc-0.2.4-0.15.el7.x86_64 1/16
正在安装 : rpcbind-0.2.0-47.el7.x86_64 2/16
正在安装 : libbasicobjects-0.1.1-32.el7.x86_64 3/16
正在安装 : libref_array-0.1.5-32.el7.x86_64 4/16
正在安装 : libcollection-0.7.0-32.el7.x86_64 5/16
正在安装 : libevent-2.0.21-4.el7.x86_64 6/16
正在安装 : libverto-libevent-0.2.5-4.el7.x86_64 7/16
正在安装 : tcp_wrappers-7.6-77.el7.x86_64 8/16
正在安装 : keyutils-1.5.8-3.el7.x86_64 9/16
正在安装 : libnfsidmap-0.25-19.el7.x86_64 10/16
正在安装 : libpath_utils-0.2.1-32.el7.x86_64 11/16
正在安装 : libini_config-1.3.1-32.el7.x86_64 12/16
正在安装 : gssproxy-0.7.0-21.el7.x86_64 13/16
正在安装 : 1:quota-nls-4.01-17.el7.noarch 14/16
正在安装 : 1:quota-4.01-17.el7.x86_64 15/16
正在安装 : 1:nfs-utils-1.3.0-0.61.el7.x86_64 16/16
验证中 : 1:quota-nls-4.01-17.el7.noarch 1/16
验证中 : libverto-libevent-0.2.5-4.el7.x86_64 2/16
验证中 : libpath_utils-0.2.1-32.el7.x86_64 3/16
验证中 : libnfsidmap-0.25-19.el7.x86_64 4/16
验证中 : libevent-2.0.21-4.el7.x86_64 5/16
验证中 : 1:nfs-utils-1.3.0-0.61.el7.x86_64 6/16
验证中 : gssproxy-0.7.0-21.el7.x86_64 7/16
验证中 : keyutils-1.5.8-3.el7.x86_64 8/16
验证中 : rpcbind-0.2.0-47.el7.x86_64 9/16
验证中 : tcp_wrappers-7.6-77.el7.x86_64 10/16
验证中 : libcollection-0.7.0-32.el7.x86_64 11/16
验证中 : libref_array-0.1.5-32.el7.x86_64 12/16
验证中 : libbasicobjects-0.1.1-32.el7.x86_64 13/16
验证中 : 1:quota-4.01-17.el7.x86_64 14/16
验证中 : libini_config-1.3.1-32.el7.x86_64 15/16
验证中 : libtirpc-0.2.4-0.15.el7.x86_64 16/16
已安装:
nfs-utils.x86_64 1:1.3.0-0.61.el7 rpcbind.x86_64 0:0.2.0-47.el7
作为依赖被安装:
gssproxy.x86_64 0:0.7.0-21.el7 keyutils.x86_64 0:1.5.8-3.el7 libbasicobjects.x86_64 0:0.1.1-32.el7
libcollection.x86_64 0:0.7.0-32.el7 libevent.x86_64 0:2.0.21-4.el7 libini_config.x86_64 0:1.3.1-32.el7
libnfsidmap.x86_64 0:0.25-19.el7 libpath_utils.x86_64 0:0.2.1-32.el7 libref_array.x86_64 0:0.1.5-32.el7
libtirpc.x86_64 0:0.2.4-0.15.el7 libverto-libevent.x86_64 0:0.2.5-4.el7 quota.x86_64 1:4.01-17.el7
quota-nls.noarch 1:4.01-17.el7 tcp_wrappers.x86_64 0:7.6-77.el7
完毕!
[root@linux-001 ~]# vim /etc/exports
/home/nfstestdir 192.168.141.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)
[root@linux-001 ~]# mkdir /home/nfstestdir
[root@linux-001 ~]# chmod 777 /home/nfstestdir
[root@linux-001 ~]# netstat -lnpt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6859/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7242/master
tcp6 0 0 :::3306 :::* LISTEN 7142/mysqld
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::22 :::* LISTEN 6859/sshd
tcp6 0 0 ::1:25 :::* LISTEN 7242/master
[root@linux-001 ~]#
[root@linux-001 ~]# systemctl start nfs.service
[root@linux-001 ~]# ps aux | grep nfs
root 7990 0.0 0.0 0 0 ? S< 03:57 0:00 [nfsd4_callbacks]
root 7996 0.0 0.0 0 0 ? S 03:57 0:00 [nfsd]
root 7997 0.0 0.0 0 0 ? S 03:57 0:00 [nfsd]
root 7998 0.0 0.0 0 0 ? S 03:57 0:00 [nfsd]
root 7999 0.0 0.0 0 0 ? S 03:57 0:00 [nfsd]
root 8000 0.0 0.0 0 0 ? S 03:57 0:00 [nfsd]
root 8001 0.0 0.0 0 0 ? S 03:57 0:00 [nfsd]
root 8002 0.0 0.0 0 0 ? S 03:57 0:00 [nfsd]
root 8003 0.0 0.0 0 0 ? S 03:57 0:00 [nfsd]
root 8079 0.0 0.0 112724 988 pts/0 R+ 03:57 0:00 grep --color=auto nfs
[root@linux-001 ~]# ps aux | grep rpc
rpc 7937 0.0 0.0 69264 1544 ? Ss 03:57 0:00 /sbin/rpcbind -w
root 7939 0.0 0.0 0 0 ? S< 03:57 0:00 [rpciod]
rpcuser 7954 0.0 0.0 42432 1768 ? Ss 03:57 0:00 /usr/sbin/rpc.statd
root 7981 0.0 0.0 45956 544 ? Ss 03:57 0:00 /usr/sbin/rpc.idmapd
root 7985 0.0 0.0 42624 952 ? Ss 03:57 0:00 /usr/sbin/rpc.mountd
root 8088 0.0 0.0 112724 984 pts/0 R+ 03:58 0:00 grep --color=auto rpc
[root@linux-001 ~]#
[root@linux-001 ~]# systemctl enable nfs.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@linux-02 ~]# showmount -e 192.168.141.128
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host
[root@linux-02 ~]# showmount -e 192.168.141.128
Export list for 192.168.141.128:
/home/nfstestdir 192.168.141.0/24
如果出现上面得信息,说明可以与服务端进行通信。然后可以挂载服务端的目录到客户端。
[root@linux-02 ~]# mount -t nfs 192.168.141.128:/home/nfstestdir /mnt/
[root@linux-02 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 16G 5.9G 10G 37% /
devtmpfs 900M 0 900M 0% /dev
tmpfs 911M 0 911M 0% /dev/shm
tmpfs 911M 9.5M 901M 2% /run
tmpfs 911M 0 911M 0% /sys/fs/cgroup
/dev/sda1 197M 115M 82M 59% /boot
tmpfs 183M 0 183M 0% /run/user/0
192.168.141.128:/home/nfstestdir 16G 7.8G 8.1G 50% /mnt
[root@linux-02 ~]#
服务端设置tmp目录为共享目录,并且root用户不做任何限制,使用exportfs重新加载配置文件。
[root@linux-001 nfstestdir]# vim /etc/exports
/home/nfstestdir 192.168.141.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)
/tmp 192.168.141.129(rw,sync,no_root_squash)
[root@linux-001 nfstestdir]# exportfs -arv
exporting 192.168.141.129:/tmp
exporting 192.168.141.0/24:/home/nfstestdir
客户端使用showmount命令查看nfs服务器共享得目录,并挂载tmp目录。
[root@linux-02 mnt]# showmount -e 192.168.141.128
Export list for 192.168.141.129:
/home/nfstestdir 192.168.141.0/24
/tmp 192.168.141.129
[root@linux-02 mnt]# mount -t nfs 192.168.141.128:/tmp /home/tmp
[root@linux-02 mnt]#
服务端创建一个11.txt文件,在server端可以查看到,用户和用户组都为root,在使用nfs得时候一般会对root用户做权限设置。
NFS 4版本在centos6上常见此问题,我们在分享一个目录且权限设置为no_root_squash,客户端看到的文件属主、组不是root,却是nobody。 这个不是设置错误,是软件本身自带的BUG。
在客户端挂载的时候加上 -o nfsvers=3,其目的是指定nfs使用3版本。
[root@linux-02 tmp]# mount -t nfs -o,nfsvers=3 192.168.141.128:/tmp /mnt/
[root@linux-02 tmp]#
或者添加remount,重新挂载。
[root@linux-02 tmp]# mount -t nfs -oremount,nfsvers=3 192.168.141.128:/tmp /mnt
[root@linux-02 tmp]#
在服务端和客户端配置:vim /etc/idmapd.conf 配置文种把“#Domain = local.domain.edu” 改为 “Domain = xxx.com” (这里的xxx.com,随意定义吧),然后再重启rpcidmapd服务,centos7没有 rpcidmapd 服务,重启 rpcbind 服务即可。
[root@linux-001 tmp]# vi /etc/idmapd.conf
#Domain = local.domain.edu // 改为 Domain = xxx.com
[root@linux-001 ~]# yum install -y vsftpd
已加载插件:fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 vsftpd.x86_64.0.3.0.2-25.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
====================================================================================================================================
Package 架构 版本 源 大小
====================================================================================================================================
正在安装:
vsftpd x86_64 3.0.2-25.el7 base 171 k
事务概要
====================================================================================================================================
安装 1 软件包
总下载量:171 k
安装大小:353 k
Downloading packages:
vsftpd-3.0.2-25.el7.x86_64.rpm | 171 kB 00:00:06
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : vsftpd-3.0.2-25.el7.x86_64 1/1
验证中 : vsftpd-3.0.2-25.el7.x86_64 1/1
已安装:
vsftpd.x86_64 0:3.0.2-25.el7
完毕!
[root@linux-001 ~]#
ftp默认支持使用系统账号登录,但是因为安全原因,建议使用虚拟用户映射到系统登录。
## 创建一个系统用户,-s指定用户的shell ##
[root@linux-001 ~]# useradd -s /sbin/nologin vsftp
## 创建一个虚拟用户的文件,奇数行用户名,偶数行密码 ##
[root@linux-001 ~]# vim /etc/vsftpd/vsftpd_login
[root@linux-001 ~]# cat !$
cat /etc/vsftpd/vsftpd_login
ftpuser1
ftpuser1
ftpuser2
ftpuser2
[root@linux-001 ~]# chmod 600 /etc/vsftpd/vsftpd_login
由于我们设置的vsftpd_login文件是一个明文文本文件,所以需要生成一个二进制文件让系统能够识别。
[root@linux-001 ~]# db_load -T -t hash -f /etc/vsftpd/vsftpd_login /etc/vsftpd/vsftpd_login.db
[root@linux-001 ~]# ls -l /etc/vsftpd/
总用量 36
-rw------- 1 root root 125 10月 31 2018 ftpusers
-rw------- 1 root root 361 10月 31 2018 user_list
-rw------- 1 root root 5116 10月 31 2018 vsftpd.conf
-rwxr--r-- 1 root root 338 10月 31 2018 vsftpd_conf_migrate.sh
-rw------- 1 root root 36 5月 25 09:07 vsftpd_login
-rw-r--r-- 1 root root 12288 5月 25 09:11 vsftpd_login.db
[root@linux-001 ~]#
创建一个虚拟用户存放配置的文件夹,在创建虚拟用户的配置文件的时候,一个虚拟用户一个配置文件,并且虚拟用户的配置文件名是以虚拟用户的名称来命名。
[root@linux-001 ~]# mkdir /etc/vsftpd/vsftpd_user_conf
[root@linux-001 ~]# cd !$
cd /etc/vsftpd/vsftpd_user_conf
[root@linux-001 vsftpd_user_conf]# vim ftpuser1
local_root=/home/vsftp/ftpuser1 //虚拟用户的家目录
anonymous_enable=NO //是否允许匿名用户
write_enable=YES //是否允许可写
local_umask=022 //创建新目录和文件的权限
anon_upload_enable=NO //是否允许匿名用户上传
anon_mkdir_write_enable=NO //是否允许匿名用户可创建
idle_session_timeout=600 //连接后没有任何操作的超时时间,空闲时间段
data_connection_timeout=120 //数据传输超时时间
max_clients=10 //最大允许连接的clients客户端
[root@linux-001 vsftpd_user_conf]# vim ftpuser2
local_root=/home/vsftp/ftpuser2
anonymous_enable=NO
write_enable=YES
local_umask=022
anon_upload_enable=NO
anon_mkdir_write_enable=NO
idle_session_timeout=600
data_connection_timeout=120
max_clients=10
在上面创建虚拟用户的时候已经设置过虚拟用户的家目录,所以我们在此处创建下用户的家目录,并且给虚拟用户创建的家目录设置属主属组的权限。此处设置属主属组权限不是虚拟用户的权限,而是映射到ftp用户的权限。
[root@linux-001 vsftpd_user_conf]# mkdir /home/vsftp/ftpuser1
[root@linux-001 vsftpd_user_conf]# mkdir /home/vsftp/ftpuser2
[root@linux-001 vsftpd_user_conf]# chown -R vsftp:vsftp /home/vsftp/ftpuser1
[root@linux-001 vsftpd_user_conf]# chown -R vsftp:vsftp /home/vsftp/ftpuser2
需要注意的是,在centos 6中,系统是区分32位和64位,如果我们设置的文件 /lib64/security/pam_userdb.so 这个文件是没有的,那我们的设置的ftp其他位置都正确,那我们的ftp也是无法登录,db后面跟的是 /etc/vsftpd/vsftpd_login 虽然我们需要认证的文件是vsftpd_login.db 文件,但是我们这儿是不可以加“.db”的。注意每行语句后面不能有空格。
[root@linux-001 vsftpd_user_conf]# vim /etc/pam.d/vsftpd
#%PAM-1.0
auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login // 新增行
account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login // 新增行
session optional pam_keyinit.so force revoke
auth required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
auth required pam_shells.so
auth include password-auth
account include password-auth
session required pam_loginuid.so
session include password-auth
[root@linux-001 vsftpd_user_conf]# ls /lib64/security/pam_userdb.so
/lib64/security/pam_userdb.so
[root@linux-001 vsftpd_user_conf]# vim /etc/vsftpd/vsftpd.conf
将anonymous_enable=YES 改为 anonymous_enable=NO
将#anon_upload_enable=YES 改为 anon_upload_enable=NO
将#anon_mkdir_write_enable=YES 改为 anon_mkdir_write_enable=NO
chroot_local_user=YES
guest_enable=YES
guest_username=vsftp
virtual_use_local_privs=YES
user_config_dir=/etc/vsftpd/vsftpd_user_conf
allow_writeable_chroot=YES
注意:21端口FTP; 22端口SSHD; 23端口TELNET
[root@linux-001 ftpuser2]# service vsftpd start
Redirecting to /bin/systemctl start vsftpd.service
[root@linux-001 ftpuser2]# ps aux | grep vsftp
root 10742 0.0 0.0 53276 576 ? Ss 09:48 0:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
root 10753 0.0 0.0 112724 988 pts/0 R+ 09:48 0:00 grep --color=auto vsftp
[root@linux-001 ftpuser2]#
## 安装lftp软件 ##
[root@linux-001 ftpuser2]# yum install -y lftp
已加载插件:fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 7.5 kB 00:00:00
* base: mirrors.aliyun.com
* epel: mirrors.njupt.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
正在解决依赖关系
--> 正在检查事务
---> 软件包 lftp.x86_64.0.4.4.8-11.el7 将被 安装
--> 正在处理依赖关系 libgnutls.so.28(GNUTLS_1_4)(64bit),它被软件包 lftp-4.4.8-11.el7.x86_64 需要
--> 正在处理依赖关系 libgnutls.so.28()(64bit),它被软件包 lftp-4.4.8-11.el7.x86_64 需要
--> 正在检查事务
---> 软件包 gnutls.x86_64.0.3.3.29-9.el7_6 将被 安装
--> 正在处理依赖关系 trousers >= 0.3.11.2,它被软件包 gnutls-3.3.29-9.el7_6.x86_64 需要
--> 正在处理依赖关系 libnettle.so.4()(64bit),它被软件包 gnutls-3.3.29-9.el7_6.x86_64 需要
--> 正在处理依赖关系 libhogweed.so.2()(64bit),它被软件包 gnutls-3.3.29-9.el7_6.x86_64 需要
--> 正在检查事务
---> 软件包 nettle.x86_64.0.2.7.1-8.el7 将被 安装
---> 软件包 trousers.x86_64.0.0.3.14-2.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
====================================================================================================================================
Package 架构 版本 源 大小
====================================================================================================================================
正在安装:
lftp x86_64 4.4.8-11.el7 base 752 k
为依赖而安装:
gnutls x86_64 3.3.29-9.el7_6 updates 680 k
nettle x86_64 2.7.1-8.el7 base 327 k
trousers x86_64 0.3.14-2.el7 base 289 k
事务概要
====================================================================================================================================
安装 1 软件包 (+3 依赖软件包)
总下载量:2.0 M
安装大小:5.9 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/4): gnutls-3.3.29-9.el7_6.x86_64.rpm | 680 kB 00:00:00
(2/4): nettle-2.7.1-8.el7.x86_64.rpm | 327 kB 00:00:00
(3/4): trousers-0.3.14-2.el7.x86_64.rpm | 289 kB 00:00:00
(4/4): lftp-4.4.8-11.el7.x86_64.rpm | 752 kB 00:00:06
------------------------------------------------------------------------------------------------------------------------------------
总计 311 kB/s | 2.0 MB 00:00:06
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : nettle-2.7.1-8.el7.x86_64 1/4
正在安装 : trousers-0.3.14-2.el7.x86_64 2/4
正在安装 : gnutls-3.3.29-9.el7_6.x86_64 3/4
正在安装 : lftp-4.4.8-11.el7.x86_64 4/4
验证中 : trousers-0.3.14-2.el7.x86_64 1/4
验证中 : gnutls-3.3.29-9.el7_6.x86_64 2/4
验证中 : lftp-4.4.8-11.el7.x86_64 3/4
验证中 : nettle-2.7.1-8.el7.x86_64 4/4
已安装:
lftp.x86_64 0:4.4.8-11.el7
作为依赖被安装:
gnutls.x86_64 0:3.3.29-9.el7_6 nettle.x86_64 0:2.7.1-8.el7 trousers.x86_64 0:0.3.14-2.el7
完毕!
[root@linux-001 ftpuser2]#
[root@linux-001 vsftpd]# lftp ftpuser1@127.0.0.1
口令:
lftp ftpuser1@127.0.0.1:~> ls
-rw-r--r-- 1 1014 1014 0 May 25 01:47 1.txt
-rw-r--r-- 1 1014 1014 0 May 25 01:47 2.txt
lftp ftpuser1@127.0.0.1:/> ?
!<shell-command> (commands) alias [<name> [<value>]] attach [PID]
bookmark [SUBCMD] cache [SUBCMD] cat [-b] <files> cd <rdir>
chmod [OPTS] mode file... close [-a] [re]cls [opts] [path/][pattern]
debug [<level>|off] [-o <file>] du [options] <dirs> exit [<code>|bg]
get [OPTS] <rfile> [-o <lfile>] glob [OPTS] <cmd> <args> help [<cmd>]
history -w file|-r file|-c|-l [cnt] jobs [-v] [<job_no...>] kill all|<job_no> lcd <ldir>
lftp [OPTS] <site> ln [-s] <file1> <file2> ls [<args>]
mget [OPTS] <files> mirror [OPTS] [remote [local]] mkdir [-p] <dirs>
module name [args] more <files> mput [OPTS] <files> mrm <files>
mv <file1> <file2> [re]nlist [<args>] open [OPTS] <site>
pget [OPTS] <rfile> [-o <lfile>] put [OPTS] <lfile> [-o <rfile>] pwd [-p]
queue [OPTS] [<cmd>] quote <cmd> repeat [OPTS] [delay] [command]
rm [-r] [-f] <files> rmdir [-f] <dirs> scache [<session_no>]
set [OPT] [<var> [<val>]] site <site-cmd> source <file>
torrent [-O <dir>] <file|URL>... user <user|URL> [<pass>] wait [<jobno>] zcat <files>
zmore <files>
lftp ftpuser1@127.0.0.1:/>
pure-ftpd软件包是在epel源中,所以安装pure-ftpd需要先安装扩展源:epel
[root@linux-001 vsftpd]# yum install -y pure-ftpd
已加载插件:fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Loading mirror speeds from cached hostfile
pure-ftpd
* base: mirrors.aliyun.com
* epel: mirrors.njupt.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 pure-ftpd.x86_64.0.1.0.47-2.el7 将被 安装
--> 正在处理依赖关系 usermode,它被软件包 pure-ftpd-1.0.47-2.el7.x86_64 需要
--> 正在处理依赖关系 libpq.so.5()(64bit),它被软件包 pure-ftpd-1.0.47-2.el7.x86_64 需要
--> 正在检查事务
---> 软件包 postgresql-libs.x86_64.0.9.2.24-1.el7_5 将被 安装
---> 软件包 usermode.x86_64.0.1.111-5.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
====================================================================================================================================
Package 架构 版本 源 大小
====================================================================================================================================
正在安装:
pure-ftpd x86_64 1.0.47-2.el7 epel 263 k
为依赖而安装:
postgresql-libs x86_64 9.2.24-1.el7_5 base 234 k
usermode x86_64 1.111-5.el7 base 193 k
事务概要
====================================================================================================================================
安装 1 软件包 (+2 依赖软件包)
总下载量:690 k
安装大小:2.1 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/3): usermode-1.111-5.el7.x86_64.rpm | 193 kB 00:00:00
(2/3): pure-ftpd-1.0.47-2.el7.x86_64.rpm | 263 kB 00:00:03
(3/3): postgresql-libs-9.2.24-1.el7_5.x86_64.rpm | 234 kB 00:00:05
------------------------------------------------------------------------------------------------------------------------------------
总计 112 kB/s | 690 kB 00:00:06
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : usermode-1.111-5.el7.x86_64 1/3
正在安装 : postgresql-libs-9.2.24-1.el7_5.x86_64 2/3
正在安装 : pure-ftpd-1.0.47-2.el7.x86_64 3/3
验证中 : pure-ftpd-1.0.47-2.el7.x86_64 1/3
验证中 : postgresql-libs-9.2.24-1.el7_5.x86_64 2/3
验证中 : usermode-1.111-5.el7.x86_64 3/3
已安装:
pure-ftpd.x86_64 0:1.0.47-2.el7
作为依赖被安装:
postgresql-libs.x86_64 0:9.2.24-1.el7_5 usermode.x86_64 0:1.111-5.el7
完毕!
[root@linux-001 vsftpd]#
vim /etc/pure-ftpd/pure-ftpd.conf//找到pureftpd.pdb这行,把行首的#删除
[root@linux-001 vsftpd]# vim /etc/pure-ftpd/pure-ftpd.conf/
PureDB /etc/pure-ftpd/pureftpd.pdb
因为vsftpd和pure-ftpd 共用21端口,因此需要把vsftpd服务关掉,再开启pure-ftpd。
[root@linux-001 vsftpd]# systemctl start pure-ftpd
[root@linux-001 vsftpd]# ps aux | grep pure-ftpd
root 2376 0.0 0.0 202520 1204 ? Ss 14:44 0:00 pure-ftpd (SERVER)
root 2378 0.0 0.0 112720 984 pts/0 S+ 14:44 0:00 grep --color=auto pure-ftpd
[root@linux-001 vsftpd]# mkdir /data/ftp
[root@linux-001 vsftpd]# useradd -u 1010 pure-ftp
[root@linux-001 vsftpd]# chown -R pure-ftp:pure-ftp /data/ftp
通过pure-pw命令增加ftp用户以及配置用户库文件
[root@linux-001 vsftpd]# pure-pw useradd ftp_usera -u pure-ftp -d /data/ftp
Password:
Enter it again:
[root@linux-001 vsftpd]# pure-pw mkdb
[root@linux-001 vsftpd]#
[root@linux-001 vsftpd]# lftp ftp_usera@127.0.0.1
口令:
lftp ftp_usera@127.0.0.1:~> ls
drwxr-xr-x 2 1010 pure-ftp 21 Jul 15 14:51 .
drwxr-xr-x 2 1010 pure-ftp 21 Jul 15 14:51 ..
-rw-r--r-- 1 1010 pure-ftp 0 Jul 15 14:51 123.txt
lftp ftp_usera@127.0.0.1:/>
lftp ftp_usera@127.0.0.1:/> quit
NFS网络文件系统适用于5台以内,超过5台得使用场景并不合适,并不支持高并发,访问量比较少。类似于windows系统上得磁盘映射功能。
FTP使用范围也是小范围,使用比较方便,但是ftp传输得协议是明文,所以不安全。小公司可能会使用ftp来上传文件,正规得方式是使用git代码平台来发布。 SFTP和FTP的区别是:SFTP使用SSH协议。所以更安全。
http://ask.apelearn.com/question/961
主动模式: PORT中文称为主动模式,工作的原理: FTP客户端连接到FTP服务器的21端口,发送用户名和密码登录,登录成功后要list列表或者读取数据时,客户端随机开放一个端口(1024以上),发送 PORT命令到FTP服务器,告诉服务器客户端采用主动模式并开放端口;FTP服务器收到PORT主动模式命令和端口号后,通过服务器的20端口和客户端开放的端口连接,发送数据,原理如下图:
被动模式: PASV是Passive的缩写,中文成为被动模式,工作原理:FTP客户端连接到FTP服务器的21端口,发送用户名和密码登录,登录成功后要list列表或者读取数据时,发送PASV命令到FTP服务器, 服务器在本地随机开放一个端口(1024以上),然后把开放的端口告诉客户端, 客户端再连接到服务器开放的端口进行数据传输,原理如下图:
从上面的运行原来看到,主动模式和被动模式的不同简单概述为: 主动模式传送数据时是“服务器”连接到“客户端”的端口;被动模式传送数据是“客户端”连接到“服务器”的端口。
主动模式需要客户端必须开放端口给服务器,很多客户端都是在防火墙内,开放端口给FTP服务器访问比较困难。
被动模式只需要服务器端开放端口给客户端连接就行了。