nfs概念
NFS(Network Files System)即网络文件系统,NFS文件系统协议允许网络中的主机通过TCP/IP协议进行资源共享,NFS客户端可以
像使用本地资源一样读写远端NFS服务端的资料,需要注意NFS服务依赖于RPC服务与外部通信,所以必需保证RPC服务能够正常
注册服务的端口信息才能正常使用NFS服务,但在红帽RHEL7系统中RPC服务已经默认运行(active)了,所以无需再配置RPC服务。
安装
yum install nfs-utils rpcbind -y
配置
服务端
nfs配置火墙策略
[root@desktop ~]# firewall-cmd --permanent --add-service=nfs
success
[root@desktop ~]# firewall-cmd --reload
success
[root@desktop ~]# firewall-cmd --permanent --add-service=mountd
success
[root@desktop ~]# firewall-cmd --reload
success
[root@desktop ~]# firewall-cmd --permanent --add-service=rpc-bind
success
[root@desktop ~]# firewall-cmd --reload
success
配置挂载目录
[root@desktop ~]# vim /etc/exports
/westos *(sync,rw)
## 格式: 共享目录的绝对路径 允许访问NFS资源的客户端(权限参数)
[root@desktop ~]# exportfs -rv ##检测刷新
exporting *:/westos
[root@desktop ~]# systemctl start nfs
客户端
#安装
yum install nfs-utils rpcbind -y
#检查是否有挂载可用
[root@foundation44 ~]# showmount -e 172.25.254.110 ##显示nfs共享列表
Export list for 172.25.254.110:
/westos *
# 挂载
[root@foundation44 ~]# mount 172.25.254.144:/westos /mnt/
# 设置开机自动挂载
echo "172.25.254.144:/westos /mnt/ nfs defaults 0 0" >>/etc/fstab
nfs系统可以在使用时自动挂载,在规定时间之后自动卸载
客户端配置
yum install autofs.x86_64 -y
systemctl start autofs.service
修改挂载时长
[root@foundation44 ~]# vim /etc/sysconfig/autofs ##不同版本配置文件路径会有所不同,采用rpm -qc autofs 查看文件存放目录
13 TIMEOUT=10
[root@foundation44 ~]# systemctl restart autofs.service
10秒之后会发现被自动卸载
修改挂载目录
客户端:
mkdir /westos/llc/share
vim /etc/auto.master
8 /nfs /etc/auto.nfs
9 /westos/llc /etc/auto.nfs ##/westos/llc为共享目录的上层目录
vim /etc/auto.nfs ##编辑挂载方式
1 westos -rw,vers=3 172.25.254.100:/westos
2 share -ro,vers=4 172.25.254.110:/westos ##挂载子目录 权限 挂载版本 挂载的绝对路径
测试:
mkdir /westos/llc/share -p
cd /westos/llc/share
df
172.25.254.144:/westos 10473984 3226880 7247104 31% /westos/llc/share
nfs配置文件参数详解
vim /etc/exports
/westos 172.25.254.124(sync,rw,anonuid=1000,anongid=1000,no_root_squash) 172.25.254.0/24(rync,ro)
systemctl restart nfs
共享路径 允许该ip登陆 (文件同步,读写权限,允许该用户登陆,当NFS客户端使用root用户访问时,映射为NFS服务端的root用户)
exportfs -rv
iscsi文件系统
服务端
[root@localhost ~]# yum install targetd.noarch targetcli.noarch -y
Complete!
[root@localhost ~]# systemctl start target
[root@localhost ~]# systemctl start firewalld
[root@localhost ~]# firewall-cmd --permanent --add-port=3260/tcp
success
[root@localhost ~]# firewall-cmd --reload
success
创建磁盘分区
fdisk /dev/vdb
....
partprobe
创建存储对象
[root@localhost ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb34
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> backstores/block create westos:storage1 /dev/vdb2
Created block storage object westos:storage1 using /dev/vdb2
/> /iscsi create iqn.2017-12.com.example:storage1
Created target iqn.2017-12.com.example:storage1.
/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/acls create iqn.2017-12.com.exam
/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/acls create iqn.2017-12.com.example:storagekey1
Created Node ACL for iqn.2017-12.com.example:storagekey1
/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/luns create /backstores/block/westos:storage1
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2017-12.com.example:storagekey1
/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/portals create 172.25.254.124
Using default IP port 3260
Created network portal 172.25.254.244:3260.
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
客户端
yum install iscsi-initiator-utils.x86_64 -y
2 vim /etc/iscsi/initiatorname.iscsi ##编辑客户端文件名称
InitiatorName=iqn.2017-12.com.example:storagekey1
3 systemctl restart iscsi
4 iscsiadm -m discovery -t st -p 172.25.254.100 ##发现iscsi存储
5 iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.254.100 -l ##登陆iscsi存储
iscsiadm -m discovery -t st -p 172.25.254.100
15 iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.254.100 -l
18 fdisk -l
19 history
[root@localhost ~]#
当无法登陆成功时,可以尝试进行如下操作:
7 yum install tree
8 tree /var/lib/iscsi/
9 rm -fr /var/lib/iscsi/nodes/*
10 rm -fr /var/lib/iscsi/send_targets/*
11 ls
12 tree /var/lib/iscsi/
14 systemctl restart iscsid.service
#设置开机自动挂载
由于是网络文件系统,所以挂载方式略有不同,如下,在开机文件中注明网络设备
403 fdisk -l
404 fdisk /dev/sda
405 partprobe
406 mkfs.xfs /dev/sda1
407 vim /etc/fstab
/dev/sda1 /mnt xfs defaults,_netdev 0 0