2016-12-10
最初始配置地址:
cobbler:一个自动网络安装系统的工具,集成PXE、dhcp、dns、tftpd、sync等服务。可以供大家管理安装操作系统
kvm:Linux系统自带的虚拟化软件,自行找资料学习。
环境描述:cobbler: 系统:CentOS_x86 6.8 网卡: eth0:vm1 (管理)10.10.100.131 ech1:NAT (上网)DHCPkvm: 系统:CentOS_x86 6.8 网卡: eth0:vm1 (管理)10.10.100.130 ech1:NAT (上网)DHCP系统环境准备:(两台主机上配置)epel源配置:yum -y install wgetwget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo初始化配置:yum -y install vim lrzsz ntp htop防火墙:selinux配置:service iptables stopchkconfig iptables offsed -i 's/^SELINUX/SELINUX=disabled/' /etc/selinux/configcrond配置同步系统时间:# rsync sys time0 */2 * * * /usr/sbin/ntpdate time.windows.comcobbler:安装相关cobbler组件: yum -y install cobbler dhcp httpd xinetd tftp-server syslinux pykickstart debmirror cman fence-agents配置相关选项:sed -i "s/server: 127.0.0.1/server: $(ifconfig eth0 | awk -F'[ :]+' 'NR==2{print $4}')/g" /etc/cobbler/settingsgrep --color "server:" /etc/cobbler/settingssed -i "s/manage_dhcp: 0/manage_dhcp: 1/g" /etc/cobbler/settingssed -i "s/manage_rsync: 0/manage_rsync: 1/g" /etc/cobbler/settingsgrep --color '^manage_[a-zA-Z]\{4,\}\:' /etc/cobbler/settingssed -i "s/disable\t\t\t= yes/disable\t\t\t= no/g" /etc/xinetd.d/tftpsed -i "s/disable\t= yes/disable = no/g" /etc/xinetd.d/rsyncgrep --color "disable" /etc/xinetd.d/tftp /etc/xinetd.d/rsynccp /etc/cobbler/dhcp.template{,.bak}sed -i "s/192.168.1.[0-9]\{0,3\}/10.10.100.0/g" /etc/cobbler/dhcp.templatedhcp配置说明一下,这里只是修改为自己的网段:全局修改后,在单独修改配置sed -i 's/@dists="sid"/#@dists="sid"/' /etc/debmirror.confsed -i 's/@arches/#@arches;/' /etc/debmirror.conf启动服务:service httpd startservice cobblerd startcobbler get-loaders# 配置安装好后的系统root初始密码,这里命令比较繁琐;因为都可以直接使用;所以不修改。同学们可以修改为自己想要的。# 注意,这里生成的字符串码:不单单要配置到settings文件中,还需要替换到 kickstarts (sample_end.ks )文件中rootpw项 sed -i "s@$(grep --color -o '\$[0-9A-Za-z]\{0,\}\$[0-9A-Za-z]\{0,\}\/[0-9A-Za-z]\{0,\}\$[0-9A-Za-z]\{0,\}\.' /etc/cobbler/settings)@$(openssl passwd -1 -salt 'random-phrase-here' '12345678')@" /etc/cobbler/settings检查配置:service cobblerd restartcobbler check创建镜像:mount /dev/cdrom /media/cobbler import --path=/media --name=CentOS-6.8-x86_64-minimal --arch=x86_64ln -s /var/www/cobbler/links/CentOS-6.8-minimal-x86_64/ /var/www/cobbler/links/CentOS-6.8-x86_64cobbler distro edit --name=CentOS-6.8-minimal-x86_64 --ksmeta="tree=http://@@http_server@@/cobbler/links/CentOS-6.8-x86_64"创建profile:cobbler profile add --name=CentOS-6.8-x86_64-minimal_base --distro=CentOS-6.8-minimal-x86_64 --kickstart=/var/lib/cobbler/kickstarts/sample_end.ks同步数据:cobbler sync创建system:(同学们注意下,这里创建system;主要目的是无人工干预安装操作系统。mac是kvm创建好后的虚拟机copy过来的。我这里是先前配置好的,写文档直接写了)cobbler system add --profile=CentOS-6.8-x86_64-minimal_base --name=CentOS-6.8-x86_64-minimal_base --interface=eth0 --mac=52:54:00:96:af:34 --ip-address=10.10.100.241 --netmask=255.255.255.0 --gateway=10.10.100.131 --static=1 --dns-name=10.10.100.131kvm(前提:cpu支持虚拟化):查看cpu是否支持虚拟化:Intel:vmxAMC:svmgrep -Ei --color "(vmx|svm)" /proc/cpuinfo配置网卡桥接:这里使用eth0:cp ifcfg-eth0 ifcfg-br0配置:[root@kvm network-scripts]# cat ifcfg-eth0DEVICE=eth0ONBOOT=yesBRIDGE="br0"[root@kvm network-scripts]# cat ifcfg-br0DEVICE="br0"TYPE="Bridge"ONBOOT="yes"BOOTPROTO=staticIPADDR=10.10.100.130PREFIX=24DELAY=0重启网卡,生效安装相关组件:yum -y install kvm qemu-kvm qemu-kvm-tools libvirt && ln -sv /usr/libexec/qemu-kvm /usr/sbin/ && service libvirtd start && chkconfig libvirtd on注意:这里所有主机都是最小化安装、为了使用管理kvm方便;这边在kvm主机上安装了virtual machine manager 安装组件:virtual machine manager 虚拟机管理控制台 linux安装yum -y install virt-managerxwindows linux安装 yum groupinstall "X Window System" -y 到这里cobbler和kvm基本都已安装好:还有注意一点kvm启动网卡桥接:需要关闭网络管理工具:NetworkManager,这里是因为没有安装此工具。操作端:win系统:这里需要连接kvm使用virtual machine manager管理kvm虚拟机,所有需要在win端安装xmanage控制台。网上有连接: 配置: 创建虚拟主机:copy mac地址到cobbler上创建 cobbler system运行即可实现无人值守安装系统一些小坑:1、dhcp:获取不到地址,正确配置好dhcp;确定dhcp服务启动。dhcp是要cobbler sync之后才会启动的。2、安装系统找不到kickstarts 文件,创建profile文件的时候;确保文件名正确3、xamnage 启动安装提示sda 问题。创建的时候,硬盘资源不要给太小。运维同学都知道默认分配系统盘资源空间
附带kickstarts文件:注意:密码字符串
# 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 --service=ssh# Run the Setup Agent on first boot firstboot --disable # System keyboard keyboard us # System language lang en_US # 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 rebootnetwork --onboot yes --device eth0 --bootproto dhcp --noipv6rootpw --iscrypted $1$random-p$hWRi.9FanNH4IXjhdupym/firewall --service=sshauthconfig --enableshadow --passalgo=sha512selinux --disabledtimezone --utc Asia/Shanghaibootloader --location=mbr --driveorder=sda --append="nomodeset crashkernel=auto rhgb quiet"# The following is the partition information you requested# Note that any partitions you deleted are not expressed# here so unless you clear all partitions first, this is# not guaranteed to work#clearpart --linux --drives=sdazerombr yesclearpart --all --drives=sda --initlabel#volgroup VolGroup --pesize=4096 pv.008002part /boot --fstype=ext4 --size=200part swap --size=512part / --fstype=ext4 --grow --size=1%packages --nobase@coreopenssh-clientscurl%end%pre $SNIPPET('log_ks_pre') $SNIPPET('kickstart_start') $SNIPPET('pre_install_network_config') # Enable installation monitoring $SNIPPET('pre_anamon') %end %packages --nobase@coreopenssh-clients$SNIPPET('func_install_if_enabled') %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 iptables -Fchkconfig iptables offrm -rf /etc/security/limits.d/90-nproc.confcat >>/etc/hosts<>/etc/resolv.conf< /var/spool/cron/root%end