Cobbler自动部署装机
Cobbler 概述与环境配置
- Cobbler是一个使用Python开发的开源项目,通过将部署系统所涉及的所有服务集中在一起,来提供一个全自动批量快速建立linux系统的网络安装环境。
- 使用VMware虚拟机软件演示,需连接上互联网,且虚拟机都使用NAT模式。一台CentOS7虚拟机作为服务端,另一台CentOS7虚拟机当做客户端,留作最终测试,安装系统等正常配置。客户端测试机内存需≥2G
Cobbler自动装机服务搭建步骤
- 1. 导入epel源
[root@localhost 1]# rz -E (直接把文件拖进来)
rz waiting to receive.
[root@localhost 1]# ls
epel-release-latest-7.noarch.rpm
[root@localhost ~]# rpm -ivh epel-release-latest-7.noarch.rpm
- 2.安装Cobbler以及其相关服务软件包
[root@localhost ~]# yum install -y cobbler dhcp tftp-server pykickstart httpd rsync xinetd
各软件包作用如下
软件名 | 说明 |
---|---|
cobbler | 用来快速建立Linux网络安装环境 |
dhcp | 用来为空白主机自动分配IP地址 |
tftp-server | 提供引导镜像文件的下载 |
pykickstart | 实现无人值守安装 |
httpd | 作为控制台程序运行 |
rsync | 实现数据同步 |
xinetd | 提供访问控制、加强的日志和资源管理功能 |
- 3.修改cobbler主配置文件
[root@localhost 1]# vim /etc/cobbler/settings
next_server: 192.168.131.13 (指向tftp服务器的IP,即本机IP)
server: 192.168.131.13 (指向cobbler服务器的IP,即本机IP)
manage_dhcp: 1 (让cobbler管理dhcp服务)
manage_rsync: 1 (让cobbler管理rsync服务)
manage_tftpd: 1 (让cobbler管理tftp服务)
- 4.启动相关服务并关闭防火墙和selinux
[root@localhost ~]# systemctl start httpd.service
[root@localhost ~]# systemctl start cobblerd.service
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
- 5.修改tftp的配置文件,并开启服务
[root@localhost ~]# vim /etc/xinetd.d/tftp
service tftp
{
disable = no (开启tftp服务,此处将yse改为no)
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -B 1380 -v -s /var/lib/tftpboot
per_source = 11
cps = 100 2
flags = IPv4
}
[root@localhost ~]# systemctl restart xinetd.service
[root@localhost ~]# systemctl start rsyncd.service
- 6.下载引导操作系统文件
[root@localhost ~]# cobbler get-loaders
task started: 2021-02-24_111551_get_loaders
task started (id=Download Bootloader Content, time=Wed Feb 24 11:15:51 2021)
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***
- 7.使用盐值加密方式设置 Cobbler用户初始密码
[root@localhost ~]# openssl passwd -1 -salt '11312' '11312' (使用盐值加密方式生成密钥。前面‘ ’里面的可以任意填写字符,后面
的‘ ’里面为安装完系统后root用户的密码)
$1$5514$rQPa3RgJ5WEG3TaZT6toR1
[root@localhost ~]# vim /etc/cobbler/settings (将生成的密钥加入Cobbler配置文件中)
:/default_password
default_password_crypted: "$1$5514$rWPa3RgJ5XQG3IaZT6toM1"
- 8.配置 DHCP 服务
[root@localhost 1]# vim /etc/cobbler/dhcp.template
subnet 192.168.131.0 netmask 255.255.255.0 { (这里修改的是网段)
option routers 192.168.131.13; (修改网关)
option domain-name-servers 192.168.131.2; (修改DNS,如果网卡使用的是dhcp模式,可通过nslookup 127.0.0.1 | grep
server 查询DNS地址)
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.131.10 192.168.131.100;(修改地址池)
default-lease-time 21600;
max-lease-time 43200;
- 9.将配置好的模板文件同步到DHCP服务的配置文件中并重启DHCP服务
[root@localhost 1]# cobbler sync
...省略...
*** TASK COMPLETE ***
[root@localhost ~]# systemctl restart dhcpd.service
- 10.导入ISO镜像文件
[root@localhost ~]# mount /dev/cdrom /mnt/
[root@localhost ~]# cobbler import --path=/mnt/ --name=CentOS-7-x86_64 --arch=x86_64
(--path:表示镜像所挂载的目录;--name:表示为安装源定义的名字;--atch:表示指定安装源的系统位数; 默认导入存放路径
为/var/www/cobbler/ks_mirror/CentOS-7-x86_64)
- 11.查看内核和初始化文件是否在在tftp-server 共享目录中
[root@localhost ~]# yum -y install tree (系统默认没有安装,需手动安装tree)
[root@localhost ~]# tree /var/lib/tftpboot/images (查看文件是否存在)
/var/lib/tftpboot/images
└── CentOS-7-x86_64
├── initrd.img
└── vmlinuz
- 12.重启所有服务并用cobbler check 对Cobbler做检查设置
[root@localhost ~]# systemctl restart cobblerd.service
[root@localhost ~]# systemctl restart dhcpd.service
[root@localhost ~]# systemctl restart xinetd.service
[root@localhost ~]# systemctl restart httpd.service
[root@localhost ~]# cobbler check
The following are potential configuration items that you may want to fix:
1 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
https://github.com/cobbler/cobbler/wiki/Selinux
2 : enable and start rsyncd.service with systemctl
3 : debmirror package is not installed, it will be required to manage debian deployments and repositories
4 : 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.
-
13.所有配置完成后开启空白主机即可自动安装系统
-
此安装方式为最小化安装,安装的系统只有字符界面
-
登录账户:root 密码:11312
-
登录上后查询ip并使用Xshell进行连接操作
如需图形化界面可自行手动安装
[root@localhost ~]# yum update grub2-common
[root@localhost ~]# yum install -y fwupdate-efi
[root@localhost ~]# yum install -y net-tools
[root@localhost ~]# yum groupinstall "GNOME Desktop" "Graphical Administration Tools"
[root@localhost ~]# reboot
- 将语言修改成中文
[root@localhost ~]# vim /root/anaconda-ks.cfg
1 #version=DEVEL
...略...
14 lang zh_CN.UTF-8
[root@localhost ~]# locale
LANG=zh_CN.UTF-8
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=