Shell Script Installation Nfs-server

Source: Internet
Author: User
Tags aliyun egrep

#!/bin/bash
: <<desc
Program:
NFS Server installbr/>[email protected]
20171129 v1.0
20171130 v1.1 Modify the following:
1. Cancel the grep "style" file &>/dev/null if [$?-ne 0];then Usage, modify to if grep-q "style" file; then method
2, all changed to function, the user can call as needed, if you do not need to determine whether you can connect to the Internet, you can comment in main function or it will take effect
DESC
Export lang= "ZH_CN. UTF-8 "
Export Path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
[-e/etc/init.d/functions] &&. /etc/init.d/functions

1 Deciding whether to root

Root_user () {
[$UID-ne 0] && {echo "Please use root user"; exit 1;}
}

2 Determine if you can connect to the Internet

Con_internet () {
PING-C2 mirrors.aliyun.com &>/dev/null
[$?-ne 0] && {echo "Cannot connect to the Internet"; exit 1;}
}

3 is selinux off

Selinux_cls () {
if [! getenforce = "Disabled"];then
Setenforce 0
Sed-ir ' s/^ (selinux=). */\1disabled/'/etc/sysconfig/selinux
Fi
}

4 Iptables whether to close

Iptables_cls () {
if! /etc/init.d/iptables status|grep-q ' not running ';
/etc/init.d/iptables stop
Chkconfig iptables off
Fi
}

5 Yum Modifications

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
}

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 Configuring the/etc/exports document, the NFS server default directory is set to/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 Optimizing NFS, setting/etc/sysctl.conf documentation

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 Place NFS Server on boot to/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

Shell Script Installation Nfs-server

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.