本文以虚拟机RED HAT6.10系统上安装cobbler服务,来批量安装操作系统Centos7为案例讲解。
服务器配置:
- 型号:dell R730
- 磁盘:2 * 1T stat磁盘 2 * 1T sas磁盘
- 内存:4 * 16G
要求:
- 2块sas 1T磁盘做阵列,用于系统盘
- 2块sata 1T磁盘做数据盘
第一部分:虚拟机安装cobbler服务
1.系统配置
2.安装cobbler服务
3.配置服务
4.自定义Kickstart模板(Centos7)
第二部分:需安装操作系统的服务器
一、以虚拟机为例演示
二、以真实服务器演示为例
曾遇到的坑
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.1.200
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=114.114.114.114
HWADDR=00:0C:29:51:C9:33
service iptables stop
chkconfig iptables off
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
reboot
# 卸载本地yum
rpm -qa|grep yum|xargs rpm -e --nodeps
# 下载centos yum 程序
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-3.2.29-81.el6.centos.noarch.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-41.el6.noarch.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
# 安装centos yum程序
rpm -ivh yum-3.2.29-81.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-41.el6.noarch.rpm yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
# 下载163镜像
cd /etc/yum.repos.d/
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
sed -i 's/$releasever/6/g' CentOS6-Base-163.repo
# 清除缓存并更新
yum clean all
yum makecache
yum update
yum remove 'rhn-check-1.0.0.1-16.el6.noarch'
yum -y install PackageKit-glib
yum -y install abrt-addon-ccpp
yum -y install PackageKit-yum
yum -y install PackageKit-yum-plugin
yum -y install python-simplejson
wget https://kojipkgs.fedoraproject.org//packages/Django14/1.4.14/1.el6/noarch/Django14-1.4.14-1.el6.noarch.rpm
rpm -ivh Django14-1.4.14-1.el6.noarch.rpm
yum install -y cobbler cobbler-web tftp xinetd dhcp cman pykickstart debmirror syslinux net-tools
yum install -y ed patch perl perl-Compress-Zlib perl-Digest-SHA1 perl-LockFile-Simple perl-libwww-perl fence-agents
chkconfig httpd on
chkconfig dhcpd on
chkconfig xinetd on
chkconfig cobblerd on
sed -i 's/#ServerName www.example.com:80/ServerName 127.0.0.1:80/' /etc/httpd/conf/httpd.conf
service httpd restart
sed -i 's/server: 127.0.0.1/server: 192.168.1.200/g' /etc/cobbler/settings
[root@sky yum.repos.d]# openssl passwd -1 -salt 'root' 'sky@123'
$1$root$8e67rDXAsnndS790noSQV0
[root@sky yum.repos.d]# vim /etc/cobbler/settings
default_password_crypted: "$1$root$8e67rDXAsnndS790noSQV0"
useradd admin
passwd admin
sed -i 's/admin = ""/admin = "admin"/' /etc/cobbler/users.conf
sed -i 's/module = authn_configfile/module = authn_pam/' /etc/cobbler/modules.conf
sed -i '14s/yes/no/' /etc/xinetd.d/tftp
service xinetd restart
sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings
sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings
mv /etc/cobbler/dhcp.template /etc/cobbler/dhcp.template.bak
vim /etc/cobbler/dhcp.template
########################### 以下为编辑内容 #############################
ddns-update-style interim;
allow booting;
allow bootp;
ignore client-updates;
set vendorclass = option vendor-class-identifier;
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option domain-name-servers 114.114.114.114;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.1.100 192.168.1.250;
filename "/pxelinux.0";
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.1.200;
}
##################################################################
service cobblerd restart
service xinetd restart
cobbler sync
service dhcpd restart
访问:https://192.168.1.200/cobbler_web
账号密码:admin / admin (前面设置)
# 挂载
mkdir -p /var/www/cobbler/ks_mirror/Centos7-x86_64
mount -t iso9660 -o loop /opt/CentOS-7-x86_64-DVD-1810.iso /var/www/cobbler/ks_mirror/Centos7-x86_64
# 开机自动挂载
echo "/opt/CentOS-7-x86_64-DVD-1810.iso /var/www/cobbler/ks_mirror/Centos7-x86_64 iso9660 defaults,ro,loop 0 0" >> /etc/fstab
vi /var/lib/cobbler/kickstarts/Centos7-x86_64.ks
############################# 以下为编辑内容 ########################################
install
lang zh_CN.UTF-8
keyboard us
timezone Asia/Shanghai
auth --useshadow --enablemd5
selinux --disabled
firewall --disabled
services --enabled=NetworkManager,sshd
reboot
bootloader --location=mbr
zerombr
clearpart --all --initlabel
part /boot --fstype=xfs --size=200 --ondisk=/dev/sdc
part / --fstype=xfs --size=204800 --ondisk=/dev/sdc
part /data0 --fstype=xfs --grow --ondisk=/dev/sdc
part /data1 --fstype xfs --size=100 --grow --ondisk=/dev/sda
part /data2 --fstype xfs --size=100 --grow --ondisk=/dev/sdb
rootpw --iscrypted $default_password_crypted
repo --name=base --baseurl=http://192.168.1.200/cobbler/ks_mirror/Centos7-x86_64
url --url=http://192.168.1.200/cobbler/ks_mirror/Centos7-x86_64
%packages --ignoremissing
@base
@core
@chinese-support
ntp
net-tools
%end
%post
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
echo "0 1 * * * /usr/sbin/ntpdate 202.120.2.101;hwclock -w;" >>/var/spool/cron/root
/usr/sbin/ntpdate 202.120.2.101 >/dev/null 2>&1
cd /root
wget http://192.168.1.200/cobbler/ks_mirror/config/autoip7.sh
sh /root/autoip7.sh
%end
###################################################################################
说明:sdc是阵列虚拟盘,sda、sdb分别是stat盘
ks配置参考资料:
https://www.linuxidc.com/Linux/2017-08/146168.htm
https://www.linuxidc.com/Linux/2013-07/87299.htm
vi /var/www/cobbler/ks_mirror/config/autoip7.sh
########################## 以下为编辑内容 ################################
#!/bin/sh
DEVICE=$(ip addr | grep '^[0-9]' |grep -v "lo"|awk -F': ' '{print $2}')
ROUTE=$(route -n|grep "^0.0.0.0"|awk '{print $2}')
BROADCAST=$(/sbin/ifconfig $DEVICE|grep broadcast|awk '{print $6}')
HWADDR=$(/sbin/ifconfig $DEVICE|grep ether|awk '{print $2}')
IPADDR=$(/sbin/ifconfig $DEVICE|grep inet|grep -v "inet6"|awk '{print $2}')
NETMASK=$(/sbin/ifconfig $DEVICE|grep netmask|awk '{print $4}')
cat >/etc/sysconfig/network-scripts/ifcfg-$DEVICE<
cobbler import --path=/var/www/cobbler/ks_mirror/Centos7-x86_64 --name=Centos7-x86_64 --arch=x86_64
# 移除cobbler默认指定的错误profile
cobbler profile remove --name=Centos7-x86_64
# 添加我们自己设置的新profile
cobbler profile add --name=Centos7-x86_64 --distro=Centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/Centos7-x86_64.ks
# 刷新编辑profile
cobbler profile edit --name=Centos7-x86_64 --distro=Centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/Centos7-x86_64.ks
# 查看profile设置
cobbler profile report --name Centos7-x86_64
cobbler sync
# 修改默认配置
vi /etc/cobbler/pxe/pxedefault.template
############################## 以下为编辑内容 ######################################
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT Centos7-x86_64 <== 改成超时未选择自动安装Centos7-x86_64系统
LABEL local
MENU LABEL (local)
MENU DEFAULT
LOCALBOOT -1
$pxe_menu_items
MENU end
###################################################################################
# 同步配置
cobbler sync