一次性裝100台電腦的系統「批量安裝系統軟件」

Cobbler是一款Linux生態的自動化運維工具,基於Python2開發,用於自動化批量部署安裝操作系統;其提供基於CLI的管理方式和WEB配置界面,其中WEB配置界面是基於Python2和Django框架開發。另外,cobbler還提供了API,方便二次開發。Cobbler屬於C/S模型(客戶端/服務器模型)

1、查看系統版本

# cat /etc/redhat-release

CentOS Linux release 7.1.1503 (Core) (備註本次部署是在Centos7中進行)

# uname -rm

3.10.0-229.el7.x86_64 x86_64

2、安裝epel源,安裝epel庫

#yum install -y epel-release
#wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

3、安裝cobbler環境所需的包

下載最新版的pip,然後安裝

#wget https://bootstrap.pypa.io/get-pip.py
#python get-pip.py
#ln -s /usr/local/python27/bin/pip2.7 /usr/bin/pip2
#pip2 install Django==1.8.9

4、開始安裝cobbler

#yum install -y httpd dhcp tftp tftp-server rsync pykickstart xinetd 
#yum install -y cobbler

5、centos7安裝cobbler-web(cobbler-web2.8版本必須用django1.8.9版本)

#yum install httpd-devel
#yum install -y cobbler-web

6、配置HTTPD的配置文件,更改項目存放的權限

#vim /etc/httpd/conf/httpd.conf
<Directory "/usr/share/cobbler/web/">
        <IfModule mod_ssl.c>
            SSLRequireSSL
        </IfModule>
        <IfModule mod_nss.c>
            NSSRequireSSL
        </IfModule>
        SetEnv VIRTUALENV
        Options Indexes MultiViews
        Order allow,deny     ##apache2.4必須改為AllowOverride All
        Allow from all     ##apache2.4必須改為Require all granted        
</Directory>

7、開啟服務和加開機啟動

#systemctl enable xinetd
#systemctl start xinetd
#systemctl start httpd
#systemctl start cobblerd
#systemctl enable httpd
#systemctl enable cobblerd
#systemctl enable rsyncd
#systemctl start rsyncd

8、檢查cobbler

#cobbler check
通過cobbler實現自動化開機批量裝CentOS系統部署安裝

按照上面的提示,逐步修改配置如下:

修改cobbler的settings文件,備份

# cp /etc/cobbler/settings{,.ori}     

修改server,Cobbler服務器的IP。

#sed -i 's/server: 127.0.0.1/server: 192.168.0.131/' /etc/cobbler/settings

如果用Cobbler管理DHCP,修改本項

#sed -i 's/next_server: 127.0.0.1/next_server: 192.168.0.131/' /etc/cobbler/settings
#sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings

防止循環裝系統,適用於服務器第一啟動項是PXE啟動。

#sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings

設置新裝系統的默認root密碼123456。random-phrase-here為干擾碼,可以自行設定。

# openssl passwd -1 -salt 'cobbler' '123456'

$1$cobbler$sqDDOBeLKJVmxTCZr52/11

# vim /etc/cobbler/settings

default_password_crypted: “$1$cobbler$sqDDOBeLKJVmxTCZr52/11”

修改tftp配置,啟用tftp

#vim /etc/xinetd.d/tftp  

將disable = yes改為:disable = no

配置DHCP

# vim /etc/cobbler/dhcp.template

配置修改如下:

	subnet 192.168.1.0 	netmask 255.255.255.0 {
	option routers		192.168.1.1;
	option domain-name-servers 	114.114.114.114;
	option subnet-mask	255.255.255.0;
	range dynamic-bootp	10.0.0.100 10.0.0.200;

下載boot-loaders

#cobbler get-loaders

同步配置

#systemctl restart cobblerd
#cobbler sync

9、導入鏡像到cobbler中

#mount /dev/cdrom /mnt
#cobbler import --path=/mnt/ --name=CentOS-7-x86_64 --arch=x86_64

10、編輯kickstart文件

#cd /var/lib/cobbler/kickstarts/
#vim CentOS-7-x86_64.cfg

配置文件如下:

#Kickstart Configurator for cobbler by Jason Zhao
#platform=x86, AMD64, or Intel EM64T
#System  language
lang en_US
#System keyboard
keyboard us
#Sytem timezone
timezone Asia/Shanghai
#Root password
rootpw --iscrypted $default_password_crypted
#Use text mode install
text
#Install OS instead of upgrade
install
#Use NFS installation Media
url --url=$tree
#System bootloader configuration
bootloader --location=mbr
#Clear the Master Boot Record
zerombr
#Partition clearing information
clearpart --all --initlabel
#Disk partitioning information
part /boot --fstype xfs --size 1024 --ondisk sda
part swap --size 1024 --ondisk sda
part / --fstype xfs --size 1 --grow --ondisk sda
#System authorization infomation
auth  --useshadow  --enablemd5
#Network information
$SNIPPET('network_config')
#network --bootproto=dhcp --device=em1 --onboot=on
# Reboot after installation
reboot
#Firewall configuration
firewall --disabled
#SELinux configuration
selinux --disabled
#Do not configure XWindows
skipx
#Package install information
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end
 
%packages
@ base
@ core
sysstat
iptraf
ntp
lrzsz
ncurses-devel
openssl-devel
zlib-devel
OpenIPMI-tools
mysql
nmap
screen
%end
 
%post
systemctl disable postfix.service
%end

11、更改centos6和centos7的ks文件位置

#cobbler profile edit --name=CentOS-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg

12、Cobbler 常用命令

cobbler check #檢查cobbler配置

cobbler sync #同步配置到dhcp/pxe和數據目錄

cobbler list #列出所有的cobbler元素

cobbler import #導入安裝的系統鏡像

cobbler report #列出各元素的詳細信息

cobbler distro #查看導入的發行版系統信息

cobbler profile #查看配置信息

cobbler system #查看添加的系統信息

cobbler reposync #同步yum倉庫到本地

13、查看詳細配置信息,這裡把centos7配置信息都顯示了

# cobbler profile report
# cobbler sync

14、配置綁定mac地址和IP地址 ,開機自動選擇

# cobbler system add --name=centos711 --mac=00:0C:29:70:E8:A3 --profile=Centos-7-x86_64  
--ip-address=192.168.0.40 --subnet=255.255.255.0 --gateway=192.168.0.1 --interface=eth0 
--static=1 --hostname=centos711 --name-servers="223.5.5.5"
# cobbler sync

到此cento7系統的也可以裝機了

原創文章,作者:投稿專員,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/274377.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
投稿專員的頭像投稿專員
上一篇 2024-12-17 14:12
下一篇 2024-12-17 14:13

相關推薦

發表回復

登錄後才能評論