linux進階-利用cobbler快速網絡安裝linux系統全get

實現cobbler服務

什麼是cobbler?

1.Cobbler翻譯爲中文是補鞋匠,在linux方面則一個免費的用於系統安裝部署的開源軟件,官方地址 http://cobbler.github.io/,
2.cobbler是對技術的二次基於python的開發,提供了CLI(命令行)和Web的管理方式,另外還提供了API(應用程序編程接口)接口,方便二次開發使用,
3.相比PXE,cobbler支持多系統同時引導,而PXE只能一次引導一個系統的安裝,
4.cobbler通常與開源軟件puppet、saltstack配合使用,進行操作系統的批量安裝與部署優化,從而實現大批量linux系統的無人值守安裝與服務部署,大大提升運維的工作效率,
4.cobbler工作於服務端,結合DHCP/TFTP/saltstack等服務提供批量系統安裝部署,
5.cobbler需要結合PXE技術對客戶端進行操作系統的安裝

在這裏插入圖片描述

1.client裸機配置了從網絡啓動後,開機後會廣播包請求DHCP服務器(cobbler server)發送其分配好的一個IP
2.DHCP服務器(cobbler server)收到請求後發送responese,包括其ip地址
3.client裸機拿到ip後再向cobbler server發送請求OS引導文件的請求
4.cobbler server告訴裸機OS引導文件的名字和TFTP server的ip和port
5.client裸機通過上面告知的TFTPserver地址通信,下載引導文件
6.client裸機執行執行該引導文件,確定加載信息,選擇要安裝的os,期間會再向cobbler server請求kickstart文件和os image
7.cobbler server發送請求的kickstart和os iamge.
8.client裸機加載kickstart文件 .client裸機接收os image,安裝該os image
cobbler常用命令

在這裏插入圖片描述

cobbler配置文件目錄

在這裏插入圖片描述

在這裏插入圖片描述

大家好我們又見面了!我們今天是利用cobbler服務快速安裝linux系統!
準備好,我們就開始咯

軟件準備

在這裏插入圖片描述

安裝前準備

關閉SElinux
vim /etc/sysconfig/selinux

編輯文件
······
SELINUX=disabled ✅
······
-------------------------------
關閉防火牆
systenctl stop firewalld   #臨時關閉 ✅
systemctl disable firewalld   #禁止開機啓動 ✅
-------------------------------------------
使用/misc/cd 本機是cnetos7對應的是/misc/cd
yum install autofs -y ✅
systenctl start autos ✅
systemctl enable autofs ✅
----------------------------------------------
安裝epel源
yum -y install epel-release ✅
--------------------------------
自己創建yum源
mkdir /etc/yum.repos.d/yum/
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/yum/

vim /etc/yum.repos.d/base.repo

編輯文件
······
[base]
name=base
baseurl=file:///misc/cd
gpgcheck=0

[epel]
name=epel
baseurl=http://mirrors.sohu.com/fedora-epel/7/x86_64/
gpgcheck=0
enabled=1
······
https://mirrors.aliyun.com/epel/7/x86_64/   
#上爲阿里雲鏡像文件,後面的實現cobbler web管理,無法使用
------------------------------------------------------
yum repolist   #確認epel源可用
---------------------------------
掛載光盤
[root@centos7 ~]# mkdir -pv /mnt/{centos6,centos7} ✅
[root@centos7 ~]# mount /dev/sr0 /mnt/centos7 ✅
[root@centos7 ~]# mount /dev/sr1 /mnt/centos6 ✅
[root@centos7 ~]# lsblk 
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0   50G  0 part /data
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    3G  0 part [SWAP]
sr0     11:0    1 10.3G  0 rom  /mnt/centos7
sr1     11:1    1  3.7G  0 rom  /mnt/centos6
-------------------------------------

確認橋接網卡,須能上網。第一塊橋接,第二塊NAT

能夠訪問外網的地址

在這裏插入圖片描述

在這裏插入圖片描述

cobbler 安裝

cobbler常見8項問題

[root@centos7 ~]# yum -y install cobbler dhcp tftp-server pykickstart httpd    #安裝cobbler ✅
---------------------------------------------------------------------
[root@centos7 ~]# systemctl start tftp.socket httpd cobblerd   #啓動服務 ✅
[root@centos7 ~]# systemctl enable  tftp httpd dhcpd cobblerd   #開機自啓 ✅
ss -ntul #tcp80端口   udp69端口打開
---------------------------------------------------------------------
cobbler chaeck   #測試cobbler
[root@centos7 ~]# 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 : 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

8 : 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.

8項問題解決方法

---------------------------------------------------------
1.#解決辦法 cobbler get-loaders #下載缺失的文件 ✅
----------------------------------------------------------
2.#解決辦法 systemctl enable rsyncd #添加rsync到自啓動並啓動rsync 
[root@Centos7 ~]#systemctl start rsyncd ✅
[root@Centos7 ~]#systemctl enable rsyncd.service ✅
----------------------------------------------------------
3.#解決辦法 service tftp
  {
           socket_type             = dgram
           protocol                = udp
           wait                    = yes
           user                    = root
           server                  = /usr/sbin/in.tftpd
           server_args             = -s /var/lib/tftpboot
           disable                 = no  # 修改爲no ✅
           per_source              = 11
           cps                     = 100 2
           flags                   = IPv4
  }
-----------------------------------------------------------
4.#解決辦法 cobbler get-loaders #下載缺失的文件 ✅
-----------------------------------------------------------
5.#解決辦法 systemctl enable rsyncd #添加rsync到自啓動並啓動rsync
[root@Centos7 ~]#systemctl start rsyncd ✅
[root@Centos7 ~]#systemctl enable rsyncd.service ✅
-----------------------------------------------------------
6.#跟debian 相關,可以忽略 ❌
-----------------------------------------------------------
7.#解決方法 # 修改密碼爲123456 ,salt後面是常用的加鹽方式加密
[root@Centos7 ~]#openssl passwd -1 -salt '123456' '123456'
Password: 
Verifying - Password: 
$1$123456$wOSEtcyiP2N/IfIl15W6Z0
vim /etc/cobbler/settings

編輯文件
······
default_password_crypted: "$1$123456$wOSEtcyiP2N/IfIl15W6Z0" ✅
······
------------------------------------------------------------
8.#fence設備相關,不需要 ❌
------------------------------------------------------------
vim /etc/cobbler/settings(注意:配置文件中改這四項:後面必需有一個空格)❗❗❗

在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

下面兩項和本章無關可忽略
[root@centos7 ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : debmirror package is not installed, it will be required to manage debian deployments and repositories   #dabian相關 ❌
2 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them   #fence設備相關,不需要 ❌

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

配置cobbler生成dhcp服務

[root@centos7 ~]# vim /etc/cobbler/dhcp.template

編輯文件
······
subnet 192.168.26.0 netmask 255.255.255.0 {                    ✅
     option routers             192.168.26.254;                ✅
     option domain-name-servers 1.1.1.1;                       ✅
     option subnet-mask         255.255.255.0;                 ✅
     range dynamic-bootp        192.168.26.100 192.168.26.254; ✅
······
--------------------------------------------------------------
[root@centos7 ~]# cobbler sync   #自動啓動dhcp服務 ✅
--------------------------------------------------------------
[root@centos7 ~]# systemctl restart tftp httpd cobblerd   #重啓服務 ✅
--------------------------------------------------------------

導入安裝源文件

[root@centos7 data]# cp /data/ks6_mini.cfg /var/lib/cobbler/kickstarts/ ✅
[root@centos7 data]# cp /data/ks7_mini.cfg /var/lib/cobbler/kickstarts/ ✅
-----------------------------------------------------------------------
vim /var/lib/cobbler/kickstarts/ks6_mini.cfg

編輯文件
······
url --url==$tree ✅
······
-----------------------------------------------------------------------
vim /var/lib/cobbler/kickstarts/ks7_mini.cfg

編輯文件
······
url --url==$tree ✅
······

將ks文件和系統關聯,生成啓動菜單

-------------------------------------------------------------------
[root@centos7 ~]# cobbler profile add --name=centos-6-x86_64_mini --distro=centos-6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks6_mini.cfg ✅
[root@centos7 ~]# cobbler profile add --name=centos-7-x86_64_mini --distro=centos-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7_mini.cfg ✅
--------------------------------------------------------------------
[root@centos7 ~]# cobbler profile list   #應答文件
   centos-6-x86_64_mini
   centos-7-x86_64_mini
-----------------------------------------   
[root@centos7 ~]# cobbler distro list   #源文件
   centos-6-x86_64
   centos-7-x86_64
-----------------------------------------
[root@centos7 ~]# cobbler profile remove --name=centos-6-x86_64  #刪除默認的文件 ✅
[root@centos7 ~]# cobbler profile remove --name=centos-7-x86_64  #刪除默認的文件 ✅
----------------------------------------------------------------

實現cobbler web管理

yum -y install cobbler-web ✅
--------------------------------------------------------------------
systemctl restart httpd ✅
--------------------------------------------------------------------
systemctl restart cobblerd ✅
--------------------------------------------------------------------
[root@centos7 ~]# htdigest /etc/cobbler/users.digest Cobbler cobbler2 ✅
Adding user cobbler2 in realm Cobbler
New password: 
Re-type new password: 
---------------------------------------------------------------------
https://192.168.26.7/cobbler_web
---------------------------------------------------------------------

在這裏插入圖片描述

在這裏插入圖片描述

在這裏插入圖片描述

在這裏插入圖片描述

看到這條信息,首先謝謝您😘其次表示本次實驗到這就完全結束了,歡迎下次光臨!(~ ̄▽ ̄)~
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章