Unattended installation of Linux systems

Source: Internet
Author: User
Tags create directory

First, demand analysis

With the growing Internet technology, the number of servers is also increasing, from the initial several servers to a large data center, alone can not meet in the technology, business, management and other aspects of the requirements, then standardization, automation, architecture optimization, The factors that reduce IT service cost such as process optimization are becoming more and more important. How to automate batch deployment to install a stable system is the first step towards automation.

Second, PXE introduction

PXE, which is the pre-boot execution environment, is a way to boot. This kind of protocol usually consists of two parts, one is server side and the other is client. In short, we can create an "installation source" in this way, so that the system can be installed as long as the "source" can be found when the system is installed. Before implementing an unattended installation, we have to set up some services to implement the installation source, such as FTP, HTTP, TFTP, DHCP, and so on. When a host is started, the standard input output will send the PXE client into our memory for related operations and prompt for relevant options, where we can make a selection. The PXE client downloads (download) the file from the network to run locally. The process is that the PXE client sends IP requests through the network card to the LAN, and then the DHCP server gives it an IP address and the files required for the system installation, and then uses the received file for system installation. And the installation of the process requires other resources provided by the server, such as: Yum source, kernel files, etc., when the host to get these resources, it can be successfully installed. The end result is: Any host in the selected network boot will obtain the DHCP server distributed IP, through the acquired IP address and the local area network TFTP server communication and get boot files, and FTP or HTTP communication and get Yum source files and kernel files. After that, the automatic installation begins, and the process does not require anyone to do anything.

PXE installation advantages, this installation system can not be affected by the optical drive, CD-ROM and some external equipment restrictions, but also can be unattended, greatly reducing the workload of operation and maintenance personnel, such as in some large number of host computer room for batch installation, PXE will be your choice.

Third, server construction

1. Preparation before installation
Because of the different protocol-based communication between hosts, we chose to turn off the firewall and SELinux in order to avoid unnecessary hassles.

2. Configuring a static IP address


After modifying the configuration, remember to restart the NIC to make the configuration effective
3. Installation Services
[[email protected] ~]# yum -y install dhcp tftp-server httpd syslimux xinetd
Start the service and set it to boot

[[email protected] ~]# systemctl enable dhcpd[[email protected] ~]# systemctl enable tftp[[email protected] ~]# systemctl enable httpd[[email protected] ~]# systemctl start httpd[[email protected] ~]# systemctl start tftp[[email protected] ~]# vim  /etc/xinetd.d/tftp {...    disable     =yes         # 修改这一项为"disable     =no"...} [[email protected] ~]# systemctl restart xinetd

4. Configuring the DHCP service

[[email protected] ~]# cd /etc/dhcp/[[email protected] dhcp]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example dhcpd.conf          
[[email protected] ~]# vim dhcpd.conf           # 打开模板文件并添加一下内容 subnet  192.168.92.0 netmask 255.255.255.0{                  #这里写的ip地址为子网的地址    range 192.168.92.200 192.168.92.224;            #子网的范围,之后主机请求获取的ip地址就是这其中的一个    next-server 192.168.92.33;         # 指明tftp服务器的地址      option routers 192.168.92.33;          #网关地址也就是服务器地址    filename "pxelinux.0";           # 指明PXE文件位置,这个在申请ip的时候会发送给安装主机 }[[email protected] dhcp]# systemctl restart dhcpd          #重启服务

5. Prepare the Yum source file and the Kickstart file

[[email protected] dhcp]# cd /var/www/html/[[email protected] html]# mkdir -p centos/{6,7}[[email protected] html]# mkdir ksdir关于Yum源文件,我们可以从光盘中复制,也可以直接把光盘挂载到指定目录,这里我选择把光盘挂载到指定目录[[email protected] dhcp]# mount /dev/sr0 centos/6     # 挂载CentOS 6光盘值6目录下 [[email protected] dhcp]# mount /dev/sr1 centos/7     # 挂载CentOS 7光盘值7目录下 [[email protected] dhcp]# yum  install -y system-config-kickstart [[email protected] dhcp]# system-config-kickstart


You can customize the configuration in order, and then save it to the/var/www/html/ksdir/directory
or copy the Anaconda-ks.cfg file under the/root directory for modification

[[email protected] ~]# CP anaconda-ks.cfg/var/www/html/ksdir/ks7.cfg[[email protected] ~]# vim/var/www/ Html/ksdir/ks7.cfg[[email protected] ~]# chmod +r/var/www/html/ksdir/ks7.cfg[[email protected] ~]# CAT/ var/www/html/ksdir/ks7.cfg#version=devel# System Authorization Informationauth--enableshadow--passalgo=sha512# use CDROM installation Mediaurl--url= "HTTP://192.168.92.33/CENTOS/7" #指明yum源路径 # Use graphical Installtext # will C Drom modified to text, we are not CD-based installation, we are based on the character interface installation # Run the setup Agent on first bootfirstboot--enableignoredisk--only-use=sda# Keyboard layoutskeyboard--vckeymap=us--xlayouts= ' Us ' # System Languagelang en_US. utf-8# Network informationnetwork--bootproto=dhcp--device=ens33--ipv6=auto--activatenetwork--hostname= centos7.cyz# Root PASSWORDROOTPW--iscrypted $6$cvwgc8f2z/my2uc9$mhmvs1.bvzmfmzanm9leyhw19587xij9d4ce9mg0glat4etx/ hnjbxuookhmrlch2gy2mot361w0crfaangje0# system servicesservices--disabled= "chronyd" # system Timezonetimezone asia/shanghai# X Window System configuration Informationxconfig--startxonboot# system bootloader Configurationbootloader --LOCATION=MBR--boot-drive=sda# Partition clearing informationclearpart--all--initlabel# Disk Partitioning Informationpart/app--fstype= "XFS"--ONDISK=SDA--size=19073part swap--fstype= "swap"--ONDISK=SDA--size=4096part/ Boot--fstype= "XFS"--ONDISK=SDA--size=190part/--fstype= "XFS"--ondisk=sda--size=19073%packages #安装软件包, I this is M INI installation so the installation package is relatively small, you can customize the installation. @^minimal@corevim%end%addon com_redhat_kdump--disable--reserve-mb= ' auto '%end

Centos6 Kickstart file

#version =develinstalltext # Install Lang en_US based on the character interface. Utf-8keyboard usnetwork--onboot Yes--device eth0--bootproto dhcp--noipv6rootpw--iscrypted $6$hfb25yoyzdu3yztl$vxtkh Ggjggbbr59opny5ktjzvj9hb9nrwrh5fmhlialxh9vq74pyok7qzpwyn0zajrm3mv/ip0fdkhxfglni6/firewall--service=     Sshauthconfig--enableshadow--passalgo=sha512url--url= "HTTP://192.168.92.33/CENTOS/6" # Yum source path SELinux--disabled # close Selinuxtimezone asia/shanghaibootloader--location=mbr--driveorder=sda--append= "Crashkernel=auto rhgb quiet" # Th E Following is the partition information you requested# Note This any partitions you deleted be not expressed# here so UN Less you clear all partitions first, this is# not guaranteed to Workzerombr # clear Mbrclearpart--all # clear Partition Letter Reboot # restart Part/boot--FSTYPE=EXT4--size=1000 # partition information part/--FSTYPE=EXT4--size=50000part/ap after installation is complete        P--FSTYPE=EXT4--size=40000part swap--size=2048#repo--name= "CentOS"--baseurl=cdrom:sr0--cost=100 # comment out this line% Packages@base@core@debugging@basic-desktop@desktop-debugging@desktop-platform@directory-client@fonts@general-desktop@grap Hical-admin-tools@input-methods@internet-applications@internet-browser@java-platform@kde-desktop@legacy-x@network-file-sy Stem-client@office-suite@print-client@remote-desktop-clients@server-platform@server-policy@workstation-policy@x11mtoolspa Xpython-dmidecodeoddjobwodimsgpiogenisoimagedevice-mapper-persistent-dataabrt-guiqt-mysqlsamba-winbindcertmongerpam _krb5krb5-workstationxtermxorg-x11-xdmlibxmurdesktop%end%post # Post-installation script, after installing the system to do what configuration, can be written in the middle of%post...%end rm-rf/etc/ Yum.repos.d/*cat >/etc/yum.repos.d/base.repo <<eof[base]name=basebaseurl=file:///misc/cdgpgcheck=0eof%end

6. Prepare kernel files, menu files

[[email protected] ~]# cd/var/lib/tftpboot/[[email protected] tftpboot]# mkdir-p centos{6,7} # Create directory file [[em Ail protected] tftpboot]# cp/var/www/html/centos/6/{vmlinuz,initrd.img} centos6/# Copy kernel, virtual root file [[Email prot Ected] tftpboot]# cp/var/www/html/centos/7/{vmlinuz,initrd.img} centos7/# because you have previously mounted a different system, you can copy the corresponding file directly [email prote CTED] tftpboot]# cp/usr/share/syslinux/pxelinux.0.         # pxelinux files are from the Syslinux package and can be copied directly [[email protected] tftpboot]# cp/usr/share/syslinux/vesamenu.c32. #复制菜单文件 [[email protected] tftpboot]# mkdir pxelinux.cfg [[email protected] tftpboot]# cp/var/www/html/ Centos/6/isolinux/isolinux.cfg Pxelinux.cfg/default # Copy and rename [[email protected] tftpboot]# vim pxelinux.cfg/ default [[email protected] tftpboot]# cat pxelinux.cfg/default # View Modified Menu file contents default Vesamenu.c32timeout 600dis Play boot.msg# Clear The exiting the menu, instead of leaving the menu displayed.# for vesamenu, this means th EGraphical background is still displayed without# the menu itself for as long as the screen remains in graphics Mode.menu C Learmenu background splash.pngmenu title CentOS 7menu vshift 8menu rows 18menu margin 8#menu hiddenmenu helpmsgrow 15menu Tabmsgrow 13# Border areamenu Color Border * #00000000 #00000000 none# Selected itemmenu color sel 0 #ffffffff #00000000 N one# title Barmenu color Title 0 #ff7ba3d0 #00000000 none# Press [Tab] Messagemenu color tabmsg 0 #ff3a6496 #00000000 None # unselected Menu Itemmenu color Unsel 0 #84b8ffff #00000000 none# Selected hotkeymenu color Hotsel 0 #84b8ffff #00000000 none# unselected Hotkeymenu Color Hotkey 0 #ffffffff #00000000 none# help Textmenu color help 0 #ffffffff #00000000 none# A scrollbar of some type? Not Sure.menu color scrollbar 0 #ffffffff #ff355594 none# Timeout msgmenu color Timeout 0 #ffffffff #00000000 nonemenu Col or timeout_msg 0 #ffffffff #00000000 none# Command prompt Textmenu color cmdmark 0 #84b8ffff #00000000 nonemenu color cmDline 0 #ffffffff #00000000 none# do not display the actual menu unless the user presses a key. All, is displayed are a timeout Message.menu tabmsg press Tab for full configuration options on menu Items.menu Separat      Or # Insert an empty linemenu separator # Insert an empty Linelabel Linux menu label ^install CentOS 7 Menu Default   #光标默认在这一行 kernel centos7/vmlinuz append initrd=centos7/initrd.img ks=http://192.168.92.33/ksdir/ks7.cfglabel centos6 Menu Label Auto Install CentOS Linux ^6 kernel centos6/vmlinuz append initrd=centos6/initrd.img ks=http://192.168.92.3 3/ksdir/ks6.cfg label Linux menu label Boot from ^local Drive localboot 0xffffmenu End

Four, commissioning and installation
Create a new virtual machine, set the network segment in the network segment where the DHCP service is located, and select Use physical Drive Auto-detect.


The system has been installed.

Unattended installation of Linux systems

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.