码迷,mamicode.com
首页 > 其他好文 > 详细

Centos 远程重装系统脚本

时间:2016-05-20 17:40:59      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:kickstart pxe 远程安装 重装系统 centos

因公司有些服务器需要经常重装系统,每次跑机房比较麻烦,特做此脚本进行远程安装

目前因Http服务器空间有限,只左右Centos6.1-7.0 64位系统的远程安装

如需增加  只需按照以前的步骤和方法添加即可。

1、http服务器的搭建

我这里使用IIS作为http服务器(linux下最好)

启用IIS目录浏览功能,并在http头标签页的MIME类型 中添加相应的MIME类型,方便下载此目录下所有文件。

技术分享

新建MIME类型,在拓展名和MIME类型中都填*

确定保存。

 技术分享

2、解压镜像文件到http服务器

技术分享

技术分享

3、在需要重装系统的服务器上运行一下脚本

   使用您自己的http服务器地址替换脚本中的IP地址

#!/bin/bash
 
# Centos AutoInstall 
# VER. 1.1.0 - http://www.fenei.net
# 此脚本主要为方便远程重装centos系统使用,目前因空间问题只做到6.1-7.0的64位版本
# 此脚本需要搭建一套http服务器并启用目录浏览,将需要远程安装的镜像解压到http服务器
# 脚本运行完成以后需要使用vnc客户端连接服务器进行安装.重装系统的服务器需和VNC客户端互通
# http://babyfenei.blog.51cto.com/443861/1775441
# 2016年5月20日
# 
#
# Fenei QQ:407603129 Mail:babyfenei@qq.com
# VER. 1.1.0 - http://www.fenei.net
#
#=====================================================================
stty erase ^h 
stty erase ^H
while true
do
	printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
	printf "             +                                                    +\n"
	printf "             +                  请输入服务器IP地址                +\n"
	printf "             +         ※注意:此IP地址用作VNC远程连接使用※      +\n"
	printf "             +         ※      同时,此IP为重装后系统默认IP※      +\n"
	printf "             +         ※      建议输入您将要配置的IP地址 ※      +\n"
	printf "             +          eg:192.168.1.10   124.115.146.254        +\n"
	printf "             +                                                    +\n"
	printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
	read IPADDRESS
	clear
	printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
	printf "             +                                                    +\n"
	printf "             +                  请输入服务器子网掩码              +\n"
	printf "             +          eg:255.255.255.0  255.255.255.248        +\n"
	printf "             +                                                    +\n"
	printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
	read NETMASK
	clear
	printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
	printf "             +                                                    +\n"
	printf "             +                  请输入服务器网关地址              +\n"
	printf "             +          eg:192.168.1.1  255.255.255.248          +\n"
	printf "             +                                                    +\n"
	printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
	read GATEWAY
	clear
	printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
	printf "             +                                                    +\n"
	printf "             +                  请输入服务器DNS地址               +\n"
	printf "             +          eg:180.76.76.76 114.114.114.114          +\n"
	printf "             +                                                    +\n"
	printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
	read DNS
	clear
	printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
	printf "             +                                                    +\n"
	printf "             +                  请输入VNC远程密码                 +\n"
	printf "             +          eg:admin    Admin#@!1234567              +\n"
	printf "             +                                                    +\n"
	printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
	read PASSWD
	clear
	printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
	printf "             +              您的服务器IP配置信息为                          +\n"
	printf "             +        IP地址: $IPADDRESS  子网掩码:$NETMASK	            +\n"
	printf "             +        网关  :$GATEWAY    DNS     : $DNS	   	    +\n"
	printf "             +        请确保配置信息正确,否则将无法远程登录                +\n"
	printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
	read anykey
	clear
	printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
	printf "             ++++++++++++请选择需要安装的Centos系统版本++++++++++++++++\n"
	printf "             +                                                        +\n"
	printf "             +        		  1.CentOS 6.1-X86_64                 +\n"
	printf "             +       		  2.CentOS 6.2-X86_64                 +\n"
	printf "             +       	          3.CentOS 6.3-X86_64                 +\n"
	printf "             +       		  4.CentOS 6.4-X86_64                 +\n"
	printf "             +       		  5.CentOS 6.5-X86_64                 +\n"
	printf "             +       		  6.CentOS 6.6-X86_64                 +\n"
	printf "             +       		  7.CentOS 6.7-X86_64                 +\n"
	printf "             +      		  8.CentOS 7.0-X86_64                 +\n"
	printf "             +                                                        +\n"
	printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
	printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
	read selec
		case "$selec" in
			"1")
			##### CentOS 6.1-X86_64 #####
		    mkdir /centos_install
			cd /centos_install
			wget http://服务器IP地址/XP/linux/centos/x86_64/6.1/images/pxeboot/initrd.img
			wget http://服务器IP地址/XP/linux/centos/x86_64/6.1/images/pxeboot/vmlinuz
			cp vmlinuz /boot/vmlinuz.cent.pxe
			cp initrd.img /boot/initrd.img.cent.pxe
			#在"hiddenmenu" 和 "title CentOS..." 增加一项:
			#method中的url为安装centos的源
			sed -i -e "/hiddenmenu/a\title CentOS 6.1-X86_64  Install (PXE)\nroot (hd0,0) \nkernel \/vmlinuz.cent.pxe vnc vncpassword=${PASSWD} headless ip=${IPADDRESS} IP netmask=${NETMASK} gateway=${GATEWAY} dns=${DNS} ksdevice=eth0 method=http:\/\/服务器IP地址\/XP\/linux\/centos\/x86_64\/6.1\/ lang=en_US keymap=us\ninitrd \/initrd.img.cent.pxe" /boot/grub/grub.conf
			;;
		

			"2")
			##### CentOS 6.2-X86_64 #####
			clear
			mkdir /centos_install
			cd /centos_install
			wget http://服务器IP地址/XP/linux/centos/x86_64/6.2/images/pxeboot/initrd.img
			wget http://服务器IP地址/XP/linux/centos/x86_64/6.2/images/pxeboot/vmlinuz
			cp vmlinuz /boot/vmlinuz.cent.pxe
			cp initrd.img /boot/initrd.img.cent.pxe
			#在"hiddenmenu" 和 "title CentOS..." 增加一项:
			#method中的url为安装centos的源
			sed -i -e "/hiddenmenu/a\title CentOS 6.2-X86_64  Install (PXE)\nroot (hd0,0) \nkernel \/vmlinuz.cent.pxe vnc vncpassword=${PASSWD} headless ip=${IPADDRESS} IP netmask=${NETMASK} gateway=${GATEWAY} dns=${DNS} ksdevice=eth0 method=http:\/\/服务器IP地址\/XP\/linux\/centos\/x86_64\/6.2\/ lang=en_US keymap=us\ninitrd \/initrd.img.cent.pxe" /boot/grub/grub.conf
			;;
			

			"3")
			##### CentOS 6.3-X86_64 #####
			clear
			mkdir /centos_install
			cd /centos_install
			wget http://服务器IP地址/XP/linux/centos/x86_64/6.3/images/pxeboot/initrd.img
			wget http://服务器IP地址/XP/linux/centos/x86_64/6.3/images/pxeboot/vmlinuz
			cp vmlinuz /boot/vmlinuz.cent.pxe
			cp initrd.img /boot/initrd.img.cent.pxe
			#在"hiddenmenu" 和 "title CentOS..." 增加一项:
			#method中的url为安装centos的源
			sed -i -e "/hiddenmenu/a\title CentOS 6.3-X86_64  Install (PXE)\nroot (hd0,0) \nkernel \/vmlinuz.cent.pxe vnc vncpassword=${PASSWD} headless ip=${IPADDRESS} IP netmask=${NETMASK} gateway=${GATEWAY} dns=${DNS} ksdevice=eth0 method=http:\/\/服务器IP地址\/XP\/linux\/centos\/x86_64\/6.3\/ lang=en_US keymap=us\ninitrd \/initrd.img.cent.pxe" /boot/grub/grub.conf
			;;
			

			"4")
			##### CentOS 6.4-X86_64 #####
			clear
			mkdir /centos_install
			cd /centos_install
			wget http://服务器IP地址/XP/linux/centos/x86_64/6.4/images/pxeboot/initrd.img
			wget http://服务器IP地址/XP/linux/centos/x86_64/6.4/images/pxeboot/vmlinuz
			cp vmlinuz /boot/vmlinuz.cent.pxe
			cp initrd.img /boot/initrd.img.cent.pxe
			#在"hiddenmenu" 和 "title CentOS..." 增加一项:
			#method中的url为安装centos的源
			sed -i -e "/hiddenmenu/a\title CentOS 6.4-X86_64  Install (PXE)\nroot (hd0,0) \nkernel \/vmlinuz.cent.pxe vnc vncpassword=${PASSWD} headless ip=${IPADDRESS} IP netmask=${NETMASK} gateway=${GATEWAY} dns=${DNS} ksdevice=eth0 method=http:\/\/服务器IP地址\/XP\/linux\/centos\/x86_64\/6.4\/ lang=en_US keymap=us\ninitrd \/initrd.img.cent.pxe" /boot/grub/grub.conf
			;;
			

			"5")
			##### CentOS 6.5-X86_64 #####
			clear
			mkdir /centos_install
			cd /centos_install
			wget http://服务器IP地址/XP/linux/centos/x86_64/6.5/images/pxeboot/initrd.img
			wget http://服务器IP地址/XP/linux/centos/x86_64/6.5/images/pxeboot/vmlinuz
			cp vmlinuz /boot/vmlinuz.cent.pxe
			cp initrd.img /boot/initrd.img.cent.pxe
			#在"hiddenmenu" 和 "title CentOS..." 增加一项:
			#method中的url为安装centos的源
			sed -i -e "/hiddenmenu/a\title CentOS 6.5-X86_64  Install (PXE)\nroot (hd0,0) \nkernel \/vmlinuz.cent.pxe vnc vncpassword=${PASSWD} headless ip=${IPADDRESS} IP netmask=${NETMASK} gateway=${GATEWAY} dns=${DNS} ksdevice=eth0 method=http:\/\/服务器IP地址\/XP\/linux\/centos\/x86_64\/6.5\/ lang=en_US keymap=us\ninitrd \/initrd.img.cent.pxe" /boot/grub/grub.conf
			;;
			

			"6")
			##### CentOS 6.6-X86_64 #####
			clear
			mkdir /centos_install
			cd /centos_install
			wget http://服务器IP地址/XP/linux/centos/x86_64/6.6/images/pxeboot/initrd.img
			wget http://服务器IP地址/XP/linux/centos/x86_64/6.6/images/pxeboot/vmlinuz
			cp vmlinuz /boot/vmlinuz.cent.pxe
			cp initrd.img /boot/initrd.img.cent.pxe
			#在"hiddenmenu" 和 "title CentOS..." 增加一项:
			#method中的url为安装centos的源
			sed -i -e "/hiddenmenu/a\title CentOS 6.6-X86_64  Install (PXE)\nroot (hd0,0) \nkernel \/vmlinuz.cent.pxe vnc vncpassword=${PASSWD} headless ip=${IPADDRESS} IP netmask=${NETMASK} gateway=${GATEWAY} dns=${DNS} ksdevice=eth0 method=http:\/\/服务器IP地址\/XP\/linux\/centos\/x86_64\/6.6\/ lang=en_US keymap=us\ninitrd \/initrd.img.cent.pxe" /boot/grub/grub.conf
			;;

			
			"7")
			##### CentOS 6.7-X86_64 #####
			clear
			mkdir /centos_install
			cd /centos_install
			wget http://服务器IP地址/XP/linux/centos/x86_64/6.7/images/pxeboot/initrd.img
			wget http://服务器IP地址/XP/linux/centos/x86_64/6.7/images/pxeboot/vmlinuz
			cp vmlinuz /boot/vmlinuz.cent.pxe
			cp initrd.img /boot/initrd.img.cent.pxe
			#在"hiddenmenu" 和 "title CentOS..." 增加一项:
			#method中的url为安装centos的源
			sed -i -e "/hiddenmenu/a\title CentOS 6.7-X86_64  Install (PXE)\nroot (hd0,0) \nkernel \/vmlinuz.cent.pxe vnc vncpassword=${PASSWD} headless ip=${IPADDRESS} IP netmask=${NETMASK} gateway=${GATEWAY} dns=${DNS} ksdevice=eth0 method=http:\/\/服务器IP地址\/XP\/linux\/centos\/x86_64\/6.7\/ lang=en_US keymap=us\ninitrd \/initrd.img.cent.pxe" /boot/grub/grub.conf
			;;
			
			"8")
			##### CentOS 7.0-X86_64 #####
			clear
			mkdir /centos_install
			cd /centos_install
			wget http://服务器IP地址/XP/linux/centos/x86_64/6.8/images/pxeboot/initrd.img
			wget http://服务器IP地址/XP/linux/centos/x86_64/6.8/images/pxeboot/vmlinuz
			cp vmlinuz /boot/vmlinuz.cent.pxe
			cp initrd.img /boot/initrd.img.cent.pxe
			#在"hiddenmenu" 和 "title CentOS..." 增加一项:
			#method中的url为安装centos的源
			sed -i -e "/hiddenmenu/a\title CentOS 7.0-X86_64  Install (PXE)\nroot (hd0,0) \nkernel \/vmlinuz.cent.pxe vnc vncpassword=${PASSWD} headless ip=${IPADDRESS} IP netmask=${NETMASK} gateway=${GATEWAY} dns=${DNS} ksdevice=eth0 method=http:\/\/服务器IP地址\/XP\/linux\/centos\/x86_64\/7.0\/ lang=en_US keymap=us\ninitrd \/initrd.img.cent.pxe" /boot/grub/grub.conf
			;;
			
		esac
	clear
	printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
	printf "             +              Centos重装脚本执行成功                +\n"
	printf "             +     请重启服务器后使用VNC客户端远程进行系统安装	  +\n"
	printf "             +             VNC服务器地址:$IPADDRESS:1   	   	  +\n"
	printf "             +             VNC服务器密码:$PASSWD                 +\n"
	printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
	read anykey	
	
	exit
done		

4、运行结束后检查运行结果

less /boot/grub/grub.conf

技术分享

ll /boot/

技术分享

验证成功后重启服务器进行安装

技术分享

技术分享

至此安装完成

Centos 远程重装系统脚本

标签:kickstart pxe 远程安装 重装系统 centos

原文地址:http://babyfenei.blog.51cto.com/443861/1775441

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!