COBBLER無人設置

19899 ワード

csdnはmarkdownの文法サポートが下手で、レイアウトエラーが発生した場合、ドキュメントを参照して国語のCOBBLER無人インストールを自動化することができます
COBBLER無人設置
ここではCobblerを見る前にKickstartの無人インストールを見て、Cobblerの実現原理を理解してください.しかし、Cobblerは独立しており、KickstartをインストールしてからCobblerをインストールする必要はありません.これはKickstartを知らない人に書かれています.
1.Cobbler紹介
CobblerはLinuxサーバのインストールサービスで、ネットワーク起動(PXE)方式で物理サーバと仮想マシンを迅速にインストール、再インストールできるとともに、DHCP、DNSなども管理できる.
Cobblerはコマンドライン方式で管理でき、Webベースのインタフェース管理ツール(cobbler-web)も提供され、APIインタフェースも提供され、二次開発の使用を容易にすることができる.
Cobblerは以前のkickstartのアップグレード版で、構成が容易で、Webインタフェースも持参して管理しやすいという利点があります.
Cobblerには軽量レベルの構成管理システムが内蔵されていますが、Puppetなどの他の構成管理システムとの統合もサポートされており、SaltStackは一時的にサポートされていません.
Cobbler公式サイト
1.1 Cobbler統合サービス
  • PXEサービスサポート
  • DHCPサービス管理
  • DNSサービス管理(オプションbind,dnsmasq)
  • 電源管理
  • Kickstartサービスサポート
  • YUM倉庫管理
  • TFT P(PXE起動時に必要)Apache(kickstartのインストールソースを提供し、カスタマイズされたkickstart構成を提供する)
  • 1.2システム環境準備
    [root@localhost ~]# cat /etc/redhat-release 
    CentOS Linux release 7.5.1804 (Core) 
    [root@localhost ~]# uname -r
    3.10.0-862.el7.x86_64
    [root@localhost ~]# getenforce 
    Disabled
    [root@localhost ~]# iptables -L
    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination         
    
    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination         
    
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination 
    [root@localhost ~]# ifconfig ens33|grep 'inet '|awk '{print $2}'
    192.168.56.11
    [root@linux-node01 ~]# hostname
    linux-node01.zte.com.cn
    
    
    
    
    
    #アリクラウドのepelソースを構成する[root@linux-node01 ~]# wget -O/etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
    に注意
  • 仮想マシンネットワークカードはNATモードを採用し、ブリッジモードを使用しないでください.後でDHCPサーバーを構築するので、同じローカルエリアネットワークで複数のDHCPサービスが競合します.
  • VMwareのNATモードのdhcpサービスも停止し、干渉を回避する.

  • 2.Cobbler取付構成
    2.1 Cobblerの取り付け
    [root@model ~]# yum install cobbler cobbler-web dhcp tftp-server pykickstart httpd -y
    [root@linux-node1 ~]# rpm -ql cobbler  #        ,      。
    /etc/cobbler                  #       
    /etc/cobbler/settings         # cobbler     ,     YAML  ,Cobbler python    。
    /etc/cobbler/dhcp.template    # DHCP       
    /etc/cobbler/tftpd.template   # tftp       
    /etc/cobbler/rsync.template   # rsync       
    /etc/cobbler/iso              # iso        
    /etc/cobbler/pxe              # pxe      
    /etc/cobbler/power            #          
    /etc/cobbler/users.conf       # Web        
    /etc/cobbler/users.digest     #   web            
    /etc/cobbler/dnsmasq.template # DNS       
    /etc/cobbler/modules.conf     # Cobbler      
    
    /var/lib/cobbler              # Cobbler    
    /var/lib/cobbler/config       #     
    /var/lib/cobbler/kickstarts   #     kickstart  
    /var/lib/cobbler/loaders      #          
    
    /var/www/cobbler              #         
    /var/www/cobbler/ks_mirror    #          
    /var/www/cobbler/images       #            
    /var/www/cobbler/repo_mirror  # yum     
    
    /var/log/cobbler              #     
    /var/log/cobbler/install.log  #          
    /var/log/cobbler/cobbler.log  # cobbler  
    

    2.2 Cobblerの構成
    [root@linux-node01 ~]# systemctl start httpd
    [root@linux-node01 ~]# systemctl start cobblerd
    [root@linux-node01 ~]# 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 : 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 : enable and start rsyncd.service with systemctl
    6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
    7 : 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
    8 : 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.
    
    
    
    
    
    
    #上記のヒントに従って、問題を一つ一つ解決します.1、2、6つ目の質問がてら他の機能を修正[root@linux-node 01~]#cp/etc/cobbler/settings{,.ori}#バックアップ#server,CobblerサーバのIP.[root@linux-node01 ~]# sed -i 's/server: 127.0.0.1/server: 192.168.56.11/'/etc/cobbler/settings # next_server,CobblerでDHCPを管理する場合,本項を修正し,役割は説明せずkickstartを見る.[root@linux-node01 ~]# sed -i 's/next_server: 127.0.0.1/next_server:192.168.56.11/'/etc/cobbler/settings#DHCPをCobblerで管理[root@linux-node01 ~]# sed -i 's/manage_dhcp: 0/manage_dhcp:1/'/etc/cobbler/settings#リサイクル防止システム、サーバに適用される最初の起動項目はPXE起動です.[root@linux-node01 ~]# sed -i 's/pxe_just_once: 0/pxe_just_once:1/'/etc/cobbler/settings#新規インストールシステムのデフォルトrootパスワード123456を設定します.次のコマンドは、ヒント6に由来します.random-phrase-hereは干渉コードで、自分で設定できます.[root@linux-node01 ~]# openssl passwd -1 -salt 'baizuo' '123456'
    1 1 baizuo
    Wtro4OlXkhyUBAqBpkA611[root@linux-node01 ~]# vi /etc/cobbler/settingsdefault_password_crypted: "Wtro4OlXkhyUBAqBpkA611[root@linux-node01 ~]# vi /etc/cobbler/settingsdefault_password_crypted: " 1
    Baizuo b a i z u o Wtro 4 OlXkhyUBAqBpkA 611"#3番目の質問[root@linux-node01 ~]# cobbler get-loaders [root@linux-node 1~]#cd/var/lib/cobbler/loaders/#ダウンロードの内容[root@linux-node 1 loaders]#ls COPYING.elilo COPYING.yaboot grub-x 86_64.efi menu.c 32 README COPYING.syslinux elilo-ia 64.efi grub-x 86.efi pxelinux.0 yaboot#4番目の質問[root@linux-node01 loaders]# vi/etc/xinetd.d/tftp disable = no [root@linux-node01 xinetd.d]# systemctl restart xinetd [root@linux-node01 loaders]#systemctl restart cobblerd [root@linux-node01 xinetd.d]# cobbler check The following are potential configuration items that you may want to fix: 1 : enable and start rsyncd.service with systemctl 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 cobbled and then run'cobbler sync'to apply changes.#これらの問題は無視でき、使用に影響しません.
    2.3 DHCPの構成
     # 修改cobbler的dhcp模版,不要直接修改dhcp本身的配置文件,因为cobbler会覆盖。 [root@linux-node1 ~]# vim /etc/cobbler/dhcp.template # 仅列出修改过的字段 …… subnet 192.168.56.0 netmask 255.255.255.0 { option routers 192.168.56.2; option domain-name-servers 192.168.56.2; option subnet-mask 255.255.255.0; range dynamic-bootp 192.168.56.100 192.168.56.254; …… 
      

    2.4 同步cobbler配置

    [root@linux-node01 xinetd.d]# cobbler sync
    task started: 2018-05-27_171527_sync
    task started (id=Sync, time=Sun May 27 17:15:27 2018)
    running pre-sync triggers
    cleaning trees
    removing: /var/lib/tftpboot/grub/images
    copying bootloaders
    trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
    trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
    trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
    trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
    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
    
    running shell triggers from /var/lib/cobbler/triggers/sync/post/*
    running python triggers from /var/lib/cobbler/triggers/change/*
    running python trigger cobbler.modules.scm_track
    running shell triggers from /var/lib/cobbler/triggers/change/*
    *** TASK COMPLETE ***
    
    
    
    
    
    #dhcpのプロファイルが変更されたかどうかもう一度見てみましょう[root@linux-node01 xinetd.d]# head -20/etc/dhcp/dhcpd.conf# ****************************************************************** # Cobbler managed dhcpd.conf file # generated from cobbler dhcp.conf template (Sun May 27 09:15:28 2018) # 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 192.168.56.0 netmask 255.255.255.0 { option routers 192.168.56.2;
    2.5起動
     #设置开机自启动 [root@linux-node01 xinetd.d]# systemctl enable httpd.service [root@linux-node01 xinetd.d]# systemctl enable xinetd.service [root@linux-node01 xinetd.d]# systemctl enable cobblerd.service #重启相关服务 [root@linux-node01 xinetd.d]# systemctl restart httpd.service [root@linux-node01 xinetd.d]# systemctl restart xinetd.service [root@linux-node01 xinetd.d]# systemctl restart cobblerd.service 
      

    3. Cobbler的命令行管理

    3.1 查看命令帮助

    [root@linux-node1 ~]# cobbler
    
    
    
    
    
    usage ===== cobbler
    3.2ミラーのインポート
    [root@linux-node1 ~]# mount /dev/cdrom /mnt/  #   CentOS7     。
    [root@linux-node1 ~]# cobbler import --path=/mnt/ --name=CentOS-7-x86_64 --arch=x86_64
    
    
    
    
    
    --pathミラーパス#--nameはインストールソースの名前を定義します.--archはインストールソースが32ビット、64ビット、ia 64であることを指定します.現在サポートされているオプションは、x 86|x 86_64|ia 64|インストールソースの一意の表示はnameパラメータに基づいて定義されます.この例のインポートに成功した後、インストールソースの一意の表示はCentOS-7-x 86_64です.繰り返した場合、インポートに失敗することを示すシステムがあります.[root@linux-node 01 xinetd.d]#cobbler distro list#ミラーリストCentOS-7-x 86_64#ミラー格納ディレクトリを表示します.cobblerはミラー内のすべてのインストールファイルをローカルにコピーし、/var/www/cobbler/ks_mirrorの下にあるCentOS-7.1-x 86_64ディレクトリの下に配置します.したがって/var/www/cobblerディレクトリにはインストールファイルを格納するのに十分なスペースが必要です.[root@linux-node01 xinetd.d]# cd/var/www//cobbler/ks_mirror/[root@linux-node01 ks_mirror]# ls CentOS-7-x86_64 config [root@linux-node01 ks_mirror]# ls CentOS-7-x86_64/CentOS_BuildTag EFI EULA GPL images isolinux LiveOS Packages repodata RPM-GPG-KEY-CentOS-7 RPM-GPG-KEY-CentOS-Testing-7 TRANS.TBL
    3.3 ks.cfgファイルの指定とカーネルパラメータの調整
     # Cobbler的ks.cfg文件存放位置 [root@linux-node01 ks_mirror]# cd /var/lib/cobbler/kickstarts/ [root@linux-node01 kickstarts]# ls #自带很多 default.ks esxi5-ks.cfg legacy.ks sample_autoyast.xml sample_esx4.ks sample_esxi5.ks sample.ks sample.seed esxi4-ks.cfg install_profiles pxerescue.ks sample_end.ks(默认使用的ks文件) sample_esxi4.ks sample_esxi6.ks sample_old.seed [root@linux-node01 kickstarts]# vi CentOS-7-x86_64.cfg #检测ks文件是否有问题 [root@linux-node01 kickstarts]# cobbler validateks task started: 2018-05-27_183403_validateks task started (id=Kickstart Validation, time=Sun May 27 18:34:03 2018) ---------------------------- osversion: rhel7 checking url: http://192.168.56.11/cblr/svc/op/ks/profile/CentOS-7-x86_64 running: /usr/bin/ksvalidator -v "rhel7" "http://192.168.56.11/cblr/svc/op/ks/profile/CentOS-7-x86_64" received on stdout: received on stderr: *** all kickstarts seem to be ok *** *** TASK COMPLETE *** # 在第一次导入系统镜像后,Cobbler会给镜像指定一个默认的kickstart自动安装文件在/var/lib/cobbler/kickstarts下的sample_end.ks。 [root@linux-node01 kickstarts]# cobbler list distros: CentOS-7-x86_64 profiles: CentOS-7-x86_64 systems: repos: images: mgmtclasses: packages: files: # 查看安装镜像文件信息 [root@linux-node01 kickstarts]# cobbler distro report --name=CentOS-7-x86_64 Name : CentOS-7-x86_64 Architecture : x86_64 TFTP Boot Files : {} Breed : redhat Comment : Fetchable Files : {} Initrd : /var/www/cobbler/ks_mirror/CentOS-7-x86_64/images/pxeboot/initrd.img Kernel : /var/www/cobbler/ks_mirror/CentOS-7-x86_64/images/pxeboot/vmlinuz Kernel Options : {} Kernel Options (Post Install) : {} Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/CentOS-7-x86_64'} Management Classes : [] OS Version : rhel7 Owners : ['admin'] Red Hat Management Key : # 查看所有的profile设置 [root@linux-node01 kickstarts]# cobbler distro report --name=CentOS-7-x86_64 Name : CentOS-7-x86_64 Architecture : x86_64 TFTP Boot Files : {} Breed : redhat Comment : Fetchable Files : {} Initrd : /var/www/cobbler/ks_mirror/CentOS-7-x86_64/images/pxeboot/initrd.img Kernel : /var/www/cobbler/ks_mirror/CentOS-7-x86_64/images/pxeboot/vmlinuz Kernel Options : {} Kernel Options (Post Install) : {} Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/CentOS-7-x86_64'} Management Classes : [] OS Version : rhel7 Owners : ['admin'] Red Hat Management Key : #编辑profile,修改关联的ks文件 [root@linux-node01 kickstarts]# cobbler profile edit --name=CentOS-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg # 修改安装系统的内核参数,在CentOS7系统有一个地方变了,就是网卡名变成eno16777736这种形式,但是为了运维标准化,我们需要将它变成我们常用的eth0,因此使用下面的参数。但要注意是CentOS7才需要下面的步骤,CentOS6不需要。 [root@linux-node01 kickstarts]# cobbler profile edit --name=CentOS-7-x86_64 --kopts='net.ifnames=0 biosdevname=0' [root@linux-node01 kickstarts]# cobbler profile report Name : CentOS-7-x86_64 TFTP Boot Files : {} Comment : DHCP Tag : default Distribution : CentOS-7-x86_64 Enable gPXE? : 0 Enable PXE Menu? : 1 Fetchable Files : {} Kernel Options : {'biosdevname': '0', 'net.ifnames': '0'} Kernel Options (Post Install) : {} Kickstart : /var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg Kickstart Metadata : {} Management Classes : [] Management Parameters : # 每次修改完都要同步一次 [root@linux-node1 ~]# cobbler sync 
      

    3.4 安装系统

    可以很愉快的告诉你到这里就可以安装系统了!
    新建一台虚拟机,不解释,开机就可以看到下面的图片了!

    有没有发现不美观的地方?

    网址不是我的!改!

     #修改Cobbler提示 [root@linux-node1 ~]# vim /etc/cobbler/pxe/pxedefault.template MENU TITLE Cobbler | http://wwww.zte.com.cn/ [root@linux-node1 ~]# cobbler sync # 修改配置都要同步 
      

    OK,现在好看多了。选择第二项就可以继续装机了。你可以让系统飞着,然后接着看下文!!

    4. ks.cfg文件简析

    [root@linux-node01 kickstarts]# cat CentOS-7-x86_64.cfg 
    
    
    
    
    
    #System timezone timezone Asia/Shanghai #Root password rootpw --iscrypted $default_password_crypted #Use text mode install text #Install OS installed of upgrade install #Use NFS installation Media url --url="$tree"#System bootloader configuration bootloader --location=mbr #Clear the Master Boot Record zerombr #Partition clearing information clearpart --all initlabel #Disk partitioning information part/boot --fstype xfs --size 102 part swap --size 1024 part/--fstype xfs --size 1 --grow firstboot --disable selinux --disabled firewall --disabled logging --level=info #System authorization information auth --useshadow --enablemd5 #Network information $SNIPPET('network_config') #network --bootproto=dhcp --device=em1 --onboot=on #reoot after installation reboot #Firewall configuration firewall --disabled #Selinux configuration selinux --disabled #Do not configure XWindows skipx #Package install information %pre
    SNIPPET(′logkspre′) S N I P P E T ( ′ l o g k s p r e ′ ) SNIPPET('kickstart_start') $SNIPPET('pre_install_network_config') # Enable installation monitoring $SNIPPET('pre_anamon') %end %packages @base @compat-libraries @debugging @development tree nmap sysstat lrzsz dos2unix telnet iptraf ncurses-devel openssl-devel zlib-devel OpenIPMI-tools screen %end %post systemctl disable postfix.service %end
    5.カスタマイズインストール
    kickstartの学習から、あるサーバが指定ksファイルを使用する方法を指定したい人がいるかもしれませんが、kickstartはこの機能を実現するのは複雑かもしれませんが、Cobblerは簡単です.
    1台のサーバを区別する最も簡単な方法は、物理MACアドレスです.
    物理サーバのMACアドレスはサーバ上のラベルに書かれています.
    仮想マシンのMAC表示
    [root@linux-node01 kickstarts]#  cobbler system add --name=linux-node2.oldboyedu.com --mac=00:50:56:3A:F8:56 --profile=CentOS-7-x86_64 --ip-address=192.168.56.12 --subnet=255.255.255.0 --gateway=192.168.56.2 --interface=eth0 --static=1 /var/lib/cobbler/kickstarts/CentOS7-x86_64.cfg --name-servers="192.168.56.2" --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg
    
    
    
    
    
    --nameカスタムですが、定義されたリストを繰り返し表示することはできません[root@linux-node1 ~]# cobbler system list oldboy [root@linux-node1 ~]# cobbler sync
    再度電源を入れてインストールすると、選択を聞かずに直接インストールします.
    6.CobblerのWeb管理インタフェースのインストールと構成
    cobbler-webソフトウェアがインストールされています.
    Webサイトへのアクセス:https://192.168.56.11/cobbler_web デフォルトユーザー名:cobblerデフォルトパスワード:cobbler
    /etc/cobbler/users.conf       # Web        
    /etc/cobbler/users.digest     #   web            
    [root@linux-node1 ~]# cat /etc/cobbler/users.digest
    cobbler:Cobbler:a2d6bae81669d707b72c0bd9806e01f3
    
    
    
    
    
    #Cobbler webユーザー登録パスワードの設定#Cobblerグループにcobblerユーザーを追加し、パスワード確認の2パス入力を促す[root@linux-node1 ~]# htdigest/etc/cobbler/users.digest "Cobbler"cobbler Changing password for user cobbler in realm Cobbler New password: 123456 Re-type new password:123456 [root@linux-node1 ~]# cobbler sync [root@linux-node1 ~]#systemctl restart cobblerd [root@linux-node1 ~]#systemctl restart httpd
    これからは123456というパスワードでログインする必要があります.
    次の操作はマウスを点すことです.
    7.koanによるシステム再インストール
    クライアントにkoanをインストールする(ソースを構成する)
    [root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
    [root@localhost ~]# yum install koan
    

    cobblerのプロファイルの表示
    [root@localhost ~]# koan --server=192.168.56.11 --list=profiles
    - looking for Cobbler at http://192.168.56.11:80/cobbler_api
    Centos-7-x86_64
    

    クライアントシステムの再インストール
    [root@localhost ~]# koan --replace-self --server=192.168.56.11 --profile=webserver1
    

    システムを再起動すると自動的に再インストールされます
    apiを使用したカスタムインストール
    apiは保存場所を構成します:
    [root@localhost ~]# cat /etc/httpd/conf.d/cobbler.conf
    ProxyPass /cobbler_api http://127.0.0.1:25151/
    ProxyPassReverse /cobbler_api http://127.0.0.1:25151/
    

    Pythonのスクリプトを書いてapiをテストします.
    [root@localhost scripts]# cat test_cobbler-api.py 
    
    
    
    
    
    #!/usr/bin/python import xmlrpclib server=xmlrpclib.Server("http://192.168.56.11/cobbler_api") #print server.get_distors() print server.get_profiles() print server.get_systems() #print server.get_images() print server.get_repos()
    実行結果の表示:
    [root@linux-node01 zxin10]# python test_cobbler-api.py 
    [{'comment': '', 'kickstart': '/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg', 'name_servers_search': [], 'ks_meta': {}, 'kernel_options_post': {}, 'repos': [], 'redhat_management_key': '