bash 脚本编程十六 NFS server自动部署


现在创建nfs/server目录,这个脚本要自动安装并配置nfs server。

install.sh脚本:

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

当前目录下已经准备了exports, hosts.deny和hosts.allow 文件。

里面的内容参考前面的文章:

应该根据具体部署的环境修改IP地址。

这里重用了前面开发的hasDpkg函数。

相关内容