六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 40|回复: 0

架设中央文件服务器

[复制链接]

升级  69.33%

42

主题

42

主题

42

主题

秀才

Rank: 2

积分
154
 楼主| 发表于 2013-1-15 02:44:40 | 显示全部楼层 |阅读模式
引言:
在架设网站的时候,往往需要考虑将用户文件保存或同步到一台或多台文件,这样确保服务的可扩展性,有滴时候我们选择在程序中实现,有滴时候我们选择各种各样的方法,但是,要做一个好的解决方案,每个模块的耦合性应该足够小,让程序员只关心需要实现的需求,在这里我提出的文件系统解决方案是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 "$(grep  lockd:ALL /etc/hosts.deny)" ]then echo 'lockd:ALL'  >> /etc/hosts.denyfiif [ -z "$(grep  mountd:ALL /etc/hosts.deny)" ]then echo 'mountd:ALL'  >> /etc/hosts.denyfiif [ -z "$(grep  mountd:ALL /etc/hosts.deny)" ]then echo 'mountd:ALL'  >> /etc/hosts.denyfiif [ -z "$(grep  rquotad:ALL /etc/hosts.deny)" ]then echo 'rquotad:ALL'  >> /etc/hosts.denyfiif [ -z "$(grep  statd:ALL /etc/hosts.deny)" ]then echo 'statd:ALL'  >> /etc/hosts.denyfi###处理host.allowif [ -z "$(grep  portmap /etc/hosts.allow)" ]then echo 'portmap:10.10.1.'  >> /etc/hosts.allowfiif [ -z "$(grep  lockd /etc/hosts.allow)" ]then echo 'lockd:10.10.1.'  >> /etc/hosts.allowfiif [ -z "$(grep  rquotad /etc/hosts.allow)" ]then echo 'rquotad:10.10.1.'  >> /etc/hosts.allowfiif [ -z "$(grep  mountd /etc/hosts.allow)" ]then echo 'mountd:10.10.1.'  >> /etc/hosts.allowfiif [ -z "$(grep  statd /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
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表