1.cobbler安装
使用脚本安装。install_cobbler.sh
#!/bin/bash ####################### ### install cobbler ### ####################### [ $# -ne 1 ] && echo "Usage:`basename $0` <private ip for cobbler server>" && echo "eg:`basename $0` 192.168.1.1" && exit 1 cobbler_ip=$1 # check if network ping ok if ping -c2 www.shdkx.com >/dev/null 2>&1;then echo "Network is OK,now continue ..." else echo "Error: Network unreachable,now exit !" exit 1 fi is_private_ip() { local ip=$1 local int=0 echo $ip | egrep -q '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' || return 2 PRIVATE_RANGES="167772160:184549375 2886729728:2887778303 3232235520:3232301055" STEP=(shdkx shdkx 16777216 65536 256 1) for i in {1..4};do field=`echo $ip | cut -d'.' -f$i` int=$(($field*${STEP[$i]}+$int)) done for RANGE in $PRIVATE_RANGES;do RANGE_MIN=${RANGE%:*} RANGE_MAX=${RANGE#*:} [ $int -ge $RANGE_MIN -a $int -le $RANGE_MAX ] && return 0 done return 1 } ###################### check if private ip echo "ip=${cobbler_ip}" if is_private_ip $cobbler_ip;then echo "Available private ip,now continue ..." else echo "Error: Not a valid private ip,now exit !" exit 1 fi ##################### check os type ,then install distributor=`lsb_release -i | awk '{print$3}'` release=`lsb_release -r | awk '{print substr($2,1,1)}'` architecture=`arch` [ x"$architecture" != x"x86_64" ] && architecture="i386" ostype="$distributor$release" check_epel5() { if yum repolist | grep epel >/dev/null;then echo "epel already exist" else echo "install epel ..." #rpm -Uvh "http://mirrors.yun-idc.com/epel/5Server/${architecture}/epel-release-5-4.noarch.rpm" rpm -ivh http://centos.yum.sandai.net/.help/epel-release-5-4.noarch.rpm mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo_backup wget http://centos.yum.sandai.net/.help/epel5.repo -O /etc/yum.repos.d/epel.repo fi } check_epel6() { if yum repolist | grep epel >/dev/null;then echo "epel already exist" else echo "install epel ..." #rpm -Uvh "http://mirrors.yun-idc.com/epel/5Server/${architecture}/epel-release-6-8.noarch.rpm" rpm -ivh http://centos.yum.sandai.net/.help/epel-release-6-8.noarch.rpm mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo_backup wget http://centos.yum.sandai.net/.help/epel6.repo -O /etc/yum.repos.d/epel.repo fi } case $ostype in RedHatEnterpriseServer5) echo "ostype=$ostype" check_epel5 rpm -Uvh "http://centos.yum.sandai.net/centos/5.9/os/${architecture}/CentOS/python-simplejson-2.0.9-8.el5.${architecture}.rpm" wget -O /tmp/Django-1.1.4-1.el5.noarch.rpm "http://thunder:[email protected]/mahongzhan/soft/Django-1.1.4-1.el5.noarch.rpm" rpm -Uvh /tmp/Django-1.1.4-1.el5.noarch.rpm #rpm -Uvh "http://centos.yum.sandai.net/epel/5Client/x86_64/Django-1.1.4-1.el5.noarch.rpm" apt-get install httpd mod_ssl dhcp createrepo yum-utils pykickstart OpenIPMI ipmitool cman mkisofs -y || exit 1 yum install PyYAML python-netaddr python-cheetah mod_wsgi tftp-server python-ctypes cobbler cobbler-web -y ;; CentOS5) echo "ostype=$ostype" check_epel5 rpm -Uvh "http://centos.yum.sandai.net/centos/5.9/os/${architecture}/CentOS/python-simplejson-2.0.9-8.el5.${architecture}.rpm" wget -O /tmp/Django-1.1.4-1.el5.noarch.rpm "http://shdkx:[email protected]/shdkx/soft/Django-1.1.4-1.el5.noarch.rpm" rpm -Uvh /tmp/Django-1.1.4-1.el5.noarch.rpm yum install PyYAML python-netaddr python-cheetah mod_wsgi mod_ssl dhcp tftp-server httpd createrepo yum-utils pykickstart OpenIPMI ipmitool cman mkisofs python-ctypes cobbler cobbler-web -y ;; CentOS6) echo "ostype=$ostype" check_epel6 yum install PyYAML python-netaddr python-cheetah mod_wsgi mod_ssl dhcp tftp-server httpd createrepo yum-utils pykickstart ipmitool cman mkisofs Django14 python-ctypes cobbler cobbler-web -y ;; *) echo "Error: Unkown OS type,now exit !" exit 1 esac ##################### configure network cobbler_ip_sub=${cobbler_ip%.*} eth_num=`/sbin/ifconfig | grep -w eth[0-9] | wc -l` if [ $eth_num -gt 0 ]; then nic=eth lan=${nic}0 wan=${nic}1 else nic=em lan=${nic}1 wan=${nic}2 fi [ -z $lan -a -z $wan ] && echo "Error: no nic interface,now exit !" && exit 1 netmask=`/sbin/ifconfig $lan | awk '/inet addr/{print$4}' | cut -d: -f2` echo "netmask=${netmask}" echo "DEVICE=${lan}:cobbler BOOTPROTO=static IPADDR=${cobbler_ip} NETMASK=${netmask} ONBOOT=yes">/etc/sysconfig/network-scripts/ifcfg-${lan}:cobbler /sbin/ifup ${lan}:cobbler || exit 1 grep "${cobbler_ip_sub}.0" /etc/sysconfig/iptables || { sed -i "/-A INPUT -j RH-Firewall-1-INPUT/ i -A INPUT -s ${cobbler_ip_sub}.0/${netmask} -j ACCEPT" /etc/sysconfig/iptables } iptables -nvL | grep "${cobbler_ip_sub}.0" >/dev/null || { iptables -I INPUT -s ${cobbler_ip_sub}.0/${netmask} -j ACCEPT } grep "tftpd" /etc/hosts.allow || { chattr -i /etc/hosts.allow && echo "in.tftpd:192.168.1.0/255.255.255.0" >> /etc/hosts.allow && chattr +i /etc/hosts.allow } echo "${lan}:cobbler configure successfully !" #################### configure utils # configure httpd sed -i 's/Listen 80/Listen 3196/' /etc/httpd/conf/httpd.conf sed -i 's/#LoadModule wsgi_module/LoadModule wsgi_module/' /etc/httpd/conf.d/wsgi.conf # Cobbler relies on fencing agents, provided by the 'cman' package for some distributions or 'fence-agents' for others. # These scripts are installed in the /usr/sbin directories. # Cobbler will automatically find any files in that directory named fence_* and allow them to be used for power management. ln -s /sbin/fence_* /usr/sbin/ #disable selinux sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config #setenforce 0 #ennable tftp sed -i '/disable/c\\tdisable\t\t\t= no' /etc/xinetd.d/tftp #enable rsync sed -i -e 's/\=\ yes/\=\ no/g' /etc/xinetd.d/rsync ###################### configure cobbler #what users can log into the WebUI and Read-Write XMLRPC? #use /etc/cobbler/users.digest (for basic setups) sed -i 's/authn_denyall/authn_configfile/g' /etc/cobbler/modules.conf #this is the address of the cobbler server sed -i "s/server: 127.0.0.1/server: ${cobbler_ip}/g" /etc/cobbler/settings # Preventing boot loops: This will set the machines not to PXE-boot on successive boots once they complete one install. sed -i 's/pxe_just_once: 0/pxe_just_once: 1/g' /etc/cobbler/settings #if using cobbler with manage_dhcp, put the IP address of the cobbler server here so that PXE booting guests can find it sed -i "s/next_server: 127.0.0.1/next_server: ${cobbler_ip}/g" /etc/cobbler/settings #set to 1 to enable Cobbler's RSYNC management features. sed -i 's/manage_rsync: 0/manage_rsync: 1/g' /etc/cobbler/settings #set to 1 to enable Cobbler's DHCP management features. sed -i 's/manage_dhcp: 0/manage_dhcp: 1/g' /etc/cobbler/settings sed -i 's/http_port: 80/http_port: 3196/' /etc/cobbler/settings #configure dhcp.conf sed -i "s/192.168.1/${cobbler_ip_sub}/g" /etc/cobbler/dhcp.template #disable uefi boot sed -i -e 's=filename "ia64/elilo.efi"=#filename "ia64/elilo.efi"=' -e 's=filename "grub/grub-x86.efi"=#filename "grub/grub-x86.efi"=' -e 's=filename "grub/grub-x86_64.efi"=#filename "grub/grub-x86_64.efi"=' /etc/cobbler/dhcp.template #configure user=root,password=<what you entered> htdigest /etc/cobbler/users.digest "Cobbler" root /etc/init.d/xinetd restart /etc/init.d/httpd restart /etc/init.d/cobblerd restart sleep 1 cobbler get-loaders cobbler check cobbler sync ############################## COMMAND SAMPLE ############################# #mkdir -p /data/iso/CentOS-5.8-x86_64 #mount -o loop /data/iso/CentOS-5.8-x86_64-bin-DVD-1of2.iso /data/iso/CentOS-5.8-x86_64 #echo '/data/iso/CentOS-5.8-x86_64' >> /usr/local/monitor-base/log/disk.deny #cobbler import --path=/data/iso/CentOS-5.8-x86_64 --name=CentOS-5.8-x86_64 --kickstart=/data/iso/5u8_cobbler.ks #cobbler import --path=/data/iso/CentOS-6.4-x86_64 --name=CentOS-6.4-x86_64 --kickstart=/data/iso/6u4_cobbler.ks # iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT ######## 常规情况下这样就可以了 ######### 若要设置两个接口的IP需要分两次操作 # Note: **You can only edit one interface at a time!** # If you specify multiple --interface options, only the last one will be used. #cobbler system add \ #--name=hj_test \ #--hostname=hj_test \ #--profile=CentOS-5.8-x86_64 \ #--interface=eth0 --mac-address=e4:1f:13:62:c4:6c --ip-address=10.1.1.125 --netmask=255.255.255.0 --static=1 \ #--power-type=ipmilan --power-user=shdkx --power-pass=PASSW0RD --power-address=10.1.2.125 \ #--kopts=nousb --clobber #cobbler system edit \ #--name=hj_test \ #--interface=eth1 --mac-address=e4:1f:13:62:C4:6e \ #--ip-address=192.168.1.54 --netmask=255.255.255.0 --gateway=192.168.1.254 --static=1 ################ IBM的ipmi over lan: #F1进入BIOS #System Settings->Devices and I/O Ports->Console Redirection Settings->Serial Port Sharing 将此项设置为Enable即可 #legacy only的引导顺序必须位于pxe之前,否则会进入efi引导,导致安装不成功。若手动选,也不能选pxe,需要选legacy only ############### DELL的ipmi over lan: #CTRL+E进入DRAC卡手动开启ipmi over lan #或者远程登入DRAC执行命令 racadm config -g cfgIpmiLan -o cfgIpmiLanEnable 1 ############### 通用ipmi over lan开启方法: #ipmitool lan set 1 access on # racadm config -g cfgIpmiLan -o cfgIpmiLanEnable 1 # racadm getconfig -g cfgIpmiLan #for((i=1;i<=1000;++i));do sh pxe.sh;sleep 1;done #cobbler system report | egrep '^Name |Netboot Enabled' #cat /var/log/messages | grep dhcpd | grep 'DHCPDISCOVER from' | awk '{print$8}' | sort |uniq | wc -l # for i in 32 33 41 42 43 51 53 55;do echo -n "10.1.1.1$i ";ping -c2 -W1 10.1.1.1$i|awk '/pack/{print$6,$7}';done # last thing # /etc/init.d/httpd stop;/etc/init.d/dhcpd stop;/etc/init.d/cobblerd stop # /etc/init.d/iptables start
2.挂载镜像和导入kickstart
mkdir -p /data/iso && cd /data/iso wget http://centos.yum.sandai.net/centos/6.4/isos/x86_64/CentOS-6.4-x86_64-bin-DVD1.iso mkdir CentOS-6.4-x86_64 mount -o loop CentOS-6.4-x86_64-bin-DVD1.iso CentOS-6.4-x86_64 echo "/data/iso/CentOS-6.4-x86_64" >> /usr/local/monitor-base/log/disk.deny cobbler import --path=/data/iso/CentOS-6.4-x86_64 --name=CentOS-6.4-x86_64 --kickstart=/data/iso/6u4_cobbler.ks
3.给cobbler添加主机 使用add_host.sh添加机器
[root@hj iso]# cat add_host.sh while read hostname profile eth0_mac eth0_ip ilo_user ilo_pass ilo_ip eth1_mac eth1_ip eth1_mask gw do cobbler system add --name=$hostname --hostname=$hostname --profile=$profile --kopts="nousb noapic acpi=off" --interface=eth0 --mac-address=$eth0_mac --ip-address=$eth0_ip --netmask=255.255.255.0 --static=1 --power-type=ipmilan --power-user=$ilo_user --power-pass=$ilo_pass --power-address=$ilo_ip cobbler system edit --name=$hostname --interface=eth1 --mac-address=$eth1_mac --ip-address=$eth1_ip --netmask=$eth1_mask --gateway=$gw --static=1 done<add_host.list
add_host.list格式:
#hostname profile eth0_mac eth0_ip ilo_user ilo_pass ilo_ip eth1_mac eth1_ip eth1_mask gw
附属:利用pssh收集主机的设备信息:cobbler_host_list.sh
#!/bin/bash host=$(hostname) eth0_ip=`ifconfig |grep eth0 -A1 |grep "inet addr:" |awk '{print $2}' |awk -F: '{print $2}'` if [ -z $eth0_ip ];then eth0_ip=`ifconfig |grep em1 -A1 |grep "inet addr:" |awk '{print $2}' |awk -F: '{print $2}'` fi eth0_mac=`ifconfig |grep eth0 |awk '{print $NF}'` if [ -z $eth0_mac ];then eth1_mac=`ifconfig |grep em1 |awk '{print $NF}'` fi eth1_ip=`ifconfig |grep eth1 -A1 |grep "inet addr:" |awk '{print $2}' |awk -F: '{print $2}'` if [ -z $eth1_ip ];then eth1_ip=`ifconfig |grep em2 -A1 |grep "inet addr:" |awk '{print $2}' |awk -F: '{print $2}'` fi eth1_mac=`ifconfig |grep eth1 |awk '{print $NF}'` if [ -z $eth1_mac ];then eth1_mac=`ifconfig |grep em2 |awk '{print $NF}'` fi eth1_mask=`ifconfig |grep eth1 -A1 |grep "inet addr:" |awk '{print $4}' |awk -F: '{print $2}'` if [ -z $eth1_mask ];then eth1_mask=`ifconfig |grep em2 -A1 |grep "inet addr:" |awk '{print $4}' |awk -F: '{print $2}'` fi gw=`route -n|awk '/UG/ {print $2}'` profile="CentOS-6.2-x86_64" ilo_user="root" ilo_pass="XXXX" ilo_ip=`echo "$eth0_ip" | awk -F. '{ip=2} END { print $1"."$2"."ip"."$4}'` echo -e "$host $profile $eth0_mac $eth0_ip $ilo_user $ilo_pass $ilo_ip $eth1_mac $eth1_ip $eth1_mask $gw"
4.ks文件:6u4_cobbler.ks 系统基础化设置和程序部署都在ks文件的post段。
# Kickstart file automatically generated by anaconda. install key --skip lang en_US.UTF-8 keyboard us rootpw --iscrypted $6$8YBEugaR2vIqSbej$A0R7d4cO0f.jvvZpU9jZ/cWIkIBSXl5YRGiHrurtejEr6 firewall --service=ssh authconfig --enableshadow --passalgo=sha512 selinux --enforcing timezone --utc Asia/Shanghai bootloader --location=mbr --driveorder=sda --append="noapic acpi=off" #bootloader --location=mbr --driveorder=sda,sdb,sdc clearpart --all --initlabel --drives=sda #clearpart --all --initlabel text skipx url --url=$tree $SNIPPET('network_config') reboot part / --fstype=ext4 --asprimary --size=70000 --ondisk=sda part swap --size=20000 --ondisk=sda part /usr/local --fstype=ext4 --size=1 --grow --ondisk=sda #hp disk array #part / --fstype ext4 --size=70000 --ondisk=cciss/c0d0 #part swap --size=20000 --ondisk=cciss/c0d0 #part /usr/local --fstype ext4 --size=100000 --ondisk=cciss/c0d0 #part /data --fstype ext4 --size=1 --grow --ondisk=cciss/c0d0 %pre $SNIPPET('pre_install_network_config') %end #repo --name="Red Hat Enterprise Linux" --baseurl=cdrom:sr0 --cost=100 #repo --name="High Availability" --baseurl=file:///mnt/source/HighAvailability/ --cost=1000 %packages @additional-devel @base @chinese-support @client-mgmt-tools @core @debugging @desktop-platform-devel @development @directory-client @emacs @fonts @general-desktop @graphical-admin-tools @graphics @hardware-monitoring @input-methods @internet-browser @java-platform @legacy-unix @legacy-x @network-file-system-client @performance @perl-runtime @print-client @remote-desktop-clients @security-tools @server-platform @server-platform-devel @server-policy @system-management @system-admin-tools @system-management-messaging-server @tex @technical-writing libXinerama-devel xorg-x11-proto-devel startup-notification-devel libgnomeui-devel libbonobo-devel libXau-devel libgcrypt-devel popt-devel libdrm-devel libXrandr-devel libxslt-devel libglade2-devel gnutls-devel mtools pax python-dmidecode oddjob sgpio genisoimage wodim desktop-file-utils jpackage-utils certmonger pam_krb5 krb5-workstation netpbm-progs tcp_wrappers libXmu perl-DBD-SQLite hmaccalc wget %end #%post --nochroot %post --log=/tmp/anaconda-post.log --erroronfail #ifconfig em1:tmp 10.1.1.1/24 mkdir /usr/local/src cd /usr/local/src wget http://192.168.1.2:3195/6u4x64.tar.gz wget http://192.168.1.2:3195/puppet3.tar.gz wget http://192.168.1.2:3195/chunk_server.tar.gz wget http://192.168.1.2:3195/user.sh wget http://192.168.1.2:3195/install_soft.sh chmod a+x install_soft.sh chmod a+x user.sh echo "sh /usr/local/src/install_soft.sh" >> /etc/rc.d/rc.local $SNIPPET('kickstart_done') %end
5.打开web页面即可安装
本文出自 “网络空间” 博客,谢绝转载!