#!/bin/bash
#Auth:Darius
#CentOS_7配备实验环境
eno=`ifconfig|awk
‘{print $1}’|head -1|awk -F “:” ‘{print $1}’`
file=/etc/sysconfig/network-scripts/ifcfg-$eno
dir=/etc/yum.repos.d
#关闭防火墙
systemctl stop
firewalld.service
systemctl disable
firewalld.service
#查看防火墙是不是打开
firewall-cmd
–state
#清空防火墙规则
iptables -F
#临时关门selinux
setenforce 0

#!/bin/bash
#Auth:Darius
#自动化安装dhcp服务
#shell脚本达成虚拟机实验环境的简练安顿,shell搭建CentOS_7基础环境。”$1″为测试IP,用来查阅IP段是不是能通
eno=`ifconfig|awk
‘{print $1}’|head -1|awk -F “:” ‘{print $1}’`
file=/etc/sysconfig/network-scripts/ifcfg-$eno
file1=/etc/dhcp/dhcpd.conf
dir=/etc/yum.repos.d
#ip地址设置
ping -c 4 -i 0.1 -W 2
$1 &>/dev/null
if [ $? -ne 0
];then
echo -e
“DEVICE=$eno\nTYPE=Ethernet\nONBOOT=yes\nBOOTPROTO=static”
>$file
read -p
“请输入ip地址”: ip
read -p
“请输入子网掩码”: nt
read -p “请输入网关”:
gw
echo “IPADDR=$ip”
>> $file
echo “NETMASK=$nt”
>>$file
echo “GATEWAY=$gw”
>>$file
if [ $? -eq 0
]
then
[ $? -eq 0 ] && echo
“IP地址配置成功”
else
echo
“IP地址配置战败”
fi
else
echo
“互联网测试成功”
fi
#创设yum本地仓库
mkdir
/media/cdrom
mount /dev/sr0
/media/cdrom/
#安装光盘活动挂载
echo “/dev/sr0
/media/cdrom iso9660 defaults 0 0” >> /etc/fstab
mkdir $dir/bak
mv $dir/C*
$dir/bak/
echo -e
“[yum]\nname=yum\nbaseurl=file:///media/cdrom\ngpgcheck=0\nenabled=1”
>$dir/yum.repo
yum clean all
&>/dev/null
yum makecache
&>/dev/null
echo
“yum仓库打造达成”
#检测并设置dhcp服务
yum install -y dhcp
&>/dev/null
echo
“dhcp服务安装成功”
cat
/usr/share/doc/dhcp*/dhcpd.conf.sample >$file1
[ $? -eq 0 ] && echo
“模板复制成功”
cp $file1
/etc/dhcp/dhcpd.conf.bak
echo -e “subnet
192.168.1.0 netmask 255.255.255.0{\nrange 192.168.1.2
192.168.1.100;\noption routers 192.168.1.1;\n}”
>>$file1
echo
“文件配置落成”
service dhcpd start
&>/dev/null
chkconfig dhcpd on
&>/dev/null
[ $? -eq 0 ] && echo
“dhcp服务已启动”

亲自写过shell脚本后才意识,那玩意真是太方便了,当你想把部分零碎的、细节性的小指令一遍性来完结时,脚本无疑是最好的选项,方便、快速,关键是真是懒人必备啊。

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

本文永久更新链接地址:

亲自写过shell脚本后才察觉,那东西真是太方便了,当您想把有些零星的、细节性的小指令三遍性…

#永恒关闭selinux
sed -i
‘s/=enforcing/=disabled/’ /etc/sysconfig/selinux
sed -i
‘s/^SELINUX=.*/SELINUX=disabled/g’ /etc/selinux/config
#修改主机名
echo
“当前主机名:$(hostname)”
read -p
“请输入新主机名:” hostname_input
hostname
$hostname_input &> /dev/null
hostnamectl
set-hostname $hostname_input &> /dev/null

鉴于设置的CentOS6.5是最小化安装,且是尝试环境,即安装在vmware
workstations上边,在首次安装到位后,配置完IP地址的相关新闻后,就做了一个发端的快照,以便下次实验完后,可以经过快照连忙还原系统。

#ip地址设置
rm -rf
/etc/udev/*
echo -e
“DEVICE=$eno\nTYPE=Ethernet\nONBOOT=yes\nBOOTPROTO=static”
>$file
read -p “请输入ip地址”:
ip
read -p
“请输入子网掩码”: nt
read -p “请输入网关”:
gw
echo “IPADDR=$ip”
>> $file
echo “NETMASK=$nt”
>>$file
echo “GATEWAY=$gw”
>>$file
[ $? -eq 0 ] && echo
“IP地址配置成功”
#打造yum本地仓库
mkdir
/media/cdrom
mount /dev/sr0
/media/cdrom/
#安装光盘活动挂载
echo “/dev/sr0
/media/cdrom iso9660 defaults 0 0” >> /etc/fstab
mkdir $dir/bak
mv $dir/C*
$dir/bak/
echo -e
“[yum]\nname=yum\nbaseurl=file:///media/cdrom\ngpgcheck=0\nenabled=1”
>$dir/yum.repo
yum clean all
&>/dev/null
yum makecache
&>/dev/null
echo
“yum仓库营造完结”
yum install -y vim gcc
gcc-c++ make &>/dev/null

只是出于试验环境的须求,例如防火墙、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

澳门金沙国际 1

相关文章