centos7系列Cobbler+kickstart全自动装机实战

时间:2021-10-01 11:10:45

配置yum源,以及epel源

[root@crobbler-90111 ~]# cat /etc/yum.repos.d/aliyun.repo

[epel]
name=ailiyun
baseurl=http://mirrors.aliyun.com/epel/7/x86_64/
enabled=
gpgcheck=
[centos]
name=cobbler
baseurl=http://mirrors.aliyun.com/centos/7/os/x86_64/
enabled=
gpgcheck=

#yum install epel-release  #安装epel扩展源

#yum install -y httpd  dhcp  tftp rsync cobbler cobbler-web  pykickstart  xinetd    #安装所需服务~
[root@cobbler-90111 ~]# systemctl start  cobblerd httpd xinetd    #启动cobblerd,httpd以及xinetd服务

[root@cobbler-90111 ~]# systemctl enable cobblerd httpd xinetd    #设置开机自启cobblerd,httpd以及xinetd服务
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

[root@crobbler-90111 ~]# cobbler check   #检测cobbler

centos7系列Cobbler+kickstart全自动装机实战

 #修改主配置文件

[root@cobbler-90111 ~]# cp /etc/cobbler/settings /etc/cobbler/settings.back

[root@cobbler- ~]# sed -i '/^\<server/s/127.0.0.1/10.15.90.111/' /etc/cobbler/settings

[root@cobbler- ~]# sed -i '/next_server/s/127.0.0.1/10.15.90.111/' /etc/cobbler/settings

[root@cobbler- ~]# egrep "^\<server|next_server" /etc/cobbler/settings
next_server: 10.15.90.111
server: 10.15.90.111

#设置tftp服务

[root@cobbler- ~]# sed -i "/disable/s/yes/no/" /etc/xinetd.d/tftp

[root@cobbler- ~]# egrep "disable" /etc/xinetd.d/tftp
disable = no

[root@cobbler-90111 ~]# systemctl restart rsyncd
[root@cobbler-90111 ~]# systemctl enable rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.

  #下载网络引导文件

[root@crobbler-90111 ~]# cobbler get-loaders 

centos7系列Cobbler+kickstart全自动装机实战

#启动rsyncd服务

[root@crobbler-90111 ~]# systemctl start rsyncd   

[root@cobbler-90111 ~]# systemctl enable rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.

[root@crobbler-90111 ~]# ps -ef | grep rsync
root 14747 1 0 20:09 ? 00:00:00 /usr/bin/rsync --daemon --no-detach
root 15030 10105 0 20:45 pts/0 00:00:00 grep --color=auto rsync

#修改 etc/cobbler/settings 中'default_password_crypted'的值

[root@crobbler- ~]#xiaoyu=`openssl passwd - -salt 'xiaoyu' 'root'`    #定义变量
[root@crobbler- ~]# echo $xiaoyu [root@cobbler- ~]# sed -i "/default_password_crypted/c\/default_password_crypted: \"$xiaoyu"\" /etc/cobbler/settings #赋值即可
[root@cobbler- ~]# sed -n "/default_password_crypted/p " /etc/cobbler/settings
/default_password_crypted: "$1$xiaoyu$cZpdAZwX0o.3cAfeBTRoJ/"

 #安装电源管理工具fence-agents

[root@crobbler-90111 ~]# yum install -y fence-agents  

#重启cobbler服务,再次检测cobbler服务

[root@crobbler-90111 ~]# systemctl restart cobblerd

[root@cobbler-90111 ~]# cobbler check

centos7系列Cobbler+kickstart全自动装机实战

【配置DHCP】

[root@crobbler-90111 ~]# vim /etc/cobbler/dhcp.template

[root@cobbler-90111 ~]#sed -i '/^subnet/s/192.168.1.0/10.15.90.0/' /etc/cobbler/dhcp.template

[root@cobbler-90111 ~]# sed -i '/routers/s/192.168.1.5/10.15.90.254/' /etc/cobbler/dhcp.template
[root@cobbler-90111 ~]# sed -i '/domain-name-servers/s/192.168.1.1/144.144.144.144/' /etc/cobbler/dhcp.template
[root@cobbler-90111 ~]# sed -i '/dynamic-bootp/s/192.168.1.100 192.168.1.254/10.15.90.100 10.15.90.150/' /etc/cobbler/dhcp.template

centos7系列Cobbler+kickstart全自动装机实战

#绑定dhcp,tftp以及rsyncd服务托管

[root@cobbler-90111 ~]# sed -i '/manage_dhcp:/s/0/1/' /etc/cobbler/settings

[root@cobbler-90111 ~]# sed -i '/manage_rsync:/s/0/1/' /etc/cobbler/settings

[root@cobbler-90111 ~] sed -i '/manage_tftpd:/s/0/1/' /etc/cobbler/settings

#检查三个服务时候托管

[root@cobbler-90111 ~]# sed -n -e '/manage_tftpd:/p' -e '/manage_dhcp:/p' -e '/manage_rsync:/p' /etc/cobbler/settings
manage_dhcp: 1
manage_tftpd: 1
manage_rsync: 1

root@cobbler-90111 ~]# systemctl restart cobblerd   #重启cobbler服务

[root@cobbler-90111 ~]# cobbler sync   #设置sync同步

centos7系列Cobbler+kickstart全自动装机实战

[root@cobbler-90111 ~]# cat /etc/dhcp/dhcpd.conf   #重启cobbler服务之后,检查dhcp配置文件中的配置是否生成!

centos7系列Cobbler+kickstart全自动装机实战

[配置系统安装镜像]

[root@cobbler-90111 ~]# mkdir /mnt/centos7.6
[root@cobbler-90111 ~]# mount -o loop CentOS-7-x86_64-DVD-1810.iso /mnt/centos7.6/   #挂载cnetos7.6镜像
mount: /dev/loop0 is write-protected, mounting read-only

[root@cobbler-90111 ~]# cobbler import --path=/mnt/centos7.6 --name=Centos7.6-x86_64 --arch=x86_64   #导入centos镜像到cobbler服务中

[root@cobbler-90111 ~]# cobbler profile list
Centos7.6-x86_64

[root@crobbler-90111 ~]# cobbler distro report    #查看distro

[root@cobbler- ~]# cobbler distro report
Name : centos7.-x86_64
Architecture : x86_64
TFTP Boot Files : {}
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/ks_mirror/centos7./images/pxeboot/initrd.img
Kernel : /var/www/cobbler/ks_mirror/centos7./images/pxeboot/vmlinuz
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/centos7.6-x86_64'}
Management Classes : []
OS Version : rhel6
Owners : ['admin']
Red Hat Management Key : <<inherit>>
Red Hat Management Server : <<inherit>>
Template Files : {}

[root@cobbler-90111 ~]# cobbler profile report     #查看导入系统之后的过程中,cobbler生成的配置文件,关联dhcp,pxe安装菜单
Name : Centos7.6-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : Cebtos7.6-x86_64
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/sample_end.ks    #生成的kickstart文件,
Kickstart Metadata : {}
Management Classes : []
Management Parameters : <<inherit>>
Name Servers : []
Name Servers Search Path : []
Owners : ['admin']
Parent Profile :
Internal proxy :
Red Hat Management Key : <<inherit>>
Red Hat Management Server : <<inherit>>
Repos : []
Server Override : <<inherit>>
Template Files : {}
Virt Auto Boot : 1
Virt Bridge : xenbr0
Virt CPUs : 1
Virt Disk Driver Type : raw
Virt File Size(GB) : 5
Virt Path :
Virt RAM (MB) : 512
Virt Type : kvm

[root@cobbler-90111 kickstarts]# cobbler profile list

centos7.6-x86_64

[root@cobbler-90111 ~]# cd /var/lib/cobbler/kickstarts/

[root@cobbler-90111 ~]#mv sample_end.ks sample_end.ks.back    #将原生成的ks文件备份重命名备份一下,我们使用自定义的ks文件

[root@cobbler-90111 kickstarts]# vim  centos7u6-x64.ks   #自定义配置文件

#version=RHEL7
# System authorization information
url --url=$tree
#url --url http://10.15.90.111/cobbler/ks_mirror/Cebtos7.6-x86_64/
# Run the Setup Agent on first boot
firewall --disabled
selinux --disabled
reboot ignoredisk --only-use=sda # Keyboard
keyboard us
# System language
lang en_US.UTF- # Network information
network --onboot=yes --bootproto=dhcp --device=eth0 --ipv6=no # Installation logging level
logging --level=debug # Root password
rootpw --iscrypted $$MfJqPNgPVd8b4aoL$VOHUZHT22qqOLp3e4uXEB.kcdRtW4s8mcqRKAnoL5L9CmHPDaZj/p17jsSvdif98VR0g0cW8wLgoxlooDcwfh.
# System timezone
timezone Asia/Shanghai --isUtc # System bootloader configuration
#bootloader --location=mbr
bootloader --location=mbr --driveorder=sda
# Partition clearing information
zerombr
clearpart --all --initlabel
#clearpart --none --initlabel # Disk partitioning information
# Disk partitioning information
#part / --fstype="xfs" --ondisk=sda --size=
#part /home --fstype="xfs" --ondisk=sda --size=
part /boot --fstype="xfs" --ondisk=sda --size=
part swap --fstype="swap" --ondisk=sda --size=
#part /opt --fstype="xfs" --ondisk=sda --size= --grow
part / --fstype="xfs" --ondisk=sda --size= --grow %packages
@base
@core
@development
@compat-libraries
@scientific
kexec-tools
tree
net-snmp
nmap
sysstat
lrzsz
dos2unix
telnet
iptraf
ncurses-devel
openssl-devel
zlib-devel
OpenIPMI-tools
screen
chrony
wget
net-tools
ntp
ntpdate
%end %post
cat << EOF > /etc/cron.hourly/ntp
#!/bin/sh
/usr/sbin/ntpdate itime.hexun.com;/usr/sbin/hwclock -w > /dev/null >&
EOF
/bin/chmod /etc/cron.hourly/ntp
# Set default language
[ -f /etc/sysconfig/i18n ] && cp /etc/sysconfig/i18n /etc/syconfig/i18n.ksbak
cat << EOF > /etc/sysconfig/i18n
LANG="en_US"
SUPPORTED="en_US.UTF-8:en_US:en"
SYSFONT="latarcyrheb-sun16"
EOF cat << EOF >> /etc/rc.d/rc.tune
echo > /proc/sys/kernel/panic
echo "" > /proc/sys/net/ipv4/ip_conntrack_max
echo "" >/proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_timeout_established
EOF if [ -f /etc/rc.d/rc.tune ]; then
chmod +x /etc/rc.d/rc.tune
echo ". /etc/rc.d/rc.tune" >> /etc/rc.d/rc.local
echo "* soft nofile 65535" >> /etc/security/limits.conf
echo "* hard nofile 65535" >> /etc/security/limits.conf
echo "* soft nproc 65535" >> /etc/security/limits.conf
echo "* hard nproc 65535" >> /etc/security/limits.conf
else
echo Error! rc.tune can not be found!
fi
#confirm network-device eth0
/bin/mv /etc/sysconfig/network-scripts/ifcfg-ens160 /etc/sysconfig/network-scripts/ifcfg-eth0
/bin/sed -i 's#NAME="ens160"#NAME="eth0"#g' /etc/sysconfig/network-scripts/ifcfg-eth0
/bin/sed -i 's#DEVICE="ens160"#DEVICE="eth0"#g' /etc/sysconfig/network-scripts/ifcfg-eth0
cat << EOF > /etc/sysconfig/grub
GRUB_TIMEOUT=
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb net.ifnames=0 biosdevname=0 quiet"
EOF
/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg
#Set key
/bin/wget http://10.0.251.154/scripts/hxyw_admin-key-centos7.sh
/bin/chmod u+x /hxyw_admin-key-centos7.sh
/bin/sh /hxyw_admin-key-centos7.sh # Set nameserver
#cat << EOF > /etc/resolv.conf
#nameserver 10.0.250.46
#nameserver 10.0.250.40
#EOF
echo "nameserver 10.0.250.40" >> /etc/resolv.conf
echo "nameserver 10.0.250.46" >> /etc/resolv.conf
# Set default run level to
echo "id:3:initdefault:" >> /etc/inittab
#Disable IPV6
echo "net.ipv6.conf.all.disable_ipv6 =1" >> /etc/sysctl.conf
echo "net.ipv6.conf.default.disable_ipv6 =1" >> /etc/sysctl.conf
systemctl disable postfix.service
systemctl disable ntpd.service
%end

[root@cobbler-90111 kickstarts]# cobbler profile list

Centos7.6-x86_64

[root@cobbler-90111 ~]# cobbler profile getks --name "centos7.6-x86_64"   #自检

[root@cobbler-90111 kickstarts]# cobbler profile edit --name=Centos7.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7u6-x64.ks

[root@cobbler-90111 kickstarts]# cobbler profile edit --name=syscentos7.6-x86_64 --kopts='net.ifnames=0 biosdevname=0'   #修改centos配置文件中的kickstart值
[root@cobbler-90111 kickstarts]# cobbler sync   #执行rsync同步
task started: 2019-04-18_174012_sync
task started (id=Sync, time=Thu Apr 18 17:40:12 2019)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos7.6-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/images/centos7.6-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying files for distro: centos7.6-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos7.6/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos7.6-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos7.6/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos7.6-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: centos7.6-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos7.6/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos7.6-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos7.6/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos7.6-x86_64/initrd.img
Writing template files for centos7.6-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: centos7.6-x86_64
cleaning link caches
rendering Rsync files
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout:
received on stderr:
running: service dhcpd restart
received on stdout:
received on stderr: Redirecting to /bin/systemctl restart dhcpd.service

running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***

#检查服务是否启动

 #systemctl  restart dhcp xinetd conler tftp

#最终确保下面这些服务在运行,其中 25151 是 xmlrpc_port 端口 netstat -anutlp|egrep "httpd|rsync|xinetd|dhcpd|25151"

centos7系列Cobbler+kickstart全自动装机实战

centos7系列Cobbler+kickstart全自动装机实战

centos7系列Cobbler+kickstart全自动装机实战