Nfs实现代码同步

来自linux中国网wiki
跳到导航 跳到搜索

Nfs实现日志集中查看 程序有个需求 要求一台只有ftp的机器一一个目录要同步到另外一台

一开始是想用rsyn + innotify 来实现的 后来 小伙伴说 nfs 于是

Installation

centos 6(portmap服务由rpcbind负责) : 
yum -y install nfs-utils rpcbind

配置

主要配置文件:/etc/exports
[root@localhost /]# vi /etc/exports
/tmp 192.168.0.0/24(rw)                       //把“/tmp”共享给192.168.0.0网段(可读)。
/tmp 192.168.0.65(rw,sync,no_root_squash)     //把“/tmp”共享给192.168.0.65(可读可写,同步)。


[root@ftp ~]# cat /etc/exports
/data1/ftp_dovo/iso   192.168.14.0/22(ro,all_squash)

[root@localhost etc]# service portmap (rpcbind)  restart
停止 portmap:[  确定  ]
启动 portmap:[  确定  ]
[root@localhost etc]# service nfs restart    //设置完成后重启服务
关闭 NFS mountd:[  确定  ]
关闭 NFS 守护进程:[  确定  ]
关闭 NFS quotas:[  确定  ]
关闭 NFS 服务: [失败]
启动 NFS 服务: [  确定  ]
关掉 NFS 配额:[  确定  ]
启动 NFS 守护进程:[  确定  ]
启动 NFS mountd:[  确定  ]

chkconfig  --level 345  rpcbind  on

chkconfig  --level 345  nfs  on 

[root@localhost etc]# showmount -e    //查看自己共享的服务
Export list for localhost.localdomain:
/tmp 192.168.0.0/24,localhost


[root@localhost tmp]# showmount -a    //显示已经与客户端连接上的目录信息
All mount points on localhost.localdomain:
192.168.0.213:/tmp
================================

 
使用exportfs命令,当改变/etc/exports配置文件后,不用重启nfs服务直接用这个exportfs即可。

[root@localhost ~]# cat /etc/exports

/tmp/   10.0.2.0/24(rw,sync,no_root_squash)

[root@localhost ~]# exportfs -arv (nfs服务器上)

exporting 10.0.2.0/24:/tmp

更改目录后,直接exportfs -arv即可生效。



客户端连接:
# showmount -e 192.168.0.248    //列出可供使用的NFS
Export list for 192.168.0.248:
/tmp 192.168.0.65,192.168.0.213


# mount 192.168.0.248:/tmp /mnt    //挂载“/tmp”目录到“/mnt”下。

 

 mount -t nfs -o nolock,nfsvers=3,vers=3 192.168.30.60:/tmp   /mnt/tmp

 

自动挂载

vi  /etc/fstab

192.168.30.62:/tmp   /mnt/tmp/   nfs   defaults    0   0

trouble shooting

NFS的挂载错误:
# mount 192.168.0.70:/tmp /mnt/tmp

mount:1831-008 放弃:

192.168.0.70:/tmp

vmount: 操作不允许执行。

# nfso -p -o nfs_use_reserved_ports=1

正在将 nfs_use_reserved_ports 设置为 1

正在 nextboot 文件中将 nfs_use_reserved_ports 设置为 1

# mount 192.168.0.70:/tmp /mnt/tmp

# ls /mnt/tmp



注:正常能显示出上面设置的共享目录,如果报如下错误:

clnt_create: RPC: Program not registered

说明 rpcbind服务与NFS服务 启动顺序不对,把他俩都停了,重新启动,先启动rpcbind服务再启动nfs服务

SEE ALSO

http://www.7edown.com/edu/article/soft_5100_1.html http://blog.csdn.net/a3470194/article/details/19554187 http://www.cnblogs.com/mchina/archive/2013/01/03/2840040.html NFS版本 http://blog.csdn.net/ycnian/article/details/8515517


文件监控同步工具

利用rsync自动同步服务器与本地代码的python脚本