通过curlftpfs来将远程ftp某个目录映射到本地目录,可以达到多台机器共享同一目录的效果。我们是用它来共享脚本的。curlftpfs是通过yum本地源安装的,需要epel支持,需要提前弄好,或者提交下载好rpm包https://download.csdn.net/download/shy_snow/87261059。
一、 安装FTP服务
-
在联网环境下安装epel
yum -y install epel-release
注意:如果在离线环境下,需要提前在联网环境的机器上做好,然后拷贝到离线环境上,建一个本地的epel源。具体参考:Linux离线部署epel源: https://blog.csdn.net/weixin_45579026/article/details/118358603 -
#安装配置vsftpd服务
yum install vsftpd
cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak -
#修改配置文件/etc/vsftpd/vsftpd.conf
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=NO
listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
#该目录下的用户才允许登录ftp
userlist_file=/etc/vsftpd/user_list
tcp_wrappers=YES
# 禁止自由切换目录,YES代表禁用切换,所有用户都被限制在主目录home下
chroot_local_user=YES
chroot_list_enable=YES
#例外的账号,chroot_local_user=YES时,其中的用户可以不被限制在主目录home下
chroot_list_file=/etc/vsftpd/chroot_list
#local_root表示用户登录到ftp时的默认目录
local_root=/home/vsftpd/data
-
#操作系统上建主目录(与配置文件保持一致)
mkdir -p /home/vsftpd/data
chmod 777 -R /home/vsftpd/data -
#建OS用户,改默认密码
useradd user1
passwd user1 -
#写入到访问权限列表
echo ‘user1’ >> /etc/vsftpd/chroot_list -
#永久关闭SELINUX(需要重新启动服务器,已改过不用管)
vim /etc/selinux/config,修改为 SELINUX = disabled,保存退出 -
#启服务关防火墙
systemctl restart vsftpd.service
systemctl stop firewalld -
验证ftp命令
二、各节点挂载ftp目录
- 安装curlftpfs
在联网环境下直接安装
yum install curlftpfs
如果是离线环境可以先再联网机器上下载安装包;也可以直接下载离线安装包https://download.csdn.net/download/shy_snow/87261059
https://blog.csdn.net/shy_snow/article/details/126171657
#rpm安装:
rpm -ivh curlftpfs-0.9.2-14.el7.x86_64.rpm
#编译安装:
wget http://sourceforge.net/projects/curlftpfs/files/latest/download
tar xvzf curlftpfs-0.9.2.tar.gz
cd curlftpfs-0.9.2
./configure
make
make install
- 使用curlftpfs挂载远程ftp目录
#建一个挂载点目录
mkdir -p /home/share
#挂载共享目录
curlftpfs -o codepage=utf8 ftp://user1:123456@192.168.129.123/ /home/share
#列表目录、创建文件测试
在 /home/share下面创建的文件实际上是在ftp的/home/vsftpd/data下,并且各节点都能通过本地挂载的/home/share访问到。
三、权限
1.ftp服务器端权限与挂载ftp用户权限
ftp服务器端目录权限可以控制目录的查看和读写(相对于挂载的ftp用户)。
客户端curlftpfs挂载目录的权限等同于curlftpfs中使用的ftp用户的权限;
例如:user1和user2目录分别属于用户user1和user2。
分别使用user1和user2用户挂载后,只能看到各自有权限的目录下的文件。
curlftpfs -o codepage=utf8 -o rw,allow_other ftp://user1:123456@192.168.129.123 /home/share1
curlftpfs -o codepage=utf8 -o rw,allow_other ftp://user2:123456@192.168.129.123 /home/share2
2.客户端挂载权限控制
默认除了挂载用户外,其他用户无法查看挂载目录。
如果需要允许客户端的其他用户访问挂载的共享目录,那么需要在挂载时增加allow_other参数。
curlftpfs -o codepage=utf8 -o rw,allow_other ftp://username:password@ftp.yourserver.com /mnt/ftp
如果除了自己之外只让root用户查看则可以使用allow_root参数;
四、附录
[1]https://wiki.archlinuxcn.org/wiki/CurlFtpFS
[2]https://blog.csdn.net/qq_38423256/article/details/119773336
Linux下用curlftpfs挂载FTP服务器
- Fedora可以直接yum install curlftpfs,CentOS不行,得用DAG repository,所以得先安装DAG repository。在rpm官网去搜索rpmforge-release并下载长传至linux上;
- 执行如下命令进行安装:rpm -Uhv rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
- 安装curlftpfs:yum install curlftpfs
- 挂载FTP服务器
curlftpfs -o codepage=utf8 ftp://username:password@192.168.192.168 /ftp
curlftpfs -o rw,allow_other ftp://centos:cloud4c@192.168.17.195 /home/centos/ftp
curlftpfs -o rw,allow_other ftp://192.168.17.195 /home/centos/ftp - 开机自动挂载
echo “curlftpfs#username:password@192.168.1.111 /ftp fuse allow_other,uid=0,gid=0 0 0” >> /etc/fstab - 卸载挂载
fusermount -u /ftp