kvm cobbler无人值守批量安装操作系统
cobbler:一个自动网络安装系统的工具,集成PEX、dhcp、dns、tftpd、sync等服务。可以供大家管理安装操作系统
kvm:Linux系统自带的虚拟化软件,自行找资料学习。
环境描述:
cobbler:
系统:CentOS_x86 6.8
网卡:
eth0:vm1 (管理)10.10.100.131
ech1:NAT (上网)DHCP
kvm:
系统:CentOS_x86 6.8
网卡:
eth0:vm1 (管理)10.10.100.130
ech1:NAT (上网)DHCP
系统环境准备:(两台主机上配置)
epel源配置:
yum -y install wget
wget -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 stop
chkconfig iptables off
sed -i 's/^SELINUX/SELINUX=disabled/' /etc/selinux/config
crond配置同步系统时间:
# rsync sys time
0 */2 * * * /usr/sbin/ntpdate time.windows.com
cobbler:
安装相关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/settings
grep --color "server:" /etc/cobbler/settings
sed -i "s/manage_dhcp: 0/manage_dhcp: 1/g" /etc/cobbler/settings
sed -i "s/manage_rsync: 0/manage_rsync: 1/g" /etc/cobbler/settings
grep --color '^manage_[a-zA-Z]\{4,\}\:' /etc/cobbler/settings
sed -i "s/disable\t\t\t= yes/disable\t\t\t= no/g" /etc/xinetd.d/tftp
sed -i "s/disable\t= yes/disable = no/g" /etc/xinetd.d/rsync
grep --color "disable" /etc/xinetd.d/tftp /etc/xinetd.d/rsync
cp /etc/cobbler/dhcp.template{,.bak}
sed -i "s/192.168.1.[0-9]\{0,3\}/10.10.100.0/g" /etc/cobbler/dhcp.template
dhcp配置说明一下,这里只是修改为自己的网段:全局修改后,在单独修改配置
sed -i 's/@dists="sid"/#@dists="sid"/' /etc/debmirror.conf
sed -i 's/@arches/#@arches;/' /etc/debmirror.conf
启动服务:
service httpd start
service cobblerd start
cobbler 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 restart
cobbler check
创建镜像:
mount /dev/cdrom /media/
cobbler import --path=/media --name=CentOS-6.8-x86_64-minimal --arch=x86_64
ln -s /var/www/cobbler/links/CentOS-6.8-minimal-x86_64/ /var/www/cobbler/links/CentOS-6.8-x86_64
cobbler 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.131
kvm(前提:cpu支持虚拟化):
查看cpu是否支持虚拟化:
Intel:vmx
AMC:svm
grep -Ei --color "(vmx|svm)" /proc/cpuinfo
配置网卡桥接:
这里使用eth0:
cp ifcfg-eth0 ifcfg-br0
配置:
[root@kvm network-scripts]# cat ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BRIDGE="br0"
[root@kvm network-scripts]# cat ifcfg-br0
DEVICE="br0"
TYPE="Bridge"
ONBOOT="yes"
BOOTPROTO=static
IPADDR=10.10.100.130
PREFIX=24
DELAY=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-manager
xwindows linux安装
yum groupinstall "X Window System" -y
到这里cobbler和kvm基本都已安装好:还有注意一点kvm启动网卡桥接:需要关闭网络管理工具:NetworkManager,这里是因为没有安装此工具。