Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of the principle of kickstart installation system

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Preface

As the operation and maintenance of small and medium-sized companies, we often encounter some mechanical repetitive work, such as: sometimes the company launches dozens or even hundreds of servers at the same time, and requires us to complete the system installation in a short time.

What's the usual way?

CD installation system = > one server DVD has hundreds of built-in optical drives, and it is wasted for a hundred servers to be equipped with optical drives, because one server begins to install the system that can be used, and there are only a handful of opportunities to use in the future. Use USB external optical drive, plug it back and forth and get drunk.

U disk installation system = = > the same problem, one server to plug in the USB disk.

Network installation system (ftp,http,nfs) = = > this method is good, as long as the server can be connected to the Internet, you can install the system, but you still need one server to click the mouse. We who want to be lazy all the time, is there a better way!

The method of high pressure grid:

1. Kickstart

2. Cobbler

Chapter 1 PXE introduction 1.1 what is PXE

PXE, full name Pre-boot Execution Environmrnt, pre-start execution environment

Start the computer through a network interface without relying on a local storage device (such as a hard disk) or a locally installed operating system

Technology announced by intel and Systemsoft on September 20, 1999

The working mode of Client/Server

PXE clients will call network protocols such as Internet Protocol (IP), user Datagram Protocol (UDP), dynamic Host configuration Protocol (DHCP), small File transfer Protocol (TFTP), etc.

The term PXE client (client) refers to the role of the machine during PXE startup. A PXE client can be a server, laptop or other machine with PXE startup code (our computer's network card)

Detailed explanation of working principle of PXE working Diagram 1.3PXE

PXE Client sends a request to DHCP

PXE Client starts from its own PXE network card and sends a broadcast request using UDP (simple user data message Protocol) through PXE BootROM (self-booting chip) to request IP from the DHCP server in this network.

DHCP server provides information

The DHCP server receives a request from the client, verifies that it comes from a legitimate PXEClient, and verifies that it will provide the client with a "provide" response that contains the IP address assigned to the client, the location of the pxelinux launcher (TFTP), and the location of the configuration file.

PXE client requests download startup file

When the client receives a "response" from the server, it responds with a frame to request the transfer of the files needed to start. These startup files include: pxelinux.0, pxelinux.cfg/default, vmlinuz, initrd.img and other files.

Boot Server responds to client requests and transfers files

When the server receives the request from the client, there will be more information between them to reply between the client and the server to determine the startup parameters. BootROM downloads the files (pxelinux.0, pxelinux.cfg/default) necessary to start the installer lock from Boot Server by the TFTP communication protocol. When the default file is downloaded, the boot kernel of the Linux installer is started according to the boot order defined in the file.

Request to download auto answer file

After the client successfully boots Linux to install the kernel through the pxelinux.cfg/default file, the installer must first determine what installation media you use to install Linux. If it is installed through a network (NFS, FTP, HTTP), it will initialize the network at this time and locate the installation source location. It then reads the location of the autoanswer file ks.cfg specified in the default file and requests to download the file according to that location.

Note:

There is a problem. The network is initialized twice in steps 2 and 5, because PXE gets the kernel and installer, etc., and the installer needs to get the binaries and configuration files needed to install the system. Therefore, the PXE module and the installer are relatively independent, and the network configuration of PXE cannot be passed to the installer, thus going through the process of obtaining the IP address twice, but the IP address is the same during the lease term of the DHCP.

Client installs operating system

After downloading the ks.cfg file, find the OSServer through the file and download the package required for the installation process in accordance with the configuration request of the file. After the OS Server and the client establish a connection, the software package will be transferred and the client will begin to install the operating system. When the installation is complete, you will be prompted to reboot the computer.

Chapter 2 introduction to kickstart configuration and manual network installation 2.1 batch installation software

There are mainly two kinds of Kickstart and Cobbler in Redhat system.

Kickstart is an unattended installation. It works by recording various parameters filled in by human intervention during installation and generating a file called ks.cfg. If you need to fill in the parameters during the automatic installation process, the installer will first look for the ks.cfg file, and if it finds the right parameters, it will use the parameters found; if it does not find the right parameters, it will pop up a dialog box for the installer to fill in manually. So, if the ks.cfg file covers all the parameters that need to be filled in during the installation process, the installer can just tell the installer where to download the ks.cfg file and mind his own business. When the installation is complete, the installer restarts / shuts down the system according to the settings in ks.cfg, and ends the installation.

Cobbler centralizes and simplifies the configuration of DHCP, TFTP, and DNS services that are required to install operating systems over the network. Cobbler not only has a command line interface, but also provides a Web interface, which greatly reduces the entry level of users. Cobbler has a lightweight configuration management system built in, but it also supports integration with other configuration management systems, such as Puppet, but does not support SaltStack for the time being.

* * to put it simply, Cobbler is an encapsulation of kickstart, which simplifies the installation steps and usage process, and lowers the threshold for users. **

2.2 Environmental preparation

The network card must have PXE function.

DHCP dynamically allocates IP addresses

TFTP is responsible for system startup file transfer

HTTP provides CentOS system file download service.

[root@m01 ~] # cat / etc/redhat-release

CentOS release 6.8 (Final) # CentOS 6.8

[root@m01 ~] # uname-r

2.6.32-642.el6.x86_64

[root@m01 ~] # / etc/init.d/iptables status # Firewall needs to be turned off

Iptables: Firewall is not running.

[root@m01 ~] # getenforce # selinux needs to be closed

Disabled

[root@m01 ~] # ll-d / tmp/ # / tmp directory permission is 1777

Drwxrwxrwt. 3 root root 4096 Jun 12 08:42 / tmp/

Note:

Virtual machine network card adopts NAT mode, do not use bridge mode, because we will build DHCP server later, and there will be conflicts among multiple DHCP servers in the same LAN.

VMware's dhcp service in NAT mode is also turned off to avoid interference

2.3 introduction to installing DHCP Service 2.3.1DHCP Service

DHCP (Dynamic Host Configuration Protocol, dynamic host configuration protocol) is usually used in large-scale local area network environment, its main function is centralized management, assign IP address, make the host in the network environment dynamic live IP address, gateway address, DNS server address and other information, and can improve the address utilization. Port is 67

2.3.2DHCP service installation configuration

Install dhcp software through yum

Yum-y install dhcp

View profile location

[root@m01 ~] # rpm-ql dhcp | grep dhcpd.conf

/ etc/dhcp/dhcpd.conf

The contents of the configuration file are modified to

[root@m01 ~] # cat / etc/dhcp/dhcpd.conf

Subnet172.16.1.0 netmask 255.255.255.0 {

Range 172.16.1.100 172.16.1.200

Option subnet-mask 255.255.255.0

Default-lease-time 21600

Max-lease-time 43200

Next-server 172.16.1.61

Filename "/ pxelinux.0"

}

Description of the profile content:

Subnet 172.16.1.0 netmask 255.255.255.0 # specify the network segment and subnet mask where the DHCP server is located

Range 172.16.1.100172.16.1.200; # specify the starting IP- ending IP (IP pool range) that can be assigned by the DHCP server

Option subnet-mask255.255.255.0; # specify the netmask subnet mask

Default-lease-time 21600; # set the default IP lease term

Max-lease-time 43200; # set the maximum IP lease period

Next-server 172.16.1.61; # tell the client the IP of the TFTP server (we can deploy it on a write native IP)

Filename "/ pxelinux.0"; # tells the client to download pxelinux.0 files from the TFTP root directory

Start the dhcpd service

/ etc/init.d/dhcpd start

View dhcpd service port

[root@m01 ~] # netstat-luntp | grep dhcp

Udp 0 0 0.0.0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0

Note:

Originally, after the software is installed, it is necessary to add boot self-startup, but this Kickstart system cannot boot automatically, and the service should be shut down after use to prevent the server from restarting the system automatically in the future.

If there are too many machines, pay attention to the address pool of the dhcp server, so that the dhcpd server does not have the IP address release because it runs out of IP.

A server automatically assigns two IP addresses at a time, so it is common to set the number of IP in the address pool to be more than twice the number of machines to avoid running out of address pools and unable to install the system normally.

2.4 introduction to installing TFTP Service 2.4.1TFTP

TFTP (Trivial File Transfer Protocol, simple File transfer Protocol) is a protocol used for simple file transfer between client and server in the TCP/IP protocol suite, which provides file transfer services with no complexity and low overhead. The port number is 69.

2.4.2TFTP installation configuration

Install the tftp service through yum

Yum-y install tftp-server

Enable tftp service (modify)

[root@m01 ~] # vim / etc/xinetd.d/tftp

# default: off

# description: The tftp server serves files usingthe trivial file transfer\

# protocol. The tftp protocol is often used to bootdiskless\

# workstations,download configuration files to network-aware printers,\

# and to startthe installation process for some operating systems.

Service tftp

{

Socket_type = dgram

Protocol = udp

Wait = yes

User = root

Server = / usr/sbin/in.tftpd

Server_args =-s/var/lib/tftpboot # specify the tftp root directory and keep it unmodified by default

Disable = no # changing the original yes to no means that xinetd starts the tftp daemon

Per_source = 11

Cps = 100 2

Flags = IPv4

}

Start xinetd and view the port

[root@m01 ~] # / etc/init.d/xinetd start

Starting xinetd: [OK]

[root@m01 ~] # netstat-luntp | grep xinet

Udp 0 0 0.0.0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 9. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0

2.5HTTP service installation-- apache

Install apache software through yum

Yum-y install httpd

Start apache

[root@m01 ~] # / etc/init.d/httpd start

Starting httpd: httpd: Could not reliablydetermine the server's fully qualified domain name, using 172.16.1.61 forServerName

[OK]

Cancel warning method

Sed-I "277i ServerName 127.0.0.1 sed 80" / etc/httpd/conf/httpd.conf

Mount iso image files to virtual machines (production environment can upload mirror files)

Mount: you must specify the filesystem type

# the solution is to connect the virtual machine to the following state points

Create a mount directory

Mkdir-p / var/www/html/CentOS6.8

Mount the iso image to the directory

Mount / dev/cdrom / var/www/html/CentOS6.8

# after mounting, you will be prompted that this device is read-only

# mount: block device / dev/sr0 is write-protected,mounting read-only

View mount information

[root@m01] # df-h

Filesystem Size Used Avail Use% Mounted on

/ dev/sda3 6.9G 1.5G 5.1G 23% /

Tmpfs 238M 0 238m 0% / dev/shm

/ dev/sda1 190M 34M 147M 19% / boot

/ dev/sr0 3.7G 3.7g 0100% / var/www/html/CentOS6.8

Test whether the browser can access it properly.

Or use the curl command to test

[root@m01] # curl-I 172.16.1.61/CentOS6.8/

HTTP/1.1 200 OK

Date: Mon, 12 Jun 2017 02:24:14 GMT

Server: Apache/2.2.15 (CentOS)

Connection: close

Content-Type: text/html;charset=UTF-8

Configure PXE launcher 2.6.1PXE Boot configuration (bootstrap)

Syslinux is a powerful boot loader and is compatible with a variety of media. SYSLINUX is a small Linux operating system designed to simplify the time it takes to install Linux for the first time and to create a boot disk for repair or other special purposes. If you can't find the pxelinux.0 file, you can install it.

Configure syslinux

Install syslinux through yum

Yum-y install syslinux

Copy the startup file to the tftp root directory

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

# check whether the file is available in the directory

[root@m01 ~] # ls / var/lib/tftpboot/

Pxelinux.0

Copy the relevant startup files to the tftp root directory

Cp-a / var/www/html/CentOS6.8/isolinux/*/var/lib/tftpboot/

# check whether the startup files related to Linux have been copied properly

[root@m01 ~] # ls / var/lib/tftpboot/

Boot.cat grub.conf isolinux.bin memtest splash.jpg vesamenu.c32

Boot.msg initrd.img isolinux.cfg pxelinux.0 TRANS.TBL vmlinuz

Create a pxelinux.cfg directory to hold configuration files

Mkdir-p / var/lib/tftpboot/pxelinux.cfg

# Note that this is the directory where the configuration files are stored. It is not a file. It can store many configuration files.

Cd / var/lib/tftpboot/pxelinux.cfg

Cp / var/www/html/CentOS6.8/isolinux/isolinux.cfg/var/lib/tftpboot/pxelinux.cfg/default

# copy the isolinux.cfg configuration file in the image to this directory and rename it to default

[root@m01 pxelinux.cfg] # ll

Total 4

1 root root 923 Jun 12 10:31 default

Detailed explanation of 2.6.2PXE configuration file default

The following figure shows the startup menu directory where we installed the CentOS system

[root@m01 ~] # cat/var/lib/tftpboot/pxelinux.cfg/default

Default vesamenu.c32 # loads a menu by default

When # prompt 1 # is turned on, the command line 'boot:' prompt is displayed. A value of 0 will not be displayed, and the content specified in the default parameter will be launched directly.

Timeout 600 # timeout time is the time to wait for the user to select manually when booting. It is set to 1 to boot directly, and the unit is 1pm 10 seconds.

Display boot.msg

# launch menu background picture, title, color

Menu background splash.jpg

Menu title Welcome to CentOS 6.8!

Menu color border 0 # ffffffff # 00000000

Menu color sel 7 # ffffffff # ff000000

Menu color title 0 # ffffffff # 00000000

Menu color tabmsg 0 # ffffffff # 00000000

Menu color unsel 0 # ffffffff # 00000000

Menu color hotsel 0 # ff000000 # ffffffff

Menu color hotkey 7 # ffffffff # ff000000

Menu color scrollbar 0 # ffffffff # 00000000

# label specifies the keywords entered at the boot: prompt, such as boot:linux [ENTER], which launches the kernel and initrd.img files marked under label linux.

Label linux # A tag is a line of options in the previous picture

Menu Label ^ install or upgrade an existing system

Menudefault

Kernelvmlinuz # specifies the kernel to boot. Also pay attention to the path, the default is the / tftpboot directory.

Appendinitrd=initrd.img # specifies the parameters appended to the kernel, and initrd.img is the smallest Linux system

Label vesa

Menu labelInstall system with ^ basic video driver

Kernelvmlinuz

Appendinitrd=initrd.img nomodeset

Label rescue

Menu label ^ Rescue installed system

Kernelvmlinuz

Appendinitrd=initrd.img rescue

Label local

Menu labelBoot from ^ local drive

Localboot0xffff

Label memtest86

Menu Label ^ memory test

Kernelmemtest

Append-

2.7 Manual network installation CentOS6.82.7.1 create a new virtual machine

Create a new virtual machine = > CentOS 64-bit = > specify 100G disk = > LAN section is the same as kickstart server = > take snapshots for easy repeated use = > turn on power

Expansion: after the DELL R710 server is started, press F12 according to the prompts to start PXE. The physical server has four network cards, so you will also have to choose which network card to boot from.

After turning on the power, assign the IP address and download the startup file

2.7.2 choose to install the system

Go to the startup menu and select the first new installation system

2.7.3 Select language and keyboard

Language selection English = > Keyboard Select us

2.7.4 choose the installation method and disable IPv6 on the network card

Here we choose Network installation = > URL installation = > eth2 installation

Note: use NFS to write nfs:10.0.0.1:/data/sys/kickstart/ks.cfg

Disable IPv6 after selecting eth2

2.7.5 enter the address of HTTP to download the image

Enter the URL of the page accessed by the previous browser, but change the extranet IP to the intranet IP

The subsequent installation steps are exactly the same as the CD-ROM installation system (for more information, please see the enterprise standard installation CentOS6.8 system)

Chapter 3 create ks.cfg Auto answer File 3.1ks.cfg Auto answer File description

Based on the previous installation and configuration of kickstart and manual network installation, we do the following

Usually, in the process of installing the operating system, we need a lot of server interaction, in order to reduce this interaction process, kickstart was born. Using this kind of kickstart, you only need to define a kickstart auto-answer configuration file ks.cfg (usually stored on the installation server), and let the installer know the location of the configuration file, and the installer can read the installation configuration from the file during the installation process, so as to avoid multiple human-computer interactions in the installation process, thus realizing unattended automatic installation.

There are three ways to generate kickstart auto-answer files:

Method 1: every time a Centos machine is installed, the Centos installer will create a kickstart configuration file to record your actual installation configuration. If you want to implement an installation similar to a system, you can generate your own kickstart configuration file based on the system's kickstart configuration file. (the generated file is named anaconda-ks.cfg at / root/anaconda-ks.cfg)

The method 2:Centos provides a graphical kickstart configuration tool. Run the tool on any installed Linux system and you can easily create your own kickstart configuration file. The kickstart configuration tool command is redhat-config-kickstart (RHEL3) or system-config-kickstart (RHEL4,RHEL5). There are many articles on the Internet that use CentOS desktop version to generate ks files, and if there is an off-the-shelf system, there is nothing to say. But there is no ready-made, there is no need to use the desktop version, the command line is also very simple.

Method 3: read the manual of the kickstart configuration file. You can create your own kickstart configuration file with any text editor.

View the anaconda-ks.cfg file

This file is a record file automatically generated after the system is created. By default, it is in the / root directory.

[root@m01 ~] # cat anaconda-ks.cfg

# Kickstart file automatically generated byanaconda.

# version=DEVEL

Install

Cdrom

Lang en_US.UTF-8

Keyboard us

Network-onboot no-device eth0-bootproto dhcp--noipv6

Rootpw-- iscrypted $6 $Nj4ZBqCyoqEjruZ3 $WDEW1bpKzDvffzYUv70FSZi60W6AAyzHXCQErNgw2tQE9OCVAB547mqm160aVb5pYG6v5mrUnbsbqNepJMDpX/

Firewall-service=ssh

Authconfig-enableshadow-passalgo=sha512

Selinux-enforcing

Timezone Asia/Shanghai

Bootloader-location=mbr-driveorder=sda--append= "crashkernel=auto rhgb quiet"

# The following is the partition information yourequested

# Note that any partitions you deleted are notexpressed

# here so unless you clear all partitions first,this is

# not guaranteed to work

# clearpart-none

# part / boot-fstype=ext4-asprimary-size=200

# part swap-asprimary-size=768

# part /-- fstype=ext4-- grow-- asprimary--size=200

Repo-name= "CentOS"-baseurl=cdrom:sr0-cost=100

% packages

@ base

@ compat-libraries

@ core

@ debugging

@ development

@ server-policy

@ workstation-policy

Python-dmidecode

Sgpio

Device-mapper-persistent-data

Systemtap-client

% end

Detailed explanation of 3.3ks.cfg automatic answer file

Official website document

CentOS5: http://www.centos.org/docs/5/html/Installation_Guide-en-US/s1-kickstart2-options.html

CentOS6: https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Installation_Guide/s1-kickstart2-options.html

The official website has its own Chinese version, you can choose the language.

The composition of ks.cfg files is roughly divided into three segments.

Command segment

Keyboard type, language, installation mode and other system configuration, there are required options and options, if a required option is missing, the installation will be interrupted and the user will be prompted to select the option of this item.

Software package segment

% packages

@ groupname: specify the package group to install

Package_name: specify the package to install

-package_name: specify packages that are not installed

Software packages installed by default during installation, dependencies are automatically analyzed when the software is installed.

Script segment (optional)

% pre: commands or scripts executed before installing the system (because only rely on the boot image, few commands are supported)

% post: commands or scripts executed after installing the system (almost all commands are supported)

Explanation of the specific meaning:

Keyword

Meaning

Install

Tell the installer that this is a fresh installation, not an upgrade of upgrade

Url-url= ""

Install from the installation tree on the remote server via FTP or HTTP

Url-- url ftp://:@/

Url-url= "http://10.0.0.7/CentOS-6.8/"

Nfs

Install from a specified NFS server

Nfs-server=nfsserver.example.com-dir=/tmp/install-tree

Text

Install using text mode

Lang

Set the language used during the installation process and the default language of the system: lang en_US.UTF-8

Keyboard

Set system keyboard type: keyboard us

Zerombr

Clear mbr boot information

Bootloader

The system boots the relevant configuration.

Bootloader-location=mbr-driveorder=sda-append= "crashkernel=auto rhgb quiet"

-- location=, specifies where the boot record is written. Valid values are: mbr (the default), partition (install the bootloader in the first sector of the partition containing the kernel), or none (no bootloader is installed).

-- driveorder, which specifies the drive at the top of the BIOS boot sequence.

-- append=, specifies kernel parameters. To specify multiple parameters, separate them with spaces.

Network

Configure networking information for kickstart installation over the network and for installed systems.

Network-bootproto=dhcp-device=eth0-onboot=yes-noipv6-hostname=CentOS6

-- one of the bootproto= [dhcp/bootp/static], the default value is dhcp. Bootp and dhcp are considered to be the same.

The static method requires that all the network information be entered in the kickstart file.

Network-bootproto=static-ip=10.0.0.100-netmask=255.255.255.0-gateway=10.0.0.2-nameserver=10.0.0.2

Note that all configuration information must be specified on one line and cannot be wrapped with a backslash.

-- the IP address of the machine to be installed by ip=,.

-- default gateway in gateway=,IP address format.

-- the subnet mask of the system installed by netmask=,.

-- the hostname of the system installed by hostname=,.

Whether onboot=, enables the device at boot time.

Noipv6=, disables IPv6 for this device.

-- nameserver=, configures dns resolution.

Timezone

Set system time zone: timezone-- utc Asia/Shanghai

Authconfig

System authentication information. Authconfig-enableshadow-passalgo=sha512

Set password encryption method to enable shadow files for sha512

Rootpw

Root password, followed by a password generated using grub-crypt

Clearpart

Clear partition clearpart-- all-- initlabel

-- all clears all partitions from the system,-- initlable initializes disk labels

Part

Disk partition

Part / boot-fstype=ext4-asprimary-size=200

Part swap-asprimary-size=768

Part /-- fstype=ext4-- grow-- asprimary-- size=200

Fstype=: sets the file system type for the partition. Valid types are ext2,ext3,swap and vfat.

-- asprimary: forces the partition to be assigned to the primary partition, otherwise it indicates that the partition failed.

-- the minimum value of the partition in MB for size=:. Specify an integer value here, such as 500. Do not add MB after the number.

-- grow: tells the partition to use all available space, if any, or to use the maximum value set.

Firstboot

Responsible for assisting in configuring some important information about redhat

Firstboot-disable

Selinux

Close selinux:selinux-- disabled

Firewall

Turn off the firewall: firewall-- disabled

Logging

Set log level: logging-- level=info

Reboot

Set to restart after the installation is complete, this option must exist, otherwise kickstart displays a message and waits for the user to press any key before rebooting, or you can choose halt to shut down

3.4.Writing ks.cfg auto-answer files

First use grub-crypt to generate a password backup

[root@m01 ~] # grub-crypt

Password: 123456

Retype password: 123456

$6 $VTNRZpXZjvvzA3WO$t1upYjcs7mDa31O5OnnoMxIuJ0W6icoaFEG9y8xsQUtDUuzLi1.E67Uht7tf8BLBY4PnHT2/zMo5S2.tymqeS/

Create a directory where ks files are stored (under the site directory)

[root@m01] # mkdir-p / var/www/html/ks_config

[root@m01 ~] # vim/var/www/html/ks_config/CentOS-6.8-ks.cfg

# Kickstart Configurator for CentOS 6.8 by hujing

Install

Url--url= "http://172.16.1.61/CentOS6.8/"

Text

Lang en_US.UTF-8

Keyboard us

Zerombr

Bootloader-location=mbr-driveorder=sda--append= "crashkernel=auto rhgb quiet"

Network-bootproto=dhcp-device=eth2--onboot=yes-noipv6-hostname=CentOS6

Timezone-utc Asia/Shanghai

Authconfig-enableshadow-passalgo=sha512

Clearpart-all-initlabel

Part / boot-fstype=ext4-asprimary-size=200

Part swap-size=1024

Part /-- fstype=ext4-- grow-- asprimary-- size=200

Firstboot-disable

Selinux-disabled

Firewall-disabled

Logging-level=info

Reboot

% packages

@ base

@ compat-libraries

@ debugging

@ development

Tree

Nmap

Sysstat

Lrzsz

Dos2unix

Telnet

% post

Wget-O / tmp/optimization.sh http://172.16.1.61/ks_config/optimization.sh & > / dev/null

/ bin/sh / tmp/optimization.sh

% end

3.5 Boot Optimization script

That is, the optimization.sh in the% post in the ks.cfg above

[root@m01 ~] # cat/var/www/html/ks_config/optimization.sh

#! / bin/bash

. / etc/init.d/functions

Ip=172.16.1.61

Port=80

ConfigDir=ks_config

# Judge Http server is ok?

PortNum= `nmap $Ip-p $Port 2 > / dev/null | grep open | wc-l`

[$PortNum-lt 1] & & {

Echo "Http server is bad!"

Exit 1

}

# Defined result function

Function Msg () {

If [$?-eq 0]; then

Action "$1" / bin/true

Else

Action "$1" / bin/false

Fi

}

# Defined IP function

Function ConfigIP () {

Suffix= `ifconfigeth2 | awk-F "[.] +" NR==2 {print $6}'`

Cat > / etc/sysconfig/network-scripts/ifcfg-eth0 / dev/null & &\

Echo "123456" | passwd-- stdin hujing & > / dev/null & &\

Sed-I '98a hujing ALL= (ALL) NOPASSWD:ALL' / etc/sudoers & &\

Visudo-c & > / dev/null

Msg "AddUser hujing"

}

# Defined Hide the system version number Functions

Function HideVersion () {

[- f "/ etc/issue"] & & > / etc/issue

Msg "Hide issue"

[- f "/ etc/issue.net"] & & > / etc/issue.net

Msg "Hide issue.net"

}

# Defined SSHD config Functions

Function sshd () {

SshdDir=/etc/ssh

[- f "$SshdDir/sshd_config"] & & / bin/mv$SshdDir/sshd_config {, .ori}

Wget-O$SshdDir/sshd_config http://$Ip:$Port/$ConfigDir/sshd_config & > / dev/null&&\

Chmod 600$ SshdDir/sshd_config

Msg "sshd config"

}

# Defined OPEN FILES Functions

Function openfiles () {

[- f "/ etc/security/limits.conf"] & & {

Echo'*-nofile 65535'> > / etc/security/limits.conf

Msg "open files"

}

}

# Defined Kernel parameters Functions

Function kernel () {

KernelDir=/etc

[- f "$KernelDir/sysctl.conf"] & & / bin/mv$KernelDir/sysctl.conf {, .ori}

Wget-O$KernelDir/sysctl.conf http://$Ip:$Port/$ConfigDir/sysctl.conf&>/dev/null

Msg "Kernel config"

}

# Defined hosts file Functions

Function hosts () {

HostsDir=/etc

[- f "$HostsDir/hosts"] & & / bin/mv $HostsDir/hosts {, .ori}

Wget-O $HostsDir/hosts http://$Ip:$Port/$ConfigDir/hosts & > / dev/null

Msg "Hosts config"

}

# Defined System Startup Services Functions

Function boot () {

For hujingin `chkconfig-- list | grep "3:on" | awk'{print $1}'| grep-vE "crond | network | rsyslog | sshd | sysstat" `

Do

Chkconfig $hujing off

Done

Msg "BOOT config"

}

# Defined Time Synchronization Functions

Function Time () {

Echo "# time sync by zhangyao at $(date +% F)" > > / var/spool/cron/root

Echo'* / 5* / usr/sbin/ntpdate ntp1.aliyun.com & > / dev/null' > > / var/spool/cron/root

Msg "Time Synchronization"

}

# Defined main Functions

Function main () {

ConfigIP

Yum

AddUser

HideVersion

Sshd

Openfiles

Kernel

Hosts

Boot

Time

}

Main

3.6 integrate and edit default configuration files

Quick execution of commands

Cat > / var/lib/tftpboot/pxelinux.cfg/default

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report