cobbler自动化安装Linux系统
cobbler簡介
Cobbler是一個Linux服務器快速網絡安裝的服務,而且在經過調整也可以支持網絡安裝windows。該工具使用python開發,小巧輕便(才15k行python代碼),可以通過網絡啟動(PXE)的方式來快速安裝、重裝物理服務器和虛擬機,同時還可以管理DHCP,DNS,TFTP、RSYNC以及yum倉庫、構造系統ISO鏡像。
Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),還提供了API接口,可以方便二次開發使用。
Cobbler是kickstart的升級版,優點是比較容易配置,還自帶web界面比較易于管理。
Cobbler客戶端Koan支持虛擬機安裝和操作系統重新安裝,使重裝系統更便捷。
cobbler安裝部署
操作系統:CentOS release 7.1
防火墻、Selinux關閉
安裝eple源
# yum -y install epel-release安裝cobbler所需要的軟件包
# yum -y install cobbler cobbler-web pykickstart httpd dhcp tftp-server啟動服務
# /etc/init.d/httpd start # /etc/init.d/cobblerd start初次啟動httpd會有報錯
Starting httpd: httpd: apr_sockaddr_info_get() failed for Template httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName #遇見報錯需要修改apache的配置文件,添加一行 # vim /etc/httpd/conf/httpd.conf ServerName localhost:80啟動服務后,使用cobbler check檢查配置文件查看是否有問題,一般第一次啟動的時候會有報錯,不過不用管,重啟cobbler后就會正常
# cobbler check Traceback (most recent call last):File "/usr/bin/cobbler", line 36, in <module>sys.exit(app.main())File "/usr/lib/python2.6/site-packages/cobbler/cli.py", line 657, in mainrc = cli.run(sys.argv)File "/usr/lib/python2.6/site-packages/cobbler/cli.py", line 270, in runself.token = self.remote.login("", self.shared_secret)File "/usr/lib64/python2.6/xmlrpclib.py", line 1199, in __call__return self.__send(self.__name, args)File "/usr/lib64/python2.6/xmlrpclib.py", line 1489, in __requestverbose=self.__verboseFile "/usr/lib64/python2.6/xmlrpclib.py", line 1253, in requestreturn self._parse_response(h.getfile(), sock)File "/usr/lib64/python2.6/xmlrpclib.py", line 1392, in _parse_responsereturn u.close()File "/usr/lib64/python2.6/xmlrpclib.py", line 838, in closeraise Fault(**self._stack[0]) xmlrpclib.Fault: <Fault 1: "<class 'cobbler.cexceptions.CX'>:'login failed'">再次運行cobbler check檢查配置文件,會出現如下錯誤,檢查的時候一定要要在httpd與cobbler都啟動的情況下檢查
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 themRestart cobblerd and then run 'cobbler sync' to apply changes.上述問題解答方法如下:
1.需要修改/etc/cobbler/setting配置文件,將server行的IP改為本機IP# sed -i 's#server: 127.0.0.0#server: 本機IP#g' /etc/cobbler/settings
2.需要修改/etc/cobbler/setting配置文件,將server_next行的IP改為本機IP
# sed -i 's#next_server: 127.0.0.1#next_server: 本機IP#g' /etc/cobbler/settings
3.修改/etc/xinetd.d/tftp配置文件,將disable = yes改為no
# sed -i 's#disable.* ?= yes#disable ? ? ? ? ? ? ? ? = no #g' /etc/xinetd.d/tftp
4.運行cobbler get-loaders命令就行
5.修改/etc/xinetd.d/rsync配置文件,將disable = yes改為no
# sed -i 's#disable.*= yes# disable = no#g' /etc/xinetd.d/rsync
6.
7.安裝debmirror包,如果不安裝debian系統可以忽略
# yum install -y debmirror
8.使用openssl設置一個新的密碼來代替默認密碼
# openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'"
9.安裝cman?fence-agents
# yum install -y cman fence-agents
?再次檢測配置文件,會有關于debian的報錯。注釋配置文件就行
注釋如下兩行 # vim /etc/debmirro.conf #@dists="sid"; #@arches="i386";然后執行cobbler sync,同步更改后的配置文件
# cobbler synccobbler可以管理dhcp,tftp,rsync服務
# vim /etc/cobbler/setting manage_dhcp = 1 manage_tftp = 1 manage_rsync = 1cobbler管理dhcp后,只需修改cobbler提供的dhcp模板就行,不需要單獨的修改dhcp服務的配置文件
subnet 10.0.0.0 netmask 255.255.255.0 { #本機電腦所在的子網option routers 10.0.0.2; #設置客戶端默認網關option domain-name-servers 10.0.0.2; #設置客戶端默認DNSoption subnet-mask 255.255.255.0;range dynamic-bootp 10.0.0.100 10.0.0.254; #客戶端獲取到的地址范圍default-lease-time 21600;max-lease-time 43200;next-server $next_server;注意:每次修改完cobbler配置信息的時候一定要使用check sync同步配置文件。
給cobbler服務器導入鏡像
掛載鏡像
將有鏡像的分區掛載到服務上 # mount /dev/cdrom /mnt導入鏡像
# cobbler import --path=/mnt --name=CentOS-6.7-x86_64 --arch=x86_64 # --path 鏡像路徑 # --name 為安裝源定義一個名字 # --arch 指定安裝源是32位、64位、ia64, 目前支持的選項有: x86│x86_64│ia64 # 安裝源的唯一標示就是根據name參數來定義,本例導入成功后,安裝源的唯一標示就是:CentOS-6.6-x86_64,如果重復,系統會提示導入失敗。查看鏡像
# ll /var/www/cobbler/ks_mirror/# cobbler distro list
配置ks配置文件
# more CentOS-6.7-x86_64.ks #Install OS install #Install type text#Use network installation url --url=http://10.0.0.222/cobbler/links/CentOS-6.7-x86_64/ #System authorization information auth --useshadow --enablemd5 #Root password rootpw 123456 rootpw --iscrypted $1$123456$wOSEtcyiP2N/IfIl15W6Z0#System bootloader bootloader --location=mbr#Clear the Master Boot Record zerombr#Run the Setup Agent firs boot firstboot --disable#System Keyboard keyboard us#System Language lang en_US#System Timezone timezone --isUtc Asia/Shanghai#Installation logging level logging --level=info#Firewall configuration firewall --disable#Selinux configuration selinux --disable#Disk partition information part /boot --bytes-per-inode=4096 --fstype="ext4" --size=200 part / --asprimary --bytes-per-inode=4096 --fstype="ext4" --size=10240reboot#This packages is for CentOS6.7 %packages @base @core @compat-libraries @debugging @development @hardware-monitoring @performance @perl-runtime @large-systems lrzsz tree telnet nmap %end配置完成后需要cobbler sync
然后啟動一臺新的機器就可以使用cobbler安裝系統了。
cobbler重裝
由于我是選擇安裝7的操作系統,現在由于我對centos7的操作系統不熟悉,想要重裝為6的操作系統,該如何做呢?
安裝koan
# yum install -y koan查看cobbler可用的鏡像
# koan --server=10.0.0.222 --list=profiles - looking for Cobbler at http://10.0.0.222:80/cobbler_api CentOS-6.7-x86_64在已經的客戶端進行重裝系統操作 ,這個操作一定要在客戶端操作
# koan --replace-self --server=10.0.0.222 --profile=CentOS-6.7-x86_64Cobbler使用python調用API
#!/usr/bin/python import xmlrpclib server = xmlrpclib.Server("http://xx.xx.xx.xx/cobbler_api") print server.get_distros() print server.get_profiles() print server.get_systems() print server.get_images() print server.get_repos()#!/usr/bin/env python # -*- coding: utf-8 -*- import xmlrpclib class CobblerAPI(object):def __init__(self,url,user,password):self.cobbler_user= userself.cobbler_pass = passwordself.cobbler_url = urldef add_system(self,hostname,ip_add,mac_add,profile):''' Add Cobbler System Infomation''' ret = {"result": True,"comment": [],}#get tokenremote = xmlrpclib.Server(self.cobbler_url) token = remote.login(self.cobbler_user,self.cobbler_pass) #add systemsystem_id = remote.new_system(token) remote.modify_system(system_id,"name",hostname,token) remote.modify_system(system_id,"hostname",hostname,token) remote.modify_system(system_id,'modify_interface', { "macaddress-eth0" : mac_add, "ipaddress-eth0" : ip_add, "dnsname-eth0" : hostname, }, token) remote.modify_system(system_id,"profile",profile,token) remote.save_system(system_id, token) try:remote.sync(token)except Exception as e:ret['result'] = Falseret['comment'].append(str(e))return ret def main():cobbler = CobblerAPI("http://xx.xx.xx.xx/cobbler_api","cobbler","cobbler")ret = cobbler.add_system(hostname='cobbler-api-test',ip_add='xx.xx.xx.xx',mac_add='xx:xx:xx:xx:xx:xx',profile='CentOS-7-x86_64')print ret if __name__ == '__main__':main()?添加repo
# cobbler repo add --name=xxoo --mirror=http://xxoo同步repo
# cobbler reposync添加repo到對應的profile
# cobbler profile --name=xxoo --repos=xxoo修改kickstart文件,添加(寫到%post %end中間)
%postsystemctl disable postfix.service$yum_config_stanza%end添加定時任務,定期同步repo
# echo "1 3 * * * /usr/bin/cobbler reposync --tries=3 --no-fail" >>/va/spool/cron/root?
轉載于:https://www.cnblogs.com/ebay/p/7443299.html
總結
以上是生活随笔為你收集整理的cobbler自动化安装Linux系统的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 面向面试编程?
- 下一篇: Beanutils-No origin