shell指令碼實現虛擬機器實驗環境的簡單配置

來源:互聯網
上載者:User

shell指令碼實現虛擬機器實驗環境的簡單配置

親自寫過shell指令碼後才發現,這玩意真是太方便了,當你想把一些瑣碎的、細節性的小指令一次性來完成時,指令碼無疑是最好的選擇,方便、快捷,關鍵是真是懶人必備啊。

由於安裝的CentOS6.5是迷你安裝,且是實驗環境,即安裝在vmware workstations上面,在首次安裝完成後,配置完IP地址的相關資訊後,就做了一個初始的快照,以便下次實驗完後,可以通過快照快速還原系統。

但是由於實驗環境的要求,例如防火牆、SELinux、光碟片掛載、yum源配置等,都是最常需要修改的選項,並且由於迷你安裝,系統裡並沒有vim編譯工具和man手冊的查詢,所以導致每次還原快照後,還要處理這些瑣碎的問題。為此,我就專門寫了這麼一個小指令碼,內容並不複雜,但是也是一種學習過程,發出來和大家一起分享一下,順便求指教......

#!/bin/bash
# Config some simple order when the system start
# Create by phoenix
 
# Specify the path
server=/etc/init.d
yum=/etc/yum.repos.d
mountdir=/media/cdrom
selinux=/etc/selinux/config
 
# stop the iptabes and set it can't start when the system start
$server/iptables stop &>/dev/null
if [ "$?" = "0" ]; then
  chkconfig iptables off
  chkconfig ip6tables off
  echo "1# The iptables stop successfully"
else
  echo "1# The iptables stop failed"
fi
 
# shutdown the selinxu system
setenforce 0 && sed -e 's/^SELINUX=enforcing/SELINUX=disabled/g' $selinux >$selinux.bak
mv -f $selinux.bak $selinux
echo "2# The selinux system is disabled"
 
# Mount the CD-ROM
mount |grep sr0 &>/dev/null
if [ ! "$?" = "0" ]; then
  if [ ! -e $mountdir ]; then
      mkdir -p $mountdir &>/dev/null
  else
      mount /dev/cdrom $mountdir &>/dev/null
      echo "3# The CD-ROM is mounting successfully"
  fi 
else
  echo "3# The CD-ROM is already mounted"
fi
 
# Config the source of yum
if [ -e $yum/CentOS-Base.repo ];then
  mv -f $yum/CentOS-Base.repo $yum/CentOS-Base.repo.bak &>/dev/null
else
  echo "4# Starting config the source of yum"
    sleep 3
fi
 
 sed  -e 's/^enabled=0/enabled=1/g' $yum/CentOS-Media.repo >$yum/CentOS-Media.repo.bak
 mv -f $yum/CentOS-Media.repo.bak $yum/CentOS-Media.repo>>/dev/null
 
yum clean all &>/dev/null &&echo "5# The source of yum configed successfully"
 
# Modify the code of language
echo "#LANG=zh_CN.UTF-8" >/etc/sysconfig/i18n
echo "6# The language is modify successfully"
 
# Install the tools "VIM" and "MAN"
echo "7# Starting install vim and man,please wait......"
sleep 3
yum install vim man -y &>/dev/null
 
# Reboot the system when all the work is done
echo "#########  All work is done  ########"
sleep 2
echo "Please wait the syatem restart......"
sleep 2
init 6

本文永久更新連結地址:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.