edisonlz 发表于 2013-1-28 19:10:20

架设中央文件服务器

引言:
在架设网站的时候,往往需要考虑将用户文件保存或同步到一台或多台文件,这样确保服务的可扩展性,有滴时候我们选择在程序中实现,有滴时候我们选择各种各样的方法,但是,要做一个好的解决方案,每个模块的耦合性应该足够小,让程序员只关心需要实现的需求,在这里我提出的文件系统解决方案是NFS。

NFS介绍:
NFS(Network File System, 网络文件系统)可以通过网络将分享不同主机(不同的OS)的目录——可以通过NFS挂载远程主机的目录, 访问该目录就像访问本地目录一样!

通过NFS我们使用中央的文件系统服务器就像本地一样,完全可以解决文件共享问题,同时还建议使用rsync进行文件同步备份(下一篇文章进行讲解)

以下是bash代码,直接运行,就可以安装和部署好NFS-SERVER


#!/bin/bash###安装NFS#首先要输入 sudo 的秘密#安装nfs-serversudo apt-get install nfs-kernel-server #(安装nfs-kernel-server时,apt会自动安装nfs-common和portmap)sudo chmod go+wx /etc/hosts.allowsudo chmod go+wx /etc/hosts.denysudo chmod go+wx /etc/exports###处理host.denyif [ -z "$(grep portmap:ALL /etc/hosts.deny)" ]then echo 'portmap:ALL'>> /etc/hosts.denyfiif [ -z "$(greplockd:ALL /etc/hosts.deny)" ]then echo 'lockd:ALL'>> /etc/hosts.denyfiif [ -z "$(grepmountd:ALL /etc/hosts.deny)" ]then echo 'mountd:ALL'>> /etc/hosts.denyfiif [ -z "$(grepmountd:ALL /etc/hosts.deny)" ]then echo 'mountd:ALL'>> /etc/hosts.denyfiif [ -z "$(greprquotad:ALL /etc/hosts.deny)" ]then echo 'rquotad:ALL'>> /etc/hosts.denyfiif [ -z "$(grepstatd:ALL /etc/hosts.deny)" ]then echo 'statd:ALL'>> /etc/hosts.denyfi###处理host.allowif [ -z "$(grepportmap /etc/hosts.allow)" ]then echo 'portmap:10.10.1.'>> /etc/hosts.allowfiif [ -z "$(greplockd /etc/hosts.allow)" ]then echo 'lockd:10.10.1.'>> /etc/hosts.allowfiif [ -z "$(greprquotad /etc/hosts.allow)" ]then echo 'rquotad:10.10.1.'>> /etc/hosts.allowfiif [ -z "$(grepmountd /etc/hosts.allow)" ]then echo 'mountd:10.10.1.'>> /etc/hosts.allowfiif [ -z "$(grepstatd /etc/hosts.allow)" ]then echo 'statd:10.10.1.'>> /etc/hosts.allowfisudo /etc/init.d/portmap restart###定义 共享配置文件if [ -z "$(grep /home/worker/test /etc/exports)" ]then echo '/home/worker/test 10.10.1.*(rw,sync,no_root_squash)' >> /etc/exportsfi##echo "config is:`showmount -e `"sudo /etc/init.d/nfs-kernel-server restart#客户端配置sudo mount 10.10.1.21:/home/worker/test /mnt#显示磁盘信息dfsudo chmod go-wx /etc/hosts.allowsudo chmod go-wx /etc/hosts.denysudo chmod go-wx /etc/exports#成功返回#exit 0
页: [1]
查看完整版本: 架设中央文件服务器