Centos系统远程重装脚本

因公司centos服务器重装需求较多,且服务器没有远控卡,每次重装系统需要到机房操作,费时费力.特作此脚本.

此脚本适用于Centos6.1-Centos7.3 64系统的远程安装.如需其他版本请自行添加!

运行脚本如下:

使用VNC进行远程重装操作!

脚本如下:

#!/bin/bash
 
# Centos AutoInstall 
# VER. 1.1.0 - http://www.fenei.net
# 此脚本主要为方便远程重装centos系统使用,目前因空间问题只做到6.1-7.0的64位版本
# 此脚本需要搭建一套http服务器并启用目录浏览,将需要远程安装的镜像解压到http服务器
# 脚本运行完成以后需要使用vnc客户端连接服务器进行安装.重装系统的服务器需和VNC客户端互通
# 
# 2016年5月20日3

# VER. 2.1.0 - http://www.fenei.net
# 更改自动获取服务器IP地址.
# 新增镜像站点网络连接判断
# 新增centos7系列grub2的安装
# 
# 2017年4月24日
# 
#
# [email protected] Sinpul Network
# http://www.fenei.net
#
#=====================================================================

# 获取本机IP及版本信息
IPADDRESS=$(ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk ‘{print $2}‘|tr -d "addr:")
NETMASK=$(ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk ‘{print $4}‘|tr -d "Mask:")
GATEWAY=$(ip route |grep default|awk ‘{print $3}‘)
DNS=$(cat /etc/resolv.conf | awk ‘NR>1‘ |awk ‘{print $2}‘ | head -n 1)
RELEASE=$(rpm -q centos-release | cut -d ‘-‘ -f 3)

stty erase ^h 
stty erase ^H
stty erase ^?
#将shell运行过程中读取退格键 替换为退格命令,否则会输出 ^H!^?

host=192.168.1.11
ping -c2 $host >>/dev/null
if [ $? -eq 0 ];then
echo “Mirrors network is ok,wait to install ...” 
ping -c5 $host >>/dev/null

	if [ "$RELEASE" = "6" ];
		then
			clear
			printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
			printf "             +                                                    +\n"
			printf "             +                  请输入VNC远程密码                 +\n"
			printf "             +                    ■ 必须6-8位 ■                   +\n"
			printf "             +                    eg:    12345678                +\n"
			printf "             +                                                    +\n"
			printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
			read PASSWD
				clear
				printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
				printf "             +              您的服务器IP配置信息为                           \n"
				printf "             +        IP地址  : $IPADDRESS 									 \n"
				printf "             +        子网掩码:$NETMASK	       						     \n"
				printf "             +        网关    :$GATEWAY   								     \n"
				printf "             +        DNS     : $DNS	   	         				         \n"
				printf "             +        请确保配置信息正确,否则将无法远程登录                 \n"
				printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
				read anykey
					clear                        
					printf "             +++++++++++++++++++++++++++++++++++++++++++++++++++\n"
					printf "             ++++++请选择需要安装的Centos系统版本+++++++++++++++\n"
					printf "             +                                                 +\n"
					printf "             +    1.CentOS 6.1-X86_64   2.CentOS 6.2-X86_64    +\n"
					printf "             +    3.CentOS 6.3-X86_64   4.CentOS 6.4-X86_64    +\n"
					printf "             +    5.CentOS 6.5-X86_64   6.CentOS 6.6-X86_64    +\n"
					printf "             +    7.CentOS 6.7-X86_64   8.CentOS 6.8-X86_64    +\n"
					printf "             +    9.CentOS 6.9-X86_64   a.CentOS 7.0-X86_64    +\n"
					printf "             +    b.CentOS 7.1-X86_64   c.CentOS 7.2-X86_64    +\n"
					printf "             +    d.CentOS 7.3-X86_64                          +\n"
					printf "             +                                                 +\n"
					printf "             +++++++++++++++++++++++++++++++++++++++++++++++++++\n"
					printf "             +++++++++++++++++++++++++++++++++++++++++++++++++++\n"
					read selec
					case "$selec" in
							"1")
							##### CentOS 6.1-X86_64 #####
							clear
							mkdir /centos_install
							cd /centos_install
							curl -O  http://192.168.1.11/linux/centos/x86_64/6.1/images/pxeboot/initrd.img
							curl -O  http://192.168.1.11/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..." 增加一项:
							#repo中的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} noselinux headless ip=${IPADDRESS} IP netmask=${NETMASK} gateway=${GATEWAY} dns=${DNS} ksdevice= method=http:\/\/192.168.1.11\/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
							curl -O  http://192.168.1.11/linux/centos/x86_64/6.2/images/pxeboot/initrd.img
							curl -O  http://192.168.1.11/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..." 增加一项:
							#repo中的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} noselinux headless ip=${IPADDRESS} IP netmask=${NETMASK} gateway=${GATEWAY} dns=${DNS} ksdevice= method=http:\/\/192.168.1.11\/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
							curl -O  http://192.168.1.11/linux/centos/x86_64/6.3/images/pxeboot/initrd.img
							curl -O  http://192.168.1.11/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..." 增加一项:
							#repo中的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} noselinux headless ip=${IPADDRESS} IP netmask=${NETMASK} gateway=${GATEWAY} dns=${DNS} ksdevice= method=http:\/\/192.168.1.11\/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
							curl -O  http://192.168.1.11/linux/centos/x86_64/6.4/images/pxeboot/initrd.img
							curl -O  http://192.168.1.11/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..." 增加一项:
							#repo中的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} noselinux headless ip=${IPADDRESS} IP netmask=${NETMASK} gateway=${GATEWAY} dns=${DNS} ksdevice= method=http:\/\/192.168.1.11\/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
							curl -O  http://192.168.1.11/linux/centos/x86_64/6.5/images/pxeboot/initrd.img
							curl -O  http://192.168.1.11/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..." 增加一项:
							#repo中的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} noselinux headless ip=${IPADDRESS} IP netmask=${NETMASK} gateway=${GATEWAY} dns=${DNS} ksdevice= method=http:\/\/192.168.1.11\/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
							curl -O  http://192.168.1.11/linux/centos/x86_64/6.6/images/pxeboot/initrd.img
							curl -O  http://192.168.1.11/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..." 增加一项:
							#repo中的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} noselinux headless ip=${IPADDRESS} IP netmask=${NETMASK} gateway=${GATEWAY} dns=${DNS} ksdevice= method=http:\/\/192.168.1.11\/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
							curl -O  http://192.168.1.11/linux/centos/x86_64/6.7/images/pxeboot/initrd.img
							curl -O  http://192.168.1.11/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..." 增加一项:
							#repo中的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} noselinux headless ip=${IPADDRESS} IP netmask=${NETMASK} gateway=${GATEWAY} dns=${DNS} ksdevice= method=http:\/\/192.168.1.11\/linux\/centos\/x86_64\/6.7\/ lang=en_US keymap=us\ninitrd \/initrd.img.cent.pxe" /boot/grub/grub.conf
							;;

							"8")
							##### CentOS 6.8-X86_64 #####
							clear
							mkdir /centos_install
							cd /centos_install
							curl -O  http://192.168.1.11/linux/centos/x86_64/6.8/images/pxeboot/initrd.img
							curl -O  http://192.168.1.11/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..." 增加一项:
							#repo中的url为安装centos的源
							sed -i -e "/hiddenmenu/a\title CentOS 6.8-X86_64  Install (PXE)\nroot (hd0,0) \nkernel \/vmlinuz.cent.pxe vnc vncpassword=${PASSWD} noselinux headless ip=${IPADDRESS} IP netmask=${NETMASK} gateway=${GATEWAY} dns=${DNS} ksdevice= method=http:\/\/192.168.1.11\/linux\/centos\/x86_64\/6.8\/ lang=en_US keymap=us\ninitrd \/initrd.img.cent.pxe" /boot/grub/grub.conf
							;;

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

							"a")
							##### CentOS 7.0-X86_64 #####
							clear
							mkdir /centos_install
							cd /centos_install
							curl -O  http://192.168.1.11/linux/centos/x86_64/7.0/images/pxeboot/initrd.img
							curl -O  http://192.168.1.11/linux/centos/x86_64/7.0/images/pxeboot/vmlinuz
							cp vmlinuz /boot/vmlinuz.cent.pxe
							cp initrd.img /boot/initrd.img.cent.pxe
							#在"hiddenmenu" 和 "title CentOS..." 增加一项:
							#repo中的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} noselinux headless ip=${IPADDRESS} IP netmask=${NETMASK} gateway=${GATEWAY} dns=${DNS} ksdevice= method=http:\/\/192.168.1.11\/linux\/centos\/x86_64\/7.0\/ lang=en_US keymap=us\ninitrd \/initrd.img.cent.pxe" /boot/grub/grub.conf
							;;

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

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

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

						esac

	elif [ "$RELEASE" = "7" ];
	then
		clear
		printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
		printf "             +                                                    +\n"
		printf "             +                  请输入VNC远程密码                 +\n"
		printf "             +                    ■ 必须6-8位 ■                   +\n"
		printf "             +                  eg:     12345678                 +\n"
		printf "             +                                                    +\n"
		printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
		read PASSWD
			clear
			printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
			printf "             +              您的服务器IP配置信息为                           \n"
			printf "             +        IP地址  : $IPADDRESS 									 \n"
			printf "             +        子网掩码:$NETMASK	       						     \n"
			printf "             +        网关    :$GATEWAY   								     \n"
			printf "             +        DNS     : $DNS	   	         				         \n"
			printf "             +        请确保配置信息正确,否则将无法远程登录                 \n"
			printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
			read anykey
				clear                        
				printf "             +++++++++++++++++++++++++++++++++++++++++++++++++++\n"
				printf "             ++++++请选择需要安装的Centos系统版本+++++++++++++++\n"
				printf "             +                                                 +\n"
				printf "             +    1.CentOS 6.1-X86_64   2.CentOS 6.2-X86_64    +\n"
				printf "             +    3.CentOS 6.3-X86_64   4.CentOS 6.4-X86_64    +\n"
				printf "             +    5.CentOS 6.5-X86_64   6.CentOS 6.6-X86_64    +\n"
				printf "             +    7.CentOS 6.7-X86_64   8.CentOS 6.8-X86_64    +\n"
				printf "             +    9.CentOS 6.9-X86_64   a.CentOS 7.0-X86_64    +\n"
				printf "             +    b.CentOS 7.1-X86_64   c.CentOS 7.2-X86_64    +\n"
				printf "             +    d.CentOS 7.3-X86_64                          +\n"
				printf "             +                                                 +\n"
				printf "             +++++++++++++++++++++++++++++++++++++++++++++++++++\n"
				printf "             +++++++++++++++++++++++++++++++++++++++++++++++++++\n"
				read selec
				case "$selec" in
					"1")
					##### CentOS 6.1-X86_64 #####
					clear
					mkdir /centos_install
					cd /centos_install
					curl -O  http://192.168.1.11/linux/centos/x86_64/6.1/images/pxeboot/initrd.img
					curl -O  http://192.168.1.11/linux/centos/x86_64/6.1/images/pxeboot/vmlinuz
					cp vmlinuz /boot/vmlinuz.cent.pxe
					cp initrd.img /boot/initrd.img.cent.pxe

					cat >> /etc/grub.d/40_custom << EOF
				menuentry "NetInstall" {
					set root=(hd0,1)
					linux /vmlinuz.cent.pxe repo=http://192.168.1.11/linux/centos/x86_64/6.1/ vnc vncpassword=${PASSWD} ip=${IPADDRESS} netmask=${NETMASK} gateway=${GATEWAY} nameserver=${DNS} noselinux headless
					initrd /initrd.img.cent.pxe
				}
EOF

					grub2-mkconfig --output=/boot/grub2/grub.cfg
					grub2-reboot NetInstall
					;;

					"2")
					##### CentOS 6.2-X86_64 #####
					clear
					mkdir /centos_install
					cd /centos_install
					curl -O  http://192.168.1.11/linux/centos/x86_64/6.2/images/pxeboot/initrd.img
					curl -O  http://192.168.1.11/linux/centos/x86_64/6.2/images/pxeboot/vmlinuz
					cp vmlinuz /boot/vmlinuz.cent.pxe
					cp initrd.img /boot/initrd.img.cent.pxe

					cat >> /etc/grub.d/40_custom << EOF
				menuentry "NetInstall" {
					set root=(hd0,1)
					linux /vmlinuz.cent.pxe repo=http://192.168.1.11/linux/centos/x86_64/6.2/ vnc vncpassword=${PASSWD} ip=${IPADDRESS} netmask=${NETMASK} gateway=${GATEWAY} nameserver=${DNS} noselinux headless
					initrd /initrd.img.cent.pxe
				}
EOF

					grub2-mkconfig --output=/boot/grub2/grub.cfg
					grub2-reboot NetInstall
					;;

					"3")
					##### CentOS 6.3-X86_64 #####
					clear
					mkdir /centos_install
					cd /centos_install
					curl -O  http://192.168.1.11/linux/centos/x86_64/6.3/images/pxeboot/initrd.img
					curl -O  http://192.168.1.11/linux/centos/x86_64/6.3/images/pxeboot/vmlinuz
					cp vmlinuz /boot/vmlinuz.cent.pxe
					cp initrd.img /boot/initrd.img.cent.pxe

					cat >> /etc/grub.d/40_custom << EOF
				menuentry "NetInstall" {
					set root=(hd0,1)
					linux /vmlinuz.cent.pxe repo=http://192.168.1.11/linux/centos/x86_64/6.3/ vnc vncpassword=${PASSWD} ip=${IPADDRESS} netmask=${NETMASK} gateway=${GATEWAY} nameserver=${DNS} noselinux headless
					initrd /initrd.img.cent.pxe
				}
EOF

					grub2-mkconfig --output=/boot/grub2/grub.cfg
					grub2-reboot NetInstall
					;;

					"4")
					##### CentOS 6.4-X86_64 #####
					clear
					mkdir /centos_install
					cd /centos_install
					curl -O  http://192.168.1.11/linux/centos/x86_64/6.4/images/pxeboot/initrd.img
					curl -O  http://192.168.1.11/linux/centos/x86_64/6.4/images/pxeboot/vmlinuz
					cp vmlinuz /boot/vmlinuz.cent.pxe
					cp initrd.img /boot/initrd.img.cent.pxe

					cat >> /etc/grub.d/40_custom << EOF
				menuentry "NetInstall" {
					set root=(hd0,1)
					linux /vmlinuz.cent.pxe repo=http://192.168.1.11/linux/centos/x86_64/6.4/ vnc vncpassword=${PASSWD} ip=${IPADDRESS} netmask=${NETMASK} gateway=${GATEWAY} nameserver=${DNS} noselinux headless
					initrd /initrd.img.cent.pxe
				}
EOF

					grub2-mkconfig --output=/boot/grub2/grub.cfg
					grub2-reboot NetInstall
					;;

					"5")
					##### CentOS 6.5-X86_64 #####
					clear
					mkdir /centos_install
					cd /centos_install
					curl -O  http://192.168.1.11/linux/centos/x86_64/6.5/images/pxeboot/initrd.img
					curl -O  http://192.168.1.11/linux/centos/x86_64/6.5/images/pxeboot/vmlinuz
					cp vmlinuz /boot/vmlinuz.cent.pxe
					cp initrd.img /boot/initrd.img.cent.pxe

					cat >> /etc/grub.d/40_custom << EOF
				menuentry "NetInstall" {
					set root=(hd0,1)
					linux /vmlinuz.cent.pxe repo=http://192.168.1.11/linux/centos/x86_64/6.5/ vnc vncpassword=${PASSWD} ip=${IPADDRESS} netmask=${NETMASK} gateway=${GATEWAY} nameserver=${DNS} noselinux headless
					initrd /initrd.img.cent.pxe
				}
EOF

					grub2-mkconfig --output=/boot/grub2/grub.cfg
					grub2-reboot NetInstall
					;;

					"6")
					##### CentOS 6.6-X86_64 #####
					clear
					mkdir /centos_install
					cd /centos_install
					curl -O  http://192.168.1.11/linux/centos/x86_64/6.6/images/pxeboot/initrd.img
					curl -O  http://192.168.1.11/linux/centos/x86_64/6.6/images/pxeboot/vmlinuz
					cp vmlinuz /boot/vmlinuz.cent.pxe
					cp initrd.img /boot/initrd.img.cent.pxe

					cat >> /etc/grub.d/40_custom << EOF
				menuentry "NetInstall" {
					set root=(hd0,1)
					linux /vmlinuz.cent.pxe repo=http://192.168.1.11/linux/centos/x86_64/6.6/ vnc vncpassword=${PASSWD} ip=${IPADDRESS} netmask=${NETMASK} gateway=${GATEWAY} nameserver=${DNS} noselinux headless
					initrd /initrd.img.cent.pxe
				}
EOF

					grub2-mkconfig --output=/boot/grub2/grub.cfg
					grub2-reboot NetInstall
					;;

					"7")
					clear
					mkdir /centos_install
					cd /centos_install
					curl -O  http://192.168.1.11/linux/centos/x86_64/6.7/images/pxeboot/initrd.img
					curl -O  http://192.168.1.11/linux/centos/x86_64/6.7/images/pxeboot/vmlinuz
					cp vmlinuz /boot/vmlinuz.cent.pxe
					cp initrd.img /boot/initrd.img.cent.pxe

					cat >> /etc/grub.d/40_custom << EOF
				menuentry "NetInstall" {
					set root=(hd0,1)
					linux /vmlinuz.cent.pxe repo=http://192.168.1.11/linux/centos/x86_64/6.7/ vnc vncpassword=${PASSWD} ip=${IPADDRESS} netmask=${NETMASK} gateway=${GATEWAY} nameserver=${DNS} noselinux headless
					initrd /initrd.img.cent.pxe
				}
EOF

					grub2-mkconfig --output=/boot/grub2/grub.cfg
					grub2-reboot NetInstall
					;;

					"8")
					##### CentOS 6.8-X86_64 #####
					clear
					mkdir /centos_install
					cd /centos_install
					curl -O  http://192.168.1.11/linux/centos/x86_64/6.8/images/pxeboot/initrd.img
					curl -O  http://192.168.1.11/linux/centos/x86_64/6.8/images/pxeboot/vmlinuz
					cp vmlinuz /boot/vmlinuz.cent.pxe
					cp initrd.img /boot/initrd.img.cent.pxe

					cat >> /etc/grub.d/40_custom << EOF
				menuentry "NetInstall" {
					set root=(hd0,1)
					linux /vmlinuz.cent.pxe repo=http://192.168.1.11/linux/centos/x86_64/6.8/ vnc vncpassword=${PASSWD} ip=${IPADDRESS} netmask=${NETMASK} gateway=${GATEWAY} nameserver=${DNS} noselinux headless
					initrd /initrd.img.cent.pxe
				}
EOF

					grub2-mkconfig --output=/boot/grub2/grub.cfg
					grub2-reboot NetInstall
					;;

					"9")
					##### CentOS 6.9-X86_64 #####
					clear
					mkdir /centos_install
					cd /centos_install
					curl -O  http://192.168.1.11/linux/centos/x86_64/6.9/images/pxeboot/initrd.img
					curl -O  http://192.168.1.11/linux/centos/x86_64/6.9/images/pxeboot/vmlinuz
					cp vmlinuz /boot/vmlinuz.cent.pxe
					cp initrd.img /boot/initrd.img.cent.pxe

					cat >> /etc/grub.d/40_custom << EOF
				menuentry "NetInstall" {
					set root=(hd0,1)
					linux /vmlinuz.cent.pxe repo=http://192.168.1.11/linux/centos/x86_64/6.9/ vnc vncpassword=${PASSWD} ip=${IPADDRESS} netmask=${NETMASK} gateway=${GATEWAY} nameserver=${DNS} noselinux headless
					initrd /initrd.img.cent.pxe
				}
EOF

					grub2-mkconfig --output=/boot/grub2/grub.cfg
					grub2-reboot NetInstall
					;;

					"a")
					##### CentOS 7.0-X86_64 #####
					clear
					mkdir /centos_install
					cd /centos_install
					curl -O  http://192.168.1.11/linux/centos/x86_64/7.0/images/pxeboot/initrd.img
					curl -O  http://192.168.1.11/linux/centos/x86_64/7.0/images/pxeboot/vmlinuz
					cp vmlinuz /boot/vmlinuz.cent.pxe
					cp initrd.img /boot/initrd.img.cent.pxe

					cat >> /etc/grub.d/40_custom << EOF
				menuentry "NetInstall" {
					set root=(hd0,1)
					linux /vmlinuz.cent.pxe repo=http://192.168.1.11/linux/centos/x86_64/7.0/ vnc vncpassword=${PASSWD} ip=${IPADDRESS} netmask=${NETMASK} gateway=${GATEWAY} nameserver=${DNS} noselinux headless
					initrd /initrd.img.cent.pxe
				}
EOF

					grub2-mkconfig --output=/boot/grub2/grub.cfg
					grub2-reboot NetInstall
					;;

					"b")
					##### CentOS 7.1-X86_64 #####
					clear
					mkdir /centos_install
					cd /centos_install
					curl -O  http://192.168.1.11/linux/centos/x86_64/7.1/images/pxeboot/initrd.img
					curl -O  http://192.168.1.11/linux/centos/x86_64/7.1/images/pxeboot/vmlinuz
					cp vmlinuz /boot/vmlinuz.cent.pxe
					cp initrd.img /boot/initrd.img.cent.pxe

					cat >> /etc/grub.d/40_custom << EOF
				menuentry "NetInstall" {
					set root=(hd0,1)
					linux /vmlinuz.cent.pxe repo=http://192.168.1.11/linux/centos/x86_64/7.1/ vnc vncpassword=${PASSWD} ip=${IPADDRESS} netmask=${NETMASK} gateway=${GATEWAY} nameserver=${DNS} noselinux headless
					initrd /initrd.img.cent.pxe
				}
EOF

					grub2-mkconfig --output=/boot/grub2/grub.cfg
					grub2-reboot NetInstall
					;;

					"c")
					##### CentOS 7.2-X86_64 #####
					clear
					mkdir /centos_install
					cd /centos_install
					curl -O  http://192.168.1.11/linux/centos/x86_64/7.2/images/pxeboot/initrd.img
					curl -O  http://192.168.1.11/linux/centos/x86_64/7.2/images/pxeboot/vmlinuz
					cp vmlinuz /boot/vmlinuz.cent.pxe
					cp initrd.img /boot/initrd.img.cent.pxe

					cat >> /etc/grub.d/40_custom << EOF
				menuentry "NetInstall" {
					set root=(hd0,1)
					linux /vmlinuz.cent.pxe repo=http://192.168.1.11/linux/centos/x86_64/7.2/ vnc vncpassword=${PASSWD} ip=${IPADDRESS} netmask=${NETMASK} gateway=${GATEWAY} nameserver=${DNS} noselinux headless
					initrd /initrd.img.cent.pxe
				}
EOF

					grub2-mkconfig --output=/boot/grub2/grub.cfg
					grub2-reboot NetInstall
					;;

					"d")
					##### CentOS 7.3-X86_64 #####
								clear
					mkdir /centos_install
					cd /centos_install
					curl -O  http://192.168.1.11/linux/centos/x86_64/7.3/images/pxeboot/initrd.img
					curl -O  http://192.168.1.11/linux/centos/x86_64/7.3/images/pxeboot/vmlinuz
					cp vmlinuz /boot/vmlinuz.cent.pxe
					cp initrd.img /boot/initrd.img.cent.pxe

					cat >> /etc/grub.d/40_custom << EOF
				menuentry "NetInstall" {
					set root=(hd0,1)
					linux /vmlinuz.cent.pxe repo=http://192.168.1.11/linux/centos/x86_64/7.3/ vnc vncpassword=${PASSWD} ip=${IPADDRESS} netmask=${NETMASK} gateway=${GATEWAY} nameserver=${DNS} noselinux headless
					initrd /initrd.img.cent.pxe
				}
EOF

					grub2-mkconfig --output=/boot/grub2/grub.cfg
					grub2-reboot NetInstall
					;;			

				esac
	else
		echo "当前系统不支持此安装脚本,无法进行安装"
	fi

	printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
	printf "             +              Centos重装脚本执行成功                 \n"
	printf "             +     请重启服务器后使用VNC客户端远程进行系统安装	   \n"
	printf "             +             VNC服务器地址:$IPADDRESS:1   	   	   \n"
	printf "             +             VNC服务器密码:$PASSWD                  \n"
	printf "             ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
	read anykey
		exit
else
echo “network is Unreachable,This script can not run! Now Exit!!!” 
exit
fi
时间: 2024-10-10 08:41:11

Centos系统远程重装脚本的相关文章

Centos 系统初始化管理脚本

系统初始化脚本可以统一.自动配置,减少人力. 这里浅谈一下yum安装与源码编译安装,请各位不吝指正.我一直坚持yum安装,原因如下 一.安装方便,不需要再花精力考虑依赖问题 二.配置统一,方便后期维护,自动化等 三.方便升级 四.好吧,我是菜鸡,我承认了 #!/bin/sh #判断用户身份 username=`whoami`; if [ $username != "root" ] then     echo "当前用户权限不足,即将退出脚本";     exit 2

Centos 远程重装系统脚本

因公司有些服务器需要经常重装系统,每次跑机房比较麻烦,特做此脚本进行远程安装 目前因Http服务器空间有限,只左右Centos6.1-7.0 64位系统的远程安装 如需增加  只需按照以前的步骤和方法添加即可. 1.http服务器的搭建 我这里使用IIS作为http服务器(linux下最好) 启用IIS目录浏览功能,并在http头标签页的MIME类型 中添加相应的MIME类型,方便下载此目录下所有文件. 新建MIME类型,在拓展名和MIME类型中都填* 确定保存. 2.解压镜像文件到http服务

给异地服务器远程ssh重装CentOS系统

英国idc机房服务器,无法过去,让idc工程师配合安装系统,太麻烦,于是采用远程重装的方法,省时省力. 目前该方法,只适用于CentOS5.x和CentOS6.x.CentOS 7.x由于变成了grub2,所以该方法不太适用,正在研究中. 基础环境介绍: 1.英国idc服务器一台: 2.原系统版本:CentOS5.6: 3.重装系统版本:CentOS6.8: 4.该系统已经调通网络,可以访问互联网. 方法步骤如下: 一.安装桌面环境 给需要重装系统的服务器安装桌面环境,目的是为了使用vnc远程连

CentOS系统MySQL双机热备配置

1  概述 在集成项目中需要应对不同环境下的安装配置,主流操作系统大致可以分为三种:Linux.Windows以及UNIX.其中Linux备受青睐的主要原因有两个: 首先,Linux作为自由软件有两个特点:一是它免费提供源码,二是爱好者可以按照自己的需要自由修改.复制和发布程序的源码,并公布在Internet上.这就吸引了世界各地的操作系统高手为Linux编写各种各样的驱动程序和应用软件,使得Linux成为一种不仅只是一个内核,而且包括系统管理工具.完整的开发环境和开发工具.应用软件在内,用户很

Linux学习之CentOS(二)----远程登录管理工具SecureCRT的使用

[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3919940.html 联系方式:[email protected] [正文] 虚拟机版本:VMware Workstation_10.0.3 Linux系统版本:CentOS_6.5(64位) 一.前言: 前几天做了一回小白,安装了上个月发布的最新版CentOS 7 ,发现在学习的时候有很多地方和

CentOS系统下NFS服务器

NFS服务器 NFS是Network File System的缩写,功能可将其简单的看作一个文件服务器,可以通过网络,使不同的主机和不同操作系统可以共享文件. 现在尤其在机房是Linux集群的环境下,几十或者几百台服务器,使用NFS共享文件,可以极大保证效率. 配置环境: VMware虚拟机,安装两台CentOS 6.5服务器 NFS-Server: IP:192.168.30.129 共享目录:/data NFS-Client: IP:192.168.30.130 挂载目录:/data 在服务

初涉定制linux系统之——自动化安装Centos系统镜像制作

最近碰到个需求:要在内网环境安装centos6.5系统并搭建服务,但由于自动部署脚本里安装依赖包使用的是yum安装,而服务器无法连接外网,实施人员也不会本地yum源搭建O__O "….. 本来想法是打算把需要的依赖包全找出来打包发给实施人员自己安装去,后来考虑到系统安装人员的安装方式不一致,分区及安装包的不统一会对之后的维护造成负担,干脆就决定做个自动化安装的镜像,并把需要的业务依赖包全打包进去 ok,首先我们来看看环境准备: 1.一台刚安装好的.符合业务要求的系统(博主选择的是minimal

Xmanager连接CentOS的远程桌面

本文主要介绍通过Xmanager连接CentOS远程桌面时,在CentOS系统上需要做的一些配置. 1. Xmanager简介 Xmanager是一个运行于 Windows平台上的高性能的X Server软件.它能把远端Unix/Linux的桌面无缝地带到你的Windows上,甚至电脑是在内网或防火墙后,也能通过SSH协议安全的运行远端的X应用程序. 特点包括: 可通过Xcongfig工具设置多个Xmanager设置: 支持多用户的Windows终端环境: 支持多个IP地址: 支持本地资源数据库

cobbler安装centos系统

整个安装系统的流程与pxe还是一样的,只不过由手动变成了自动,各个版本之间也更好管理. 这里还是centos系统的.cobbler的大致基础使用. 环境: 平台:VirtualBox 虚拟机 服务机:CentOS7 所安装的系统:CentOS7, CentOS6 cobbler里面有几个概念要首先了解一下: distro: 用来标识一个发行版.因为安装不同版本的系统起码要用不同的内核与initrd来启动安装程序.这个就是用来区分它们的.注意distro主要是来标识不同的内核与initrd,与整个