Simple System Installation Optimization script

Source: Internet
Author: User
Tags i18n

#!/bin/bash#by caosm  #time  20161122ipaddr () {echo  "=============== Configure IP Address and host name ==========="         read -p  "Please enter your IP address:"  IPADDR         read -p  "Please enter your subnet mask:"  NETMASK          read -p  "Please enter your gateway address:"  GATEWAY         read -p  "Please enter your DNS1:"  DNS1sed -i   '/^ipaddr.*$/d '  /etc/sysconfig/ network-scripts/ifcfg-eth0sed -i   '/^netmask.*$/d '  /etc/sysconfig/network-scripts/ ifcfg-eth0sed -i   '/^gateway.*$/d '  /etc/sysconfig/network-scripts/ifcfg-eth0sed -i    '/^dns1.*$/d '  /etc/sysconfig/network-scripts/ifcfg-eth0sed -i   ' s/onboot=no/ Onboot=yes/g '  /etc/sysconfig/network-scripts/ifcfg-eth0sed -i   ' S/bootproto=dhcp/bootproto =static/g '  /etc/sysconfig/network-scripts/ifcfg-eth0echo  "Ipaddr= $IPADDR"  >> /etc/sysconfig/network-scripts/ifcfg-eth0echo   "netmask= $NETMASK"  >> /etc/sysconfig/network-scripts/ifcfg-eth0echo  "gateway=$ GATEWAY " >> /etc/sysconfig/network-scripts/ifcfg-eth0echo " dns1= $DNS 1 " >>  /etc/sysconfig/network-scripts/ifcfg-eth0        service   network restart >&/dev/nullping -c 3 -w 5 www.baidu.com  >&/dev/nullif  [[ $? != 0 ]];then      echo   "  No Internet access please check configuration  "     fiecho  "============================================ ===== "echo " "  sleep 2} #HOSTNAMEhostname () {echo " ================== Configure host name ============ ======== "read  -p " Please enter your host name: " HOSTNAMEsed -i  ' 3, $d '  /etc/hostssed -i   ' 2, $d '  /etc/sysconfig/networksed -i   '/^hostname.*$/d '  /etc/sysconfig/network-scripts/ifcfg-eth0sed  -i   '/^hostname.*$/d '  /etc/hostsecho  "hostname= $HOSTNAME"  >> /etc/ Sysconfig/networkipaddr= ' ip a  | grep  "Global eth0"  | awk  ' {print  $2} '  | awk -F  '/'   ' {print $1} ' echo  ' $IPADDR    $HOSTNAME '  >>/etc/hosts#echo -n   "  $HOSTNAME"  >> /etc/hostsecho  "= = = ================================================= "echo " "  sleep 2}# yum_163configyum () {echo  "================ Update for domestic yum source =================="   cd /etc/yum.repos.d/    \cp centos-base.repo centos-base.repo.$ (date +%f)   ping -c 1  www.163.com>/dev/null  if [ $? -eq 0 ];then  wget http:// Mirrors.163.com/.help/centos6-base-163.repo  else    echo  "Unable to connect to the network. "    exit $?  fi  \cp CentOS-Base-sohu.repo  centos-base.repoyum clean all#yum makecache  >& /dev/nullaction  " Configure domestic yum complete "  /bin/trueecho " ================================================= "echo "   &NBSP;SLEEP&NBSP;2} #time  syncsyncsystime () {echo  "================ Configure time synchronization ====================="    \cp /var/spool/cron/root /var/spool/cron/root.$ (date +%f)  2>/dev/null   Ntpdate= ' Grep ntpdate /var/spool/cron/root 2>/dev/null |wc -l '   if  [  $NTPDATE  -eq 0 ];then    echo  "#times  sync by  lee at $ (date +% f) " >>/var/spool/cron/root    echo " * /5 * * * * /usr/sbin/ntpdate timE.windows.com >/dev/null 2>&1 " >> /var/spool/cron/root  fi   echo  ' #crontab  -l '     crontab -l#action  "Configure time synchronization Complete"  /bin/ trueecho  "=================================================" echo  ""   sleep 2} #Charset  zh_cn. utf-8initi18n () {echo  "================ changed to Chinese character set ================="   \cp /etc/sysconfig/i18n  /etc/sysconfig/i18n.$ (date +%f)   echo  "lang=" ZH_CN. UTF-8 " >/etc/sysconfig/i18n  source /etc/sysconfig/i18n  echo " #cat  /etc/sysconfig/i18n '   grep LANG /etc/sysconfig/i18n#action  ' changes the character set ZH_CN. UTF-8 complete " /bin/trueecho " ================================================= "echo "    SLEEP&NBSP;2} #Close  selinux and iptablesfirewall () {echo  "============ disable Selinux and turn off firewall ====== ======== "  \cp /etc/selinux/config /etc/selinux/config.$ (date +%f)   /etc/init.d/iptables stop  sed -i   ' s/selinux=enforcing/selinux=disabled/g '  /etc/selinux/config  setenforce 0   /etc/init.d/iptables status  echo  ' #grep  selinux=disabled /etc/selinux/ config  '    grep SELINUX=disabled /etc/selinux/config   echo  ' #getenforce   '   getenforce  #action   ' Disable SELinux and turn off firewall completion '  /bin/trueecho  ' ===== ============================================ "echo " "  sleep 2} #menu2menu2 () {while  Truedoclearcat << eof----------------------------------------|****please enter your  choice:[0-6]****|----------------------------------------(1)   Configure IP address to   (2)   Configure for domestic yum source mirroring (3)   Set time synchronization (4)   Configure Chinese Character set (5)   Disable SELinux and shut down Firewall (6)   Configure host name (0)   Return to the previous menu eofread -p  " Please enter your&nbsP choice[0-6]:  " input2case " $input 2 " in  0)   clear  break   ;; &NBSP;&NBSP;1)   ipaddr  ;; &NBSP;&NBSP;2)   configYum  ;; &NBSP;&NBSP;3)   syncSysTime  ;; &NBSP;&NBSP;4)   initI18n  ;; &NBSP;&NBSP;5)   Firewall  ;; &NBSP;&NBSP;6)   hostname  ;;    *)  echo  "----------------------------------"      echo   "|          warning!!!             | "      echo  "|   please enter right choice!    | "      echo  "----------------------------------"      for  i in  ' seq -w 3 -1 1 '        do          echo -ne  "\b\b$i";   sleep  1;     done     clearesacdone} #menuwhile   truedoclearecho  "========================================" echo  '            Linux Optimization              '    echo  "========================================" cat << eof| -----------system infomation-----------| date       : $DATE |  HOSTNAME&NBSP;&NBSP;&NBSP: $HOSTNAME | user       : $USER | ip  &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP: $IPADDR | disk_used  : $DISK _sda| cpu_ AVERAGE: $cpu _uptime----------------------------------------|****please enter your choice:[1-3]* ***|----------------------------------------(1)   One-click Optimization (2)   Custom optimization (3)   Exit eof#choiceread -p  "Please enter your  choice[0-3]:  " input1case " $input 1 " in1)    ip_hostname   configyum  syncsystime  initi18n  initfirewall  hostname  ;; 2)   menu2  ;; 3)    clear   break  ;; *)      echo  "----------------------------------"   echo  "|           warning!!!             | "   echo  "|   please enter right choice!   |"   echo  "----------------------------------"   for i in  ' seq -w  3 -1 1 '       do         Echo -ne&nbsP; " \b\b$i ";         sleep 1;  done  clearesac   done


This article from "Innocence" blog, reproduced please contact the author!

Simple System Installation Optimization script

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.