系统自动部署

16.1 使用Centos 6部署PXE+Kickstart,安装centos6系统,ks文件自定义

16.1.1 准备工作

关闭selinux重启

[root@pxe ~]# setenforce 0
[root@pxe ~]# service iptables stop

安装软件

[root@pxe ~]# yum install -y tftp-server dhcp syslinux vsftpd
[root@pxe ~]# yum groupinstall -y "X Window System" "Desktop"
[root@pxe ~]# yum install -y system-config-kickstart	

挂载光盘

[root@pxe ~]# mkdir  /var/ftp/pub/cd
[root@pxe ~]# mount -t iso9660 /dev/cdrom /var/ftp/pub/cd

注:最好写到/etc/fstab中

16.1.2 配置tftp服务

[root@pxe ~]# vim /etc/xinetd.d/tftp

disable = no

[root@pxe ~]# service xinetd restart
Stopping xinetd: [  OK  ]
Starting xinetd: [  OK  ]

16.1.3 配置dhcp服务

[root@pxe ~]# vim /etc/dhcp/dhcpd.conf

subnet 192.168.217.0 netmask 255.255.255.0 {
  range 192.168.217.200 192.168.217.210;
  option domain-name-servers 114.114.114.114;
  option routers 192.168.217.165;
  next-server 192.168.217.165;
  filename "pxelinux.0";  
}

[root@pxe ~]# service dhcpd restart
Starting dhcpd: [  OK  ]

16.1.4 配置ftp服务

[root@pxe ~]# service vsftpd restart
Shutting down vsftpd: [  OK  ]
Starting vsftpd for vsftpd: [  OK  ]

16.1.5 准备相关文件

[root@pxe ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@pxe ~]# cp /usr/share/syslinux/pxelinux.0  /var/lib/tftpboot/
[root@pxe ~]# cp /var/ftp/pub/cd/images/pxeboot/initrd.img /var/ftp/pub/cd/images/pxeboot/vmlinuz  /var/lib/tftpboot/
[root@pxe ~]# cp /var/ftp/pub/cd/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

内容/var/lib/tftpboot/pxelinux.cfg/default

default linux
label linux
  menu label ^Install CentOS6.9
  menu default
  kernel vmlinuz
  append initrd=initrd.img ks=ftp://192.168.217.165/pub/ks.cfg

16.1.6 部署ks文件

打开图形化界面

[root@pxe ~]# init 5

打开/usr/bin/system-config-kickstart

设置密码

在这里插入图片描述

指定安装源

可以是FTP的,也可以是HTTP的

在这里插入图片描述

如果是HTTP的,就要把挂载的目录复制到/var/www/html/目录下

开启http服务

cp -r cp -rp /var/ftp/pub/cd /var/www/html

在这里插入图片描述

手动分区

在这里插入图片描述

设置网卡

在这里插入图片描述

选择安装两个基础包

在这里插入图片描述

保存ctrl +s

路径要选择

在这里插入图片描述

新建虚拟机

可以看到这里分配的ip为192.168.217.200,

在这里插入图片描述

16.1.7 完成

在这里插入图片描述

完成

16.2 使用Centos 7部署Cobbler,安装Centos7与Ubuntu

16.2.1 Cobbler安装

基础环境部署

关闭selinux:

[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld

yum配置:

#讲旧仓库配置转移到某目录中 
[root@localhost ~]# mkdir /etc/yum.repos.d/old && mv /etc/yum.repos.d/C* /etc/yum.repos.d/old/ 

#安装wget,添加aliyun Base仓库及epel仓库 
[root@localhost ~]# yum install -y wget 
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 
[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

16.2.2 Cobbler服务部署

安装服务:

[root@localhost ~]# yum install cobbler cobbler-web dhcp tftp-server pykickstart httpd xinetd python-ctypes -y

服务自启动:

[root@localhost ~]# systemctl enable httpd 
[root@localhost ~]# systemctl enable xinetd 
[root@localhost ~]# systemctl enable rsyncd 
[root@localhost ~]# systemctl enable tftp 
[root@localhost ~]# systemctl enable cobblerd

启动服务:

[root@localhost ~]# systemctl restart httpd 
[root@localhost ~]# systemctl restart xinetd 
[root@localhost ~]# systemctl restart tftp 
[root@localhost ~]# systemctl restart cobblerd

执行cobbler check检查运行环境:

[root@localhost ~]# 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 : 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
4 : change 'disable' to 'no' in /etc/xinetd.d/tftp
5 : 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.
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.

问题1,2,7:

默认密码,setting,和dhcp

生成新的默认密码

[root@localhost ~]# openssl passwd -1 -salt `openssl rand 15 -base64` '123' 
$1$Yo1o0fBf$pm5RkWqGdviwsu4YiWhF9/

注意: 此密码是系统安装后的默认密码,建议使用强密码

修改setting配置文件

[root@localhost ~]# sed -i 's%^server: 127.0.0.1%server: 192.168.217.155%g' /etc/cobbler/settings 
[root@localhost ~]# sed -i 's%^next_server: 127.0.0.1%next_server: 192.168.217.155%g' /etc/cobbler/settings 
[root@localhost ~]# sed -i 's%manage_dhcp: 0%manage_dhcp: 1%g' /etc/cobbler/settings 
[root@localhost ~]# sed -i 's%^default_password_crypted.*%default_password_crypted: "$1$Yo1o0fBf$pm5RkWqGdviwsu4YiWhF9/"%g' /etc/cobbler/settings

配置DHCP /etc/dhcp/dhcpd.conf(根据需求更改)

[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
subnet 192.168.217.0 netmask 255.255.255.0 { 
	option routers 192.168.217.155; #网关地址 
	option domain-name-servers 114.114.114.114; #dns地址 
	option subnet-mask 255.255.255.0; #掩码 
	range dynamic-bootp 192.168.217.10 192.168.217.100; #地址分配范围 		default-lease-time 21600; 
	max-lease-time 43200; 
	next-server $next_server; #引用上面setting配置的nex-server值 
	filename "/pxelinux.0"; 
}

上面的不用改,只改这个就好了。/etc/cobbler/dhcp.template

还要修改/etc/cobbler/dhcp.template 文件

[root@localhost ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.217.0 netmask 255.255.255.0 {
     option routers             192.168.217.155;
     option domain-name-servers 114.114.114.114;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.217.10 192.168.217.100;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
     class "pxeclients" {

问题3:

关闭selinux

[root@localhost ~]# setenforce 0 
#编辑/etc/selinux/config,并重启生效 
SELINUX=disabled
init 6

问题4

启动tftp服务

编辑tftp服务配置文件 /etc/xinetd.d/tftp

[root@localhost ~]# vim  /etc/xinetd.d/tftp 
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 
}

问题5:

获取引导文件

[root@localhost ~]# cobbler get-loaders

截图

在这里插入图片描述

问题6:

debian相关文件获取(如不需要部署debian系统可省略)

[root@localhost ~]# yum -y install debmirror 
#修改/etc/debmirror.conf配置文件,注释掉@dists和@arches两行 
[root@localhost ~]# vi /etc/debmirror.conf 
... 
#@dists="sid"; 
@sections="main,main/debian-installer,contrib,non-free"; 
#@arches="i386"; 
...

问题8:

电源管理工具(可选)

[root@localhost ~]# yum -y install fence-agents

重启服务并同步状态

[root@localhost ~]# systemctl restart cobblerd 
[root@localhost ~]# cobbler check
No configuration problems found.  All systems go.

这就完成

16.2.3 cobbler基础配置Ubuntu

同步配置是配置生效

[root@localhost ~]# cobbler sync

配置distro:

主要用来定义和设置系统发行版本,里包含了系统的内核,引导文件,以及安装包等内容,就相当于一个LINUX系统的ISO镜像。如:多个发行版本,同一发行版不同版本号。

1.首先上传系统iso镜像文件,此处以ubuntu12.04镜像为例,其他镜像做法类似

wget http://releases.ubuntu.com/precise/ubuntu-12.04.5-server-amd64.iso

[root@localhost ~]# mkdir -p /system/ubuntu1204 ; mount -t iso9660 ~/ubuntu-12.04.5-server-amd64.iso /system/ubuntu1204

2.导入镜像

[root@localhost ~]# cobbler import --name=ubuntu1204 --path=/system/ubuntu1204 --arch=x86_64 
task started: 2020-04-30_102441_import
task started (id=Media import, time=Thu Apr 30 10:24:41 2020)
Found a candidate signature: breed=freebsd, version=10.1
Found a candidate signature: breed=freebsd, version=10.0
Found a candidate signature: breed=freebsd, version=8.3
Found a candidate signature: breed=freebsd, version=8.2
Found a candidate signature: breed=freebsd, version=8.4
Found a candidate signature: breed=freebsd, version=11.0
Found a candidate signature: breed=freebsd, version=10.3
Found a candidate signature: breed=freebsd, version=11.2
Found a candidate signature: breed=freebsd, version=11.1
Found a candidate signature: breed=freebsd, version=12.0
Found a candidate signature: breed=freebsd, version=10.2
Found a candidate signature: breed=freebsd, version=11.3
Found a candidate signature: breed=freebsd, version=9.0
Found a candidate signature: breed=freebsd, version=9.1
Found a candidate signature: breed=freebsd, version=9.2
Found a candidate signature: breed=freebsd, version=9.3
Found a candidate signature: breed=ubuntu, version=precise
running: /usr/bin/file /var/www/cobbler/ks_mirror/ubuntu1204-x86_64/dists/precise/Release.gpg
received on stdout: /var/www/cobbler/ks_mirror/ubuntu1204-x86_64/dists/precise/Release.gpg: PGP signature

received on stderr: 
running: /usr/bin/file /var/www/cobbler/ks_mirror/ubuntu1204-x86_64/dists/precise/Release
received on stdout: /var/www/cobbler/ks_mirror/ubuntu1204-x86_64/dists/precise/Release: ASCII text

received on stderr: 
Found a matching signature: breed=ubuntu, version=precise
Adding distros from path /var/www/cobbler/ks_mirror/ubuntu1204-x86_64:
creating new distro: ubuntu1204-x86_64
trying symlink: /var/www/cobbler/ks_mirror/ubuntu1204-x86_64 -> /var/www/cobbler/links/ubuntu1204-x86_64
creating new profile: ubuntu1204-x86_64
associating repos
checking for apt repo(s)
adding apt repo for ubuntu1204-x86_64
Added repos for ubuntu1204-x86_64
*** TASK COMPLETE ***

3.查看distro配置

[root@localhost ~]# cobbler distro report 
Name                           : ubuntu1204-x86_64
Architecture                   : x86_64
TFTP Boot Files                : {}
Breed                          : ubuntu
Comment                        : 
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/ks_mirror/ubuntu1204-x86_64/install/netboot/ubuntu-installer/amd64/initrd.gz
Kernel                         : /var/www/cobbler/ks_mirror/ubuntu1204-x86_64/install/netboot/ubuntu-installer/amd64/linux
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/ubuntu1204-x86_64'}
Management Classes             : []
OS Version                     : precise
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}

查看ubuntu相关文件:

[root@localhost ~]# cobbler list 
distros: 
	ubuntu1204-x86_64 #镜像 

profiles: 
	ubuntu1204-x86_64 #配置,用于配置关联自动应答ks文件 

systems: #可以为不同的主机根据MAC设置地址及安装参数 

repos: 
	ubuntu1204-x86_64 #仓库,用于自定义仓库 

images: 

mgmtclasses: 

packages: 

files:

**(自定义)配置profifile:**定义自动安装应答文件

主要用来定义kickstart配置文件,安装时依据配置文件进行定制化安装,配置此项时要和distro进行关联。

[root@localhost ~]# cobbler profile report 
Name                           : ubuntu1204-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : ubuntu1204-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample.seed #关联的kickstart文件 (ubuntu和centos的ks文件格式有很大区别,不能混用)
Kickstart Metadata             : {}
Management Classes             : []
Management Parameters          : <<inherit>>
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 : 
Internal proxy                 : 
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos                          : []
Server Override                : <<inherit>>
Template Files                 : {}
Virt Auto Boot                 : 1
Virt Bridge                    : xenbr0
Virt CPUs                      : 1
Virt Disk Driver Type          : raw
Virt File Size(GB)             : 5
Virt Path                      : 
Virt RAM (MB)                  : 512
Virt Type                      : kvm

配置repo:定义本地或远程仓库源

查看默认repo

[root@localhost ~]# cobbler repo report 
Name                           : ubuntu1204-x86_64
Apt Components (apt only)      : ['main', 'universe']
Apt Dist Names (apt only)      : ['precise', 'precise-updates', 'precise-security']
Arch                           : x86_64
Breed                          : apt
Comment                        : 
Createrepo Flags               : <<inherit>>
Environment Variables          : {}
Keep Updated                   : True
Mirror                         : http://archive.ubuntu.com/ubuntu
Mirror locally                 : True
Owners                         : ['admin']
Priority                       : 99
External proxy URL             : 
RPM List                       : []
Yum Options                    : {'--verbose': '~', '--ignore-release-gpg': '~'}

自定义repo

cobbler repo add --help #创建
repo cobbler repo edit --help #修改repo

(自定义)配置system

主要用来定义内核参数,电源管理,计算机名,网络接口参数等(客户机),如:根据mac地址配置IP地址,通过和

profifile,distro关联实现自动化安装。

cobbler system add --help #创建
system cobbler system edit --help #修改system

测试

新建一台虚拟机,启动看到如下界面

在这里插入图片描述
选择第二个菜单,是之前制作的distro,接下来服务器会自动按照之前的ks文件自动安装

然后就等等等。

在这里插入图片描述

嫌慢可以修改配置文件/var/lib/cobbler/kickstarts/sample.seed

在这里插入图片描述

改成

192.168.217.155

/system/ubuntu1204

16.2.4 cobbler基础配置Centos 7

创建挂载点,并进行挂载

[root@localhost ~]# mkdir /system/centos7
[root@localhost ~]# mount -o loop /dev/cdrom /centos7

查看挂载后的目录

[root@localhost ~]# ls /system/centos7/
CentOS_BuildTag  GPL       LiveOS    RPM-GPG-KEY-CentOS-7
EFI              images    Packages  RPM-GPG-KEY-CentOS-Testing-7
EULA             isolinux  repodata  TRANS.TBLuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL

导入镜像

[root@localhost ~]# cobbler import --path=/system/centos7 --name=centos7 --arch=x86_64

查看导入后镜像信息

[root@localhost ~]# cobbler distro report --name=centos7-x86_64
Name                           : centos7-x86_64
Architecture                   : x86_64
TFTP Boot Files                : {}
Breed                          : redhat
Comment                        : 
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/ks_mirror/centos7-x86_64/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/centos7-x86_64/images/pxeboot/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/centos7-x86_64'}
Management Classes             : []
OS Version                     : rhel7
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}

查看profile信息

[root@localhost ~]# cobbler profile report --name=centos7-x86_64
Name                           : centos7-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : centos7-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.ks
Kickstart Metadata             : {}
Management Classes             : []
Management Parameters          : <<inherit>>
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 : 
Internal proxy                 : 
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos                          : []
Server Override                : <<inherit>>
Template Files                 : {}
Virt Auto Boot                 : 1
Virt Bridge                    : xenbr0
Virt CPUs                      : 1
Virt Disk Driver Type          : raw
Virt File Size(GB)             : 5
Virt Path                      : 
Virt RAM (MB)                  : 512
Virt Type                      : kvm

ks 文件

[root@localhost ~]# vim /var/lib/cobbler/kickstarts/centos7.ks
# Cobbler for Kickstart Configurator for CentOS 7.4 
# System language 
lang en_US 
# System keyboard 
keyboard us 
# System 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 --enablemd5 
auth --useshadow --enablemd5 
# Network information 
$SNIPPET('network_config') 
reboot 
firewall --disabled 
selinux --disabled 
skipx 

%pre 
$SNIPPET('log_ks_pre') 
$SNIPPET('kickstart_start') 
$SNIPPET('pre_install_network_config') 
$SNIPPET('pre_anamon') 
%end

%packages 

%end 

%post 
systemctl disable postfix.service 
@base 
@core 
tree 
nmap 
sysstat 
lrzsz 
dos2unix 
telnet 
iptraf 
ncurses-devel 
openssl-devel 
zlib-devel 
OpenIPMI-tools 
screen 
%end

编辑centos7镜像所使用的kickstart文件

[root@localhost ~]# cobbler profile edit --name=centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.ks
[root@localhost ~]# cobbler profile report --name=centos7-x86_64 |grep Kickstart
Kickstart                      : /var/lib/cobbler/kickstarts/centos7.ks
Kickstart Metadata             : {}

测试

在这里插入图片描述

完成

在这里插入图片描述

问题总结:https://blog.51cto.com/14012942/2436394

1、要关掉NAT的dhcp

2、ks文件中别有中文注释

3、开始安装前重启下httpd,tftp,dhcpd,cobblerd

4、ks文件中的url别写url --url=$tree,写成http连接:url --url="http://192.168.217.155/cobbler/ks_mirror/CentOS7.6/"

5、CentOS7机器的内存为1G时安装失败

6、安装CentOS7 mini安装包步骤都找不到,所以全部放到post里,安装后yum装包

7、ks文件中的rootpw可以通过shadow文件来获取

8、如果无特殊情况,一定要将/var/lib/tftpboot/pxelinux.cfg/default 默认启动项设置为local
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章