Cobbler服务器系统 :Centos 6.8 64位
服务器IP地址:192.168.159.128
需要安装部署的Linux系统:
系统版本:centos6.8-x86_x64
Eth0 IP地址段:192.168.159.150-192.168.159.250
网关:192.168.159.2
子网掩码:255.255.255.0
DNS:192.168.159.128 114.114.114.114
在Cobbler服务器上操作
一、关闭selinux
Vim /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq! #保存退出
setenforce 0 #使配置立即生效
二、配置防火墙
Vim /etc/sysconfig/iptables #编辑
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT #ssh服务需要此端口
-A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT #http服务需要此端口
-A INPUT -m state --state NEW -m udp -p udp --dport 69 -j ACCEPT #tftp服务需要此端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 25151 -j ACCEPT #cobbler需要此端口
:wq #保存退出
/etc/init.d/iptables restart #最后重启防火墙使配置生效
三、安装cobbler
wget -O /etc/yum.repos.d/aliyunepel.repo http://mirrors.aliyun.com/repo/epel-6.repo #下载aliyun yum源
yum install -y cobbler tftp tftp-server xinetd dhcp httpd rsync cobbler-web #安装cobbler
yum install -y pykickstart debmirror python-ctypes cman #安装运行cobbler需要的软件包
四、配置Cobbler
1、设置http服务
Vim /etc/httpd/conf.d/wsgi.conf
LoadModule wsgi_module modules/mod_wsgi.so #取消前面的注释
:wq! #保存退出
chkconfig httpd on #设置开机启动
service httpd start #启动
2、设置tftp服务开机启动
vim /etc/cobbler/tftpd.template #编辑
service tftp
{
disable = no #修改为no
socket_type = dgram
protocol = udp
wait = yes
user = $user
server = $binary
server_args = -B 1380 -v -s $args
per_source = 11
cps = 100 2
flags = IPv4
}
:wq! #保存退出
3、设置rsync服务开机启动
vim /etc/xinetd.d/rsync #编辑配置文件,设置开机启动rsync
service rsync
{
disable = no #修改为no
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
:wq! #保存退出
/etc/init.d/xinetd start #启动(CentOS中是以xinetd 来管理Rsync和tftp服务的)
4、配置cobbler相关参数
vi /etc/debmirror.conf #注释掉 @dists 和 @arches 两行
#@dists="sid";
#@arches="i386";
:wq! #保存退出
openssl passwd -1 -salt 'myredhat''12344321' #生成默认模板下系统安装完成之后root账号登录密码
$1$myredhat$2LHloV2OJhLZQO.b1/yg9/ #记录下这行,下面会用到
vim /etc/cobbler/settings #编辑,修改
default_password_crypted: "$1$myredhat$2LHloV2OJhLZQO.b1/yg9/"
next_server: 192.168.159.128
server: 192.168.159.128
manage_dhcp: 1
default_kickstart: /var/lib/cobbler/kickstarts/default.ks
:wq! #保存退出
5、配置dhcp服务器
vim /etc/cobbler/dhcp.template #编辑,修改
subnet 192.168.159.0 netmask 255.255.255.0 { #设置网段
option routers 192.168.159.2; #设置网关
option domain-name-servers 192.168.159.128,114.114.114.114 #设置dns服务器地址
option subnet-mask 255.255.255.0; #设置子网掩码
range dynamic-bootp 192.168.159.150 192.168.159.250; #设置dhcp服务器IP地址租用的范围
default-lease-time 21600; #默认租约时间
max-lease-time 43200; #最大租约时间
next-server $next_server;
class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
if option pxe-system-type = 00:02 {
filename "ia64/elilo.efi";
} else if option pxe-system-type = 00:06 {
filename "grub/grub-x86.efi";
} else if option pxe-system-type = 00:07 {
filename "grub/grub-x86_64.efi";
} else {
filename "pxelinux.0";
}
}
}
:wq! #保存退出
vim /etc/sysconfig/dhcpd #指定DHCP服务的网络接口
DHCPDARGS=eth0
:wq! #保存退出
dhcpd #测试dhcp服务器配置是否正确
chkconfig dhcpd on #设置开机启动
chkconfig cobblerd on #设置开机启动
cobbler get-loaders #安装cobbler相关工具包,否则检查cobbler配置会报错
service cobblerd start #启动cobbler
cobbler sync #同步配置文件到dhcp服务器
service dhcpd start #启动dhcp服务
五、挂载系统安装镜像到http服务器站点目录
由于我使用的是虚拟机环境、直接挂载的ISO文件,所以直接挂载光盘
mkdir -p /var/www/html/os/Centos6.8 #创建挂载目录
mount /dev/sr0 /var/www/html/os/Centos6.8 #挂载光盘
如果是下载到服务器的iso文件,挂载方法:
Mount -t iso9660 -o loop /usr/local/src/CentOS-6.8-x86_64-bin-DVD-1of2.iso /var/www/html/os/CentOS6.8 #挂载系统镜像
vim /etc/fstab #添加以下代码。实现开机自动挂载
/usr/local/src/CentOS-6.8-x86_64-bin-DVD-1of2.iso /var/www/html/os/CentOS6.8 iso9660 defaults,ro,loop 0 0
:wq! #保存退出
备注:重复上面的操作,把自己需要安装的CentOS系统镜像文件都挂载到/var/www/html/os/目录下
六、创建kickstarts自动安装脚本
cd /var/lib/cobbler/kickstarts #进入默认Kickstart模板目录
vim /var/lib/cobbler/kickstarts/centos-6.8-x86_64.ks #创建centos-6.8-x86_64.ks安装脚本
# Kickstart file automatically generated by anaconda.
install
url --url=http://192.168.159.128/cobbler/ks_mirror/centos6.8-x86_64/
lang en_US.UTF-8
zerombr yes
key --skip
keyboard us
network --device eth0 --bootproto dhcp --onboot on
#network --device eth0 --bootproto static --ip 192.168.159.250 --netmask 255.255.255.0 --gateway 192.168.159.2 --nameserver 192.168.159.128 --hostname CentOS
rootpw --iscrypted $1$myredhat$2LHloV2OJhLZQO.b1/yg9/
firewall --enabled --port=22:tcp
authconfig --enableshadow --enablemd5
selinux --disabled
timezone Asia/Shanghai
bootloader --location=mbr --driveorder=sda
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
#clearpart --linux
clearpart --all --initlabel
part / --bytes-per-inode=4096 --fstype="ext4" --size=2048
part /boot --bytes-per-inode=4096 --fstype="ext4" --size=128
part swap --bytes-per-inode=4096 --fstype="swap" --size=500
part /data --bytes-per-inode=4096 --fstype="ext4" --grow --size=1
reboot
%packages
ntp
@base
@core
@dialup
@editors
@text-internet
keyutils
trousers
fipscheck
device-mapper-multipath
%post
七、导入系统镜像到cobbler
cobbler import --path=/var/www/html/os/CentOS6.8 --name=CentOS-6.8-x86_64 --arch=x86_64 #导入系统镜像文件,需要一段时间
cd /var/www/cobbler/ks_mirror #进入系统镜像导入目录
命令格式:cobbler import --path=镜像路径 -- name=安装引导名 --arch=32位或64位
重复上面的操作,把其他的系统镜像文件导入到cobbler
八、设置profile,按照操作系统版本分别关联系统镜像文件和kickstart自动安装文件
在第一次导入系统镜像时,cobbler会给安装镜像指定一个默认的kickstart自动安装文件
如:CentOS-6.8-x86_64版本的kickstart自动安装文件为:/var/lib/cobbler/kickstarts/sample.ks
cobbler profile report --name centos-6.8-x86_64 #查看profile设置
cobbler distro report --name centos-6.8-x86_64 #查看安装镜像文件信息
cobbler profile remove --name= centos-6.8-x86_64 #移除profile
cobbler profile add --name=centos-6.8-x86_64 --distro= centos-6.8-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ centos-6.8-x86_64 .ks #添加
cobbler profile edit --name=centos-6.8-x86_64 --distro=CentOS-6.8-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-6.8-x86_64.ks #编辑
命令:cobbler profile add|edit|remove --name=安装引导名 --distro=系统镜像名 --kickstart=kickstart自动安装文件路径
--name:自定义的安装引导名,注意不能重复
--distro:系统安装镜像名,用cobbler distro list可以查看
--kickstart:与系统镜像文件相关联的kickstart自动安装文件
#查看Cobbler列表
cobbler list
cobbler report
cobbler profile report
cobbler distro list
也可以图形界面操作,访问http://192.168.159.128/cobbler_web/账号密码都是cobbler
登录以后点击Importer DVD (先挂载镜像ISO),然后再Importer,点击run。
导入完成后可以看到:
选择左侧profile配置ks文件
输入你所需要的ks文件路径
自动化部署系统
九、客户端从网络启动后选择对应的文件开始自动部署
开机之后,如下图所示,根据需要选择相应的系统版本进行安装,安装完成之后,系统会自动重启
安装成功重启以后,输入设置的密码,用户名root
至此,Cobbler全自动批量安装部署Linux系统完成。
2017年4月13日 上午8:38 沙发
很荣幸来访您的博客,留言只是证明我来过!
2017年4月17日 下午4:26 板凳
世事无常,但这个博客定能永保辉煌!
2017年4月21日 下午5:07 地板
时间飞快,转眼年中就要到来,祝你天天愉快!
2017年4月26日 上午9:45 4楼
我只想默默的拜读您的博客!
2017年4月27日 下午3:52 5楼
你的博客让人流连忘返!
2017年4月30日 上午7:32 6楼
闲着没事,随便逛逛,心静自然凉。
2017年5月15日 上午10:02 7楼
受教了!呵呵!
2017年5月19日 下午5:20 8楼
古人日三省其身,我从博客里吸收养分!
2017年5月31日 下午5:20 9楼
很荣幸来到这里参观!
2017年6月3日 下午4:02 10楼
学习是人前进的助力,认真拜读咯!
2017年6月5日 下午4:14 11楼
相当精彩的博客!