小記centos7.5下yum安裝cobbler遇到的問題


問題1:執行cobbler sync同步命令報錯,提示dhcpd服務錯誤和Python源碼錯誤

[root@server ~]# cobbler sync    #<===執行cobbler同步的時候,報Python源碼和dhcpd服務錯誤
task started: 2019-04-16_184408_sync
task started (id=Sync, time=Tue Apr 16 18:44:08 2019)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
copying: /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
copying: /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
cleaning link caches
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 Job for dhcpd.service failed because the control process exited with error code. See "systemctl status dhcpd.service" and "journalctl -xe" for details.

Exception occured: <class 'cobbler.cexceptions.CX'>
Exception value: 'cobbler trigger failed: cobbler.modules.sync_post_restart_services'
Exception Info:
File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 82, in run
rc = self._run(self)
File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 181, in runner
return self.remote.api.sync(self.options.get("verbose",False),logger=self.logger)
File "/usr/lib/python2.7/site-packages/cobbler/api.py", line 763, in sync
return sync.run()
File "/usr/lib/python2.7/site-packages/cobbler/action_sync.py", line 144, in run
utils.run_triggers(self.api, None, "/var/lib/cobbler/triggers/sync/post/*", logger=self.logger)
File "/usr/lib/python2.7/site-packages/cobbler/utils.py", line 928, in run_triggers
raise CX("cobbler trigger failed: %s" % m.__name__)

!!! TASK FAILED !!!

解決辦法:

1.修改 /etc/cobbler/dhcp.template,

[root@server ~]# cat /etc/dhcp/dhcpd.conf       #<===查看dhcpd服務配置文件,因hcpd服務由cobbler服務管理,所以需修改/etc/cobbler/dhcp.template此文件才生效
# ******************************************************************
# Cobbler managed dhcpd.conf file
# generated from cobbler dhcp.conf template (Tue Apr 16 10:44:09 2019)
# Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes        #<===注釋說的很明白
# in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
# overwritten.
# ******************************************************************

[root@server ~]# cat /etc/cobbler/dhcp.template          #<===修改dhcpd服務器為本機IP地址(就改動2個地方,很簡單)
# ******************************************************************
# Cobbler managed dhcpd.conf file
#
# generated from cobbler dhcp.conf template ($date)
# Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
# in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
# overwritten.
#
# ******************************************************************

ddns-update-style interim;

allow booting;
allow bootp;

ignore client-updates;
set vendorclass = option vendor-class-identifier;

option pxe-system-type code 93 = unsigned integer 16;

subnet 10.0.0.0 netmask 255.255.255.0 {                      #<===這里需改為dhcpd服務器的網段地址
option subnet-mask 255.255.255.0;
range dynamic-bootp 10.0.0.100 10.0.0.150;                   #<===這個需改為dhcp服務器地址(就這2個地方需改動,其他無需改動)
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 if option pxe-system-type = 00:09 {
filename "grub/grub-x86_64.efi";
} else {
filename "pxelinux.0";
}
}

}

#for dhcp_tag in $dhcp_tags.keys():
## group could be subnet if your dhcp tags line up with your subnets
## or really any valid dhcpd.conf construct ... if you only use the
## default dhcp tag in cobbler, the group block can be deleted for a
## flat configuration
# group for Cobbler DHCP tag: $dhcp_tag
group {
#for mac in $dhcp_tags[$dhcp_tag].keys():
#set iface = $dhcp_tags[$dhcp_tag][$mac]
host $iface.name {
#if $iface.interface_type == "infiniband":
option dhcp-client-identifier = $mac;
#else
hardware ethernet $mac;
#end if
#if $iface.ip_address:
fixed-address $iface.ip_address;
#end if
#if $iface.hostname:
option host-name "$iface.hostname";
#end if
#if $iface.netmask:
option subnet-mask $iface.netmask;
#end if
#if $iface.gateway:
option routers $iface.gateway;
#end if
#if $iface.enable_gpxe:
if exists user-class and option user-class = "gPXE" {
filename "http://$cobbler_server/cblr/svc/op/gpxe/system/$iface.owner";
} else if exists user-class and option user-class = "iPXE" {
filename "http://$cobbler_server/cblr/svc/op/gpxe/system/$iface.owner";
} else {
filename "undionly.kpxe";
}
#else
filename "$iface.filename";
#end if
## Cobbler defaults to $next_server, but some users
## may like to use $iface.system.server for proxied setups
next-server $next_server;
## next-server $iface.next_server;
}
#end for
}
#end for 

接着,修改yum安裝cobbler的Python源碼(cobbler在centos7上yum安裝的話,會有問題)

[root@server tmp]# mkdir ~/123
[root@server modules]# cd /usr/lib/python2.7/site-packages/cobbler/modules/
[root@server modules]# cp sync_post_restart_services.py ~/123/
[root@server modules]# mv sync_post_restart_services.py sync_post_restart_services.py.original        #<===操作前先備份
[root@server modules]# mv sync_post_restart_services.pyo sync_post_restart_services.pyo.original
[root@server modules]# mv sync_post_restart_services.pyc sync_post_restart_services.pyc.original
[root@server modules]# cd ~/123
[root@server 123]# vi sync_post_restart_services.py           #<===此步驟主要修改Python源碼,更改dhcpd由systemd管理
import cobbler.module_loader as module_loader
import cobbler.utils as utils

def register():
# this pure python trigger acts as if it were a legacy shell-trigger, but is much faster.
# the return of this method indicates the trigger type
return "/var/lib/cobbler/triggers/sync/post/*"

def run(api,args,logger):

settings = api.settings()

manage_dhcp = str(settings.manage_dhcp).lower()
manage_dns = str(settings.manage_dns).lower()
restart_dhcp = str(settings.restart_dhcp).lower()
restart_dns = str(settings.restart_dns).lower()

which_dhcp_module = module_loader.get_module_from_file("dhcp","module",just_name=True).strip()
which_dns_module = module_loader.get_module_from_file("dns","module",just_name=True).strip()

# special handling as we don't want to restart it twice
has_restarted_dnsmasq = False

rc = 0
if manage_dhcp != "0":
if which_dhcp_module == "manage_isc":
if restart_dhcp != "0":
rc = utils.subprocess_call(logger, "dhcpd -t -q", shell=True)
if rc != 0:
logger.error("dhcpd -t failed")
return 1
dhcp_service_name = utils.dhcp_service_name(api)         #<===主要修改下面2個地方,修改dhcpd由systemd管理
dhcp_restart_command = "/usr/bin/systemctl restart %s" % dhcp_service_name
rc = utils.subprocess_call(logger, "/bin/systemctl restart dhcpd", shell=True)
elif which_dhcp_module == "manage_dnsmasq":
if restart_dhcp != "0":
rc = utils.subprocess_call(logger, "service dnsmasq restart")
has_restarted_dnsmasq = True
else:
logger.error("unknown DHCP engine: %s" % which_dhcp_module)
rc = 411

if manage_dns != "0" and restart_dns != "0":
if which_dns_module == "manage_bind":
named_service_name = utils.named_service_name(api)
dns_restart_command = "service %s restart" % named_service_name
rc = utils.subprocess_call(logger, dns_restart_command, shell=True)
elif which_dns_module == "manage_dnsmasq" and not has_restarted_dnsmasq:
rc = utils.subprocess_call(logger, "service dnsmasq restart", shell=True)
elif which_dns_module == "manage_dnsmasq" and has_restarted_dnsmasq:
rc = 0
else:
logger.error("unknown DNS engine: %s" % which_dns_module)
rc = 412

return rc
[root@server 123]# python -m compileall *             #<===重新編譯文件
Compiling sync_post_restart_services.py ...
[root@server 123]# python -O -m compileall * 
Compiling sync_post_restart_services.py ...
[root@server 123]# ls
sync_post_restart_services.py sync_post_restart_services.pyc sync_post_restart_services.pyo
[root@server 123]# cd /usr/lib/python2.7/site-packages/cobbler/modules/
[root@server modules]# \cp ~/123/* ./                   #<===將重新編譯的文件拷貝覆蓋掉原來的

修改完成后,重啟所有服務

[root@server ~]# systemctl restart httpd.service 
[root@server ~]# systemctl restart dhcpd.service 
[root@server ~]# systemctl restart rsyncd.service 
[root@server ~]# systemctl restart tftp.socket
[root@server ~]# systemctl restart cobblerd.service 
重新執行cobbler sync同步命令,發現已經正常
[root@server ~]# cobbler sync
task started: 2019-04-16_143521_sync
task started (id=Sync, time=Tue Apr 16 14:35:21 2019)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
copying: /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
copying: /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
cleaning link caches
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: /bin/systemctl restart dhcpd
received on stdout: 
received on stderr: 
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/*
*** TASK COMPLETE ***                  #<===現在已經正常
問題2:打開網頁 https://10.0.0.6/cobbler_web,顯示500錯誤(注意:centos7.x以上,cobbler只支持https方式訪問)
解決辦法:
首先查看以下路徑日志,然后按照下面方法解決
[root@server ~]# cat /var/log/httpd/error_log  
[root@server ~]# cat /var/log/cobbler/cobbler.log      
[root@server ~]# rpm -qa | grep "python2-django" python2-django-1.11.13-4.el7.noarch 
這個包是1.11,只要這個包在1.8以上,就有問題 TEMPLATE_CONTEXT_PROCESSORS was deprecated in Django 1.8 and removed in Django 1.10. It's not possible to import it anymore. 然后執行以下命令
[root@server ~]# rpm -e --nodeps python2-django 
[root@server ~]# yum -y install python2-pip          #<===安裝pip軟件
[root@server ~]# pip install --upgrade pip 
[root@server ~]# pip install Django==1.8.17          #<===將此軟件包改為1.8.17版本
重啟cobblerd服務,輸入網址 https://10.0.0.6/cobbler_web(賬號和密碼都是cobbler),已經能夠正常訪問了
[root@server ~]# systemctl restart cobblerd.service 


Google參考幫助 https://bugzilla.redhat.com/show_bug.cgi?id=709151


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM