设为首页 收藏本站
查看: 678|回复: 0

[经验分享] linux运维、架构之路-cobbler无人值守

[复制链接]

尚未签到

发表于 2017-11-22 20:02:19 | 显示全部楼层 |阅读模式
  一、cobbler介绍
            Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等
  1、主要功能:
①Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用
②Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理
③Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack
  2、Cobbler可管理的服务
  PXE服务支持
DHCP服务管理
DNS服务管理(可选bind,dnsmasq)
电源管理
Kickstart服务支持
YUM仓库管理
TFTP(PXE启动时需要)
Apache(提供kickstart的安装源,并提供定制化的kickstart配置)
  二、Cobbler部署配置
  1、环境



[iyunv@cobbler ~]# cat /etc/redhat-release
CentOS release 6.9 (Final)
[iyunv@cobbler ~]# uname -r
2.6.32-696.el6.x86_64
[iyunv@cobbler ~]# /etc/init.d/iptables status
iptables: Firewall is not running.
[iyunv@cobbler ~]# getenforce
Disabled
[iyunv@cobbler ~]# hostname -I
10.0.0.121 172.16.1.121
  2、安装Cobbler



CentOS6安装
yum localinstall Django14-1.4.21-1.el6.noarch.rpm -y
yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd
#说明:yum源里已经去除了Diango的下载源
CentOS7安装
yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd
  3、启动Cobbler服务



[iyunv@cobbler ~]# /etc/init.d/httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[iyunv@cobbler ~]# /etc/init.d/cobblerd start
Starting cobbler daemon:                                   [  OK  ]
  4、检查Cobbler配置



[iyunv@cobbler tools]# 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 : change 'disable' to 'no' in /etc/xinetd.d/rsync
6 : file /etc/xinetd.d/rsync does not exist
7 : debmirror package is not installed, it will be required to manage debian deployments and repositories
8 : 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
9 : 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.
#只需一步一步解决上面出现的问题即可,然后重启Cobbler
  5、解决Cobbler问题



cp /etc/cobbler/settings{,.bak} #备份Cobbler主配置文件
sed -i 's/server: 127.0.0.1/server: 172.16.1.121/' /etc/cobbler/settings
sed -i 's/next_server: 127.0.0.1/next_server: 172.16.1.121/' /etc/cobbler/settings
sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings #使用cobbler管理dhcp
sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings #防止有些机子第一启动是pxe循环重装系统,此处设置为只能装一次
sed -ri "/default_password_crypted/s#(.*: ).*#\1\"`openssl passwd -1 -salt 'cobbler' '123456'`\"#" /etc/cobbler/settings #设置系统的默认密码为123456
sed -i 's#yes#no#' /etc/xinetd.d/rsync
sed -i 's#yes#no#' /etc/xinetd.d/tftp
  6、配置Cobbler的dhcp模板



sed -i 's#192.168.1#172.16.1#g;22d;23d' /etc/cobbler/dhcp.template
#修改过后内容如下:
……
subnet 172.16.1.0 netmask 255.255.255.0 {
option subnet-mask         255.255.255.0;
range dynamic-bootp        172.16.1.100 172.16.1.254;
default-lease-time         21600;
max-lease-time             43200;
next-server                $next_server;
……
[iyunv@cobbler tools]# /etc/init.d/xinetd restart
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]
[iyunv@cobbler tools]# /etc/init.d/cobblerd restart
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:                                   [  OK  ]
[iyunv@cobbler tools]# /etc/init.d/httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
  7、同步Cobbler配置



[iyunv@cobbler tools]# cobbler sync
task started: 2017-11-07_145244_sync
task started (id=Sync, time=Tue Nov  7 14:52:44 2017)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
copying distros to tftpboot
copying images
generating PXE configuration files
#再次检查cobbler
[iyunv@cobbler tools]# cobbler check
The following are potential configuration items that you may want to fix:
1 : 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.
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories
3 : 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、此时打开浏览器输入
   DSC0000.png
DSC0001.png

  三、使用Cobbler的web页面实现自动化安装系统
  1、导入镜像



[iyunv@cobbler ~]# mount /dev/cdrom /mnt/
mount: block device /dev/sr0 is write-protected, mounting read-only
[iyunv@cobbler ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        19G  1.6G   16G   9% /
tmpfs           931M     0  931M   0% /dev/shm
/dev/sda1       190M   35M  146M  19% /boot
/dev/sr0        3.7G  3.7G     0 100% /mnt
DSC0002.png

  通过rsync导入镜像



[iyunv@cobbler ~]# ps -ef|grep rsync
root       2087   1599 18 16:57 ?        00:00:05 rsync -a /mnt/ /var/www/cobbler/ks_mirror/CentOS6.9-x86_64 --progress
root       2088   2087  0 16:57 ?        00:00:00 rsync -a /mnt/ /var/www/cobbler/ks_mirror/CentOS6.9-x86_64 --progress
root       2089   2088 13 16:57 ?        00:00:03 rsync -a /mnt/ /var/www/cobbler/ks_mirror/CentOS6.9-x86_64 --progress
root       2106   1256  0 16:58 pts/1    00:00:00 grep rsync
  导入完成之后
   DSC0003.png
  2、创建ks文件
   DSC0004.png
DSC0005.png

  3、定制系统
   DSC0006.png
DSC0007.png

DSC0008.png

  根据机器的mac地址固定ip地址
  eth1
   DSC0009.png
  eth0
   DSC00010.png
  CentOS7,修改网卡名
   DSC00011.png
  保存
   DSC00012.png
  4、新建空白虚拟机测试
   DSC00013.png
DSC00014.png

DSC00015.png

  休息片刻,一会儿回来查看结果
DSC00016.png

  4、CentOS6与CentOS7的ks.cfg文件
  CentOS6.9



# Cobbler for Kickstart Configurator for CentOS 6.9 by yan xinjiang
install
url --url=$tree
text
lang en_US.UTF-8
keyboard us
zerombr
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
$SNIPPET('network_config')
timezone --utc Asia/Shanghai
authconfig --enableshadow --passalgo=sha512
rootpw  --iscrypted $default_password_crypted
clearpart --all --initlabel
part /boot --fstype=ext4 --asprimary --size=200
part swap --size=1024
part / --fstype=ext4 --grow --asprimary --size=200
firstboot --disable
selinux --disabled
firewall --disabled
logging --level=info
reboot
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end
%packages
@base
@compat-libraries
@debugging
@development
tree
nmap
sysstat
lrzsz
dos2unix
telnet
%end
%post --nochroot
$SNIPPET('log_ks_post_nochroot')
%end
%post
$SNIPPET('log_ks_post')
# Start yum configuration
$yum_config_stanza
# End yum configuration
$SNIPPET('post_install_kernel_options')
$SNIPPET('post_install_network_config')
$SNIPPET('func_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')
# Start final steps
$SNIPPET('kickstart_done')
# End final steps
%end
  CentOS7.2



# Cobbler for Kickstart Configurator for CentOS 7.2 by yan xinjiang
install
url --url=$tree
text
lang en_US.UTF-8
keyboard us
zerombr
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
# Network information
$SNIPPET('network_config')
timezone --utc Asia/Shanghai
authconfig --enableshadow --passalgo=sha512
rootpw  --iscrypted $default_password_crypted
clearpart --all --initlabel
part /boot --fstype xfs --size 1024
part swap --size 1024
part / --fstype xfs --size 1 --grow
firstboot --disable
selinux --disabled
firewall --disabled
logging --level=info
reboot
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end
%packages
@base
@compat-libraries
@debugging
@development
tree
nmap
sysstat
lrzsz
dos2unix
telnet
htop
wget
vim
bash-completion
net-tools
iptraf
ncurses-devel
openssl-devel
zlib-devel
OpenIPMI-tools
screen
%end
%post
systemctl disable postfix.service
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o  /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
%end

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-409624-1-1.html 上篇帖子: 日志巡检 下篇帖子: 初识ELF格式 ABI,EABI,OABI
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表