當前位置:
首頁 > 最新 > 操作系統批量安裝

操作系統批量安裝

學習過程都在本地電腦上搭建環境進行,將會大量使用到虛擬機,Virtualbox和VMware workstation都用過很長時間,我選擇使用workstation,因為workstation的網路配置更為專業,可以應付很多複雜的實驗環境。

幾乎所有的生產環境後端的存儲集群都不會開放訪問互聯網,為了更接近真實環境,在環境中橋接loopback網卡來進行網路模擬,在本地windows下設備管理器中添加過時硬體,選擇Microsoft KMS-TEST 環回適配器,如圖(只需要配置VMnet0網卡):

workstation中網路配置如下圖:

生產環境集群往往都有大量伺服器,小則十多台,多則幾百台,我採用了常用的PXE方式批量安裝操作系統,先搭建一台PXE-svr,安裝任一版本的linux(我選擇CentOS6.5),配置如下:

1、pxe-svr配置

2、完成最小化安裝CentOS6.5:

手工配置網路如圖(CentOS7需更改對應命令):

sed -i "s#ONBOOT=no#ONBOOT=yes#g" /etc/sysconfig/network-scripts/ifcfg-eth0

sed -i "s#BOOTPROTO=dhcp#BOOTPROTO=static#g" /etc/sysconfig/network-scripts/ifcfg-eth0

cat >/etc/sysconfig/network-scripts/ifcfg-eth0

>IPADDR=10.10.1.253

>NETMASK=255.255.255.0

>GATEWAY=10.10.1.254

chkconfig iptables off

service iptables stop

之前添加的環回口網卡IP配置如下:

可以使用ssh工具遠程登陸pxe-svr了:

下面開始配置pxe-svr:

1、掛載安裝光碟後,配置光碟本地源

mount /dev/cdrom /media

cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

cat >/etc/yum.repos.d/CentOS-Base.repo

>name=local

>baseurl=file:///media/

>gpgcheck=0

yum clean all

yum repolist

2、安裝服務

yum -y install vim

yum -y install httpd

yum -y install tftp-server

yum -y install dhcp

yum -y install syslinux

3、配置服務

tftp服務:

sed -i "14s/yes/no/g" /etc/xinetd.d/tftp

/etc/init.d/xinetd start

chkconfig xinetd on

dhcp服務

cp -f /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf

subnet 10.10.1.0 netmask 255.255.255.0 {

range dynamic-bootp 10.10.1.1 10.10.1.200; ////ip地址池

option broadcast-address 10.10.1.255;

option routers 10.10.1.253; ///網關ip

next-server 10.10.1.252; ///pxe-svr的ip

filename "pxelinux.0"; ///pxe啟動參數

}

chkconfig dhcpd on

http服務:(需要將客戶機待安裝的OS鏡像copy到/var/www/html/目錄)

mount /dev/cdrom /media

mkdir -pv /var/www/html/rhel6.5/

cp -rf /media/* /var/www/html/rhel6.5/ //拷貝rhel6.5光碟的所有內容

PXE配置:

cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

cp /var/www/html/rhel6.5/images/pxeboot/initrd.img /var/lib/tftpboot/

cp /var/www/html/rhel6.5/images/pxeboot/vmlinuz /var/lib/tftpboot/

cp /var/www/html/rhel6.5/isolinux/*.msg /var/lib/tftpboot/

mkdir -pv /var/lib/tftpboot/pxelinux.cfg

cp /var/www/html/rhel6.5/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

修改default文件如下圖:

編輯ks配置文件(以rhel6-5.cfg命名):

vim rhel6-5.cfg

#platform=x86, AMD64, 或 Intel EM64T

#version=DEVEL

# Firewall configuration

firewall --disabled

# Install OS instead of upgrade

install

# Use network installation

url --url="http://10.10.1.252/rhel6.5" //pxe地址

# Root password

rootpw --iscrypted $1$4ng921wA$KOPFTOgiDB5nc1Ntb8zyX0

# System authorization information

auth --useshadow --passalgo=sha512

# Use text mode install

text

firstboot --disable

# System keyboard

keyboard us

# System language

lang zh_CN

# SELinux configuration

selinux --disabled

# Installation logging level

logging --level=info

# Reboot after installation

reboot

# System timezone

timezone Asia/Shanghai

# Network information

network --bootproto=dhcp --device=eth0 --onboot=on

# System bootloader configuration

bootloader --location=mbr

# Clear the Master Boot Record

zerombr

# Partition clearing information

clearpart --all --initlabel

# Disk partitioning information 分區信息,可自行更改

part / --fstype="ext4" --size=15000

part /boot --fstype="ext4" --size=200

%packages ////需要安裝的軟體包,這裡選擇安裝基本系統

@base

%end

4、啟動服務

service httpd start

service dhcpd start ////排錯日誌/var/log/message

service xinetd start

5、測試服務

curl http://10.10.1.252/rhel6.5/

至此PXE-svr安裝配置完成,新建虛擬機作為hadoop節點,配置如下,數量7台:

1、虛擬機配置:內存至少4G,網卡配置與pxe伺服器一致,其餘參數隨意。

啟動虛擬機,將會啟動pxe安裝界面:

7台節點伺服器同時開始安裝:

安裝完成

節點操作系統安裝完成:

由於hadoop集群安裝需要大量的環境配置工作,生產環境中如果節點數量龐大,幾十台乃至上百台伺服器,使用手工配置勢必很蛋疼……,這個時候可以採用自動化運維工具,下一節將分別採用:shell腳本、ansible、saltstack來完成以下工作:靜態IP配置、yum本地配置、hosts文件、selinux、iptables、ssh互信、THP、環境變數配置等工作。


喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 學足跡 的精彩文章:

TAG:學足跡 |