歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> bash 腳本編程十六 NFS server自動部署

bash 腳本編程十六 NFS server自動部署

日期:2017/3/1 10:09:41   编辑:Linux編程

現在創建nfs/server目錄,這個腳本要自動安裝並配置nfs server。

install.sh腳本:

  1. #!/bin/bash
  2. source ../../common/tool.sh
  3. nfs="nfs-kernel-server"
  4. hasDpkg $nfs
  5. r=$?
  6. if [ $r -eq 1 ]
  7. then
  8. echo "$nfs was installed"
  9. else
  10. echo "$nfs was not installed"
  11. apt-get install $nfs
  12. fi
  13. if [ -d "/opt/share" ]
  14. then
  15. echo "/opt/share" exists already
  16. else
  17. mkdir -p /opt/share
  18. chmod -R 777 /opt/share
  19. fi
  20. #config /opt/share as nfs folder
  21. mv /etc/exports /etc/exports_bk
  22. mv /etc/hosts.deny /etc/hosts.deny_bk
  23. mv /etc/hosts.allow /etc/hosts.allow_bk
  24. cp exports /etc/
  25. cp hosts.deny /etc/
  26. cp hosts.allow /etc/
  27. service portmap restart
  28. service nfs-kernel-server restart

當前目錄下已經准備了exports, hosts.deny和hosts.allow 文件。

裡面的內容參考前面的文章:http://www.linuxidc.com/Linux/2012-09/70728.htm

應該根據具體部署的環境修改IP地址。

這裡重用了前面開發的hasDpkg函數。

Copyright © Linux教程網 All Rights Reserved