cobbler是一個能夠實現批量安裝系統的Linux應用程序。它有別於pxe+kickstart,cobbler能夠實現同個服務器批量安裝不一樣操做系統版本。python
開啓兩個網卡。一個僅主機模式,一個橋接模式,主機模式對內提供cobbler服務。linux
[root@ken ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:13:a1:49 brd ff:ff:ff:ff:ff:ff inet 192.168.4.190/24 brd 192.168.4.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe13:a149/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:13:a1:53 brd ff:ff:ff:ff:ff:ff inet 192.168.182.128/24 brd 192.168.182.255 scope global noprefixroute dynamic eth1 valid_lft 1786sec preferred_lft 1786sec inet6 fe80::7073:2021:e866:204f/64 scope link noprefixroute valid_lft forever preferred_lft forever
系統版本:CentOS Linux release 7.5.1804 (Core) redis
內網IP:192.168.182.128/24 #用來對內通訊,提供cobbler服務shell
外網IP:192.168.4.190/24 #鏈接外網vim
[root@ken ~]# systemctl stop firewalld #關閉防火牆 [root@ken ~]# setenforce 0 #關閉selinux
[root@ken ~]# yum install cobbler dhcp tftp-server xinetd syslinux httpd -y
syslinux: 提供pxelinux.0這個文件 ,pxelinux.0引導文件引導vmlinux和initrd兩個啓動文件centos
yum安裝cobbler須要使用下面兩個源,你們能夠複製下面的代碼到本身的yum倉庫保存便可安全
[epel]
name=epel enabled=1 gpgcheck=0
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
[centos]
name=centos base
enabled=1
gpgcheck=0
baseurl=http://mirrors.163.com/centos/7/os/x86_64/bash
第一步:配置DHCP服務服務器
[root@ken ~]# cat /etc/dhcp/dhcpd.conf subnet 192.168.182.0 netmask 255.255.255.0 { range 192.168.182.150 192.168.182.155; default-lease-time 600; max-lease-time 7200; filename "pxelinux.0"; } [root@ken ~]# systemctl restart dhcpd
第二步:配置tftp網絡
[root@ken ~]# cat /etc/xinetd.d/tftp # default: off # description: The tftp server serves files using the trivial file transfer \ # protocol. The tftp protocol is often used to boot diskless \ # workstations, download configuration files to network-aware printers, \ # and to start the installation process for some operating systems. service tftp { socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /var/lib/tftpboot disable = no #yes改成no per_source = 11 cps = 100 2 flags = IPv4 } [root@ken ~]# systemctl restart xinetd
第三步:啓動cobbler
[root@ken ~]# systemctl status cobblerd
第四步:啓動httpd
[root@ken ~]# systemctl restart httpd
第五步:檢查cobbler配置
[root@ken ~]# 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 : 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. 4 : enable and start rsyncd.service with systemctl 5 : debmirror package is not installed, it will be required to manage debian deployments and repositories 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 7 : 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.
根據如上反饋,須要一一進行修改才能繼續進行
修改配置文件/etc/cobbler/settings
cobbler文件默認是127.0.0.1本地迴環地址,須要更改成提供cobbler服務的ip地址 192.168.182.128,在384行
384 server: 192.168.182.128
netx_server也是默認本地127.0.0.1迴環地址,須要修改成提供cobbler服務的ip地址 192.163.182,128,在272行出
272 next_server: 192.168.182.128
能夠忽略
啓動rsync便可
[root@ken ~]# systemctl restart rsyncd
[root@ken ~]# systemctl enable rsyncd
問題五:
能夠忽略
問題六:
更改密碼
[root@ken ~]# openssl passwd -1 -salt "123" "123456" $1$123$7mft0jKnzzvAdU4t0unTG1
並把新生成的加密數據填寫進/etc/cobbler/settings
101 default_password_crypted: "$1$123$7mft0jKnzzvAdU4t0unTG1"
能夠忽略
以上問題解決以後,須要同步和重啓
[root@ken ~]# systemctl restart cobblerd
[root@ken ~]# cobbler sync
再次檢查是否已經更改完成
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service. [root@ken ~]# 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.
已經更改完畢!
第六步:掛載光盤並進行數據導入
掛載光盤
[root@ken ~]# mount /dev/cdrom /mnt
數據導入(須要一些時間)
[root@ken ~]# cobbler import --path=/mnt --name="centos7.5" task started: 2019-03-13_001927_import task started (id=Media import, time=Wed Mar 13 00:19:27 2019) Found a candidate signature: breed=redhat, version=rhel6 Found a candidate signature: breed=redhat, version=rhel7 Found a matching signature: breed=redhat, version=rhel7 Adding distros from path /var/www/cobbler/ks_mirror/centos7.5: creating new distro: centos7.5-x86_64 trying symlink: /var/www/cobbler/ks_mirror/centos7.5 -> /var/www/cobbler/links/centos7.5-x86_64 creating new profile: centos7.5-x86_64 associating repos checking for rsync repo(s) checking for rhn repo(s) checking for yum repo(s) starting descent into /var/www/cobbler/ks_mirror/centos7.5 for centos7.5-x86_64 processing repo at : /var/www/cobbler/ks_mirror/centos7.5 need to process repo/comps: /var/www/cobbler/ks_mirror/centos7.5 looking for /var/www/cobbler/ks_mirror/centos7.5/repodata/*comps*.xml Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos7.5/repodata *** TASK COMPLETE ***
查看distro
[root@ken ~]# cobbler distro list
centos7.5-x86_64
查看profile
[root@ken ~]# cobbler profile list
centos7.5-x86_64
distro : 發行版, 就是咱們安裝什麼版本的linux操做系統的名稱 一會咱們會導入一個 distro.
profile : 相似於一個 配置文件,相似於你的 bash_profile, 裏面包含你能夠添加 kernel 參數,對應的kickstart 文件 以及 此profile 對應的 distro 等等.
第八步:準備kickstart文件
在root目錄下找到ks文件,並移動到/var/lib/cobbler/kickstarts/到目錄下更名爲ks.cfg
[root@ken ~]# mv anaconda-ks.cfg /var/lib/cobbler/kickstarts/ks.cfg [root@ken ~]# vim /var/lib/cobbler/kickstarts/ks.cfg [root@ken ~]# cat /var/lib/cobbler/kickstarts/ks.cfg #version=DEVEL # System authorization information auth --enableshadow --passalgo=sha512 # Use CDROM installation media url --url=http://192.168.182.128/cobbler/ks_mirror/centos7.5/ #這裏須要更改成repodata所在的http地址 # Use graphical install graphical # Run the Setup Agent on first boot firstboot --enable ignoredisk --only-use=sda # Keyboard layouts keyboard --vckeymap=us --xlayouts='us' # System language lang en_US.UTF-8 # Network information network --bootproto=dhcp --device=ens33 --ipv6=auto --no-activate network --hostname=localhost.localdomain # Root password rootpw --iscrypted $6$7zu1wIUDgBGEFV1Y$KsLVeaGmyN92.QHr1fqKdTqPu8PDmd8K9V/s3Ru8NxE53NZz4gQKsmP6K0udcXVvDtponekICYUwBD7tYZJqU/ # System services services --disabled="chronyd" # System timezone timezone Asia/Shanghai --isUtc --nontp # System bootloader configuration bootloader --location=mbr --boot-drive=sda autopart --type=lvm # Partition clearing information clearpart --none --initlabel %packages @^minimal @core %end %addon com_redhat_kdump --disable --reserve-mb='auto' %end %anaconda pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty %end
第八步:自定義profile
[root@ken ~]# cobbler profile add --distro=centos7.5-x86_64 --name=centos7.5_ken --kickstart=/var/lib/cobbler/kickstarts/ks.cfg [root@ken ~]# cobbler sync task started: 2019-03-13_002724_sync task started (id=Sync, time=Wed Mar 13 00:27:24 2019) running pre-sync triggers cleaning trees removing: /var/www/cobbler/images/centos7.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/centos7.5-x86_64 removing: /var/lib/tftpboot/s390x/profile_list copying bootloaders copying distros to tftpboot copying files for distro: centos7.5-x86_64 trying hardlink /var/www/cobbler/ks_mirror/centos7.5/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos7.5-x86_64/vmlinuz trying hardlink /var/www/cobbler/ks_mirror/centos7.5/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos7.5-x86_64/initrd.img copying images generating PXE configuration files generating PXE menu structure copying files for distro: centos7.5-x86_64 trying hardlink /var/www/cobbler/ks_mirror/centos7.5/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos7.5-x86_64/vmlinuz trying hardlink /var/www/cobbler/ks_mirror/centos7.5/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos7.5-x86_64/initrd.img Writing template files for centos7.5-x86_64 rendering TFTPD files generating /etc/xinetd.d/tftp processing boot_files for distro: centos7.5-x86_64 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 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 ***
第九步:查看profile
[root@ken ~]# cobbler profile list centos7.5-x86_64 centos7.5_ken
第十步:刪除不包含ks文件的profile
[root@ken ~]# cobbler profile remove --name=centos7.5-x86_64 [root@ken ~]# cobbler profile list centos7.5_ken
新建一個虛擬機,須要和cobbler服務器所在同一個虛擬網絡中即與咱們上面設置的cobbler服務器的主機模式。內存須要3個G以上。
選擇第咱們自定義的包便可進行自動化安裝。