架设中央文件服务器

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值