本文共 2290 字,大约阅读时间需要 7 分钟。
#!/bin/bash
: <<DESCProgram:NFS Server installroot_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" ];thensetenforce 0sed -ir 's/^(SELINUX=).*/\1disabled/' /etc/sysconfig/selinuxfi} iptables_cls(){
if ! /etc/init.d/iptables status|grep -q 'not running';then/etc/init.d/iptables stopchkconfig iptables offfi}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.bakwget -O /etc/yum.repos./CentOS-Base.reop fi}ins_nfs(){
if [rpm -aq rpcbind nfs-utils|wc -l
-lt 2 ];thenyum install -y rpcbind nfs-utils &>/dev/nullif [ $? -ne 0 ];thenecho "NFS Server install fail"exit 1fi/etc/init.d/rpcbind start &>/dev/null/etc/init.d/nfs start &>/dev/nullfiif [ netstat -lntup|egrep "rpcbind|nfs"|wc -l
-lt 6 ];thenaction "NFS Server install..." /bin/fasleelseaction "NFS Server install..." /bin/truefi} nfs_conf(){
[ -d /nfsnobody ] || mkdir /nfsnobodychown -R nfsnobody:nfsnobody /nfsnobodyif [ -s /etc/exports ];thenecho '/nfsnobody 192.168.0.0/24(rw,all_squash,sync)' >>/etc/exportselseecho '/nfsnobody 192.168.0.0/24(rw,all_squash,sync)' >/etc/exportsfiexportfs -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" ];thencat >>/etc/sysctl.conf<<EOFnet.core.rmem_default = 8388608net.core.wmem_default = 8388608net.core.rmem_max = 16777216net.core.wmem_max = 16777216EOFsysctl -p &>/dev/nullfi}nfs_boot_start(){
if [egrep "(rpcbind|nfs) start" /etc/rc.local|wc -l
-lt 2 ];thenecho -e "\n#nfs server 20171129\n/etc/init.d/rpcbind start\n/etc/init.d/nfs start" >>/etc/rc.localfi} main(){
root_usercon_internetselinux_clsiptables_clsyum_modins_nfsnfs_confsysctl_optnfs_boot_start}main转载于:https://blog.51cto.com/lehappy/2089213