博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
shell脚本安装 nfs-server
阅读量:7065 次
发布时间:2019-06-28

本文共 2290 字,大约阅读时间需要 7 分钟。

#!/bin/bash

: <<DESC
Program:
NFS Server install

1 判断是否为root

root_user(){

[ $UID -ne 0 ] && { echo "请使用root用户";exit 1; }
}

2 判断是否能连接到Internet

con_internet(){

ping -c2 mirrors.aliyun.com &>/dev/null
[ $? -ne 0 ] && { echo "无法连接到Internet";exit 1; }
}

3 SELINUX是否关闭

selinux_cls(){

if [ getenforce != "Disabled" ];then
setenforce 0
sed -ir 's/^(SELINUX=).*/\1disabled/' /etc/sysconfig/selinux
fi
}

4 IPTABLES是否关闭

iptables_cls(){

if ! /etc/init.d/iptables status|grep -q 'not running';then
/etc/init.d/iptables stop
chkconfig iptables off
fi
}

5 yum修改

yum_mod(){

if ! grep -q aliyun /etc/yum.repos.d/CentOS-Base.repo;then
\cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.reop.bak
wget -O /etc/yum.repos./CentOS-Base.reop
fi
}

6 install NFS Server

ins_nfs(){

if [ rpm -aq rpcbind nfs-utils|wc -l -lt 2 ];then
yum install -y rpcbind nfs-utils &>/dev/null
if [ $? -ne 0 ];then
echo "NFS Server install fail"
exit 1
fi
/etc/init.d/rpcbind start &>/dev/null
/etc/init.d/nfs start &>/dev/null
fi
if [ netstat -lntup|egrep "rpcbind|nfs"|wc -l -lt 6 ];then
action "NFS Server install..." /bin/fasle
else
action "NFS Server install..." /bin/true
fi
}

7 配置 /etc/exports 文档,NFS Server默认目录设置为 /nfsnobody

nfs_conf(){

[ -d /nfsnobody ] || mkdir /nfsnobody
chown -R nfsnobody:nfsnobody /nfsnobody
if [ -s /etc/exports ];then
echo '/nfsnobody 192.168.0.0/24(rw,all_squash,sync)' >>/etc/exports
else
echo '/nfsnobody 192.168.0.0/24(rw,all_squash,sync)' >/etc/exports
fi
exportfs -r &>/dev/null
}

8 优化NFS,设置 /etc/sysctl.conf 文档

sysctl_opt(){

default=$(sysctl -a|grep "[rw]mem_default"|awk '{print $NF}')
max=$(sysctl -a|grep "[rw]mem_max"|awk '{print $NF}')
if [ "$default" != "8388608 8388608" -a "$max" != "16777216 16777216" ];then
cat >>/etc/sysctl.conf<<EOF
net.core.rmem_default = 8388608
net.core.wmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
EOF
sysctl -p &>/dev/null
fi
}

9 把NFS Server开机启动放置到 /etc/rc.local

nfs_boot_start(){

if [ egrep "(rpcbind|nfs) start" /etc/rc.local|wc -l -lt 2 ];then
echo -e "\n#nfs server 20171129\n/etc/init.d/rpcbind start\n/etc/init.d/nfs start" >>/etc/rc.local
fi
}

main(){

root_user
con_internet
selinux_cls
iptables_cls
yum_mod
ins_nfs
nfs_conf
sysctl_opt
nfs_boot_start
}
main

转载于:https://blog.51cto.com/lehappy/2089213

你可能感兴趣的文章
java 动态代理
查看>>
微信5.0绑定银行卡教程
查看>>
数字转换为壹仟贰佰叁拾肆的Java方法
查看>>
一个表单对应多个提交按钮,每个提交按钮对应不同的行为
查看>>
tomcat集群时统计session与在线人数
查看>>
Android程序完全退出
查看>>
【Linux】目录权限与文件权限
查看>>
如何将阿拉伯数字每三位一逗号分隔,如:15000000转化为15,000,000
查看>>
select的使用(一)
查看>>
[leetcode]Search a 2D Matrix @ Python
查看>>
java.io.BufferedOutputStream 源码分析
查看>>
Load resources from classpath in Java--reference
查看>>
关于LightMapping和NavMesh烘焙的动态载入
查看>>
(转)Android中使用ormlite实现持久化(一)--HelloOrmLite
查看>>
C语言近程型(near)和远程型(far)的区别是什么?
查看>>
jQuery选择器总结
查看>>
《Continuous Delivery》 Notes 1: The problem of delivering software
查看>>
java android 将小数度数转换为度分秒格式
查看>>
一张图知道HTML5布局(图)
查看>>
LINQ To SQL在N层应用程序中的CUD操作、批量删除、批量更新
查看>>