澳门新萄京官方网站-www.8455.com-澳门新萄京赌场网址

澳门新萄京官方网站:shell编写自动化安装dhcp服

2019-06-22 作者:澳门新萄京官方网站   |   浏览(187)

#!/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服务
#"$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=$enonTYPE=EthernetnONBOOT=yesnBOOTPROTO=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=yumnbaseurl=file:///media/cdromngpgcheck=0nenabled=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脚本后才意识,那玩意真是太方便了,当你想把部分零碎的、细节性的小指令二回性来产生时,脚本无疑是最佳的挑三拣四,方便、急忙,关键是真是懒人必备啊。

由于设置的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脚本后才发觉,那玩意儿真是太有利了,当您想把一些零星的、细节性的小指令贰回性...

亲自写过shell脚本后才察觉,这厮真是太方便了,当您想把有些零碎的、细节性的小指令叁回性来产生时,脚本无疑是最佳的挑三拣四,方便、火速,关键是当成懒人必备啊。

RAV4HEL6 无人值班守护搭建脚本:

#千古关闭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地址的连带消息后,就做了二个初叶的快速照相,以便后一次实验完后,能够经过快速照相急速还原系统。

  1. #!/bin/bash   
  2. # by kumu 2012-07-28   
  3. # 奥迪Q5HEL6 unattended deployment,用于XC90HEL6无人值班守护搭建.v0.1    
  4. # 有欠缺的地点还请见谅   
  5.   
  6. #搭建yum   
  7. Yum_build()  
  8. {  
  9.     yum clean all &>/dev/null  
  10.     num_list=$(yum list | wc -l)  
  11.     yum clean all &>/dev/null  
  12.   
  13.     if [[ $num_list < 2000 ]];then  
  14.   
  15.     mount /dev/cdrom /mnt  
  16.         if [ -d /etc/yum.repos.d/bak ];then  
  17.             mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak  
  18.         else  
  19.             mkdir /etc/yum.repos.d/bak  
  20.             mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak  
  21.         fi    
  22.   
  23. cat << EOF > /etc/yum.repos.d/base.repo  
  24. [base]  
  25. name=base  
  26. baseurl=file:///mnt  
  27. enabled=1  
  28. gpgcheck=0  
  29. EOF  
  30.     else  
  31.         echo "yum is ok!"  
  32.     fi  
  33. }  
  34.   
  35. Check_rpm()  
  36. {  
  37.     Packages=(dhcp tftp-server vsftpd syslinux)  
  38.     澳门新萄京官方网站:shell编写自动化安装dhcp服务,shell脚本完毕虚拟机实验情状的简要安排。for i in ${Packages[@]}  
  39.     do  
  40.         if ! rpm -q $i &> /dev/null;then  
  41.              yum install $i -y &>/dev/null  
  42.         fi  
  43.     done  
  44. }  
  45.   
  46. #dhcp服务搭建以及互联网安装教导文件   
  47. dhcp_build()  
  48. {  
  49.     read -p "输入所在subnet、netmask、broadcast、gateway: " subnet netmask broadcast gateway   
  50.     read -p "输入next-server地址: " next_server   
  51.     read -p "提供IP的范围start_ip end_ip: " start_ip end_ip  
  52.   
  53. cat << EOF >/etc/dhcp/dhcpd.conf  
  54. subnet $subnet netmask $netmask {  
  55.   range $start_ip $end_ip;  
  56.   option routers $gateway;  
  57.   option broadcast-address $broadcast;  
  58.   default-lease-time 600;  
  59.   max-lease-time 7200;  
  60.   filename "pxelinux.0";  
  61.   next-server $next_server;  
  62. }  
  63. EOF  
  64.   
  65. cat << EOF >/var/lib/tftpboot/pxelinux.cfg/default  
  66. default vesamenu.c32  
  67. #prompt 1   
  68. timeout 600  
  69.   
  70. display boot.msg  
  71.   
  72. menu background splash.jpg  
  73. menu title Welcome to Red Hat Enterprise Linux 6.2!  
  74. menu color border 0 #ffffffff #00000000   
  75. menu color sel 7 #ffffffff #ff000000   
  76. menu color title 0 #ffffffff #00000000   
  77. menu color tabmsg 0 #ffffffff #00000000   
  78. menu color unsel 0 #ffffffff #00000000   
  79. menu color hotsel 0 #ff000000 #澳门新萄京官方网站:shell编写自动化安装dhcp服务,shell脚本完毕虚拟机实验情状的简要安排。ffffffff   
  80. menu color hotkey 7 #ffffffff #ff000000   
  81. menu color scrollbar 0 #ffffffff #00000000   
  82.   
  83. label linux  
  84.   menu label ^Install or upgrade an existing system  
  85.   menu default  
  86.   kernel vmlinuz  
  87.   append ks=ftp://$next_server/ks.cfg initrd=initrd.img  
  88. EOF  
  89. }  
  90.   
  91. #无人值班守护配置文件   
  92. ks_cfg()  
  93. {  
  94. read -p "请输入无人值班守护ftp地址: " ftp  
  95. cat <<EOF >/var/ftp/ks.cfg  
  96. firewall --disabled  
  97. install  
  98. url --url="ftp://$ftp/iso"  
  99. rootpw --iscrypted $1$A9aGh0yl$ahDdo0eAvQFAplXTeBkX//  
  100. auth  --useshadow  --passalgo=sha512  
  101. text  
  102. firstboot --disable  
  103. keyboard us  
  104. lang zh_CN  
  105. selinux --disabled  
  106. logging --level=info  
  107. reboot  
  108. timezone  Asia/Shanghai  
  109. network --bootproto=dhcp --device=eth0 --onboot=on  
  110. bootloader --location=mbr  
  111. zerombr  
  112. clearpart --all --initlabel   
  113.   
  114. part /boot --asprimary --fstype="ext4" --size=200  
  115. part swap --asprimary --fstype="swap" --size=2048  
  116. part / --asprimary --fstype="ext4" --size=100000  
  117.   
  118. %packages  
  119. @additional-devel  
  120. @backup-client  
  121. @base 
  122. @basic-desktop  
  123. @chinese-support  
  124. @client-mgmt-tools  
  125. @compat-libraries  
  126. @console-internet  
  127. @debugging 
  128. @desktop-debugging  
  129. @desktop-platform  
  130. @desktop-platform-devel  
  131. @development 
  132. @dial-up  
  133. @directory-client  
  134. @eclipse 
  135. @emacs 
  136. @fonts 
  137. @general-desktop  
  138. @graphical-admin-tools  
  139. @graphics 
  140. @hardware-monitoring  
  141. @infiniband 
  142. @input-methods  
  143. @internet-browser  
  144. @java-platform  
  145. @kde-desktop  
  146. @large-systems  
  147. @legacy-unix  
  148. @legacy-x  
  149. @mainframe-access  
  150. @network-file-system-client  
  151. @network-tools  
  152. @performance 
  153. @perl-runtime  
  154. @remote-desktop-clients  
  155. @scientific 
  156. @security-tools  
  157. @server-platform-devel  
  158. @smart-card  
  159. @storage-client-fcoe  
  160. @storage-client-iscsi  
  161. @storage-client-multipath  
  162. @system-management  
  163. @system-management-messaging-client  
  164. @system-management-messaging-server  
  165. @system-management-snmp  
  166. @system-management-wbem  
  167. @technical-writing  
  168. @tex 
  169. @x11  
  170. hmaccalc  
  171. %end  
  172. EOF  
  173. }  
  174.   
  175. #调用函数   
  176. Yum_build  
  177. Check_rpm  
  178.   
  179. #拷贝系统引导文件   
  180. cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/  
  181. cp  -r /mnt/isolinux/* /var/lib/tftpboot/  
  182. mkdir /var/lib/tftpboot/pxelinux.cfg &>/dev/null  
  183. mv /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default  
  184.   
  185. #调用函数   
  186. dhcp_build  
  187. ks_cfg  
  188.   
  189. mkdir /var/ftp/iso &>/dev/null  
  190. mount /dev/cdrom /var/ftp/iso &>/dev/null  
  191.   
  192. #安装开机运转   
  193. chkconfig tftp on   
  194. chkconfig dhcpd on  
  195. chkconfig vsftpd on  
  196.   
  197. #刷新服务   
  198. service xinetd restart &>/dev/null  
  199. service dhcpd restart &>/dev/null  
  200. service vsftpd restart &>/dev/null  

#ip地址设置
rm -rf /etc/udev/*
echo -e "DEVICE=$enonTYPE=EthernetnONBOOT=yesnBOOTPROTO=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=yumnbaseurl=file:///media/cdromngpgcheck=0nenabled=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手册的询问,所以导致每一遍过来快速照相后,还要管理这个零碎的主题素材。为此,小编就非常写了这样多个小本子,内容并不复杂,可是也是一种学习进程,发出去和大家齐声享受一下,顺便求指教......

澳门新萄京官方网站 1

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

澳门新萄京官方网站 2

本文由澳门新萄京官方网站发布于澳门新萄京官方网站,转载请注明出处:澳门新萄京官方网站:shell编写自动化安装dhcp服

关键词: