现在创建nfs/server目录,这个脚本要自动安装并配置nfs server。install.sh脚本:
- #!/bin/bash
-
- source ../../common/tool.sh
-
- nfs="nfs-kernel-server"
-
- hasDpkg $nfs
- r=$?
-
- if [ $r -eq 1 ]
- then
- echo "$nfs was installed"
- else
- echo "$nfs was not installed"
- apt-get install $nfs
- fi
-
- if [ -d "/opt/share" ]
- then
- echo "/opt/share" exists already
- else
- mkdir -p /opt/share
- chmod -R 777 /opt/share
- fi
-
- #config /opt/share as nfs folder
- mv /etc/exports /etc/exports_bk
- mv /etc/hosts.deny /etc/hosts.deny_bk
- mv /etc/hosts.allow /etc/hosts.allow_bk
-
- cp exports /etc/
- cp hosts.deny /etc/
- cp hosts.allow /etc/
-
- service portmap restart
- service nfs-kernel-server restart
当前目录下已经准备了exports, hosts.deny和hosts.allow 文件。里面的内容参考前面的文章:http://www.linuxidc.com/Linux/2012-09/70728.htm应该根据具体部署的环境修改IP地址。这里重用了前面开发的hasDpkg函数。