cobbler实现系统的自动化安装

1.准备工作,查看防火墙、selinux是否关闭。安装httpd、dhcpd、tftp、cobblerd服务并启动,关闭VMware的dhcp。

注:本次实验主机IP地址为10.0.0.101

[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
[root@localhost ~]# grep '^SELINUX=' /etc/selinux/config 
SELINUX=disabled     

[root@localhost ~]# yum -y install vim httpd dhcp tftp-server cobbler   #cobbler服务包源于epel源,centos7以前的版本
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * BaseOS: mirrors.aliyun.com
 * epel: mirrors.aliyun.com
BaseOS                                                                                | 3.6 kB  00:00:00     
epel                                                                                  | 4.7 kB  00:00:00     

[root@localhost ~]# systemctl enable --now tftp httpd cobblerd
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf 
option domain-name "example.org";
option domain-name-servers 180.76.76.76, 233.5.5.5;

default-lease-time 86400;
max-lease-time 172800;

log-facility local7;

subnet 10.0.0.0 netmask 255.255.255.0 {
   range 10.0.0.20 10.0.0.100;
   range 10.0.0.150 10.0.0.200;
   option routers 10.0.0.2;
   next-server 10.0.0.101;     #本机地址,TFTP服务器地址
   filename "pxelinux.0";      #bootloader启动文件的名称
}
[root@localhost ~]# systemctl enable --now dhcpd    #修改dhcp配置文件后启动服务

2.配置http

#插入centos6,7,8光盘并挂载在到http服务上
[root@localhost ~]# echo - - - > /sys/class/scsi_host/host0/scan ;echo - - - > /sys/class/scsi_host/host1/scan ;echo - - - > /sys/class/scsi_host/host2/scan 
[root@localhost ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0 1000M  0 part /boot
├─sda2   8:2    0 97.7G  0 part /
└─sda3   8:3    0    2G  0 part [SWAP]
sr0     11:0    1  3.7G  0 rom  
sr1     11:1    1  4.4G  0 rom  
sr2     11:2    1    7G  0 rom  
[root@localhost ~]# mkdir -pv /var/www/html/centos/{6,7,8}/os/x86_64
mkdir: created directory ‘/var/www/html/centos’
mkdir: created directory ‘/var/www/html/centos/6’
mkdir: created directory ‘/var/www/html/centos/6/os’
mkdir: created directory ‘/var/www/html/centos/6/os/x86_64’
mkdir: created directory ‘/var/www/html/centos/7’
mkdir: created directory ‘/var/www/html/centos/7/os’
mkdir: created directory ‘/var/www/html/centos/7/os/x86_64’
mkdir: created directory ‘/var/www/html/centos/8’
mkdir: created directory ‘/var/www/html/centos/8/os’
mkdir: created directory ‘/var/www/html/centos/8/os/x86_64’
[root@localhost ~]# mount /dev/sr0 /var/www/html/centos/6/os/x86_64
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# mount /dev/sr1 /var/www/html/centos/7/os/x86_64
mount: /dev/sr1 is write-protected, mounting read-only
[root@localhost ~]# mount /dev/sr2 /var/www/html/centos/8/os/x86_64
mount: /dev/sr2 is write-protected, mounting read-only
[root@localhost ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0 1000M  0 part /boot
├─sda2   8:2    0 97.7G  0 part /
└─sda3   8:3    0    2G  0 part [SWAP]
sr0     11:0    1  3.7G  0 rom  /var/www/html/centos/6/os/x86_64
sr1     11:1    1  4.4G  0 rom  /var/www/html/centos/7/os/x86_64
sr2     11:2    1    7G  0 rom  /var/www/html/centos/8/os/x86_64

3.创建kickstart文件放在http服务上

#centos6的kickstart格式
[root@localhost ~]# mkdir /var/www/html/ksdir 
[root@localhost ~]# vim /var/www/html/ksdir/ks6.cfg
[root@localhost ~]# cat /var/www/html/ksdir/ks6.cfg
install
text
reboot
url --url=http://10.0.0.101/centos/6/os/x86_64/
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp  --noipv6
rootpw  --iscrypted $1$f0OOktfs$ZFjz9pvGPbsruDl3W9GdG/
firewall --disabled
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto quiet"
zerombr
clearpart --all --initlabel
part /boot --fstype=ext4 --size=1024
part / --fstype=ext4 --size=100000
part /data --fstype=ext4 --size=50000
part swap --size=2048
%packages
@web-server
%end

%post
mkdir -pv /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
cat > etc/yum.repos.d/base.repo <<EOF
[BaseOS]
name=base
baseurl=https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
        https://mirrors.huaweicloud.com/centos/\$releasever/os/\$basearch/
enabled=1
gpgcheck=0
[epel]
name=epel
baseurl=https://mirrors.huaweicloud.com/epel/\$releasever/\$basearch/
        https://mirrors.aliyun.com/epel/\$releasever/\$basearch/
enabled=1
gpgcheck=0
EOF
yum clean all
yum makecache

useradd hu
echo 123456 |passwd --stdin hu

%end

#centos7的kickstart文件格式
[root@localhost ~]# vim /var/www/html/ksdir/ks7.cfg
[root@localhost ~]# cat /var/www/html/ksdir/ks7.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$f0OOktfs$ZFjz9pvGPbsruDl3W9GdG/
# System language
lang en_US
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled


# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://10.0.0.101/centos/7/os/x86_64/"
# System bootloader configuration
bootloader --append="net.ifnames=0" --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --fstype="xfs" --size=100000
part /boot --fstype="xfs" --size=1000
part swap --fstype="swap" --size=2048

%post
mkdir -pv /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
cat > etc/yum.repos.d/base.repo <<EOF
[BaseOS]
name=base
baseurl=https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
        https://mirrors.huaweicloud.com/centos/\$releasever/os/\$basearch/
enabled=1
gpgcheck=0
[epel]
name=epel
baseurl=https://mirrors.huaweicloud.com/epel/\$releasever/\$basearch/
        https://mirrors.aliyun.com/epel/\$releasever/\$basearch/
enabled=1
gpgcheck=0
EOF
yum clean all
yum makecache

useradd hu
echo 123456 |passwd --stdin hu

%end

%packages

%end

#centos8的kickstart文件格式
[root@localhost ~]# vim /var/www/html/ksdir/ks8.cfg
[root@localhost ~]# cat /var/www/html/ksdir/ks8.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$f0OOktfs$ZFjz9pvGPbsruDl3W9GdG/
# System language
lang en_US
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled


# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://10.0.0.101/centos/8/os/x86_64/"
# System bootloader configuration
bootloader --append="net.ifnames=0" --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --fstype="xfs" --size=100000
part /boot --fstype="xfs" --size=1000
part swap --fstype="swap" --size=2048

%post
mkdir -pv /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
cat > etc/yum.repos.d/base.repo <<EOF
[AppStream]
name=AppStream
baseurl=https://mirrors.aliyun.com/centos/8/AppStream/x86_64/os/
        https://mirrors.huaweicloud.com/centos/8/AppStream/x86_64/os/
enabled=1
gpgcheck=0
[BaseOS]
name=base
baseurl=https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/
        https://mirrors.huaweicloud.com/centos/8/BaseOS/x86_64/os/
enabled=1
gpgcheck=0
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/8/Everything/x86_64/
        https://mirrors.huaweicloud.com/epel/8/Everything/x86_64/
enabled=1
gpgchack=0
EOF
yum clean all
yum makecache

useradd hu
echo 123456 |passwd --stdin hu

%end

%packages

%end


#如需安装后主机远程登录,在主机上执行ssh-keygen生成认证密钥,然后把公钥文件 id_rsa.pub 内容复制到新机器 .ssh/anthorized_keys 文件里就可以实现主机登录。格式如下
mkdir /root/.ssh -m 700   #.ssh文件夹的权限设置700
cat > /root/.ssh/authorized_keys <<EOF
#粘贴复制主机的公钥内容	 	
EOF
chmod 600 /root/.ssh/authorized_keys    #authorized_keys 文件权限为600

4.配置cobbler服务

[root@localhost ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work.  This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
3 : change 'disable' to 'no' in /etc/xinetd.d/tftp
4 : Some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely.  Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
5 : enable and start rsyncd.service with systemctl
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
7 : ksvalidator was not found, install pykickstart
8 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
9 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them

Restart cobblerd and then run 'cobbler sync' to apply changes.

1.更改/etc/xinetd.d/tftp配置文件
[root@localhost ~]# vim /etc/xinetd.d/tftp
disable  =  yes  -->  disable  =  no
2.联网下载boot引导程序文件
cobbler get-loaders
3.没有网络情况下拷贝启动文件到TFTP服务文件夹
cp -a /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot
4.更改/etc/cobbler/settings 配置文件的server项为提供cobblerd服务的主机地址,配置文件的next_server项指明tftp服务器地址。配置相应的选项来使用cobbler管理dhcp服务和tftpd服务。
server:127.0.0.1  -->  server:10.0.0.101
next_server:127.0.0.1  -->  next_server:10.0.0.101
manage_dhcp:1
manage_tftpd:1
5.更改/etc/cobbler/settings 配置文件的pxe_just_once选项,该选项置1表示在pxe安装块结束时在cobbler系统中做相应的记录,这样会避免如果客户机的BIOS选项中PXE启动处于第一位导致的循环重启;如果第一个启动硬件不是PXE启动那就置0
pxe_just_once:1

配置完成后重启服务
[root@localhost tftpboot]# systemctl restart cobblerd

#cobbler将系统yum源文件存放在 /var/www/cobbler/ks_mirror 目录下
[root@localhost ~]# cobbler import --name=centos6 --path=/var/www/html/centos/6/os/x86_64/ --arch=x86_64
[root@localhost ~]# cobbler import --name=centos7 --path=/var/www/html/centos/7/os/x86_64/ --arch=x86_64
[root@localhost ~]# cobbler import --name=centos8 --path=/var/www/html/centos/8/os/x86_64/ --arch=x86_64
#导入后重启服务并同步
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# cobbler sync
[root@localhost ~]# du -sh /var/www/cobbler/ks_mirror/*   #查看导入后文件大小
3.8G	/var/www/cobbler/ks_mirror/centos6-x86_64
4.5G	/var/www/cobbler/ks_mirror/centos7-x86_64
6.7G	/var/www/cobbler/ks_mirror/centos8-x86_64
8.0K	/var/www/cobbler/ks_mirror/config

#将准备好的kickstart文件拷贝到 /var/lib/cobbler/kickstart目录下
[root@localhost ~]# cp /var/www/html/ksdir/* /var/lib/cobbler/kickstarts/
#将导入的linux系统镜像与其对应的ks文件建立关联
[root@localhost ~]# cobbler profile add --name=centos6 --distro=centos6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks6.cfg 
[root@localhost ~]# cobbler profile add --name=centos7 --distro=centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7.cfg 
[root@localhost ~]# cobbler profile add --name=centos8 --distro=centos8-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks8.cfg 
#建立连接后重启服务并同步
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# cobbler sync

#修改dhcp模板,生成dhcp的配置文件
[root@localhost ks_mirror]# vim /etc/cobbler/dhcp.template 
subnet 10.0.0.0 netmask 255.255.255.0 {
     option routers             10.0.0.2;
     option domain-name-servers 180.76.76.76,233.6.6.6;	  #DNS
     option subnet-mask         255.255.255.0;         #子网掩码
     range dynamic-bootp        10.0.0.150 10.0.0.200;    #动态IP范围
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                10.0.0.101;   #tftp服务器IP

#修改后同步cobbler,重启dhcp
[root@localhost ks_mirror]# cobbler sync
[root@localhost ks_mirror]# systemctl restart dhcpd

完成配置,准备安装6,7,8
在这里插入图片描述
完成安装
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值