一、NFS
1、NFS简介
NFS全称是network file system 网络文件系统nfs依赖网络带宽的支持
NFS允许一个系统在网络上与他人共享目录和文件。通过使用NFS用户和程序可以像访问本地文件一样访问远端系统上的文件。
假如有三台机器A, B, C它们需要访问同一个目录目录中都是图片传统的做法是把这些图片分别放到A, B, C. 但是使用NFS只需要放到A上然后A共享给B和C即可。访问的时候B和C是通过网络的方式去访问A上的那个目录的。
2、安装、配置NFS服务
需要安装两个包(nfs-utils和rpcbind)
#yum install -y nfs-utils 会同时安装上依赖包rpcbind
提供nfs服务的机器上 vim /etc/exports 输入以下内容
/home/ 192.168.20.0/24(rw,sync,all_squash,anonuid=501,anongid=501)
共分为三部分
/home/ 第一部分是本地要共享出去的目录
192.168.20.0/24 第二部分为允许访问的主机可以是一个IP也可以是一个IP段
(rw,sync,all_squash,anonuid=501,anongid=501) 第三部分就是小括号里面的为一些权限选项。权限为读写同步限定所有使用者并且限定的uid和gid都为501501账号必须真实存在。
启动nfs服务先启动rpcbind再启动nfs启动顺序错误的话会导致后面出错
/etc/init.d/rpcbind start
/etc/init.d/nfs start
3、NFS配置的一些选项说明
rw 可读可写
ro 只读
sync 同步模式内存中数据时时写入磁盘
async 不同步把内存中数据定期写入磁盘中
no_root_squash squash的意思为挤压压制字面意思为不压制root的权限加上这个选项后root用户就会对共享的目录拥有至高的权限控制就像是对本机的目录操作一样。不安全不建议使用
root_squash和上面的选项对应root用户对共享目录的权限不高只有普通用户的权限即限制了root
all_squash不管使用NFS的用户是谁他的身份都会被限定成为一个指定的普通用户身份
anonuid/anongid 要和root_squash 以及all_squash一同使用用于指定使用NFS的用户限定后的uid和gid前提是本机的/etc/passwd中存在这个uid和gid。
4、客户端上挂载NFS
客户端机器也同样需要安装nfs包# yum install -y nfs-utils
同时需要检查iptables清空iptables
关闭selinux防火墙
查看服务器端都共享了哪些目录 #showmount -e 192.168.20.30nfs服务器的ip地址
客户端使用showmount -e 时报错RPC程序没有注册
[root@yong ~]# showmount -e 192.168.20.30
clnt_create: RPC: Program not registered
出错原因是rpcbind服务与NFS服务启动顺序不对先停止服务重新启动先启动rpcbind服务再启动nfs服务
[root@localhost ~]# /etc/init.d/nfs stop
[root@localhost ~]# /etc/init.d/rpcbind stop
重新启动后执行显示正确
[root@localhost ~]# /etc/init.d/rpcbind start
[root@localhost ~]# /etc/init.d/nfs start
[root@yong ~]# showmount -e 192.168.20.30
Export list for 192.168.20.30:
/home 192.168.20.0/24
在客户端上挂载服务端的nfs命令
mount -t nfs -o nolock,nfsvers=3 192.168.20.30:/home/ /mnt/
//如果不加 -onolock,nfsvers=3 则在挂载目录下的文件属主和组都是nobody如果指定nfsvers=3则显示root
-o nolock 不上锁指定nfsvers版本是3默认是4
df -h 查看挂载的情况
实验测试nfs
服务器端共享/home目录允许192.168.20.0网段的机器访问指定使用nfs用户的身份为501
[root@localhost home]# cat /etc/exports
/home/ 192.168.20.0/24(rw,sync,all_squash,anonuid=501,anongid=501)
[root@localhost /]# ls -ld home/
drwxr-xr-x. 8 root root 4096 5月 22 11:33 home/
[root@localhost home]# ls -ld
rwxr-xr-x 2 root root 4096 5月 15 15:54 logs
drwx------. 3 mysql mysql 4096 5月 11 14:47 mysql
drwx------. 4 php-fpm php-fpm 4096 5月 13 14:24 php-fpm
drwx------ 2 test test 4096 5月 22 11:40 test
[root@localhost home]# mkdir 111
[root@localhost home]# chmod 777 111
客户端机器新建立文件夹nfs挂载nfs服务器的/home目录到nfs目录挂载后使用df -h查看已挂载的nfs
12345678910 [root@yong ~]# mkdir nfs
[root@yong ~]# mount -t nfs 192.168.20.30:/home/ /root/nfs/
[root@yong ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
19G 2.9G 15G 17% /
tmpfs 250M 0 250M 0% /dev/shm
/dev/sda1 477M 46M 407M 11% /boot
/dev/sdb2 6.0G 93M 5.6G 2% /data
192.168.20.30:/home/ 18G 2.1G 15G 13% /root/nfs
ls -l 列出来共享的目录的文件所属主、组全部为nobody在nfs目录新建目录或文件提示权限被拒绝
[root@yong nfs]# ls -l
drwxr-xr-x 2 nobody nobody 4096 May 15 15:54 logs
drwx------ 3 nobody nobody 4096 May 11 14:47 mysql
drwx------ 4 nobody nobody 4096 May 13 14:24 php-fpm
drwx------ 2 nobody nobody 4096 May 22 11:40 test
[root@yong nfs]# mkdir abc
mkdir: cannot create directory `abc': Permission denied
[root@yong nfs]# touch 1.txt
touch: cannot touch `1.txt': Permission denied
服务器端/home目录新建111目录并设置权限为777客户端进入111目录下可以创建目录或文件创建的文件所属主、组都为nobodoy
12 [root@yong 111]# ls -l
-rw-r--r-- 1 nobody nobody 0 May 22 13:40 1.txt
取消挂载重新挂载添加参数-o nolock,nfsvers=3 显示的所属主则为root进入111目录新建立文件文件所属主、组权限为501因为客户端已经存在501 对应账号为user1所以这里显示账号为user1
[root@yong ~]# umount /root/nfs/
[root@yong ~]# mount -t nfs -o nolock,nfsvers=3 192.168.20.30:/home/ /root/nfs/
[root@yong nfs]# ls -l
drwxrwxrwx 2 root root 4096 May 22 14:18 111
drwxr-xr-x 2 root root 4096 May 15 15:54 logs
drwx------ 3 500 testgroup 4096 May 11 14:47 mysql
drwx------ 4 user1 user1 4096 May 13 14:24 php-fpm
drwx------ 2 php-fpm php-fpm 4096 May 22 11:40 test
[root@yong nfs]# cd 111
[root@yong 111]# touch 2.txt
[root@yong 111]# ls -l
-rw-r--r-- 1 user1 user1 0 May 22 2015 2.txt
[root@yong 111]# id -u user1
501
5、exportfs 命令的使用
-a 全部挂载或者卸载
-r 重新挂载
-u 卸载某一个目录
-v 显示共享的目录
/home/ 192.168.20.0/24(rw,sync,no_root_squash) 不限制root用户客户端再创建的用户的所属主组都是root
可以进行更改权限删除文件。
改变/etc/exports配置文件后不用重启nfs服务执行命令#exportfs -arv 使/etc/exports配置文件生效
我们还可以把要挂载的nfs目录写到client上的/etc/fstab文件中 192.168.20.10:/tmp/ /test nfs nolock 0 0 然后 mount -a
实验测试服务器端更改nfs配置不压制root的权限
1234 [root@localhost home]# cat /etc/exports
/home/ 192.168.20.0/24(rw,sync,no_root_squash)
[root@localhost home]# exportfs -arv
exporting 192.168.20.0/24:/home
客户端挂载nfs不指定nfsvers版本显示的账号还是为nobody但是可以直接创建文件已经有root权限
[root@yong ~]# mount -t nfs 192.168.20.30:/home/ /root/nfs/
[root@yong ~]# cd nfs/
[root@yong nfs]# touch 1.txt
[root@yong nfs]# ls -l
drwxrwxrwx 2 nobody nobody 4096 May 22 14:25 111
-rw-r--r-- 1 nobody nobody 0 May 22 2015 1.txt
取消挂载nfs重新指定参数挂载挂载后显示账号为root
1234567 [root@yong ~]# umount /root/nfs/
[root@yong ~]# mount -t nfs -o nolock,nfsvers=3 192.168.20.30:/home/ /root/nfs/
[root@yong ~]# cd nfs/
[root@yong nfs]# touch 1.txt
[root@yong nfs]# ls -l
drwxrwxrwx 2 root root 4096 May 22 14:25 111
-rw-r--r-- 1 root root 0 May 22 2015 1.txt
二、ftp
1、什么是ftp
FTP 是File Transfer Protocol文件传输协议的英文简称而中文简称为 “文传协议” 用于Internet上的控制文件的双向传输。
FTP的主要作用就是让用户连接上一个远程计算机这些计算机上运行着FTP服务器程序查看远程计算机有哪些文件然后把文件从远程计算机上拷到本地计算机或把本地计算机的文件送到远程计算机去。
在CentOS或者RedHat Linux上有自带的ftp软件叫做vsftpd。
2、使用pure-ftpd搭建FTP服务
pure-ftpd 官网 http://www.pureftpd.org/project/pure-ftpd
pure-ftpd 是服务端工具
关注公众号,解锁完整文章
微信扫码关注 星哥玩云,
在公众号对话框回复关键词 星哥玩云博客 获取验证码。输入后即可阅读全文,
一次解锁全站文章通用。