1、环境准备
安装一台CentOS7.2版本的的桌面版本的。 关闭防火墙、selinux,配置静态IP
systemctl stop firewalld.service
systemctl disable firewalld.service
yum -y install iptables-services
cp -rp /usr/libexec/iptables/iptables.init /etc/init.d/iptables
getenforce
2、安装epel源
yum install -y https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
cp /etc/yum.repos.d/CentOS-Base.repo{,.bak}
wget http://mirrors.aliyun.com/repo/Centos-7.repo -O /etc/yum.repos.d/CentOS-Base.repo
yum clean all
yum makecache
yum update -y
3、安装kickstart文件生成器
yum install -y system-config-kickstart
4、开始安装Cobbler服务,并又改相应的配置
cat << EOF
+--------------------------------------------+
| |
| ==install cobbler== |
| |
+--------------------------------------------+
EOF
#安装cobbler包
yum install -y cobbler httpd rsync tftp-server xinetd dhcp cobbler-web koan pykickstart* fence-agents* debmirror syslinux
# 获取静态IP地址
IPADDR=$(ifconfig eth0 | awk '/inet /{print $2}')
SET=/etc/cobbler/settings
PASS=$(openssl passwd -1 -salt 'Jalo.mu' '123456')
cp $SET{,.ori}
# 配置httpd文件服务器
mkdir /var/www/html/{confiles/{procfiles,profiles,vimfile,yumfile},image/{CentOS7.2,CentOS6.5},ksfile,script} -p
# 修改cobbler配置文件setings
cat << EOF
+--------------------------------------------+
| |
| ==Modify Cobbler configuration file== |
| |
+--------------------------------------------+
EOF
sed -i "s/server: 127.0.0.1/server: $IPADDR/" $SET
sed -i "s/next_server: 127.0.0.1/next_server: $IPADDR/" $SET
sed -i "s/manage_dhcp: 0/manage_dhcp: 1/" $SET
sed -i "#^default_password_crypted: .*$#default_password_crypted: \"$PASS\"#g" $SET
cobbler get-loaders
while [[ $? != 0 ]]
do
cobbler get-loaders
done
# set tftp service
sed -i "s/disable = yes/disable = no/g" /etc/xinetd.d/tftp
# set dhcpd serverice
BASE=$(echo $IPADDR | awk -F. '{printf("%s.%s.%s.\n",$1,$2,$3)}')
MIN=${BASE}"100"
MAX=${BASE}"200"
NAMESERVER=$(cat /etc/resolv.conf | awk '/nameserver/{printf("%s ",$2) }END{printf("\n")}')
cat > /etc/cobbler/dhcp.template <<EOF
subnet ${BASE}0 netmask 255.255.255.0 {
option routers ${BASE}254;
option domain-name-servers $NAMESERVER;
option subnet-mask 255.255.255.0;
range dynamic-bootp $MIN $MAX;
next-server $IPADDR;
filename "pxelinux.0";
}
EOF
cobbler sync
while [[ $? != 0 ]]
do
cobbler sync
done
cobbler check
systemctl restart httpd
systemctl restart xinetd
systemctl restart dhcpd
systemctl restart cobblerd
cat << EOF
+--------------------------------------------+
| |
| ==Network Yum source set up== |
| |
+--------------------------------------------+
EOF
YUMPATH=/var/www/html/image/CentOS7.2/
mount /dev/cdrom /mnt
cp -a /mnt/* $YUMPATH
createrepo -pdo $YUMPATH $YUMPATH
createrepo -g `ls ${YUMPATH}repodata/*-comps.xml` $YUMPATH
cat << EOF
+--------------------------------------------+
| |
| ==Cobbler Import Image== |
| |
+--------------------------------------------+
EOF
CNAME=CentOS-7.2-x86_64
ARCH=x86_64
KSFILE=/var/www/html/ksfile/ks7.cfg
cobbler import --path=$YUMPATH --name=$CNAME --arch=$ARCH --kickstart=$KSFILE
cobbler profile edit --name=$CNAME --kopts='net.ifnames=0 biosdevname=0'
systemctl enable httpd
systemctl enable xinetd
systemctl enable dhcpd
systemctl enable rsyncd
systemctl enable cobblerd
cobbler sync
while [[ $? != 0 ]]
do
cobbler sync
done
systemctl restart httpd
systemctl restart xinetd
systemctl restart dhcpd
systemctl restart cobblerd
cat << EOF
+--------------------------------------------+
| |
| ==Check Cobbler Install Sucess== |
| |
+--------------------------------------------+
EOF
ROW=$(cobbler check | egrep -v ^$ | wc -l)
if [ $ROW -ne 0 ]
then
echo "Cobbler set Error!!!!"
fi
systemctl status httpd | grep "active (running)"
[ $? -ne 0 ] && echo "httpd Error";exit(1)
systemctl status xinetd | grep "active (running)"
[ $? -ne 0 ] && echo "xinetd Error";exit(2)
systemctl status dhcpd | grep "active (running)"
[ $? -ne 0 ] && echo "DHCP Error";exit(3)
systemctl status cobblerd | grep "active (running)"
[ $? -ne 0 ] && echo "cobblerd Error";exit(4)
systemctl enable httpd
systemctl enable xinetd
systemctl enable dhcpd
systemctl enable rsyncd
systemctl enable cobblerd
curl -o /dev/null -s -w %{http_code} http://${IPADDR}/image/CentOS7.2/
echo
还有最重要的一步就是每次使用cobbler sync的时候都要修改ks的引导路径否者提示找不到相应的ks文件
修改/var/lib/tftpboot/pxelinux.cfg/default文件
5、ks文件编辑:
# authorization Jalo.mu
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
#rootpw --iscrypted $1$x4LFKLxm$8Jz844UWRXYMS0gX4Bb/Q.
rootpw 123456
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://172.168.1.21/image/CentOS7.2/"
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# System language
lang en_US
# Firewall configuration
firewall --disabled
# System authorization information
auth --useshadow --passalgo=md5
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Reboot after installation
reboot
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel --drives=sda,sdb
# Disk partitioning information
part /boot --fstype="xfs" --ondisk=sda --size=1024
part /boot/efi --fstype="xfs" --ondisk=sda --size=512
part pv.01 --ondisk=sda --size=1 --grow
part pv.02 --ondisk=sdb --size=1 --grow
volgroup domovg pv.01 pv.02
logvol swap --vgname=domovg --fstype="swap" --size=1024 --name=swap
logvol / --vgname=domovg --fstype="xfs" --size=10240 --name=root
logvol /usr --vgname=domovg --fstype="xfs" --size=2048 --name=usr
logvol /var --vgname=domovg --fstype="xfs" --size=1024 --name=var
logvol /opt --vgname=domovg --fstype="xfs" --size=512 --name=opt
logvol /tmp --vgname=domovg --fstype="xfs" --size=1024 --name=tmp
%pre
#/var/lib/cobbler/snippets/==$SNIPPET 预定义安装包
#$SNIPPET('log_ks_pre')
#$SNIPPET('kickstart_start')
#$SNIPPET('pre_install_network_config')
## Enable installation monitoring
#$SNIPPET('pre_anamon')
%end
# 建议带着--nochroot这个参数,如果安装完成候脚本没有执行可以去掉这个参数,但是你必须保证该脚本没有错误!!!
%post --nochroot
sed -i "/::1/d" /etc/hosts
wget http://172.168.1.21/confiles/vimfile/vimrc -O /etc/vimrc
wget http://172.168.1.21/confiles/procfiles/sysctl.conf -O /etc/sysctl.conf
wget http://172.168.1.21/confiles/profiles/profile -O /etc/profile
wget http://172.168.1.21/confiles/yumfile/CentOS-Base.repo -O /etc/yum.repos.d/CentOS-Base.repo
wget http://172.168.1.21/confiles/yumfile/epel.repo -O /etc/yum.repos.d/CentOS-Base.repo
YUM="/etc/yum.repos.d"
mv ${YUM}/CentOS-Base.repo ${YUM}/CentOS-Base.repo-bak
wget -O ${YUM}/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O ${YUM}/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache
yum -y update
yum install -y source-highlight
sysctl -p
source /etc/profile
%end
%packages
@base
@core
net-tools
telnet
wget
vim-*
nfs-utils
autoconf
automake
openssl
openssl-devel
%end
ks文件语法讲解地址:
进入桌面系统通过kickstart界面验证你编写的ks文件语法问题
system-config-kickstart
在“文件”选项中找到“打开”---> 选择你要打开的ks文件 就能验证了