===== nfs文件类挂载设置 =====
服务器(提供共享需要被挂载的磁盘空间):192.168.1.76,
客户机(将网络磁盘空间挂载本地文件夹下):192.168.1.198。
1、安装网络挂载需要的支持nfs:
yum install nfs-utils
2、设置nfs相关进程开机自启动:
chkconfig rpcbind on
chkconfig nfs on
3、启动nfs相关支持服务:
service rpcbind start
service nfs start
4、服务器192.168.1.76上的设置:
编辑配置文件:
vi /etc/exports
添加如下内容:
/root/my 192.168.1.198(insecure,rw,async,no_root_squash)
/root/my 表示设置服务器共享的目录空间路径,目录可赋予666权限。192.168.1.198(insecure,rw,async,no_root_squash)表示设置指定IP的客户机和权限。
*(insecure,rw,async,no_root_squash)表示设置任何IP的客户机和权限。
192.168.1.*(insecure,rw,sync,no_root_squash)表示设置某网段的客户机和权限。
rw:可读可写
sync:同步写磁盘(async:资料会先暂存于内存当中,而非直接写入硬盘)
no_root_squash:表示客户端root用户对该目录具备写权限。
insecure:允许从客户机过来的非授权访问。(可选)
然后重新加载 :
exportfs -rv
5、客户机192.168.1.198上查看共享:
showmount -e 192.168.1.176
如果有共享,则会显示共享信息。
6、iptables为nfs设置通行端口:
nfs服务启用时会检查/etc/sysconfig/nfs文件,此文件下来指定mountd、statd、lockd、rquotad端口号。
vi /etc/sysconfig/nfs 添加如下:
RQUOTAD_PORT=10001
LOCKD_TCPPORT=10002
LOCKD_UDPPORT=10002
MOUNTD_PORT=10003
STATD_PORT=10004
设定后需重启nfs相关服务:
service nfslock restart
service nfs restart
使用命令查看nfs端口:
rpcinfo -p
{{:zh:常见问题及解答:selection_136.png?500|}}
配置iptables规则:
iptables -I INPUT -p tcp --dport 111 -j ACCEPT
iptables -I INPUT -p udp --dport 111 -j ACCEPT
iptables -I INPUT -p tcp --dport 2049 -j ACCEPT
iptables -I INPUT -p udp --dport 2049 -j ACCEPT
iptables -I INPUT -p tcp --dport 10001:10004 -j ACCEPT
iptables -I INPUT -p udp --dport 10001:10004 -j ACCEPT
service iptables save
service iptables restart
{{:zh:常见问题及解答:selection_135.png?500|}}
7、执行挂载操作:
mount -t nfs -o rw 192.168.1.76:/root/my /mnt
8、查看是否已挂载:
df -hT
{{:zh:常见问题及解答:selection_134.png?500|}}
9、卸载删除共享:
umount 192.168.1.76:/root/my
10、设置开机自动挂载:
编辑 /etc/rc.local 文件加入:
mount -t nfs -o rw 192.168.1.76:/root/my /mnt
===== cifs文件类挂载设置 =====
服务器(提供共享需要被挂载的磁盘空间):192.168.1.76,
客户机(将网络磁盘空间挂载本地文件夹下):192.168.1.198。
1、主机上安装samba服务:
yum install samba
2、安装完成后主机上分别创建samba用户及密码:
创建samba用户:
useradd smb
设置sbu密码,并在提示时输入123321:
smbpasswd -a smb
3、修改主机上samba配置文件 /etc/samba/smb.conf,在smb.conf 文件末尾添加如下内容:
[ccastspool]
path = /root
comment = Home Directories
browseable = no
writable = yes
; valid users = %S
; valid users = MYDOMAIN\%S
create mask= 660
directory mask = 660
force user = root
4、重启服务器上的samba服务:
service smb restart
5、iptables放行samba端口:
新增入站规则:
iptables -I INPUT -p tcp -m multiport --dports 139,445 -j ACCEPT
iptables -I INPUT -p udp -m multiport --dports 137,138 -j ACCEPT
{{:zh:常见问题及解答:selection_038.png?750|}}
6、执行挂载操作:
mount -t cifs -o username=sbu,password=123321 //192.168.1.76/root /mnt
7、设置开机自动挂载,客户机上可设置开机自动挂载:
VIM编辑/etc/fstab,文件末增加如下: //192.168.1.76/root /mnt cifs defaults,username=smb,password=123321 0 0
{{:zh:常见问题及解答:selection_035.png?1000|}}
8、查看是否已挂载:
df -hT
{{:zh:常见问题及解答:selection_037.png?750|}}
9、卸载删除共享:
umount //192.168.1.76/root