Centos7.6 利用Cobbler批量自动安装操作系统

一、Cobbler服务简介

​ Cobbler 可以用来快速建立 Linux 网络安装环境,它已将 Linux 网络安装的技术门槛,从大专以上文化水平,成功降低到初中以下,连补鞋匠都能学会(cobbler中文意思就是修鞋匠)。

​ 该工具使用python开发,小巧轻便,易于使用,仅用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理DHCP、DNS、以及yum仓库、构造系统ISO镜像。

​ Cobbler支持命令行管理,web界面管理,还提供了API接口,可以方便二次开发使用。Cobbler客户端Koan支持虚拟机安装和操作系统重新安装,使重装系统更便捷。

二、Cobbler服务搭建详细步骤

实验环境:VMware 15.5、X Shell 6、Centos7.6

1、为cobbler服务器配置双网卡(NAT+仅主机)
U2n03t.md.png

2、进入yum源配置目录

[root@localhost ~]# vi /etc/yum.repos.d/

3、新建一个目录bak,将所有以.repo后缀结尾的文件移动进bak目录中

[root@localhost yum.repos.d]# mv *.repo bak/

4、新建一个yum源文件并进入编辑

[root@localhost yum.repos.d]# vi abc.repo

5、写入以下两个阿里云yum源

[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
enabled=1
gpgcheck=0

[centos]
name=centos base
baseurl=http://mirrors.163.com/centos/7/os/x86_64/
enabled=1
gpgcheck=0

## 编辑完成后保存退出

6、清空yum源缓存,并重新获取yum源列表

[root@localhost yum.repos.d]# yum clean all
[root@localhost yum.repos.d]# yum list

ps:为什么需要使用其他yum源?
    因为默认的centos7官方源或者使用光盘镜像中的本地yum源中没有cobbler相关组件

7、现在再来安装cobbler所需要的所有服务

[root@localhost yum.repos.d]# yum -y install cobbler cobbler-web dhcp vsftpd pykickstart httpd rsync xinetd

8、修改cobbler主配置文件(开启dhcp、TFTP及cobbler服务器IP)

[root@localhost ~]# vi /etc/cobbler/settings

U2na4A.md.png
U2nw9I.md.png
U2nNAH.md.png

9、开启服务(httpd、cobbler)

[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl start cobblerd

10、关闭系统核心防护和防火墙

systemctl stop firewalld
setenforce 0

10、使用命令检查cobbler服务,系统会自动显示需要优化或修改的地方

[root@localhost ~]# cobbler check

U2nUNd.md.png

11、根据系统提示进行修改

①第一项可以不修改

②修改tftp服务配置文件,将disabled后面的参数修改为no

[root@localhost ~]# vi /etc/xinetd.d/tftp

U2nBgP.md.png

③使用命令下载引导文件

[root@localhost ~]# cobbler get-loaders

④开启rsyncd服务

[root@localhost ~]# systemctl enable rsyncd

⑤第五项不需要修改

⑥设置并生成管理员密码

[root@localhost ~]# openssl passwd -1 -salt '123456' '123456'
$1$123456$wOSEtcyiP2N/IfIl15W6Z0    ## 生成的加密字符串

将生成的字符串复制到cobbler配置文件中

[root@localhost ~]# vi /etc/cobbler/settings

U2nDjf.png

⑦第七项不需要修改

12、开启服务(rsync、xinetd)

[root@localhost ~]# systemctl start rsyncd
[root@localhost ~]# systemctl restart xinetd

13、编辑dhcp配置文件

[root@localhost ~]# vi /etc/cobbler/dhcp.template 

     21 subnet 192.168.10.0 netmask 255.255.255.0 {
     22      option routers             192.168.10.100;
     23      option domain-name-servers 192.168.10.100;
     24      option subnet-mask         255.255.255.0;
     25      range dynamic-bootp        192.168.10.150 192.168.10.200;
     26      default-lease-time         21600;
     27      max-lease-time             43200;
     28      next-server                $next_server;
     
## 修改完成后使用命令进行同步:[root@localhost ~]# cobbler sync

U2nsu8.png

14、开启服务(dhcp、cobbler、xinetd)

[root@localhost ~]# systemctl start dhcpd
[root@localhost ~]# systemctl start cobblerd
[root@localhost ~]# systemctl start xinetd

15、将光盘镜像挂载到/mnt目录下

[root@localhost ~]# mount /dev/cdrom /mnt

16、向cobbler中导入镜像

[root@localhost ~]# cobbler import --path=/mnt/ --name=Centos-7-x86_64 --arch=x86_64

## 导入时间较长,要耐心等待

17、进入目录查看镜像是否导入成功

[root@localhost ~]# cd /var/www/cobbler/ks_mirror/
[root@localhost ks_mirror]# ll
总用量 0
drwxrwxr-x. 8 root root 254 11月 26 2018 Centos-7-x86_64    ## 导入成功!
drwxr-xr-x. 2 root root  34 7月  18 16:11 config

导入成功!

18、为保证运行正常,现在重启各项服务

[root@localhost Centos-7-x86_64]# systemctl restart cobblerd
[root@localhost Centos-7-x86_64]# systemctl restart dhcpd
[root@localhost Centos-7-x86_64]# systemctl restart xinetd
[root@localhost Centos-7-x86_64]# systemctl restart httpd

19、在VMware虚拟机中新建一台机器(不要挂载镜像!)

设置网卡为VM1,使其与cobbler服务器处在同一网络环境下

点击“”开启此虚拟机“
U2ngEQ.md.png

开机后自动获取dhcp服务,进入引导安装界面,这里选择第二项后回车即可
U2nyDS.md.png

安装时间较长,默认安装的是字符界面,安装完成后即可使用root用户和之前设置的密码进行登陆
U2n6Hg.md.png

到这里系统已经自动安装完成了

20、因为我们安装了,cobbler还可以通过web页面进行管理,现在来配置一下

为管理面板设置一个管理员登录用户名及密码

[root@localhost Centos-7-x86_64]# htdigest -c /etc/cobbler/users.digest Cobbler admin
Adding password for admin in realm Cobbler.
New password:            ## 设置密码
Re-type new password:     ## 重复密码

ps:第一行命令中的admin是用户名,可以自行定义修改

21、重启服务(http、cobbler)

[root@localhost Centos-7-x86_64]# systemctl restart httpd
[root@localhost Centos-7-x86_64]# systemctl restart cobblerd

22、打开浏览器,输入地址访问web控制台

https://192.168.50.136/cobbler_web

U2n2Nj.md.png

输入之前设置的用户名及密码即可登录
U2nR4s.md.png

可以看到安装的镜像文件,还可以进行重命名、删除等一些列操作

猜你喜欢

转载自blog.csdn.net/u014042047/article/details/107435008