mportant;">操作系统: CentOS7.6
cobbler:cobbler-2.8.4-4,IP地址为192.168.1.108
先关闭selinux和防火墙: firewalld selinux 关闭
1、安装
rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y tftp-server httpd dhcp yum-utils cobbler cobbler-web cman debmirror xinetd rsync pykickstart fence-agents createrepo
解决web访问cobbler报错
yum install -y python2-pip
pip install Django==1.8.9
2、设置开机自启动
sed -i ‘/disable/c\\tdisable\t\t\t= no’ /etc/xinetd.d/tftp
sed -i -e ‘s/\=\ yes/\=\ no/g’ /etc/xinetd.d/rsync
systemctl enable cobblerd.service
systemctl enable dhcpd.service
systemctl enable httpd.service
systemctl enable xinetd.service
systemctl enable rsyncd.service
3、修改配置文件,替换实际IP
sed -i ‘s/server: 127.0.0.1/server: 192.168.1.108/g’ /etc/cobbler/settings
sed -i ‘s/next_server: 127.0.0.1/next_server: 192.168.1.108/g’ /etc/cobbler/settings
sed -i ‘s/manage_rsync: 0/manage_rsync: 1/g’ /etc/cobbler/settings
sed -i ‘s/manage_dhcp: 0/manage_dhcp: 1/g’ /etc/cobbler/settings
4、修改自动部署的密码
默认密码为cobbler
openssl passwd -1 -salt ‘random-phrase-here’ ‘xxxxxx’ #自行修改
vim /etc/cobbler/settings
5、修改DHCP配置文件
vim /etc/cobbler/dhcp.template
根据实际情况修改,部分内容如下:
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.108;
option domain-name-servers 192.168.1.108;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.1.200 192.168.1.210;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
重启各项服务
systemctl restart cobblerd
systemctl restart httpd
systemctl restart xinetd
systemctl restart rsyncd
cobbler sync 先同步再重启dhcpd,否则dhcpd会报错
systemctl restart dhcpd
6、通过命令 cobbler check检查是否有错误
一些警告类的不影响cobbler正常使用
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 : comment out ‘dists’ on /etc/debmirror.conf for proper debian support
3 : comment out ‘arches’ on /etc/debmirror.conf for proper debian support
4 : 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
7、WEB访问
cobbler-2.8.4-4 这个版本的cobbler已经启用了https,若使用http访问会提示403
账号密码:cobbler/cobbler
但我访问时出现Internal Server Error的报错,反复查找各种日志,在如下日志找到一个报错:ImportError: cannot import name TEMPLATE_CONTEXT_PROCESSORS
[root@centos1 www]# tailf /var/log/httpd/ssl_error_log
[Wed Apr 24 21:11:50.584599 2019] [:error] [pid 8237] [remote 192.168.1.188:100] self._setup(name)
[Wed Apr 24 21:11:50.584617 2019] [:error] [pid 8237] [remote 192.168.1.188:100] File “/usr/lib/python2.7/site-packages/django/conf/__init__.py”, line 41, in _setup
[Wed Apr 24 21:11:50.584650 2019] [:error] [pid 8237] [remote 192.168.1.188:100] self._wrapped = Settings(settings_module)
[Wed Apr 24 21:11:50.584693 2019] [:error] [pid 8237] [remote 192.168.1.188:100] File “/usr/lib/python2.7/site-packages/django/conf/__init__.py”, line 110, in __init__
[Wed Apr 24 21:11:50.584727 2019] [:error] [pid 8237] [remote 192.168.1.188:100] mod = importlib.import_module(self.SETTINGS_MODULE)
[Wed Apr 24 21:11:50.584745 2019] [:error] [pid 8237] [remote 192.168.1.188:100] File “/usr/lib64/python2.7/importlib/__init__.py”, line 37, in import_module
[Wed Apr 24 21:11:50.584779 2019] [:error] [pid 8237] [remote 192.168.1.188:100] __import__(name)
[Wed Apr 24 21:11:50.584797 2019] [:error] [pid 8237] [remote 192.168.1.188:100] File “/usr/share/cobbler/web/settings.py”, line 89, in <module>
[Wed Apr 24 21:11:50.584830 2019] [:error] [pid 8237] [remote 192.168.1.188:100] from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
[Wed Apr 24 21:11:50.584858 2019] [:error] [pid 8237] [remote 192.168.1.188:100] ImportError: cannot import name TEMPLATE_CONTEXT_PROCESSORS
网上搜索有人也发现这问题,需要安装django来解决,而我发现当前系统已经有安装了django,版本如下:
[root@centos1 ~]# python
Python 2.7.5 (default, Oct 30 2018, 23:45:53)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import django
>>> print django.get_version()
1.11.20
网上所说需要安装1.8.9版本的django,
yum install -y python2-pip
pip install Django==1.8.9
版本升级完成
[root@centos1 ~]# python
Python 2.7.5 (default, Oct 30 2018, 23:45:53)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import django
>>> print django.get_version()
1.8.9
执行后重启httpd,访问cobbler的web界面,访问正常。
8、测试cobbler是否可用
由于cobbler目录需要存放大量iso,对虚拟机扩容,扩容10G
扩容磁盘
[root@dakvm ~]# qemu-img info /kvm/vfs/centos1.qcow2
image: /kvm/vfs/centos1.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 6.9G
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: true
[root@dakvm ~]# qemu-img resize /kvm/vfs/centos1.qcow2 +10G
Image resized.
查看磁盘信息,容量已增加10G
[root@dakvm ~]# qemu-img info /kvm/vfs/centos1.qcow2
image: /kvm/vfs/centos1.qcow2
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 6.9G
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: true
重启机器,kvm不像vmware可以重新扫描scsi总线立刻识别到新增的容量,不需要重启。
在下扩容lvm分区
fdisk /dev/sda 新建sda3分区
pvcreate /dev/sda3
vgextend centos /dev/sda3
lvextend -l +100%FREE /dev/mapper/centos-root
因文件系统是xfs,需要用xfs_growfs来在线扩容,若使用resize2fs会报错Bad magic number in super-block while trying to open
xfs_growfs /dev/mapper/centos-root
扩容前:
[root@centos1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 8.0G 6.1G 2.0G 76% /
扩容后:
[root@centos1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 18G 6.1G 12G 34% /
挂载网络存储并导入镜像
yum install -y samba cifs-utils
mkdir /mnt/soft/
mount -t cifs -o username=user01,password=123abc //192.168.1.189/soft /mnt/soft
mount -o loop /mnt/soft/CentOS-7-x86_64-DVD-1804.iso /mnt/iso/
cobbler import –path=/mnt/iso/ –name=CentOS-7.5 –arch=x86_64
新增cobbler system配置
cobbler system add –name=myos1 –mac=00:50:56:36:3D:06 –ip-address=192.168.1.111 –subnet=255.255.255.0 –gateway=192.168.1.1 –interface=eth0 –static=1 –profile=CentOS-7.5-x86_64 –hostname=myos1
cobbler system add –name=myos2 –mac=00:50:56:39:F2:36 –ip-address=192.168.1.112 –subnet=255.255.255.0 –gateway=192.168.1.1 –interface=eth0 –static=1 –profile=CentOS-7.5-x86_64 –hostname=myos2
=”cobbler system add –name=”&$A2&” –mac=”&$D2&” –ip-address=”&$B2&” –subnet=255.255.255.0 –gateway=192.168.1.1 –interface=eth0 –static=1 –profile=CentOS-7.5-x86_64 –hostname=”&$A2
这个放进excel可以批量生成多个system add语句,根据实际增删改。
若出现报错dracut-initqueue…/sbin/dmsquash-live-root…No space left on device
是因为虚拟机内存设置过小,请设置至少为2GB后尝试
此报错红帽官方链接:https://access.redhat.com/solutions/3293511
若出现报错dracut Warning: /dev/root does not exist
在cobbler的使用到的distros,在Kernel Options中填入以下内容:
ksdevice=bootif biosdevname=0 net.ifnames=0
或者
inst.repo=http://192.168.1.108/cblr/ks_mirror/CentOS-7.5-x86_64/
若出现报错dracut-initqueue timeout…starting timeout scripts,同样一个distro和profile,虚拟机没问题,物理机报此错误。
在cobbler的使用到的distros,在Kernel Options中填入以下内容:
inst.repo=http://192.168.1.108/cblr/ks_mirror/CentOS-7.5-x86_64/
新增kickstart文件,并关联到相应的profile
==========================================================
# This kickstart file should only be used with EL > 5 and/or Fedora > 7.
# For older versions please use the sample.ks kickstart file.
#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth –useshadow –enablemd5
# System bootloader configuration
bootloader –location=mbr
# Partition clearing information
clearpart –all –initlabel
# Use text mode install
text
# Firewall configuration
firewall –disable
# Run the Setup Agent on first boot
firstboot –disable
# System keyboard
keyboard us
# System language
lang en_US
# Use network installation
url –url=$tree
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET(‘network_config’)
# Reboot after installation
reboot
#Root password
rootpw –iscrypted $default_password_crypted
# SELinux configuration
selinux –disabled
# Do not configure the X Window System
skipx
# System timezone
timezone Asia/Shanghai –isUtc
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
autopart –type=lvm
%pre
$SNIPPET(‘log_ks_pre’)
$SNIPPET(‘kickstart_start’)
$SNIPPET(‘pre_install_network_config’)
# Enable installation monitoring
$SNIPPET(‘pre_anamon’)
%end
%packages
@core
@development
@base
zlib
zlib-devel
lrzsz
$SNIPPET(‘func_install_if_enabled’)
%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
==========================================================
启动虚拟机,自动进入系统安装
9、cobbler replicate主从同步
cobbler支持通过rsync来同步配置和镜像等一切配置,用于部署另外一台cobbler。在多网段又无法dhcp中继的情况下比较有用。
—主cobbler,IP地址192.168.1.108,检查其rsyncd服务是否启动,因同步需要用到rsyncd这个服务。
—检查/etc/rsyncd.conf配置文件是否包含以下内容
(不要手动更改,执行cobbler sync来更新,自行添加的distro目录也会出现在此配置文件):
==========================================================
# ******************************************************************
# Cobbler managed rsyncd.conf file
# Do NOT make changes to /etc/rsyncd.conf directly.
# Instead, make your changes to /etc/cobbler/rsync.template.
# ******************************************************************
[cobbler-distros]
path = /var/www/cobbler/ks_mirror
comment = All Cobbler Distros
[cobbler-repos]
path = /var/www/cobbler/repo_mirror
comment = All Cobbler Distros
[cobbler-kickstarts]
path = /var/lib/cobbler/kickstarts
comment = Cobbler Kickstarts
[cobbler-snippets]
path = /var/lib/cobbler/snippets
comment = Cobbler Snippets
[cobbler-triggers]
path = /var/lib/cobbler/triggers
comment = Cobbler Triggers
[cobbler-scripts]
path = /var/lib/cobbler/scripts
comment = Cobbler Scripts
[distro-CentOS-7.5-x86_64]
path = /var/www/cobbler/ks_mirror/CentOS-7.5-x86_64
comment = Cobbler Distro CentOS-7.5-x86_64
==========================================================
另外全新部署一台cobbler作为从服务器,IP地址192.168.1.109,并启动好cobbler等相应服务。
执行命令:cobbler replicate –master=192.168.1.108 –sync-all
同步完成后,查看从cobbler的相关配置,如distro、profile和包括ks_mirror镜像等配置都全部同步过来了。
部分输出内容如下:
==========================================================
sent 76,460 bytes received 4,297,780,845 bytes 14,743,935.87 bytes/sec
total size is 4,463,610,398 speedup is 1.04
received on stderr:
Rsyncing repos
Rsyncing distro repo configs
running: rsync -avzH 192.168.1.108::cobbler-distros/config/ /var/www/cobbler/ks_mirror/config
received on stdout: receiving incremental file list
sent 20 bytes received 80 bytes 200.00 bytes/sec
total size is 139 speedup is 1.39
received on stderr:
Rsyncing kickstart templates & snippets
running: rsync -avzH 192.168.1.108::cobbler-kickstarts /var/lib/cobbler/kickstarts
received on stdout: receiving incremental file list
./
sent 27 bytes received 46 bytes 146.00 bytes/sec
total size is 0 speedup is 0.00
received on stderr:
running: rsync -avzH 192.168.1.108::cobbler-snippets /var/lib/cobbler/snippets
received on stdout: receiving incremental file list
sent 20 bytes received 898 bytes 1,836.00 bytes/sec
total size is 89,367 speedup is 97.35
received on stderr:
Rsyncing triggers
running: rsync -avzH 192.168.1.108::cobbler-triggers /var/lib/cobbler/triggers
received on stdout: receiving incremental file list
sent 72 bytes received 1,080 bytes 2,304.00 bytes/sec
total size is 0 speedup is 0.00
received on stderr:
Rsyncing scripts
running: rsync -avzH 192.168.1.108::cobbler-scripts /var/lib/cobbler/scripts
received on stdout: receiving incremental file list
sent 20 bytes received 92 bytes 224.00 bytes/sec
total size is 415 speedup is 3.71
received on stderr:
Removing Objects Not Stored On Local
adding distro CentOS-7.5-x86_64
running python triggers from /var/lib/cobbler/triggers/add/distro/pre/*
running shell triggers from /var/lib/cobbler/triggers/add/distro/pre/*
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.5-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/CentOS-7.5-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.5-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/CentOS-7.5-x86_64/initrd.img
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.5-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/CentOS-7.5-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.5-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/CentOS-7.5-x86_64/initrd.img
processing boot_files for distro: CentOS-7.5-x86_64
trying symlink /var/www/cobbler/ks_mirror/CentOS-7.5-x86_64 -> /var/www/cobbler/links/CentOS-7.5-x86_64
Writing template files for CentOS-7.5-x86_64
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
running python triggers from /var/lib/cobbler/triggers/add/distro/post/*
running shell triggers from /var/lib/cobbler/triggers/add/distro/post/*
adding profile CentOS-7.5-x86_64
running python triggers from /var/lib/cobbler/triggers/add/profile/pre/*
running shell triggers from /var/lib/cobbler/triggers/add/profile/pre/*
Writing template files for CentOS-7.5-x86_64
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
running python triggers from /var/lib/cobbler/triggers/add/profile/post/*
running shell triggers from /var/lib/cobbler/triggers/add/profile/post/*
Updating Objects Newer On Remote
Linking Distro CentOS-7.5-x86_64
Syncing
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/CentOS-7.5-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/images/CentOS-7.5-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
copying distros to tftpboot
copying files for distro: CentOS-7.5-x86_64
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.5-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/CentOS-7.5-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.5-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/CentOS-7.5-x86_64/initrd.img
copying images
generating PXE configuration files
generating: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-36-3d-06
generating: /var/lib/tftpboot/grub/01-00-50-56-36-3D-06
generating: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-39-f2-36
generating: /var/lib/tftpboot/grub/01-00-50-56-39-F2-36
generating PXE menu structure
copying files for distro: CentOS-7.5-x86_64
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.5-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/CentOS-7.5-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.5-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/CentOS-7.5-x86_64/initrd.img
Writing template files for CentOS-7.5-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: CentOS-7.5-x86_64
cleaning link caches
rendering Rsync files
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout:
received on stderr:
running: service dhcpd restart
received on stdout:
received on stderr: Redirecting to /bin/systemctl restart dhcpd.service
running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
Done
*** TASK COMPLETE **
本文链接:https://www.kinber.cn/post/4375.html 转载需授权!
推荐本站淘宝优惠价购买喜欢的宝贝: