root_user(){
[ $UID -ne 0 ] && { echo "请使用root用户";exit 1; }
}
con_internet(){
ping -c2 mirrors.aliyun.com &>/dev/null
[ $? -ne 0 ] && { echo "无法连接到Internet";exit 1; }
}
selinux_cls(){
if [ getenforce
!= "Disabled" ];then
setenforce 0
sed -ir ‘s/^(SELINUX=).*/\1disabled/‘ /etc/sysconfig/selinux
fi
}
iptables_cls(){
if ! /etc/init.d/iptables status|grep -q ‘not running‘;then
/etc/init.d/iptables stop
chkconfig iptables off
fi
}
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 http://mirrors.aliyun.com/repo/Centos-6.repo
fi
}
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
}
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
}
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
}
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
原文地址:http://blog.51cto.com/lehappy/2089213