KICKSTART+HTTP+DHCP+TFTP Automatic bulk installation deployment in Linux systems

Source: Internet
Author: User
Tags mkdir stdin centos iptables nameserver
Description
Kickstart Server System: CentOS 5.10 64-bit
IP Address: 192.168.21.128
Need to install a deployed Linux system: CentOS 5.10 64-bit
Eth0 (first network card, for extranet) IP address segment: 192.168.21.160-192.168.21.200
ETH1 (second network card, for intranet) IP address segment: 10.0.0.160-10.0.0.200
Subnet Mask: 255.255.255.0
Gateway: 192.168.21.2
dns:8.8.8.8 8.8.4.4
All servers support PXE network boot
to achieve the purpose: deploy Linux systems in bulk by configuring Kickstart servers
Specific actions:
Part I: Operating in the Kickstart server system
First, close SELinux
Vi/etc/selinux/config
#SELINUX =enforcing #注释掉
#SELINUXTYPE =targeted #注释掉
Selinux=disabled #增加
: wq! #保存退出
Setenforce 0 #使配置立即生效
Second, configure the firewall, open tcp:80 port, udp:69 port
Vi/etc/sysconfig/iptables #编辑
-A rh-firewall-1-input-m state--state new-m tcp-p TCP--dport 80-j ACCEPT #http服务需要此端口
-A rh-firewall-1-input-m state--state new-m udp-p UDP--dport 69-j ACCEPT #tftp服务需要此端口
/etc/init.d/iptables Restart #最后重启防火墙使配置生效
Third, install HTTP server
Yum Install httpd #安装
Chkconfig httpd on #设置开机启动
Service httpd Start #启动
Four, mount system installation mirroring to the HTTP Server site Directory
Upload system installation image file Centos-5.10-x86_64-bin-dvd-1of2.iso to/usr/local/src/directory
Mkdir-p/var/www/html/os #创建挂载目录
Mount-t Iso9660-o Loop/usr/local/src/centos-5.10-x86_64-bin-dvd-1of2.iso/var/www/html/os #挂载系统镜像
Vi/etc/fstab #添加以下代码. Enable automatic mount on boot
/usr/local/src/centos-5.10-x86_64-bin-dvd-1of2.iso/var/www/html/os iso9660 defaults,ro,loop 0 0
: wq! #保存退出
Note: iso9660 use DF-T to view device uninstall: Umount/var/www/html/os
V. Installing a TFTP server
Yum Install TFTP tftp-server #安装
Vi/etc/xinetd.d/tftp #编辑
Service TFTP
{
Socket_type = Dgram
protocol = UDP
Wait = yes
user = root
Server =/USR/SBIN/IN.TFTPD
Server_args =-s/var/lib/tftpboot
Disable = no
Per_source = 11
CPS = 100 2
Flags = IPV4
}
: wq! #保存退出
Service xinetd Start #启动
Mkdir-p/var/lib/tftpboot
Cp/var/www/html/os/images/pxeboot/vmlinuz/var/lib/tftpboot
Cp/var/www/html/os/images/pxeboot/initrd.img/var/lib/tftpboot
Mkdir-p/var/lib/tftpboot/pxelinux.cfg
Cp/var/www/html/os/isolinux/isolinux.cfg/var/lib/tftpboot/pxelinux.cfg/default #拷贝启动菜单
Vi/var/lib/tftpboot/pxelinux.cfg/default #编辑修改
Default Linux
Prompt 0
Timeout 600
Display Boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
Label Linux
Kernel Vmlinuz
Append initrd=initrd.img ks=http://192.168.21.128/ks.cfg ksdevice=eth0 ip=dhcp
Label text
Kernel Vmlinuz
Append initrd=initrd.img Text
Label KS
Kernel Vmlinuz
Append KS initrd=initrd.img
Label Local
Localboot 1
Label Memtest86
Kernel memtest
Append-
: wq! #保存退出
chmod 644/var/lib/tftpboot/pxelinux.cfg/default #设置文件权限
Yum Install Syslinux #安装引导程序
cp/usr/share/syslinux/pxelinux.0/var/lib/tftpboot/#拷贝引导文件到tftp服务器根目录
Vi. Installing a DHCP server
Yum Install DHCP #安装
Cp/usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample/etc/dhcpd.conf #复制配置文件模板
Vi/etc/dhcpd.conf #编辑配置文件
Ddns-update-style Interim; #设置DHCP服务器模式
Ignore client-updates; #禁止客户端更新
Subnet 192.168.21.0 netmask 255.255.255.0 {#设置网段
Option routers 192.168.21.2; #设置网关
Option Subnet-mask 255.255.255.0; #设置子网掩码
Option Domain-name-servers 8.8.8.8,8.8.4.4; #设置dns服务器地址
Range DYNAMIC-BOOTP 192.168.21.160 192.168.21.200; #设置dhcp服务器IP地址租用的范围
Default-lease-time 21600; #默认租约时间
Max-lease-time 43200; #最大租约时间
Next-server 192.168.21.128; #tftp服务器地址
FileName "pxelinux.0"; #tftp服务器根目录下面的文件名
}
: wq! #保存退出
VI/ETC/SYSCONFIG/DHCPD #指定DHCP服务的网络接口
Dhcpdargs=eth0
: wq! #保存退出
DHCPD #测试dhcp服务器配置是否正确
Service DHCPD Start #启动dhcp服务
Chkconfig DHCPD on #设置开机启动
System Yun-wei Www.111cn.net warm reminder: qihang01 original Content © Copyright, reproduced please specify the source and the original link
Vii. Configuring Kickstart automatic installation files
Yum Install System-config-kickstart #安装工具包
Cd/var/www/html
VI ks.cfg #编辑
# Kickstart file automatically generated by Anaconda.
Install
URL--url=http://192.168.21.128/os/
Lang en_US. UTF-8
ZEROMBR Yes
Key--skip
Keyboard US
Network--device eth0--bootproto DHCP--onboot on
#network--device eth0--bootproto static--ip 192.168.21.250--netmask 255.255.255.0--gateway 192.168.21.2--nameserver 8.8.8.8--hostname CentOS5.10
ROOTPW--iscrypted $1$qqobzz1g$rynrawi9kyleeuuq1vcrs/
Firewall--enabled--port=22:tcp
Authconfig--enableshadow--ENABLEMD5
SELinux--disabled
TimeZone Asia/shanghai
Bootloader--LOCATION=MBR--DRIVEORDER=SDA
# The following is the partition information for you requested
# that ' any partitions ' deleted are not expressed
# Here I unless you clear all partitions the
# Not guaranteed to work
#clearpart--linux
Clearpart--all--initlabel
Part/--bytes-per-inode=4096--fstype= "ext3"--size=2048
Part/boot--bytes-per-inode=4096--fstype= "ext3"--size=128
Part swap--bytes-per-inode=4096--fstype= "swap"--size=500
Part/data--bytes-per-inode=4096--fstype= "ext3"--grow--size=1
Reboot
%packages
Ntp
Expect
@base
@core
@dialup
@editors
@text-internet
Keyutils
Trousers
Fipscheck
Device-mapper-multipath
%post
#同步系统时间
Ntpdate cn.pool.ntp.org
Hwclock--SYSTOHC
ECHO-E "0 1 * * * root/usr/sbin/ntpdate cn.pool.ntp.org >/dev/null" >>/etc/crontab
Service Crond Restart
#添加用户组
Groupadd Maintain
Groupadd Develop
Mkdir-p/home/maintain
Mkdir-p/home/develop
#添加用户
Useradd-g Maintain user01-d/home/maintain/user01-m
echo "123456" |passwd User01--stdin
Useradd-g Maintain user02-d/home/maintain/user02-m
echo "123456" |passwd user02--stdin
Useradd-g Maintain user03-d/home/maintain/user03-m
echo "123456" |passwd user03--stdin
Useradd-g Maintain user04-d/home/maintain/user04-m
echo "123456" |passwd user04--stdin
#禁止root用户直接登录系统
Sed-i "s/#PermitRootLogin yes/permitrootlogin no/g" '/etc/ssh/sshd_config '
Service sshd Restart
#禁止开机启动的服务
Chkconfig Acpid off
Chkconfig ATD Off
Chkconfig AutoFS off
Chkconfig bluetooth off
Chkconfig Cpuspeed off
Chkconfig Firstboot off
Chkconfig gpm Off
Chkconfig Haldaemon off
Chkconfig Hidd off
Chkconfig Ip6tables off
Chkconfig ISDN Off
Chkconfig Messagebus off
Chkconfig Nfslock off
Chkconfig PCSCD off
Chkconfig Portmap off
Chkconfig RPCGSSD off
Chkconfig RPCIDMAPD off
Chkconfig yum-updatesd off
Chkconfig SendMail off
#允许开机启动的服务
Chkconfig Crond on
Chkconfig kudzu on
Chkconfig Network on
Chkconfig readahead_early on
Chkconfig sshd on
Chkconfig syslog on
#禁止使用Ctrl +alt+del shortcut keys to restart the server
Sed-i "S/ca::ctrlaltdel:/sbin/shutdown-t3-r now/#ca:: Ctrlaltdel:/sbin/shutdown-t3-r now/g" '/etc/inittab '
Telinit Q
#优化系统内核
Echo-e "Ulimit-c Unlimited" >>/etc/profile
Echo-e "Ulimit-s Unlimited" >>/etc/profile
Echo-e "Ulimit-shn 65535" >>/etc/profile
Source/etc/profile
Sed-i "S/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g" '/etc/sysctl.conf '
Echo-e "net.core.somaxconn = 262144" >>/etc/sysctl.conf
Echo-e "Net.core.netdev_max_backlog = 262144" >>/etc/sysctl.conf
Echo-e "Net.core.wmem_default = 8388608" >>/etc/sysctl.conf
Echo-e "Net.core.rmem_default = 8388608" >>/etc/sysctl.conf
Echo-e "Net.core.rmem_max = 16777216" >>/etc/sysctl.conf
Echo-e "Net.core.wmem_max = 16777216" >>/etc/sysctl.conf
Echo-e "Net.ipv4.netfilter.ip_conntrack_max = 131072" >>/etc/sysctl.conf
Echo-e "net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 180" >>/etc/sysctl.conf
Echo-e "net.ipv4.route.gc_timeout =" >>/etc/sysctl.conf
Echo-e "Net.ipv4.ip_conntrack_max = 819200" >>/etc/sysctl.conf
Echo-e "Net.ipv4.ip_local_port_range = 10024 65535" >>/etc/sysctl.conf
Echo-e "Net.ipv4.tcp_retries2 = 5" >>/etc/sysctl.conf
Echo-e "net.ipv4.tcp_fin_timeout = >>/etc/sysctl.conf"
Echo-e "net.ipv4.tcp_syn_retries = 1" >>/etc/sysctl.conf
Echo-e "net.ipv4.tcp_synack_retries = 1" >>/etc/sysctl.conf
Echo-e "net.ipv4.tcp_timestamps = 0" >>/etc/sysctl.conf
Echo-e "net.ipv4.tcp_tw_recycle = 1" >>/etc/sysctl.conf
Echo-e "Net.ipv4.tcp_tw_len = 1" >>/etc/sysctl.conf
Echo-e "Net.ipv4.tcp_tw_reuse = 1" >>/etc/sysctl.conf
Echo-e "net.ipv4.tcp_keepalive_time =/etc/sysctl.conf" >>
Echo-e "Net.ipv4.tcp_keepalive_probes = 3" >>/etc/sysctl.conf
Echo-e "NET.IPV4.TCP_KEEPALIVE_INTVL =" >>/etc/sysctl.conf
Echo-e "net.ipv4.tcp_max_tw_buckets = 36000" >>/etc/sysctl.conf
Echo-e "Net.ipv4.tcp_max_orphans = 3276800" >>/etc/sysctl.conf
Echo-e "Net.ipv4.tcp_max_syn_backlog = 262144" >>/etc/sysctl.conf
Echo-e "Net.ipv4.tcp_wmem = 8192 131072 16777216" >>/etc/sysctl.conf
Echo-e "Net.ipv4.tcp_rmem = 32768 131072 16777216" >>/etc/sysctl.conf
Echo-e "Net.ipv4.tcp_mem = 94500000 915000000 927000000" >>/etc/sysctl.conf
/sbin/sysctl-p
#执行外部脚本
Cd/root
wget http://192.168.21.128/autoip.sh
sh/root/autoip.sh
: wq! #保存退出
Eight, add script, automatically set Linux system static IP address, DNS, Gateway, computer name
Cd/var/www/html
VI autoip.sh #编辑
#!/bin/sh
route=$ (route-n|grep "^0.0.0.0" |awk ' {print $} ')
broadcast=$ (/sbin/ifconfig eth0|grep-i Bcast|awk ' {print $} ' |awk-f ': ' ' {print $} ')
hwaddr=$ (/sbin/ifconfig eth0|grep-i Hwaddr|awk ' {print $} ')
ipaddr=$ (/sbin/ifconfig eth0|grep "inet addr" |awk ' {print $} ' |awk-f ":" ' {print $} ')
netmask=$ (/sbin/ifconfig eth0|grep "inet addr" |awk ' {print $} ' |awk-f ': "' {print $} ')
Cat >/etc/sysconfig/network-scripts/ifcfg-eth0<<eof
Device=eth0
Bootproto=static
broadcast= $BROADCAST
Hwaddr= $HWADDR
Ipaddr= $IPADDR
netmask= $NETMASK
gateway= $ROUTE
Onboot=yes
Eof
ipaddr1=$ (Echo $IPADDR |awk-f "." ' {print $} ')
Cat >/etc/sysconfig/network-scripts/ifcfg-eth1<<eof
Device=eth1
Bootproto=static
broadcast=10.0.0.255
hwaddr=$ (/sbin/ifconfig eth1|grep-i Hwaddr|awk ' {print $} ')
ipaddr=10.0.0. $IPADDR 1
netmask=255.255.255.0
Onboot=yes
Eof
hostname=osyunwei_hz_$ (Echo $IPADDR |awk-f "." ' {print $} ')
Cat >/etc/sysconfig/network<<eof
Networking=yes
Networking_ipv6=no
Hostname= $HOSTNAME
gateway= $ROUTE
Eof
echo "127.0.0.1 $HOSTNAME" >>/etc/hosts
Hostname= $HOSTNAME
echo "NameServer 8.8.8.8" >/etc/resolv.conf
echo "NameServer 8.8.4.4" >>/etc/resolv.conf
: wq! #保存退出
Part Two: Set up the server to be installed from the network boot
After powering on, the system is installed automatically as shown in the following illustration
System Yun-wei Www.111cn.net warm reminder: qihang01 original Content © Copyright, reproduced please specify the source and the original link
Note: After the system installation is completed, the first boot please set to the hard disk, otherwise the system will automatically install the system again!

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.