Simple configuration of Virtual Machine experiment environment using shell script

Source: Internet
Author: User

Simple configuration of Virtual Machine experiment environment using shell script

After writing the shell script, you can find that this is really convenient. When you want to complete some trivial and detailed commands at one time, the script is undoubtedly the best choice, it is convenient and quick. The key is that it is really a must for a lazy person.

Since CentOS6.5 is installed in a minimal and experimental environment, that is, it is installed on vmware workstations. After the first installation is complete, After configuring the IP address information, an initial snapshot is created so that the system can be restored quickly through the snapshot after the next experiment.

However, due to the requirements of the experiment environment, such as firewall, SELinux, CD mounting, and yum source configuration, these are the most frequently-modified options, there is no vim compilation tool or man manual query in the system, so each time you restore the snapshot, you have to deal with these trivial issues. For this reason, I wrote such a small script. The content is not complicated, but it is also a learning process. I will share it with you. By the way, please advise ......

#! /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

This article permanently updates the link address:

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.