[b]引言:[/b]
在架设网站的时候,往往需要考虑将用户文件保存或同步到一台或多台文件,这样确保服务的可扩展性,有滴时候我们选择在程序中实现,有滴时候我们选择各种各样的方法,但是,要做一个好的解决方案,每个模块的耦合性应该足够小,让程序员只关心需要实现的需求,在这里我提出的文件系统解决方案是NFS。
[b]NFS介绍:[/b]
NFS(Network File System, 网络文件系统)可以通过网络将分享不同主机(不同的OS)的目录——可以通过NFS挂载远程主机的目录, 访问该目录就像访问本地目录一样!
通过NFS我们使用中央的文件系统服务器就像本地一样,完全可以解决文件共享问题,同时还建议使用rsync进行文件同步备份(下一篇文章进行讲解)
以下是bash代码,直接运行,就可以安装和部署好NFS-SERVER
在架设网站的时候,往往需要考虑将用户文件保存或同步到一台或多台文件,这样确保服务的可扩展性,有滴时候我们选择在程序中实现,有滴时候我们选择各种各样的方法,但是,要做一个好的解决方案,每个模块的耦合性应该足够小,让程序员只关心需要实现的需求,在这里我提出的文件系统解决方案是NFS。
[b]NFS介绍:[/b]
NFS(Network File System, 网络文件系统)可以通过网络将分享不同主机(不同的OS)的目录——可以通过NFS挂载远程主机的目录, 访问该目录就像访问本地目录一样!
通过NFS我们使用中央的文件系统服务器就像本地一样,完全可以解决文件共享问题,同时还建议使用rsync进行文件同步备份(下一篇文章进行讲解)
以下是bash代码,直接运行,就可以安装和部署好NFS-SERVER
#!/bin/bash
##
#安装NFS
#首先要输入 sudo 的秘密
#安装nfs-server
sudo apt-get install nfs-kernel-server
#(安装nfs-kernel-server时,apt会自动安装nfs-common和portmap)
sudo chmod go+wx /etc/hosts.allow
sudo chmod go+wx /etc/hosts.deny
sudo chmod go+wx /etc/exports
##
#处理host.deny
if [ -z "$(grep portmap:ALL /etc/hosts.deny)" ]
then
echo 'portmap:ALL' >> /etc/hosts.deny
fi
if [ -z "$(grep lockd:ALL /etc/hosts.deny)" ]
then
echo 'lockd:ALL' >> /etc/hosts.deny
fi
if [ -z "$(grep mountd:ALL /etc/hosts.deny)" ]
then
echo 'mountd:ALL' >> /etc/hosts.deny
fi
if [ -z "$(grep mountd:ALL /etc/hosts.deny)" ]
then
echo 'mountd:ALL' >> /etc/hosts.deny
fi
if [ -z "$(grep rquotad:ALL /etc/hosts.deny)" ]
then
echo 'rquotad:ALL' >> /etc/hosts.deny
fi
if [ -z "$(grep statd:ALL /etc/hosts.deny)" ]
then
echo 'statd:ALL' >> /etc/hosts.deny
fi
##
#处理host.allow
if [ -z "$(grep portmap /etc/hosts.allow)" ]
then
echo 'portmap:10.10.1.' >> /etc/hosts.allow
fi
if [ -z "$(grep lockd /etc/hosts.allow)" ]
then
echo 'lockd:10.10.1.' >> /etc/hosts.allow
fi
if [ -z "$(grep rquotad /etc/hosts.allow)" ]
then
echo 'rquotad:10.10.1.' >> /etc/hosts.allow
fi
if [ -z "$(grep mountd /etc/hosts.allow)" ]
then
echo 'mountd:10.10.1.' >> /etc/hosts.allow
fi
if [ -z "$(grep statd /etc/hosts.allow)" ]
then
echo 'statd:10.10.1.' >> /etc/hosts.allow
fi
sudo /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/exports
fi
##
echo "config is:`showmount -e `"
sudo /etc/init.d/nfs-kernel-server restart
#客户端配置
sudo mount 10.10.1.21:/home/worker/test /mnt
#显示磁盘信息
df
sudo chmod go-wx /etc/hosts.allow
sudo chmod go-wx /etc/hosts.deny
sudo chmod go-wx /etc/exports
#成功返回
#exit 0