現在創建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函數。