- [python] view plaincopyprint?
- #!/bin/bash
- # by wu 2012-07-28
- # RHEL6 unattended deployment,用于RHEL6无人值守搭建.v1.0
- # 有不足的地方还请见谅
- #搭建yum
- Yum_build()
- {
- yum clean all &>/dev/null
- num_list=$(yum list | wc -l)
- yum clean all &>/dev/null
- if [[ $num_list < 2000 ]];then
- mount /dev/cdrom /mnt
- if [ -d /etc/yum.repos.d/bak ];then
- mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
- else
- mkdir /etc/yum.repos.d/bak
- mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
- fi
- cat << EOF > /etc/yum.repos.d/base.repo
- [base]
- name=base
- baseurl=file:///mnt
- enabled=1
- gpgcheck=0
- EOF
- else
- echo "yum is ok!"
- fi
- }
- Check_rpm()
- {
- Packages=(dhcp tftp-server vsftpd syslinux)
- for i in ${Packages[@]}
- do
- if ! rpm -q $i &> /dev/null;then
- yum install $i -y &>/dev/null
- fi
- done
- }
- #dhcp服务搭建以及网络安装引导文件
- dhcp_build()
- {
- read -p "输入所在subnet、netmask、broadcast、gateway: " subnet netmask broadcast gateway
- read -p "输入next-server地址: " next_server
- read -p "提供IP的范围start_ip end_ip: " start_ip end_ip
- cat << EOF >/etc/dhcp/dhcpd.conf
- subnet $subnet netmask $netmask {
- range $start_ip $end_ip;
- option routers $gateway;
- option broadcast-address $broadcast;
- default-lease-time 600;
- max-lease-time 7200;
- filename "pxelinux.0";
- next-server $next_server;
- }
- EOF
- cat << EOF >/var/lib/tftpboot/pxelinux.cfg/default
- default vesamenu.c32
- #prompt 1
- timeout 600
- display boot.msg
- menu background splash.jpg
- menu title Welcome to Red Hat Enterprise Linux 6.2!
- 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 ks=ftp://$next_server/ks.cfg initrdinitrd=initrd.img
- EOF
- }
- #无人值守配置文件
- ks_cfg()
- {
- read -p "请输入无人值守ftp地址: " ftp
- cat <<EOF >/var/ftp/ks.cfg
- firewall --disabled
- install
- url --url="ftp://$ftp/iso"
- rootpw --iscrypted $1$A9aGh0yl$ahDdo0eAvQFAplXTeBkX//
- auth --useshadow --passalgo=sha512
- text
- firstboot --disable
- keyboard us
- lang zh_CN
- selinux --disabled
- logging --level=info
- reboot
- timezone Asia/Shanghai
- network --bootproto=dhcp --device=eth0 --onboot=on
- bootloader --location=mbr
- zerombr
- clearpart --all --initlabel
- part /boot --asprimary --fstype="ext4" --size=200
- part swap --asprimary --fstype="swap" --size=2048
- part / --asprimary --fstype="ext4" --size=100000
- %packages
- @additional-devel
- @backup-client
- @base
- @basic-desktop
- @chinese-support
- @client-mgmt-tools
- @compat-libraries
- @console-internet
- @debugging
- @desktop-debugging
- @desktop-platform
- @desktop-platform-devel
- @development
- @dial-up
- @directory-client
- @eclipse
- @emacs
- @fonts
- @general-desktop
- @graphical-admin-tools
- @graphics
- @hardware-monitoring
- @infiniband
- @input-methods
- @internet-browser
- @java-platform
- @kde-desktop
- @large-systems
- @legacy-unix
- @legacy-x
- @mainframe-access
- @network-file-system-client
- @network-tools
- @performance
- @perl-runtime
- @remote-desktop-clients
- @scientific
- @security-tools
- @server-platform-devel
- @smart-card
- @storage-client-fcoe
- @storage-client-iscsi
- @storage-client-multipath
- @system-management
- @system-management-messaging-client
- @system-management-messaging-server
- @system-management-snmp
- @system-management-wbem
- @technical-writing
- @tex
- @x11
- hmaccalc
- %end
- EOF
- }
- #调用函数
- Yum_build
- Check_rpm
- mkdir /var/ftp/iso &>/dev/null
- mount /dev/cdrom /var/ftp/iso &>/dev/null
- #拷贝系统引导文件
- cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
- cp -r /var/ftp/iso/isolinux/* /var/lib/tftpboot/
- mkdir /var/lib/tftpboot/pxelinux.cfg &>/dev/null
- mv /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
- #调用函数
- dhcp_build
- ks_cfg
- #设置开机启动
- chkconfig tftp on
- chkconfig dhcpd on
- chkconfig vsftpd on
- #刷新服务
- service xinetd restart &>/dev/null
- service dhcpd restart &>/dev/null
- service vsftpd restart &>/dev/null