zoukankan      html  css  js  c++  java
  • Cobbler环境搭建

    Cobbler服务器系统: CentOS 6.6 64位
    Cobbler版本: cobbler-2.6.11
    IP地址:192.168.166.136

    1、安装epel库

    rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm 
    

    2、安装依赖包

    yum  -y install cobbler tftp tftp-server xinetd  dhcp  httpd  rsync pykickstart  debmirror  python-ctypes   cman 
    

    3、配置http

    sed -i 's/^#ServerName www.example.com:80/ServerName 0.0.0.0:80/g' /etc/httpd/conf/httpd.conf
    chkconfig httpd on
    /etc/init.d/httpd start
    

    4、配置tftp和rsync

    sed -i 's/disable	= yes/disable	= no/g' /etc/cobbler/tftpd.template
    sed -i 's/disable	= yes/disable	= no/g' /etc/xinetd.d/rsync
    chkconfig xinetd on
    /etc/init.d/xinetd start
    

    5、配置cobbler相关参数

    [root@VM_166_136 ~]#sed -i 's/^@dists/#@dists/g;s/^@arches/#@arches/g' /etc/debmirror.conf
    #生成root密码的密文,cobber客户端使用,该机器也必须能使用这个密码,否则执行cobbler sync/cobbler get-loaders报登录失败
    [root@VM_166_136 kickstarts]# openssl passwd -1 -salt '' '123456' 
    $1$$RmyPVMlhpXjJj8iv4w.Ul.
    [root@VM_166_136 ~]#vi /etc/cobbler/settings
    default_password_crypted: "$1$$RmyPVMlhpXjJj8iv4w.Ul."
    
    [root@VM_166_136 ~]#IP=$(ifconfig |grep -A 2 "eth0 " |grep 'inet addr'|awk '{print $2}'|awk -F: '{print $2}')
    [root@VM_166_136 ~]#sed -i "s/^next_server.*$/next_server: $IP/g" /etc/cobbler/settings 
    [root@VM_166_136 ~]#sed -i "s/^server.*$/server: $IP/g" /etc/cobbler/settings
    [root@VM_166_136 ~]#sed -i "s/^manage_dhcp.*$/manage_dhcp: 1/g" /etc/cobbler/settings
    [root@VM_166_136 ~]#sed -i "s/^pxe_just_once.*$/pxe_just_once: 1/g" /etc/cobbler/settings
    [root@VM_166_136 ~]#sed -i "s/^manage_rsync.*$/manage_rsync: 1/g" /etc/cobbler/settings
    
    #查看修改的配置
    [root@VM_166_136 ~]#grep -E "^default_password_crypted|^next_server|^server|^pxe_just_once|^manage_rsync|^manage_dhcp" /etc/cobbler/settings
    

    6、配置dhcp服务器

    #修改subnet信息
    [root@VM_166_136 ~]#vi /etc/cobbler/dhcp.template
    subnet 192.168.166.0 netmask 255.255.255.0 { 
    	#option routers            192.168.166.1;
    	option domain-name-servers 192.168.166.2;
    	option subnet-mask         255.255.255.0;
    	range dynamic-bootp        192.168.166.10 192.168.166.60;
    	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 {
    			filename "pxelinux.0";
    		}
    	}
    }
    
    
    [root@VM_166_136 ~]#echo "DHCPDARGS=eth0" >/etc/sysconfig/dhcpd 

    #检查cobber配置是否有误 ------下面这个问题,已确认有该文件,不知道为什么还是提示。。我这里忽略
    [root@VM_166_136 kickstarts]# cobbler check
    The following are potential configuration items that you may want to fix:

    1 : file /etc/xinetd.d/rsync does not exist

    Restart cobblerd and then run 'cobbler sync' to apply changes.

      

    chkconfig dhcpd on
    chkconfig cobblerd on
    cobbler get-loaders
    service cobblerd start
    cobbler sync
    #测试dhcp服务器配置是否正确
    dhcpd
    service dhcpd start

    设置cobbler相关服务启动脚本

    vi /etc/rc.d/init.d/cobbler
    #!/bin/sh
    # chkconfig: - 80 90
    # description:cobbler
    case $1 in
    start)
    	/etc/init.d/httpd start
    	/etc/init.d/xinetd start
    	/etc/init.d/dhcpd start
    	/etc/init.d/cobblerd start
    	;;
    stop)
    	/etc/init.d/httpd stop
    	/etc/init.d/xinetd stop
    	/etc/init.d/dhcpd stop
    	/etc/init.d/cobblerd stop
    	;;
    restart)
    	/etc/init.d/httpd restart
    	/etc/init.d/xinetd restart
    	/etc/init.d/dhcpd restart
    	/etc/init.d/cobblerd restart
    	;;
    status)
    	/etc/init.d/httpd status
    	/etc/init.d/xinetd status
    	/etc/init.d/dhcpd status
    	/etc/init.d/cobblerd status
    	;;
    sync)
    	cobbler sync
    	;;
    *)
    	echo "Input error,please in put 'start|stop|restart|status|sync'!";
    	exit 2>&1 >/dev/null &
    	;;
    esac
    
    chmod +x /etc/rc.d/init.d/cobbler 
    chkconfig cobbler on
    service cobbler  restart
    

    7、制作镜像

    mkdir -p /data/iso/tmp
    rz -be   #上传ios至/data/iso目录
    mount -t iso9660 -o loop /data/iso/CentOS-6.6-x86_64-bin-DVD1.iso  /data/iso/tmp
    
    #将iso导入到cobber,切记必须切换到/var/www/cobbler/ks_mirror执行,该目录开启了http访问
    cd /var/www/cobbler/ks_mirror
    cobbler import --path=/data/iso/tmp  --name=CentOS-6.6-x86_64  --arch=x86_64
    

    8、设置kickstarts安装配置文件

    #定制系统安装及脚本设置,重要
    #1、不支持中文,切记
    #2、不支持bash里面的转义字符
    #3、自定义脚本,请使用http的方式执行
    cat /var/lib/cobbler/kickstarts/CentOS-6.6-x86_64.ks
    # kickstart template for Fedora 8 and later.
    # (includes %end blocks)
    # do not use with earlier distros
    
    #platform=x86, AMD64, or Intel EM64T
    # System authorization information
    auth  --useshadow  --enablemd5
    # System bootloader configuration
    bootloader --location=mbr
    # Partition clearing information
    clearpart --all --initlabel
    # Use text mode install
    text
    # Firewall configuration
    firewall --disabled
    # Run the Setup Agent on first boot
    firstboot --disable
    # System keyboard
    keyboard us
    # System language
    lang en_US.UTF-8
    # Use network installation
    url --url=$tree
    # If any cobbler repo definitions were referenced in the kickstart profile, include them here.
    $yum_repo_stanza
    # Network information
    $SNIPPET('network_config')
    # Reboot after installation
    reboot
    
    #Root password
    rootpw --iscrypted $default_password_crypted
    # SELinux configuration
    selinux --disabled
    # Do not configure the X Window System
    skipx
    # System timezone
    timezone  Asia/Shanghai
    # Install OS instead of upgrade
    install
    # Clear the Master Boot Record
    zerombr
    # Allow anaconda to partition the system as needed
    autopart
    
    %pre
    $SNIPPET('log_ks_pre')
    $SNIPPET('kickstart_start')
    $SNIPPET('pre_install_network_config')
    # Enable installation monitoring
    $SNIPPET('pre_anamon')
    %end
    
    %packages
    $SNIPPET('func_install_if_enabled')
    %end
    
    %post --nochroot
    $SNIPPET('log_ks_post_nochroot')
    %end
    
    %post
    $SNIPPET('log_ks_post')
    # Start yum configuration
    $yum_config_stanza
    # End yum configuration
    $SNIPPET('post_install_kernel_options')
    $SNIPPET('post_install_network_config')
    $SNIPPET('func_register_if_enabled')
    $SNIPPET('download_config_files')
    $SNIPPET('koan_environment')
    $SNIPPET('redhat_register')
    $SNIPPET('cobbler_register')
    # Enable post-install boot notification
    $SNIPPET('post_anamon')
    # Start final steps
    $SNIPPET('kickstart_done')
    # End final steps
    # Custom scripts
    cd /root
    wget http://192.168.166.136/cobbler/ks_mirror/config/custom.sh
    sh custom.sh
    
    %end
    

    #设置自定义脚本,用于定制 

    [root@VM_166_136 kickstarts]# cat /var/www/cobbler/ks_mirror/config/custom.sh 
    #!/bin/bash
    
    date >>/tmp/date.log
    

    cobbler常用命令

    #查看当前配置文件
    cobbler profile report
    
    #修改profile,默认是/var/lib/cobbler/kickstarts/sample_end.ks 配置文件,必须
    cobbler profile edit --name=CentOS-6.6-x86_64 --distro=CentOS-6.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-6.6-x86_64.ks
    
    #指定安装的配置文件,需要时候,才使用
    cobbler profile remove --name=CentOS-5.10-x86_64
    
    #查看Cobbler列表
    cobbler list
    #查看所有参数
    cobbler report
    #查看配置文件相关参数
    cobbler profile report
    #查看distro列表
    cobbler distro list
    

    #修改cobber 客户端的默认启动项

    [root@VM_166_136 kickstarts]# cat /var/lib/tftpboot/pxelinux.cfg/default
    DEFAULT menu
    PROMPT 0
    MENU TITLE Cobbler | http://cobbler.github.io
    TIMEOUT 60
    TOTALTIMEOUT 6000
    #ONTIMEOUT local
    ONTIMEOUT CentOS-6.6-x86_64
    
    LABEL local
            MENU LABEL (local)
            LOCALBOOT -1
    
    LABEL CentOS-6.6-x86_64
            kernel /images/CentOS-6.6-x86_64/vmlinuz
            MENU LABEL CentOS-6.6-x86_64
            MENU DEFAULT
    	append initrd=/images/CentOS-6.6-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.166.136/cblr/svc/op/ks/profile/CentOS-6.6-x86_64
            ipappend 2
    
    MENU end
    

    到这里,新建的虚拟机,已经可以自动安装操作系统了。

    9、重新安装系统

    在需要重装系统的服务器上安装koan
    1.安装epel库
    rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm 
    2.安装koan
    yum -y install koan.noarch
    3.查看Cobbler服务器系统镜像列表
    koan --list=profiles  --server=192.168.166.136  
    4.查看Cobbler服务器系统镜像列表
    koan --replace-self --server=192.168.166.136 --profile=CentOS-6.6-x86_64
    5.重新启动系统进行自动安装
    reboot 
    

    Kickstart: /var/lib/cobbler/kickstarts/
    cobbler相关配置文件: /etc/cobbler
    cobbler数据存储目录: /var/www/cobbler
    dhcp配置文件: /etc/dhcpd.conf
    dhcp租期缓存文件: /var/lib/dhcpd/dhcpd.leases
    pxe配置文件: /tftpboot/pxelinux.cfg/default
    cobbler日志:
    /var/log/cobbler/install.log #客户端系统安装日志
    /var/log/cobbler/cobbler.log #cobbler日志

  • 相关阅读:
    Linux_vi编辑器
    Linux_几个符号命令
    Linux_权限
    Linux_用户/用户组
    Linux_文件及文件夹[创建][复制][移动][删除][重命名]
    Linux_文件查看
    Linux_初识
    码农网站
    学习网站
    软件设计师考试范围
  • 原文地址:https://www.cnblogs.com/dbcloud/p/6347823.html
Copyright © 2011-2022 走看看