環(huán)境準(zhǔn)備
[root@oldboy ~]# cat /etc/redhat-release
CentOS release 6.9 (Final)
[root@oldboy ~]# uname -r
2.6.32-696.el6.x86_64
[root@oldboy ~]# getenforce
Disabled
[root@oldboy ~]# /etc/init.d/iptables status
iptables: Firewall is not running.
[root@oldboy ~]# ifconfig eth0|awk -F "[ :]+" 'NR==2 {print $4}'
10.0.0.100
[root@oldboy ~]# hostname
oldboy
[root@oldboy ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
創(chuàng)新互聯(lián)是一家專(zhuān)業(yè)提供沙縣企業(yè)網(wǎng)站建設(shè),專(zhuān)注與成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、H5頁(yè)面制作、小程序制作等業(yè)務(wù)。10年已為沙縣眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專(zhuān)業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進(jìn)行中。
1安裝EPEL源
yum install epel-release -y
2安裝cobbler
yum install cobbler httpd rsync tftp-server xinetd dhcp python-ctypes cman pykickstart –y
3、rpm -ql cobbler # 查看安裝的文件,下面列出部分。
/etc/cobbler # 配置文件目錄
/etc/cobbler/settings # cobbler主配置文件,這個(gè)文件是YAML格式,Cobbler是python寫(xiě)的程序。
/etc/cobbler/dhcp.template # DHCP服務(wù)的配置模板
/etc/cobbler/tftpd.template # tftp服務(wù)的配置模板
/etc/cobbler/rsync.template # rsync服務(wù)的配置模板
/etc/cobbler/iso # iso模板配置文件目錄
/etc/cobbler/pxe # pxe模板文件目錄
/etc/cobbler/power # 電源的配置文件目錄
/etc/cobbler/users.conf # Web服務(wù)授權(quán)配置文件
/etc/cobbler/users.digest # 用于web訪(fǎng)問(wèn)的用戶(hù)名密碼配置文件
/etc/cobbler/DNSmasq.template # DNS服務(wù)的配置模板
/etc/cobbler/modules.conf # Cobbler模塊配置文件
/var/lib/cobbler # Cobbler數(shù)據(jù)目錄
/var/lib/cobbler/config # 配置文件
/var/lib/cobbler/kickstarts#默認(rèn)存放kickstart文件
/var/lib/cobbler/loaders # 存放的各種引導(dǎo)程序
/var/www/cobbler # 系統(tǒng)安裝鏡像目錄
/var/www/cobbler/ks_mirror # 導(dǎo)入的系統(tǒng)鏡像列表
/var/www/cobbler/images # 導(dǎo)入的系統(tǒng)鏡像啟動(dòng)文件
/var/www/cobbler/repo_mirror # yum源存儲(chǔ)目錄
/var/log/cobbler # 日志目錄
/var/log/cobbler/install.log # 客戶(hù)端系統(tǒng)安裝日志
/var/log/cobbler/cobbler.log # cobbler日志
1. [root@linux-node1 ~]# /etc/init.d/httpd restart
2. 停止 httpd: [失敗]
3. 正在啟動(dòng) httpd: [確定]
4. [root@linux-node1 ~]# /etc/init.d/cobblerd start
5. Starting cobbler daemon: [確定]
6. [root@linux-node1 ~]# cobbler check # 檢查Cobbler的配置,如果看不到下面的結(jié)果,再次執(zhí)行/etc/init.d/cobblerd restart
7. The following are potential configuration items that you may want to fix:
8.
9. 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.
10. 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.
11. 3 : 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.
12. 4 : change 'disable' to 'no' in /etc/xinetd.d/rsync
13. 5 : debmirror package is not installed, it will be required to manage debian deployments and repositories
14. 6 : 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
15. 7 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
16.
17. Restart cobblerd and then run 'cobbler sync' to apply changes.
18.
19. # 看著上面的結(jié)果,一個(gè)一個(gè)解決。
20. # 第1、2、6個(gè)問(wèn)題,順便修改其他功能
21. [root@linux-node1 ~]# cp /etc/cobbler/settings{,.ori} # 備份
22.
23. # server,Cobbler服務(wù)器的IP。
24. sed -i 's/server: 127.0.0.1/server: 10.0.0.7/' /etc/cobbler/settings
25.
26. # next_server,如果用Cobbler管理DHCP,修改本項(xiàng),作用不解釋?zhuān)磌ickstart。
27. sed -i 's/next_server: 127.0.0.1/next_server: 10.0.0.7/' /etc/cobbler/settings
28.
29. # 用Cobbler管理DHCP
30. sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings
31.
32. # 防止循環(huán)裝系統(tǒng),適用于服務(wù)器第一啟動(dòng)項(xiàng)是PXE啟動(dòng)。
33. sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings
34.
35. # 設(shè)置新裝系統(tǒng)的默認(rèn)root密碼123456。下面的命令來(lái)源于提示6。random-phrase-here為干擾碼,可以自行設(shè)定。
36. [root@linux-node1 ~]# openssl passwd -1 -salt 'oldboy' '123456'
37. $1$oldboy$Npg9Pt9k98Mlg0ZeqHAuN1
38. [root@linux-node1 ~]# vim /etc/cobbler/settings
39. default_password_crypted: "$1$oldboy$Npg9Pt9k98Mlg0ZeqHAuN1"
40.
41. # 第3個(gè)問(wèn)題
42. [root@linux-node1 ~]# cobbler get-loaders # 會(huì)自動(dòng)從官網(wǎng)下載
43. [root@linux-node1 ~]# cd /var/lib/cobbler/loaders/ # 下載的內(nèi)容
44. [root@linux-node1 loaders]# ls
45. COPYING.elilo COPYING.yaboot grub-x86_64.efi menu.c32 README
46. COPYING.syslinux elilo-ia64.efi grub-x86.efi pxelinux.0 yaboot
47.
48. # 第4個(gè)問(wèn)題
49. [root@linux-node1 ~]# vim /etc/xinetd.d/rsync
50. disable = no
51. [root@linux-node1 ~]# /etc/init.d/xinetd restart
52. 停止 xinetd: [確定]
53. 正在啟動(dòng) xinetd: [確定]
54.
55. [root@linux-node1 ~]# /etc/init.d/cobblerd restart
56. Stopping cobbler daemon: [確定]
57. Starting cobbler daemon: [確定]
58. [root@linux-node1 ~]# cobbler check
59. The following are potential configuration items that you may want to fix:
60.
61. 1 : debmirror package is not installed, it will be required to manage debian deployments and repositories # 和debian系統(tǒng)相關(guān),不需要
62. 2 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them # fence設(shè)備相關(guān),不需要
63. Restart cobblerd and then run 'cobbler sync' to apply changes.
1. 配置DHCP
1. # 修改cobbler的dhcp模版,不要直接修改dhcp本身的配置文件,因?yàn)閏obbler會(huì)覆蓋。
2.
3. [root@linux-node1 ~]# vim /etc/cobbler/dhcp.template
4. # 僅列出修改過(guò)的字段
5. ……
6. subnet 10.0.0.0 netmask 255.255.255.0 {
7. option routers 10.0.0.2;
8. option domain-name-servers 10.0.0.2;
9. option subnet-mask 255.255.255.0;
10. range dynamic-bootp 10.0.0.100 10.0.0.200;
11. ……
5、同步cobbler配置
1. # 同步最新cobbler配置,它會(huì)根據(jù)配置自動(dòng)修改dhcp等服務(wù)。
2. [root@linux-node1 ~]# cobbler sync # 同步所有配置,可以仔細(xì)看一下sync做了什么。
3. task started: 2015-12-03_204822_sync
4. task started (id=Sync, time=Thu Dec 3 20:48:22 2015)
5. running pre-sync triggers
6. cleaning trees
7. removing: /var/lib/tftpboot/pxelinux.cfg/default
8. removing: /var/lib/tftpboot/grub/images
9. copying bootloaders
10. trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
11. copying: /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
12. trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
13. trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
14. trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
15. trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
16. trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
17. copying distros to tftpboot
18. copying images
19. generating PXE configuration files
20. generating PXE menu structure
21. rendering DHCP files
22. generating /etc/dhcp/dhcpd.conf
23. rendering TFTPD files
24. generating /etc/xinetd.d/tftp
25. cleaning link caches
26. running post-sync triggers
27. running python triggers from /var/lib/cobbler/triggers/sync/post/*
28. running python trigger cobbler.modules.sync_post_restart_services
29. running: dhcpd -t -q
30. received on stdout:
31. received on stderr:
32. running: service dhcpd restart
33. received on stdout: 關(guān)閉 dhcpd:[確定]
34. 正在啟動(dòng) dhcpd:[確定]
35.
36. received on stderr:
37. running shell triggers from /var/lib/cobbler/triggers/sync/post/*
38. running python triggers from /var/lib/cobbler/triggers/change/*
39. running python trigger cobbler.modules.scm_track
40. running shell triggers from /var/lib/cobbler/triggers/change/*
41. *** TASK COMPLETE ***
42.
43. # 再看一下dhcp的配置文件。
44. [root@linux-node1 ~]# less /etc/dhcp/dhcpd.conf
45. # ******************************************************************
46. # Cobbler managed dhcpd.conf file
47. # generated from cobbler dhcp.conf template (Thu Dec 3 12:48:23 2015)
48. # Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
49. # in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
50. # overwritten.
51. # ******************************************************************
52.
53. ddns-update-style interim;
54. …………
6、開(kāi)機(jī)啟動(dòng)
1. # 啟動(dòng)相關(guān)服務(wù)并設(shè)置開(kāi)機(jī)啟動(dòng)(可選) 與第二種方法二選一
2. chkconfig httpd on
3. chkconfig xinetd on
4. chkconfig cobblerd on
5. chkconfig dhcpd on
6. /etc/init.d/httpd restart
7. /etc/init.d/xinetd restart
8. /etc/init.d/cobblerd restart
9. /etc/init.d/dhcpd restart
1. 編寫(xiě)Cobbler相關(guān)服務(wù)啟動(dòng)腳本(可選)
2. cat >>/etc/init.d/cobbler<
7、Cobbler的命令行管理導(dǎo)入鏡像
1. [root@linux-node1 ~]# cobbler
2. usage
3. =====
4. cobbler ...
5. [add|edit|copy|getks*|list|remove|rename|report] [options|--help]
6. cobbler [options|--help]
7. [root@linux-node1 ~]# cobbler import --help # 導(dǎo)入鏡像
8. Usage: cobbler [options]
9.
10. Options:
11. -h, --help show this help message and exit
12. --arch=ARCH OS architecture being imported
13. --breed=BREED the breed being imported
14. --os-version=OS_VERSION
15. the version being imported
16. --path=PATH local path or rsync location
17. --name=NAME name, ex 'RHEL-5'
18. --available-as=AVAILABLE_AS
19. tree is here, don't mirror
20. --kickstart=KICKSTART_FILE
21. assign this kickstart file
22. --rsync-flags=RSYNC_FLAGS
23. pass additional flags to rsync
24.
25. cobbler check 核對(duì)當(dāng)前設(shè)置是否有問(wèn)題
26. cobbler list 列出所有的cobbler元素
27. cobbler report 列出元素的詳細(xì)信息
28. cobbler sync 同步配置到數(shù)據(jù)目錄,更改配置最好都要執(zhí)行下
29. cobbler reposync 同步y(tǒng)um倉(cāng)庫(kù)
30. cobbler distro 查看導(dǎo)入的發(fā)行版系統(tǒng)信息
31. cobbler system 查看添加的系統(tǒng)信息
32. cobbler profile 查看配置信息
1. 導(dǎo)入鏡像
1. [root@linux-node1 ~]# mount /dev/cdrom /mnt/ # 掛載CentOS7的系統(tǒng)鏡像。
2. # 導(dǎo)入系統(tǒng)鏡像
3. [root@linux-node1 ~]# cobbler import --path=/mnt/ --name=CentOS-7.1-x86_64 --arch=x86_64
4. # --path 鏡像路徑
5. # --name 為安裝源定義一個(gè)名字
6. # --arch 指定安裝源是32位、64位、ia64, 目前支持的選項(xiàng)有: x86│x86_64│ia64
7. # 安裝源的唯一標(biāo)示就是根據(jù)name參數(shù)來(lái)定義,本例導(dǎo)入成功后,安裝源的唯一標(biāo)示就是:CentOS-7.1-x86_64,如果重復(fù),系統(tǒng)會(huì)提示導(dǎo)入失敗。
8.
9. [root@linux-node1 ~]# cobbler distro list # 查看鏡像列表
10. CentOS-7.1-x86_64
11.
12. # 鏡像存放目錄,cobbler會(huì)將鏡像中的所有安裝文件拷貝到本地一份,放在/var/www/cobbler/ks_mirror下的CentOS-7.1-x86_64目錄下。因此/var/www/cobbler目錄必須具有足夠容納安裝文件的空間。
13. [root@linux-node1 ~]# cd /var/www/cobbler/ks_mirror/
14. [root@linux-node1 ks_mirror]# ls
15. CentOS-7.1-x86_64 config
16. [root@linux-node1 ks_mirror]# ls CentOS-7.1-x86_64/
17. CentOS_BuildTag GPL LiveOS RPM-GPG-KEY-CentOS-7
18. EFI images Packages RPM-GPG-KEY-CentOS-Testing-7
19. EULA isolinux repodata TRANS.TBL
1. 指定ks.cfg文件及調(diào)整內(nèi)核參數(shù)
查看默認(rèn)配置
1. # Cobbler的ks.cfg文件存放位置
2. [root@linux-node1 ks_mirror]# cd /var/lib/cobbler/kickstarts/
3. [root@linux-node1 kickstarts]# ls # 自帶很多
4. default.ks install_profiles sample_autoyast.xml sample_esxi4.ks sample_old.seed
5. esxi4-ks.cfg legacy.ks sample_end.ks(默認(rèn)使用的ks文件) sample_esxi5.ks sample.seed
6. esxi5-ks.cfg pxerescue.ks sample_esx4.ks sample.ks
上傳自定義的ks文件
1. [root@linux-node1 kickstarts]# rz # 上傳準(zhǔn)備好的ks文件
2. rz waiting to receive.
3. Starting zmodem transfer. Press Ctrl+C to cancel.
4. Transferring Cobbler-CentOS-7.1-x86_64.cfg...
5. 100% 1 KB 1 KB/sec 00:00:01 0 Errors
6.
7. [root@linux-node1 kickstarts]# mv Cobbler-CentOS-7.1-x86_64.cfg CentOS-7.1-x86_64.cfg
8.
9. # 在第一次導(dǎo)入系統(tǒng)鏡像后,Cobbler會(huì)給鏡像指定一個(gè)默認(rèn)的kickstart自動(dòng)安裝文件在/var/lib/cobbler/kickstarts下的sample_end.ks。
查看導(dǎo)入鏡像設(shè)置及同步
1. [root@linux-node1 ~]# cobbler list
2. distros:
3. CentOS-7.1-x86_64
4.
5. profiles:
6. CentOS-7.1-x86_64
7.
8. systems:
9.
10. repos:
11.
12. images:
13.
14. mgmtclasses:
15.
16. packages:
17.
18. files:
19.
20. # 查看安裝鏡像文件信息
21. [root@linux-node1 ~]# cobbler distro report --name=CentOS-7.1-x86_64
22. Name : CentOS-7.1-x86_64
23. Architecture : x86_64
24. TFTP Boot Files : {}
25. Breed : redhat
26. Comment :
27. Fetchable Files : {}
28. Initrd : /var/www/cobbler/ks_mirror/CentOS-7.1-x86_64/images/pxeboot/initrd.img
29. Kernel : /var/www/cobbler/ks_mirror/CentOS-7.1-x86_64/images/pxeboot/vmlinuz
30. Kernel Options : {}
31. Kernel Options (Post Install) : {}
32. Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/CentOS-7.1-x86_64'}
33. Management Classes : []
34. OS Version : rhel7
35. Owners : ['admin']
36. Red Hat Management Key : <>
37. Red Hat Management Server : <>
38. Template Files : {}
39.
40. # 查看所有的profile設(shè)置
41. [root@linux-node1 ~]# cobbler profile report
42.
43. # 查看指定的profile設(shè)置
44. [root@linux-node1 ~]# cobbler profile report --name=CentOS-7.1-x86_64
45. Name : CentOS-7.1-x86_64
46. TFTP Boot Files : {}
47. Comment :
48. DHCP Tag : default
49. Distribution : CentOS-7.1-x86_64
50. Enable gPXE? : 0
51. Enable PXE Menu? : 1
52. Fetchable Files : {}
53. Kernel Options : {}
54. Kernel Options (Post Install) : {}
55. Kickstart : /var/lib/cobbler/kickstarts/sample_end.ks -->默認(rèn)ks文件
56. Kickstart Metadata : {}
57. Management Classes : []
58. Management Parameters : <>
59. Name Servers : []
60. Name Servers Search Path : []
61. Owners : ['admin']
62. Parent Profile :
63. Internal proxy :
64. Red Hat Management Key : <>
65. Red Hat Management Server : <>
66. Repos : []
67. Server Override : <>
68. Template Files : {}
69. Virt Auto Boot : 1
70. Virt Bridge : xenbr0
71. Virt CPUs : 1
72. Virt Disk Driver Type : raw
73. Virt File Size(GB) : 5
74. Virt Path :
75. Virt RAM (MB) : 512
76. Virt Type : kvm
77.
78. # 編輯profile,修改關(guān)聯(lián)的ks文件
79. [root@linux-node1 ~]# cobbler profile edit --name=CentOS-7.1-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.1-x86_64.cfg
80.
81. # 修改安裝系統(tǒng)的內(nèi)核參數(shù),在CentOS7系統(tǒng)有一個(gè)地方變了,就是網(wǎng)卡名變成eno16777736這種形式,但是為了運(yùn)維標(biāo)準(zhǔn)化,我們需要將它變成我們常用的eth0,因此使用下面的參數(shù)。但要注意是CentOS7才需要下面的步驟,CentOS6不需要。
82. [root@linux-node1 ~]# cobbler profile edit --name=CentOS-7.1-x86_64 --kopts='net.ifnames=0 biosdevname=0'
83.
84. [root@linux-node1 ~]# cobbler profile report CentOS-7.1-x86_64
85. Name : CentOS-7.1-x86_64
86. TFTP Boot Files : {}
87. Comment :
88. DHCP Tag : default
89. Distribution : CentOS-7.1-x86_64
90. Enable gPXE? : 0
91. Enable PXE Menu? : 1
92. Fetchable Files : {}
93. Kernel Options : {'biosdevname': '0', 'net.ifnames': '0'}
94. Kernel Options (Post Install) : {}
95. Kickstart : /var/lib/cobbler/kickstarts/CentOS-7.1-x86_64.cfg
96. Kickstart Metadata : {}
97. Management Classes : []
98. Management Parameters : <>
99. Name Servers : []
100. Name Servers Search Path : []
101. Owners : ['admin']
102. Parent Profile :
103. Internal proxy :
104. Red Hat Management Key : <>
105. Red Hat Management Server : <>
106. Repos : []
107. Server Override : <>
108. Template Files : {}
109. Virt Auto Boot : 1
110. Virt Bridge : xenbr0
111. Virt CPUs : 1
112. Virt Disk Driver Type : raw
113. Virt File Size(GB) : 5
114. Virt Path :
115. Virt RAM (MB) : 512
116. Virt Type : kvm
117.
118. # 每次修改完都要同步一次
119. [root@linux-node1 ~]# cobbler sync
新建一臺(tái)虛擬機(jī),不解釋?zhuān)_(kāi)機(jī)就可以看到下面的圖片
[root@linux-node1 ~]# cobbler sync # 修改配置都要同步
拓展
ks.cfg文件解析
定制化安裝
指定某臺(tái)服務(wù)器使用指定ks文件
分一臺(tái)服務(wù)器的最簡(jiǎn)單的方法就是物理MAC地址。
物理服務(wù)器的MAC地址在服務(wù)器上的標(biāo)簽上寫(xiě)了。
虛擬機(jī)的MAC查看
[root@linux-node1 ~]# cobbler sync
下次在開(kāi)機(jī)或重啟就會(huì)自動(dòng)安裝了
Cobbler的Web管理界面的安裝與配置
已經(jīng)安裝cobbler-web軟件的環(huán)境下。
訪(fǎng)問(wèn)網(wǎng)址:http://10.0.0.100/cobbler_web和https://10.0.0.100/cobbler_web
默認(rèn)用戶(hù)名:cobbler
默認(rèn)密碼 :cobbler
溫馨提示:安裝的系統(tǒng)內(nèi)存要2G以上哦