#!/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=$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服务已开行”

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

RHEL6 无人值守搭建脚本:

亲身写过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_shell搭建CentOS_7基础条件,无人值守搭建脚本。input &> /dev/null

  1. #!/bin/bash   
  2. # by kumu 2012-07-28   
  3. # RHEL6 unattended deployment,用于RHEL6无人值守搭建.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.     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 #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  

是因为设置的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

澳门金沙国际 1

唯独出于试验环境的需求,例如防火墙、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

澳门金沙国际 2

相关文章