Cobbler自动化装机
cobbler
Cobbler是一个Linux系统安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。 Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。 Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
通过点点点就可以创建系统以及ks文件。
环境准备
准备好linux机器 [root@cobbler ~]# hostname cobbler 加上一个本地hosts解析 [root@cobbler ~]# tail -1 /etc/hosts 10.0.0.50 cobbler
安装coobler
1.yum自动化安装即可,提前配置好yum源 [root@cobbler ~]# yum install cobbler cobbler-web dhcp tftp-server pykickstart httpd python-django -y 2.检查软件包 [root@cobbler ~]# rpm -qa cobbler cobbler-web dhcp tftp-server pykickstart httpd python-django cobbler-web-2.8.5-6.el7.noarch dhcp-4.2.5-83.el7.centos.1.x86_64 tftp-server-5.2-22.el7.x86_64 cobbler-2.8.5-6.el7.x86_64 httpd-2.4.6-99.el7.centos.1.x86_64 pykickstart-1.99.66.22-1.el7.noarch 3.启动cobbler,与http [root@cobbler ~]# systemctl start cobblerd httpd [root@cobbler ~]# systemctl is-active cobblerd active [root@cobbler ~]# systemctl is-active httpd active 4.检查cobbler配置 [root@cobbler ~]# cobbler check
修改cobbler配置
1.修改配置文件/etc/cobbler/settings ,修改如下参数 # 备份配置文件 [root@cobbler ~]# cp /etc/cobbler/settings{,.bak} # 防止误重装 [root@cobbler ~]# sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings # 配置Cobbler统一管理DHCP [root@cobbler ~]# sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings # 配置DHCP Cobbler模版,这里sed提供了备份功能 [root@cobbler ~]# sed -i.ori 's#192.168.1#10.0.0#g;22d;23d' /etc/cobbler/dhcp.template 2.根据cobbler check依次修改配置文件,修改如下配置,注意改了之后要重启cobblerd服务,才可以生效 # 请注意,填写ip地址 # 修改/etc/cobbler/settings [root@cobbler ~]# grep -E -n '^server|^next' /etc/cobbler/settings 278:next_server: 10.0.0.50 390:server: 10.0.0.50 # 修改xinetd配置文件, /etc/xinetd.d/tftp ,因为xinetd是管理tftp的,我们用cobbler去管理了 disable = no # 需要安装驱动,cobbler要控制其他机器 # 还需要用到rsync服务,开启该服务 [root@cobbler ~]# systemctl restart rsyncd # 修改cobbler安装的系统,默认的密码是"cobbler",可以改下 [root@cobbler ~]# openssl passwd -1 Password: Verifying - Password: $1$5eZ//t9W$X79SpNdtVvC9f2mWzkJqv1 # 在配置文件/etc/cobbler/settings修改默认root密码为,123456 default_password_crypted: "$1$5eZ//t9W$X79SpNdtVvC9f2mWzkJqv1." # 修改有关cobbler脑裂配置,可以使用fencing tools # 改完如上配置,重启cooblerd [root@cobbler ~]# systemctl restart cobblerd # 再次检查,吧修改的配置,让其生效 [root@cobbler ~]# cobbler sync # 剩下的报错无所谓 [root@cobbler ~]# cobbler check The following are potential configuration items that you may want to fix: 1 : Some network boot-loaders are missing from /var/lib/cobbler/loaders. 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. 2 : debmirror package is not installed, it will be required to manage debian deployments and repositories 3 : 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.
重启核心服务
[root@cobbler ~]# systemctl restart cobblerd httpd tftp.socket rsyncd.service [root@cobbler ~]# systemctl is-active cobblerd httpd tftp.socket rsyncd.service active active active active
访问cobbler web
访问站点是
# 必须用https协议 https://10.0.0.50/cobbler_web 账户密码都是cobbler
进入首页
导入系统镜像
在cobbler web界面,导入dvd-iso镜像文件信息
cobbler web镜像存放点在
[root@cobbler ks_mirror]# pwd /var/www/cobbler/ks_mirror
在vmware里挂在好光盘,进行mount
[root@cobbler ks_mirror]# mount /dev/cdrom /mnt/ mount: /dev/sr0 is write-protected, mounting read-only [root@cobbler ks_mirror]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 475M 0 475M 0% /dev tmpfs 487M 0 487M 0% /dev/shm tmpfs 487M 7.7M 479M 2% /run tmpfs 487M 0 487M 0% /sys/fs/cgroup /dev/mapper/centos-root 17G 2.2G 15G 13% / /dev/sda1 1014M 138M 877M 14% /boot tmpfs 98M 0 98M 0% /run/user/0 /dev/sr0 4.4G 4.4G 0 100% /mnt
配置如图所示
在linux中检查cobbler导入操作
[root@cobbler ks_mirror]# cd /var/www/cobbler [root@cobbler cobbler]# ls images ks_mirror links localmirror misc pub rendered repo_mirror svc [root@cobbler cobbler]# du -sh . 4.5G . # cobbler默认是调用rsync进行同步数据
导入结束
apache显示cobbler镜像站点
http://10.0.0.50/cobbler/
cobbler-web
新建vmware虚拟机
测试用cobbler自动装机,创建方式和手动安装方式一样,注意:
- 内存大小
- 添加网络适配器
- 删除usb
- 关闭dvd开机链接
出现如下页面,正常
该界面由pxe启动文件控制
[root@cobbler cobbler]# cat /var/lib/tftpboot/pxelinux.cfg/default DEFAULT menu PROMPT 0 MENU TITLE Cobbler | http://cobbler.github.io/ TIMEOUT 200 TOTALTIMEOUT 6000 ONTIMEOUT local LABEL local MENU LABEL (local) MENU DEFAULT LOCALBOOT -1 LABEL centos7-x86_64 kernel /images/centos7-x86_64/vmlinuz MENU LABEL centos7-x86_64 append initrd=/images/centos7-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://10.0.0.50/cblr/svc/op/ks/profile/centos7-x86_64 ipappend 2 MENU end
自动安装,选择第二个
装机使用的ks文件在这,cobbler生成的
创建自定义系统ks文件
# Kickstart Configurator for CentOS 7 by junwu install # $tree 是在cobbler-web中Distros配置中Kickstart Metadata定义的变量,在这个电脑上,地址就是 http://172.18.41.133/cblr/links/CentOS7-x86_64/ url --url=$tree text lang en_US.UTF-8 keyboard us zerombr bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet" # 有关自定义的网络配置,设置静态ip # network --bootproto=static --device=eth0 --gateway=10.0.0.2 --ip=10.0.0.102 --nameserver=223.5.5.5 --netmask=255.255.255.0 --activate # network --bootproto=static --device=eth1 --ip=10.0.0.105 --netmask=255.255.255.0 --activate # network --hostname=Cobbler # network --bootproto=dhcp --device=eth1 --onboot=yes --noipv6 --hostname=CentOS7 # cobbler网络配置,这里的配置目录在 $SNIPPET('networl_config') timezone --utc Asia/Shanghai authconfig --enableshadow --passalgo=sha512 # 设置root密码,用变量替换,该变量在cobbler-web的setting中 rootpw --iscrypted $default_password_crypted clearpart --all --initlabel part /boot --fstype xfs --size 1024 part swap --size 1024 part / --fstype xfs --size 1 --grow # 服务配置 firstboot --disable selinux --disabled firewall --disabled logging --level=info reboot #定义安装前的工作 %pre $SNIPPET('log_ks_pre') $SNIPPET('kickstart_start') $SNIPPET('pre_install_network_config') # 监控系统安装过程 $SNIPPET('pre_anamon') %end # 安装软件包 %packages @base @compat-libraries @debugging @development tree nmap sysstat lrzsz dos2unix telnet wget vim bash-completion %end %post systemctl disable postfix.service %end
此时可以去cobbler-web添加我们定义的ks文件模板,
复制粘贴即可,但是注意,不支持中文,所以中文注释都给删掉吧
该文件存放在linux上
[root@cobbler kickstarts]# pwd /var/lib/cobbler/kickstarts [root@cobbler kickstarts]# ll total 60 -rw-r--r-- 1 root root 1253 Jul 25 13:29 CentOS-7-X86_64.ks -rw-r--r-- 1 root root 115 Dec 26 2019 default.ks -rw-r--r-- 1 root root 22 Dec 26 2019 esxi4-ks.cfg -rw-r--r-- 1 root root 22 Dec 26 2019 esxi5-ks.cfg drwxr-xr-x 2 root root 56 Jul 22 01:20 install_profiles -rw-r--r-- 1 root root 1424 Dec 26 2019 legacy.ks -rw-r--r-- 1 root root 292 Dec 26 2019 pxerescue.ks -rw-r--r-- 1 root root 2825 Dec 26 2019 sample_autoyast.xml -rw-r--r-- 1 root root 1856 Dec 26 2019 sample_end.ks -rw-r--r-- 1 root root 0 Dec 26 2019 sample_esx4.ks -rw-r--r-- 1 root root 324 Dec 26 2019 sample_esxi4.ks -rw-r--r-- 1 root root 386 Dec 26 2019 sample_esxi5.ks -rw-r--r-- 1 root root 386 Dec 26 2019 sample_esxi6.ks -rw-r--r-- 1 root root 1913 Dec 26 2019 sample.ks -rw-r--r-- 1 root root 3419 Dec 26 2019 sample_old.seed -rw-r--r-- 1 root root 6694 Dec 26 2019 sample.seed
配置cobbler读取自定义的ks文件
cobbler默认读取的是
sample_end.ks
改为
CentOS-7-X86_64.ks
可以再创建个ens34
最后点击save保存
最后点击cobbler-web的sync按钮,等同于命令行执行cobbler sync
只有经历过生活的苦难
才会更加努力去生活
自己梦想的一切
更加需要自己脚踏实地的去践行
结果未必尽如人意
但是路途中的努力
一定比结果更加美丽
----by ljw