2021-05-12 14:32:11
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
本文永久更新連結地址:http://www.linuxidc.com/Linux/2015-09/122802.htm
相關文章