cobbler实现批量部署Linux服务器(CentOS7.3含自定义安装)

centos7.3下使用私有网络(我这里使用kvm自建的default1网络,网段为192.168.100.0/24)实现cobbler自动安装




		拓扑图:		cobbler server    -------    client
					192.168.100.2/24
	




第一步:
先安装cobbler相关软件包 (需要epel源,local源,centos163源;但因为需要用私有网络来做实验,但私有网络又不能和我的共享源连接,所以先可以使用桥接网络把下面的包装上,再换成私有网络)  
# yum install cobbler cobbler-web tftp* rsync xinetd http* syslinux dhcp* pykickstart fence-agents xinetd debmirror system-config-kickstart




第二步:启动服务,并使用cobbler check查询哪些需要修改

# systemctl restart cobblerd.service
# systemctl restart httpd.service 
# systemctl enable cobblerd.service
# systemctl enable httpd.service

#  cobbler check	
(报错基本上和rhel6.5的差不多,要看具体报错可以参考我上一篇同类型rhel6.5文章)

第三步:按照cobbler check对应的信息修改
# sed -i 272s/127.0.0.1/192.168.100.2/ /etc/cobbler/settings
# sed -i 384s/127.0.0.1/192.168.100.2/ /etc/cobbler/settings  
# sed -i 242s/0/1/ /etc/cobbler/settings


# openssl passwd -1 -salt 'xcvsfdsdfwq' '123456'     -- xcvsfdsdfwq 为干扰码 可以随便填
$1$xcvsfdsd$cGxdcHuQGCnu5vJw5M7zX1

# vim /etc/cobbler/settings	--在101行把上面产生的密码字符串粘贴到""里替代原来的字符串
default_password_crypted: "$1$xcvsfdsd$cGxdcHuQGCnu5vJw5M7zX1"


# systemctl restart cobblerd.service


# sed -i /disable/s/yes/no/ /etc/xinetd.d/tftp

# systemctl restart rsyncd.service
# systemctl enable rsyncd.service


第四步:导入centos7.3的iso镜像(镜像自行下载)

# cobbler import --path=/yum/ --name=centos7.3

# cobbler distro list	--导入成功后,确认导入的镜像名
   centos7.3-x86_64
# cobbler profile list	--导入成功后,确认默认的profile名
   centos7.3-x86_64

第五步:修改dhcp配置
# vim /etc/cobbler/dhcp.template  --在此文件的第21行到第25行修改成你对应的网段和ip	

subnet 192.168.100.0 netmask 255.255.255.0 {
     option routers             192.168.100.2;
     option domain-name-servers 192.168.100.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.100.100 192.168.100.254;
(这里的参数的意义在上一篇同类文章rhel6.5有介绍)


第六步:使用cobbler sync同步,并启动xinetd服务
# cobbler sync
# systemctl restart xinetd.service
# systemctl enable xinetd.service

第七步:新建另一个虚拟机(保证相同私有网络,并且最好2G内存,内存小的话会在安装时报空间不够的错误),进行安装测试 



==============================================================================


自动安装我们已经实现了,但如何自定义我们想安装的profile

重点就是你需要自定义一个ks文件


自定义ks文件的方法
1,如果你很熟悉此文件,直接拷别人的模版修改或者直接使用/root/anaconda-ks.cfg来修改
2,使用一个图形工具system-config-kickstart来帮助你配置(下面我就是使用这种方法)


# yum install system-config-kickstart
# system-config-kickstart	


# vim /etc/yum.repos.d/local.repo    --这里有个小问题,需要把软件仓库里改成development,图形才能选择包,否则图形在选择软件包那一步看不到
[development]
name=development
baseurl=file:///yum/(你的本地yum源目录)
enabled=1
gpgcheck=0



--图形的操作过程这里省略


给大家两个做好的ks.cfg文件参考:

第一个文件就是大家用来安装centos7.3宿主机的ks文件,内容如下:
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$6RbFC2nC$GBugZL7ACuGhck8DbUZgM/
# Use network installation
url --url="http://172.16.13.250/cobbler/ks_mirror/centos7.3/"
# System language
lang en_US
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled

# Network information
network  --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai --isUtc
# System bootloader configuration
bootloader --append="rhgb quiet" --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=300
part swap --fstype="swap" --size=4000
part / --fstype="xfs"  --size=150000
part /data --fstype="xfs" --size=80000


%packages
@additional-devel
@desktop-debugging
@development
@fonts
@gnome-desktop
@input-methods
@kde-desktop
@legacy-x
@platform-devel
@remote-desktop-clients
@x11
initial-setup
initial-setup-gui
vinagre

%end






=========================================================================


# cobbler profile help	--查看帮助
# cobbler profile list	--查看有哪些profile
   centos7.3-x86_64	


# cobbler profile report --name=centos7.3-x86_64 |grep Kickstart
Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.ks  --这就是这个安装方案的kickstart文件
Kickstart Metadata             : {}


我现在自定义一个ks文件,也想做成一个profile,步骤如下:
步骤一:
自定义ks文件(使用system-config-kickstart或直接找一个模版文件修改),得到如下的文件

# vim /var/lib/cobbler/kickstarts/centos7.3.ks	--复制下面一大段信息,粘到此文件里

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$6RbFC2nC$GBugZL7ACuGhck8DbUZgM/
# Use network installation
url --url="http://192.168.100.2/cobbler/ks_mirror/centos7.3/"
# System language
lang en_US
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled

# Network information
network  --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai --isUtc
# System bootloader configuration
bootloader --append="rhgb quiet" --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=300
part swap --fstype="swap" --size=2000
part / --fstype="xfs" --grow --size=1


%post
rm /etc/yum.repos.d/* -rf
cat > /etc/yum.repos.d/local.repo << EOF
[base]
name=base
baseurl=file:///yum
enabled=1
gpgcheck=0
EOF
%end


%packages
@additional-devel
@desktop-debugging
@development
@fonts
@gnome-desktop
@input-methods
@kde-desktop
@legacy-x
@platform-devel
@remote-desktop-clients
@x11
initial-setup
initial-setup-gui
vinagre

%end


步骤二:把准备好的ks文件做成一个新的profile
# cobbler profile add --name=new_centos7.3 --distro=centos7.3-x86_64  --kickstart=/var/lib/cobbler/kickstarts/centos7.3.ks

# cobbler profile list		--在原来基础上就多了自定义的安装方案
   centos7.3-x86_64
   new_centos7.3


步骤三:
测试
然后就可以新建一个客户端虚拟机,使用上面的new_centos7.3安装名字来测试了



==================================================================

对上面操作的扩展(仅供参考)
# cobbler profile edit --name=new_centos7.3 --kickstart=/var/lib/cobbler/kickstarts/xxx.ks   
# cobbler profile remove --name=new_centos7.3	



======================================================================



欢迎讨论交流!常年在线!

你可能感兴趣的:(Linux)