上一篇刚刚完成了nagios的自动安装,这篇继续吧,想到前些天手动配置kickstart服务器过程比较繁琐,思路也不够清晰,还是把安装配置过程写进脚本非常方便,感觉是一劳永逸,降低后续工作的劳动量,而且整个思路过程比较清晰。
实验环境:centos6.3 x86_64
关闭了防火墙, SELinux设为Disabled
注意:虚拟机需要先载入centos6.3 x86_64的安装镜像iso
脚本里的MAC地址需要修改为你当前机器的MAC地址
ks.cfg配置文件中关于设定客户机密码需要改为自己设定
直接执行该脚本即可开始安装配置kickstart。
本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Servers/zs/
#!/bin/bash #auto install kickstart server LANG=C mkdir /tftpboot mkdir /tftpboot/pxelinux.cfg mkdir /mnt/iso mount -o loop /dev/dvd /mnt/iso function init_pack() { yum -y install dhcp httpd xinetd tftp tftp-server syslinux chkconfig httpd on chkconfig dhcpd on chkconfig xinetd on service httpd start service dhcpd start service xinetd start } function set_tftp() { cp /etc/xinetd.d/tftp /etc/xinetd.d/tftp.bak echo 'service tftp { disable = no socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -u nobody -s /tftpboot per_source = 11 cps = 100 2 flags = IPv4 }' > /etc/xinetd.d/tftp #need to format the text } function set_eth() { echo 'DEVICE="eth0" BOOTPROTO="static" IPADDR="192.168.10.1" NETMASK="255.255.255.0" GATEWAY="192.168.10.1" HWADDR="08:00:27:6B:2F:46" NM_CONTROLLED="yes" ONBOOT="yes"' > /etc/sysconfig/network-scripts/ifcfg-eth0 #need to format the text sed -i 's/^ *//g' /etc/sysconfig/network-scripts/ifcfg-eth0 ifdown eth0;ifup eth0 } function set_dhcp() { sed -i '1,$s/^/#/g' /etc/dhcp/dhcpd.conf echo 'subnet 192.168.10.0 netmask 255.255.255.0 { option routers 192.168.10.1; option subnet-mask 255.255.255.0; range 192.168.10.10 192.168.10.50; next-server 192.168.10.1; default-lease-time 600; max-lease-time 7200; filename "pxelinux.0"; allow booting; allow bootp; }' >> /etc/dhcp/dhcpd.conf #need to format the text sed -i 's/^ *//g' /etc/dhcp/dhcpd.conf #remove the blanks at beginning service dhcpd restart } function cp_files() { cp -rv /mnt/iso/* /var/www/html cp -v /mnt/iso/isolinux/initrd.img /tftpboot cp -v /mnt/iso/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default cp -v /mnt/iso/isolinux/vmlinuz /tftpboot cp -v /mnt/iso/isolinux/vesamenu.c32 /tftpboot/vesamenu.c32 cp -v /usr/share/syslinux/pxelinux.0 /tftpboot chmod +x /tftpboot/pxelinux.cfg/default chcon -u system_u -t tftpdir_t /tftpboot -R #modify the selinux context type chcon --reference=/var/www/html /var/www/html -R } function set_kscfg() { echo '#platform=x86, AMD64, or Intel EM64T #version=DEVEL # Firewall configuration firewall --disabled # Install OS instead of upgrade install # Use network installation url --url="http://192.168.10.1/" # Root password rootpw --iscrypted $1$xhuJUwps$czE5aVuNeRhrbQYZ8YAmy1 #密码自己设定,可用明文也可加密 # System authorization information auth --useshadow --passalgo=sha512 # Use graphical install graphical firstboot --disable # System keyboard keyboard us # System language lang en_US # SELinux configuration selinux --permissive # Do not configure the X Window System skipx # Installation logging level logging --level=info # Reboot after installation reboot # System timezone timezone --isUtc Asia/Chongqing # Network information network --bootproto=dhcp --device=eth0 --onboot=on # System bootloader configuration bootloader --location=mbr # Partition clearing information clearpart --all --initlabel # Disk partitioning information part /boot --fstype="ext4" --size=200 part / --fstype="ext4" --size=6000 part swap --fstype="swap" --size=512 part /home --fstype="ext4" --size=1024 %packages @additional-devel @development %end' > /var/www/html/ks.cfg sed -i 's/^ *//g' /var/www/html/ks.cfg chmod 755 /var/www/html/ks.cfg chcon --reference=/var/www/html /var/www/html/ks.cfg } function set_default() { echo 'default vesamenu.c32 #prompt 1 timeout 30 display boot.msg menu background splash.jpg menu title Welcome to CentOS 6.3! 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 linux menu label ^Install or upgrade an existing system menu default kernel vmlinuz append initrd=initrd.img ks=http://192.168.10.1/ks.cfg label vesa menu label Install system with ^basic video driver kernel vmlinuz append initrd=initrd.img xdriver=vesa nomodeset label rescue menu label ^Rescue installed system kernel vmlinuz append initrd=initrd.img rescue label local menu label Boot from ^local drive localboot 0xffff label memtest86 menu label ^Memory test kernel memtest append -' > /tftpboot/pxelinux.cfg/default sed -i 's/^ *//g' /tftpboot/pxelinux.cfg/default chcon -u system_u -t tftpdir_t /tftpboot/pxelinux.cfg/default } init_pack if [ $(rpm -q tftp) -a $(rpm -q dhcp) -a $(rpm -q httpd) -a $(rpm -q syslinux) ]; then #check if these services have been installed set_tftp set_eth set_dhcp cp_files set_kscfg set_default else echo "installed incompleted." fi
本文出自 “努力为之” 博客,请务必保留此出处http://carllai.blog.51cto.com/1664997/1060719
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索menu
, color
, function
, label
, default
ext 权限 menu 动态
kickstart 配置、kickstart配置文件、kickstart 分区配置、kickstart配置界面、服务器自动化部署,以便于您获取更多的相关知识。