Linux Centos6 服务器之间文件共享挂载
有可能需要的目的之一:服务器设置了负载均衡,多台服务器之间的文件需要同步,此时可以把服务器a作为主文件服务器,服务器b、c……服务器挂载a的文件系统来实现同步。
服务器a:10.10.70.114 (被挂载机器)
服务器b:10.10.70.107
安装基础所需服务
1.安装nfs (所有机器都需要安装)
yum install -y nfs-utils
2、设置服务开机自启
chkconfig rpcbind on
chkconfig nfs on
3、启动服务
service rpcbind start
service nfs start
被挂载机器配置 (a服务器)
1、编辑 /etc/exports 文件添加需要被挂载的目录
#本地被挂载的目录 允许挂载的ip 挂载之后的权限
/data 10.10.70.104(rw,sync,no_root_squash) # 注意 ip和括号之间不能有空格
/data 10.10.70.0/24(rw,sync,no_root_squash) # 注意这行的ip位置,这样添加一个网段,在这个网段中的机器都可以挂载
2、重新加载文件
exportfs -r
3、共享列表查看
exportfs
- 如需添加新的共享目录,方法如上,添加之后需要重新加载文件。
4、为了方便管理,我们需要指定nfs启动使用的端口,不然端口是随机的不方便添加防火墙规则
4.1 编辑 /etc/sysconfig/nfs 文件,添加如下内容:
RQUOTAD_PORT=40001
LOCKD_TCPPORT=40002
LOCKD_UDPPORT=40002
MOUNTD_PORT=40003
STATD_PORT=40004
保存退出之后重启rpcbind和nfs
service rpcbind restart
service nfs restart
重启之后通过 rpcinfo -p 命令查看服务使用的端口,结果如下图:
4.2 添加iptables规则
iptables -I INPUT -s 10.10.70.0/24 -p tcp --dport 111 -j ACCEPT
iptables -I INPUT -s 10.10.70.0/24 -p udp --dport 111 -j ACCEPT
iptables -I INPUT -s 10.10.70.0/24 -p tcp --dport 2049 -j ACCEPT
iptables -I INPUT -s 10.10.70.0/24 -p udp --dport 2049 -j ACCEPT
iptables -I INPUT -s 10.10.70.0/24 -p tcp --dport 40001:40004 -j ACCEPT
iptables -I INPUT -s 10.10.70.0/24 -p udp --dport 40001:40004 -j ACCEPT
保存规则:
service iptables save
5、查看可以挂载的目录输入命令:**showmount -e localhost**
需要挂载目录机器配置 (b、c……服务器)
1、查看可挂载目录 showmount -e 10.10.70.114
2、在本机创建一个目录作为挂载点,并进行挂载
mkdir /datamnt
mount -t nfs -o nfsvers=3,vers=3 10.10.70.114:/data /datamnt
至此nfs挂载就完成啦,如果挂载过程中遇到问题自行百度解决吧。(#^.^#)