批量安装操作系统之cobbler

 Cobbler 部署文档 

 服务端配置 

操作系统:Centos6.4

关闭防火墙及 selinux

 安装cobbler软件 

添加yum源

rpm -Uvh https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

安装相关软件

yum -y install cobbler httpd rsync tftp-server xinetd dhcp cobbler-web syslinux cman pykickstart


 设置cobbler服务 
tftp服务和rsync服务


sed -i '/disable/c\\tdisable\t\t\t no' /etc/xinetd.d/tftp
sed -i -e 's/\\ yes/\\ no/g' /etc/xinetd.d/rsync 


允许web登录

sed -i 's/authn_denyall/authn_configfile/g' /etc/cobbler/modules.conf 


设置cobbler  web登陆,用户登陆密码

htdigest /etc/cobbler/users.digest "Cobbler" cobbler
#pass: l99.com


设置cobbler登陆服务器地址

sed -i 's/server: 127.0.0.1/server: 192.168.60.1/g' /etc/cobbler/settings


ks脚本关闭pxe,这样就不会重复安装

sed -i 's/pxe_just_once: 0/pxe_just_once: 1/g' /etc/cobbler/settings


TFTP服务器 IP地址


sed -i 's/next_server: 127.0.0.1/next_server: 192.168.60.1/g' /etc/cobbler/settings


cobbler管理rsync

sed -i 's/manage_rsync: 0/manage_rsync: 1/g' /etc/cobbler/settings


cobbler管理dhcp

sed -i 's/manage_dhcp: 0/manage_dhcp: 1/g' /etc/cobbler/settings


设置debmirror

sed -i -e 's|@dists.*|#@dists|'  /etc/debmirror.conf
sed -i -e 's|@arches.*|#@arches|'  /etc/debmirror.conf

dhcp服务是有cobbler来管理 /etc/cobbler/dhcp.template

修改下面的内容就可以。

subnet 192.168.60.0 netmask 255.255.255.0 {
     option routers             192.168.60.1;
     option domain-name-servers 192.168.60.3;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.60.100 192.168.60.150;
     filename                   "/pxelinux.0";
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
}


设置root默认密码

这个设置只针对centos有效。默认的root密码是:l99.com

openssl passwd -1 -salt 'random-phrase-here' 'l99.com'
$1$random-p$A7/aqa3cbDOPzq2CUARYK1

修改 /etc/cobbler/settings

default_password_crypted: "$1$random-p$A7/aqa3cbDOPzq2CUARYK1"


启动相关服务


chkconfig httpd on 
chkconfig cobblerd on
chkconfig dhcpd on
chkconfig xinetd on
/etc/init.d/httpd restart
/etc/init.d/cobblerd restart
/etc/init.d/dhcpd restart
/etc/init.d/xinetd restart


设置debmirror

sed -i -e 's|@dists.*|#@dists|'  /etc/debmirror.conf
sed -i -e 's|@arches.*|#@arches|'  /etc/debmirror.conf


启动菜单

cobbler get-loaders


同步配置

cobbler sync


检查cobbler

cobbler check

会看以下内容

No configuration problems found.  All systems go.

浏览cobbler_web

http://192.168.60.1/cobbler_web

如果提示:Error importing template source loader django.template.loaders.filesystem.load_template_source: "'module' object has no attribute 'load_template_source'"
由于默认安装的django版本为1.4,可能是bug,解决方法可以换成低版本的django

rpm -e Django14-1.4.5-1.el6.noarch.rpm
wget ftp://ftp.pbone.net/mirror/ftp.sourceforge.net/pub/sourceforge/e/er/errepoel/centos/6/os/x86_64/Django-1.3.1-21.el6.noarch.rpm
rm -rf /usr/lib/python2.6/site-packages/django/
rpm -ivh Django-1.3.1-21.el6.noarch.rpm

重启httpd和cobblerd服务

导入镜像

mount -t auto -o loop CentOS-6.4-x86_64-bin-DVD1.iso /mnt/
cobbler import --path/mnt --nameCentOS6.4 --archx86_64

会看到以下内容

task started: 2013-06-14_093721_import
task started (idMedia import, timeFri Jun 14 09:37:21 2013)
Found a redhat compatible signature: Packages
adding distros
creating new distro: CentOS6.4-x86_64
creating new profile: CentOS6.4-x86_64
associating repos
traversing distro CentOS6.4-x86_64
descent into /var/www/cobbler/ks_mirror/CentOS6.4-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS6.4-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS6.4-x86_64
looking for /var/www/cobbler/ks_mirror/CentOS6.4-x86_64/repodata/*comps*.xml
running: createrepo -c cache -s sha --groupfile /var/www/cobbler/ks_mirror/CentOS6.4-x86_64/repodata/2727fcb43fbe4c1a3588992af8c19e4d97167aee2f6088959221fc285cab6f72-c6-x86_64-comps.xml /var/www/cobbler/ks_mirror/CentOS6.4-x86_64
received on stdout: Spawning worker 0 with 3916 pkgs
Workers Finished
Gathering worker results
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
received on stderr: 
associating kickstarts
*** TASK COMPLETE ***


 cobbler repo仓库建立 

cobbler repo add --name163.com-6-x86_64 --mirrorhttp://mirrors.163.com/centos/6/os/x86_64/Packages/

建立repo仓库

cobbler reposync

此处遇到问题:同步了一晚上的数据,第二天发现报错如下:

reposync failed, tries left: 0
Exception occured: 
Exception value: 'reposync failed, retry limit reached, aborting'
Exception Info:
  File "/usr/lib/python2.6/site-packages/cobbler/utils.py", line 123, in die
    raise CX(msg)

Exception occured: 
Exception value: 'reposync failed, retry limit reached, aborting'
Exception Info:

查找了一些资料后有些人说是bug,具体我也不太清楚。后来直接使用本地镜像导入了,具体方法如下:

cobbler repo add --nameCentOS6.4-x86_64 --mirrorhttp://192.168.60.1/cobbler/ks_mirror/CentOS6.4-x86_64

建立仓库

cobbler reposync


完成后/var/www/cobbler/repo_mirror目录下会生成CentOS6.4-x86_64

 如果安装puppet客户端 

由于epel的源同步失败,因此此处手动将puppet所需要的包添加到本地repo中

安装pupet客户端还需要几个ruby的包,以上加的两个源里默认没有,可以从网上下载后再添加到目前有的源里:

cobbler repo add --namepuppetlabs --mirrorhttp://yum.puppetlabs.com/el/6/products/x86_64/   #把这个也加上,虽然是从网络同步的,但它却能成功

下载所需包

http://mirrors.sohu.com/fedora-epel/6/x86_64/ruby-shadow-1.4.1-13.el6.x86_64.rpm
http://mirrors.sohu.com/fedora-epel/6/x86_64/ruby-json-1.4.6-1.el6.x86_64.rpm
http://mirrors.sohu.com/fedora-epel/6/x86_64/ruby-augeas-0.4.1-1.el6.x86_64.rpmhttp://dl.marmotte.net/rpms/redhat/el6/x86_64/ruby-rgen-0.6.2-1.el6/ruby-rgen-0.6.2-1.el6.noarch.rpm
http://dl.marmotte.net/rpms/redhat/el6/x86_64/hiera-1.2.1-1.el6/hiera-1.2.1-1.el6.noarch.rpm
http://yumrepo-public.library.northwestern.edu/x86_64/rubygem-json-1.6.8-1.el6.x86_64.rpm
http://yum.theforeman.org/releases/latest/el6/x86_64/rubygems-1.8.10-1.el6.noarch.rpm

把下载下来的文件cp到/var/www/cobbler/repo_mirror/CentOS6.4-x86_64/Packages里并执行以下命令更新

createrepo -g comps.xml --update .


编写ks文件

cd /var/lib/cobbler/kickstarts
vim centos6.ks #可根据自己需要进行设置


由于服务器配置和用途不同,本例中共创建了三种ks文件:

dell服务器物理机:CentOS6.4-x86_64_Dell-Server
超微服务器物理机虚拟化:CentOS6.4-x86_64_Virtualization
超微服务器2U4物理机:CentOS6.4-x86_64_Virtualization
虚拟机:CentOS6.4-x86_64_VM-Server

创建方法

cobbler profile add --name CentOS6.4-x86_64 --distro'CentOS6.4-x86_64' --kickstart/var/lib/cobbler/kickstarts/centos6.ks --repo'CentOS6.4-x86_64 puppetlabs'


cobbler sync

依次创建profile

完成后检测
   [root@cobbler ~]# cobbler profile list
   CentOS6.4-x86_64
   CentOS6.4-x86_64_Dell-Server
   CentOS6.4-x86_64_VM-Server
   CentOS6.4-x86_64_Virtualization
   
OK!可以装系统啦!
安装时如果提示unable down load the kickstart file ..............
请检查一下ks文件,把没用的都删掉,再 cobbler sync


首次安装操作系统
1、 将需要安装系统的服务器,以下简称客户端,放到和cobbler服务端同样的子网中。

2、 启动cobbler服务端上的cobblerd等相关服务。

3、 从PXE启动客户端主机。

(1) 客户端寻找设置DHCP。

(2) 客户端从PXE启动。

(3) 客户端进入cobbler profile选择界面,用户可以根据应用的不同,选择不同的cobbler配置文件。

 指定主机名和ip配置方法 


想办法扫描到准备安装系统主机的mac地址

在/etc/dhcp/dhcpd.conf文件中添加以下内容:
注:添加完不要执行cobbler sync,因为之前配置中dhcpd服务是由cobbler来控制的,直接重启dhcpd服务就可以了。

host cobbler-test01 {
option host-name "cobbler-test01";
hardware ethernet 08:00:27:74:1B:50;
fixed-address 192.168.60.61;
}

host cobbler-test02 {
option host-name "cobbler-test02";
hardware ethernet 08:00:27:5B:0A:BD;
fixed-address 192.168.60.62;
}


 koan使用方法 

system是对待安装机器做具体设置,如设置主机名、IP地址、hostname等,这些设置根据MAC应用到具体机器上。

下面是几个添加删除修改system的例子:

添加system配置,配置文件名称:web-server01,机器IP地址192.168.60.65,机器MAC地址:08:00:27:74:1B:50,使用配置文件名称:web-server01,kickstart文件为:/var/lib/cobbler/kickstarts/centos6.ks

cobbler system add --nameweb-server01 --ip-address192.168.60.65 --mac08:00:27:74:1B:50 --profileCentOS6.4-x86_64 --kickstart/var/lib/cobbler/kickstarts/centos6.ks


修改system配置,配置文件名称:webserver1,机器IP地址由192.168.60.65变更为192.168.60.65

cobbler system edit --nameweb-server01 --ip-address192.168.60.66

变更system配置名称,名称由web-server01变更成db-server01

cobbler system rename --nameweb-server01 --newnamedb-server01

删除system配置,需要删除的profile名称为dberver1

cobbler system remove --namedbserver1


重新安装服务器的操作系统

在客户端上安装koan

yum install koan

查看cobbler server上的配置文件

koan --server192.168.60.1 --listprofiles

重新安装客户端系统

koan --replace-self --server192.168.0.2 --profilewebserver1

reboot重启服务器后,客户端服务器会自动重新安装操作系统


 ks文件记录 
 dell服务器物理机 
CentOS6.4-x86_64_Dell-Server

#platformx86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --enablemd5
# System bootloader configuration
bootloader --locationmbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --disable
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang zh_CN
# Use network installation
#url --url$tree
url --urlhttp://192.168.199.1/cobbler/links/CentOS6.4-x86_64
#url --proxy$http_server:3128 --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
user skstsuperadmin --name "skstsuperadmin" --iscrypted --password $default_password_crypted
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
#timezone  America/New_York
timezone  Asia/Shanghai
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
#autopart

clearpart --all --initlabel
part /boot --fstype"ext4" --asprimary --size200
part swap --fstype"swap" --size4096
#part /nova-volume --fstype"ext4" --size200000
part / --fstype"ext4" --size100000
part /data --fstype"ext4" --grow --size1




%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')

%packages
$SNIPPET('func_install_if_enabled')
$SNIPPET('puppet_install_if_enabled')
@base
@chinese-support
@console-internet
@legacy-unix
@system-admin-tools
ftp
telnet
tree
puppet

%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('puppet_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')

### Sync Time ###

# Start final steps
$SNIPPET('kickstart_done')
# End final steps

echo "ulimit -SHn 65535" >> /etc/rc.local
echo -e "*    soft   nofile       65535\n*    hard   nofile       65535" >> /etc/security/limits.conf
sed -i 's#exec /sbin/shutdown -r now#\#exec /sbin/shutdown -r now#' /etc/init/control-alt-delete.conf

sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
sed -i 's/#Port 22/Port 6022/g' /etc/ssh/sshd_config
sed -i 's/#PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config

echo "net.ipv4.tcp_fin_timeout  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_keepalive_time  1200" >> /etc/sysctl.conf
echo "net.ipv4.tcp_mem  94500000 915000000 927000000" >> /etc/sysctl.conf
echo "net.ipv4.tcp_tw_reuse  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_timestamps  0" >> /etc/sysctl.conf
echo "net.ipv4.tcp_synack_retries  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_syn_retries  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_tw_recycle  1" >> /etc/sysctl.conf
echo "net.core.rmem_max  16777216" >> /etc/sysctl.conf
echo "net.core.wmem_max  16777216" >> /etc/sysctl.conf
echo "netdev_max_backlog  262144" >> /etc/sysctl.conf
echo "net.core.somaxconn  262144" >> /etc/sysctl.conf
echo "net.ipv4.tcp_max_orphans  3276800" >> /etc/sysctl.conf
echo "net.ipv4.tcp_max_syn_backlog  262144" >> /etc/sysctl.conf
echo "net.core.wmem_default  8388608" >> /etc/sysctl.conf
echo "net.core.rmem_default  8388608" >> /etc/sysctl.conf

echo -e "alias net-pf-10 off\noptions ipv6 disable1" >> /etc/security/limits.conf
echo "NETWORKING_IPV6off" >> /etc/sysconfig/network

eth0_config'/etc/sysconfig/network-scripts/ifcfg-em1'
ip`/sbin/ifconfig em1 |grep 'inet addr'|awk -F ' *|:' '{print $4}'`
mask`/sbin/ifconfig em1 |grep 'inet addr'|awk -F ' *|:' '{print $8}'`
gateway`netstat -r | grep 'default' | awk '{ print $2}'`
sed -i 's/dhcp/static/g' $eth0_config
sed -i 's/ONBOOTno/ONBOOTyes/g' $eth0_config

echo IPADDR`/sbin/ifconfig eth0 |grep 'inet addr'|awk -F ' *|:' '{print $4}'` >> $eth0_config
echo NETMASK`/sbin/ifconfig eth0 |grep 'inet addr'|awk -F ' *|:' '{print $8}'` >> $eth0_config
echo GATEWAY'192.168.199.1' >> $eth0_config

 dell服务器物理机虚拟化 
CentOS6.4-x86_64_Dell_Virtualization

#platformx86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --enablemd5
# System bootloader configuration
bootloader --locationmbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --disable
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang zh_CN
# Use network installation
#url --url$tree
url --urlhttp://192.168.199.1/cobbler/links/CentOS6.4-x86_64
#url --proxy$http_server:3128 --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
user skstsuperadmin --name "skstsuperadmin" --iscrypted --password $default_password_crypted
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
#timezone  America/New_York
timezone  Asia/Shanghai
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
#autopart

clearpart --all --initlabel
part /boot --fstype"ext4" --asprimary --size200
part swap --fstype"swap" --size4096
#part /nova-volume --fstype"ext4" --size200000
part / --fstype"ext4" --size50000
part /data --fstype"ext4" --grow --size1




%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')

%packages
$SNIPPET('func_install_if_enabled')
$SNIPPET('puppet_install_if_enabled')
@base
@chinese-support
@console-internet
@legacy-unix
@system-admin-tools
@virtualization
@virtualization-client
@virtualization-platform
@virtualization-tools
ftp
telnet
tree
puppet

%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('puppet_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')

### Sync Time ###

# Start final steps
$SNIPPET('kickstart_done')
# End final steps

echo "ulimit -SHn 65535" >> /etc/rc.local
echo -e "*    soft   nofile       65535\n*    hard   nofile       65535" >> /etc/security/limits.conf
sed -i 's#exec /sbin/shutdown -r now#\#exec /sbin/shutdown -r now#' /etc/init/control-alt-delete.conf

sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
sed -i 's/#Port 22/Port 6022/g' /etc/ssh/sshd_config
sed -i 's/#PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config

echo "net.ipv4.tcp_fin_timeout  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_keepalive_time  1200" >> /etc/sysctl.conf
echo "net.ipv4.tcp_mem  94500000 915000000 927000000" >> /etc/sysctl.conf
echo "net.ipv4.tcp_tw_reuse  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_timestamps  0" >> /etc/sysctl.conf
echo "net.ipv4.tcp_synack_retries  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_syn_retries  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_tw_recycle  1" >> /etc/sysctl.conf
echo "net.core.rmem_max  16777216" >> /etc/sysctl.conf
echo "net.core.wmem_max  16777216" >> /etc/sysctl.conf
echo "netdev_max_backlog  262144" >> /etc/sysctl.conf
echo "net.core.somaxconn  262144" >> /etc/sysctl.conf
echo "net.ipv4.tcp_max_orphans  3276800" >> /etc/sysctl.conf
echo "net.ipv4.tcp_max_syn_backlog  262144" >> /etc/sysctl.conf
echo "net.core.wmem_default  8388608" >> /etc/sysctl.conf
echo "net.core.rmem_default  8388608" >> /etc/sysctl.conf

echo -e "alias net-pf-10 off\noptions ipv6 disable1" >> /etc/security/limits.conf
echo "NETWORKING_IPV6off" >> /etc/sysconfig/network

eth0_config'/etc/sysconfig/network-scripts/ifcfg-em1'
ip`/sbin/ifconfig em1 |grep 'inet addr'|awk -F ' *|:' '{print $4}'`
mask`/sbin/ifconfig em1 |grep 'inet addr'|awk -F ' *|:' '{print $8}'`
gateway`netstat -r | grep 'default' | awk '{ print $2}'`
sed -i 's/dhcp/static/g' $eth0_config
sed -i 's/ONBOOTno/ONBOOTyes/g' $eth0_config

echo IPADDR`/sbin/ifconfig eth0 |grep 'inet addr'|awk -F ' *|:' '{print $4}'` >> $eth0_config
echo NETMASK`/sbin/ifconfig eth0 |grep 'inet addr'|awk -F ' *|:' '{print $8}'` >> $eth0_config
echo GATEWAY'192.168.199.1' >> $eth0_config

超微服务器(3U8)物理机虚拟化 
CentOS6.4-x86_64_Virtualization

#platformx86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --enablemd5
# System bootloader configuration
bootloader --locationmbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --disable
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang zh_CN
# Use network installation
#url --url$tree
url --urlhttp://192.168.199.1/cobbler/links/CentOS6.4-x86_64
#url --proxy$http_server:3128 --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
user skstsuperadmin --name "skstsuperadmin" --iscrypted --password $default_password_crypted
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
#timezone  America/New_York
timezone  Asia/Shanghai
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
#autopart

clearpart --all --initlabel
part /boot --fstype"ext4" --asprimary --size200
part swap --fstype"swap" --size4096
part / --fstype"ext4" --size50000
part /var --fstype"ext4" --grow --size1



%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')

%packages
$SNIPPET('func_install_if_enabled')
$SNIPPET('puppet_install_if_enabled')
@base
@chinese-support
@console-internet
@legacy-unix
@system-admin-tools
@virtualization
@virtualization-client
@virtualization-platform
@virtualization-tools
ftp
telnet
tree
salt-minion
puppet

%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('puppet_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')

### Sync Time ###

# Start final steps
$SNIPPET('kickstart_done')
# End final steps

echo "ulimit -SHn 65535" >> /etc/rc.local
echo -e "*    soft   nofile       65535\n*    hard   nofile       65535" >> /etc/security/limits.conf
sed -i 's#exec /sbin/shutdown -r now#\#exec /sbin/shutdown -r now#' /etc/init/control-alt-delete.conf

sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
sed -i 's/#Port 22/Port 6022/g' /etc/ssh/sshd_config
sed -i 's/#PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config

echo "net.ipv4.tcp_fin_timeout  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_keepalive_time  1200" >> /etc/sysctl.conf
echo "net.ipv4.tcp_mem  94500000 915000000 927000000" >> /etc/sysctl.conf
echo "net.ipv4.tcp_tw_reuse  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_timestamps  0" >> /etc/sysctl.conf
echo "net.ipv4.tcp_synack_retries  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_syn_retries  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_tw_recycle  1" >> /etc/sysctl.conf
echo "net.core.rmem_max  16777216" >> /etc/sysctl.conf
echo "net.core.wmem_max  16777216" >> /etc/sysctl.conf
echo "netdev_max_backlog  262144" >> /etc/sysctl.conf
echo "net.core.somaxconn  262144" >> /etc/sysctl.conf
echo "net.ipv4.tcp_max_orphans  3276800" >> /etc/sysctl.conf
echo "net.ipv4.tcp_max_syn_backlog  262144" >> /etc/sysctl.conf
echo "net.core.wmem_default  8388608" >> /etc/sysctl.conf
echo "net.core.rmem_default  8388608" >> /etc/sysctl.conf

echo -e "alias net-pf-10 off\noptions ipv6 disable1" >> /etc/security/limits.conf
echo "NETWORKING_IPV6off" >> /etc/sysconfig/network

eth0_config'/etc/sysconfig/network-scripts/ifcfg-eth0'
ip`/sbin/ifconfig eth0 |grep 'inet addr'|awk -F ' *|:' '{print $4}'`
mask`/sbin/ifconfig eth0 |grep 'inet addr'|awk -F ' *|:' '{print $8}'`
gateway`netstat -r | grep 'default' | awk '{ print $2}'`
sed -i 's/dhcp/static/g' $eth0_config
sed -i 's/ONBOOTno/ONBOOTyes/g' $eth0_config

echo IPADDR`/sbin/ifconfig eth0 |grep 'inet addr'|awk -F ' *|:' '{print $4}'` >> $eth0_config
echo NETMASK`/sbin/ifconfig eth0 |grep 'inet addr'|awk -F ' *|:' '{print $8}'` >> $eth0_config

超微服务器2U4物理机 
CentOS6.4-x86_64_Supermicr-2U4

#platformx86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --enablemd5
# System bootloader configuration
bootloader --locationmbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --disable
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang zh_CN
# Use network installation
#url --url$tree
url --urlhttp://192.168.199.1/cobbler/links/CentOS6.4-x86_64
#url --proxy$http_server:3128 --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
user skstsuperadmin --name "skstsuperadmin" --iscrypted --password $default_password_crypted
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
#timezone  America/New_York
timezone  Asia/Shanghai
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
#autopart

clearpart --all --initlabel
part /boot --fstype"ext4" --asprimary --size200
part swap --fstype"swap" --size4096
part / --fstype"ext4" --size100000
part /data --fstype"ext4" --grow --size1



%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')

%packages
$SNIPPET('func_install_if_enabled')
$SNIPPET('puppet_install_if_enabled')
@base
@chinese-support
@console-internet
@legacy-unix
@system-admin-tools
ftp
telnet
tree
puppet

%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('puppet_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')

### Sync Time ###

# Start final steps
$SNIPPET('kickstart_done')
# End final steps

echo "ulimit -SHn 65535" >> /etc/rc.local
echo -e "*    soft   nofile       65535\n*    hard   nofile       65535" >> /etc/security/limits.conf
sed -i 's#exec /sbin/shutdown -r now#\#exec /sbin/shutdown -r now#' /etc/init/control-alt-delete.conf

sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
sed -i 's/#Port 22/Port 6022/g' /etc/ssh/sshd_config
sed -i 's/#PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config

echo "net.ipv4.tcp_fin_timeout  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_keepalive_time  1200" >> /etc/sysctl.conf
echo "net.ipv4.tcp_mem  94500000 915000000 927000000" >> /etc/sysctl.conf
echo "net.ipv4.tcp_tw_reuse  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_timestamps  0" >> /etc/sysctl.conf
echo "net.ipv4.tcp_synack_retries  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_syn_retries  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_tw_recycle  1" >> /etc/sysctl.conf
echo "net.core.rmem_max  16777216" >> /etc/sysctl.conf
echo "net.core.wmem_max  16777216" >> /etc/sysctl.conf
echo "netdev_max_backlog  262144" >> /etc/sysctl.conf
echo "net.core.somaxconn  262144" >> /etc/sysctl.conf
echo "net.ipv4.tcp_max_orphans  3276800" >> /etc/sysctl.conf
echo "net.ipv4.tcp_max_syn_backlog  262144" >> /etc/sysctl.conf
echo "net.core.wmem_default  8388608" >> /etc/sysctl.conf
echo "net.core.rmem_default  8388608" >> /etc/sysctl.conf

echo -e "alias net-pf-10 off\noptions ipv6 disable1" >> /etc/security/limits.conf
echo "NETWORKING_IPV6off" >> /etc/sysconfig/network

eth0_config'/etc/sysconfig/network-scripts/ifcfg-eth0'
ip`/sbin/ifconfig eth0 |grep 'inet addr'|awk -F ' *|:' '{print $4}'`
mask`/sbin/ifconfig eth0 |grep 'inet addr'|awk -F ' *|:' '{print $8}'`
gateway`netstat -r | grep 'default' | awk '{ print $2}'`
sed -i 's/dhcp/static/g' $eth0_config
sed -i 's/ONBOOTno/ONBOOTyes/g' $eth0_config

echo IPADDR`/sbin/ifconfig eth0 |grep 'inet addr'|awk -F ' *|:' '{print $4}'` >> $eth0_config
echo NETMASK`/sbin/ifconfig eth0 |grep 'inet addr'|awk -F ' *|:' '{print $8}'` >> $eth0_config
echo "192.168.199.199 puppet" >> /etc/hosts
chkconfig puppet on
service puppet start


虚拟机 
CentOS6.4-x86_64_VM-Server

#platformx86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --enablemd5
# System bootloader configuration
bootloader --locationmbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --disable
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang zh_CN
# Use network installation
#url --url$tree
url --urlhttp://192.168.199.1/cobbler/links/CentOS6.4-x86_64
#url --proxy$http_server:3128 --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
user skstsuperadmin --name "skstsuperadmin" --iscrypted --password $default_password_crypted
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
#timezone  America/New_York
timezone  Asia/Shanghai
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
#autopart

clearpart --all --initlabel
part /boot --fstype"ext4" --asprimary --size200
part swap --fstype"swap" --size4096
#part /nova-volume --fstype"ext4" --size200000
#part / --fstype"ext4" --size50000
part / --fstype"ext4" --grow --size1




%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')

%packages
$SNIPPET('func_install_if_enabled')
$SNIPPET('puppet_install_if_enabled')
@base
@chinese-support
@console-internet
@legacy-unix
@system-admin-tools
ftp
telnet
tree
puppet

%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('puppet_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')

### Sync Time ###

# Start final steps
$SNIPPET('kickstart_done')
# End final steps

echo "ulimit -SHn 65535" >> /etc/rc.local
echo -e "*    soft   nofile       65535\n*    hard   nofile       65535" >> /etc/security/limits.conf
sed -i 's#exec /sbin/shutdown -r now#\#exec /sbin/shutdown -r now#' /etc/init/control-alt-delete.conf

sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
sed -i 's/#Port 22/Port 6022/g' /etc/ssh/sshd_config
sed -i 's/#PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config

echo "net.ipv4.tcp_fin_timeout  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_keepalive_time  1200" >> /etc/sysctl.conf
echo "net.ipv4.tcp_mem  94500000 915000000 927000000" >> /etc/sysctl.conf
echo "net.ipv4.tcp_tw_reuse  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_timestamps  0" >> /etc/sysctl.conf
echo "net.ipv4.tcp_synack_retries  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_syn_retries  1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_tw_recycle  1" >> /etc/sysctl.conf
echo "net.core.rmem_max  16777216" >> /etc/sysctl.conf
echo "net.core.wmem_max  16777216" >> /etc/sysctl.conf
echo "netdev_max_backlog  262144" >> /etc/sysctl.conf
echo "net.core.somaxconn  262144" >> /etc/sysctl.conf
echo "net.ipv4.tcp_max_orphans  3276800" >> /etc/sysctl.conf
echo "net.ipv4.tcp_max_syn_backlog  262144" >> /etc/sysctl.conf
echo "net.core.wmem_default  8388608" >> /etc/sysctl.conf
echo "net.core.rmem_default  8388608" >> /etc/sysctl.conf

echo -e "alias net-pf-10 off\noptions ipv6 disable1" >> /etc/security/limits.conf
echo "NETWORKING_IPV6off" >> /etc/sysconfig/network

eth0_config'/etc/sysconfig/network-scripts/ifcfg-eth0'
ip`/sbin/ifconfig eth0 |grep 'inet addr'|awk -F ' *|:' '{print $4}'`
mask`/sbin/ifconfig eth0 |grep 'inet addr'|awk -F ' *|:' '{print $8}'`
gateway`netstat -r | grep 'default' | awk '{ print $2}'`
sed -i 's/dhcp/static/g' $eth0_config
sed -i 's/ONBOOTno/ONBOOTyes/g' $eth0_config

echo IPADDR`/sbin/ifconfig eth0 |grep 'inet addr'|awk -F ' *|:' '{print $4}'` >> $eth0_config
echo NETMASK`/sbin/ifconfig eth0 |grep 'inet addr'|awk -F ' *|:' '{print $8}'` >> $eth0_config
echo GATEWAY'192.168.199.1' >> $eth0_config

 安装实战(超微3U8) 
列出3U8服务器宿主机和虚拟机ip分配

^服务器类型^宿主机名^主机名^虚拟机^
|3U8|apphost-05-zhaowei-bj|apphost-chinacache-bj-199.107|app-chinacache-bj-199.49|
|:::|:::|:::|app-chinacache-bj-199.64|
|:::|:::|:::|app-chinacache-bj-199.68|
|:::|:::|:::|app-chinacache-bj-199.70|
|:::|:::|apphost-chinacache-bj-199.108|app-chinacache-bj-199.71|
|:::|:::|:::|app-chinacache-bj-199.72|
|:::|:::|:::|app-chinacache-bj-199.73|
|:::|:::|:::|app-chinacache-bj-199.74|
|:::|:::|apphost-chinacache-bj-199.109|app-chinacache-bj-199.75|
|:::|:::|:::|app-chinacache-bj-199.76|
|:::|:::|:::|app-chinacache-bj-199.77|
|:::|:::|:::|app-chinacache-bj-199.78|
|:::|:::|apphost-chinacache-bj-199.110|app-chinacache-bj-199.79|
|:::|:::|:::|app-chinacache-bj-199.91|
|:::|:::|:::|app-chinacache-bj-199.92|
|:::|:::|:::|app-chinacache-bj-199.93|
|:::|:::|apphost-chinacache-bj-199.111|app-chinacache-bj-199.94|
|:::|:::|:::|app-chinacache-bj-199.95|
|:::|:::|:::|app-chinacache-bj-199.96|
|:::|:::|:::|app-chinacache-bj-199.97|
|:::|:::|apphost-chinacache-bj-199.112|app-chinacache-bj-199.98|
|:::|:::|:::|app-chinacache-bj-199.99|
|:::|:::|:::|app-chinacache-bj-199.100|
|:::|:::|:::|app-chinacache-bj-199.101|
|:::|:::|apphost-chinacache-bj-199.113|app-chinacache-bj-199.102|
|:::|:::|:::|app-chinacache-bj-199.103|
|:::|:::|:::|app-chinacache-bj-199.104|
|:::|:::|:::|app-chinacache-bj-199.105|
|:::|:::|apphost-chinacache-bj-199.114|app-chinacache-bj-199.106|
|:::|:::|:::|app-chinacache-bj-199.124|
|:::|:::|:::|app-chinacache-bj-199.125|
|:::|:::|:::|app-chinacache-bj-199.126|
|3U8|apphost-06-zhaowei-bj|apphost-chinacache-bj-199.115|app-chinacache-bj-199.30|
|:::|:::|:::|app-chinacache-bj-199.31|
|:::|:::|apphost-chinacache-bj-199.116|app-chinacache-bj-199.32|
|:::|:::|:::|app-chinacache-bj-199.34|
|:::|:::|apphost-chinacache-bj-199.117|app-chinacache-bj-199.35|
|:::|:::|:::|app-chinacache-bj-199.36|
|:::|:::|apphost-chinacache-bj-199.118|app-chinacache-bj-199.38|
|:::|:::|:::|app-chinacache-bj-199.39|
|:::|:::|apphost-chinacache-bj-199.119|app-chinacache-bj-199.41|
|:::|:::|:::|app-chinacache-bj-199.42|
|:::|:::|apphost-chinacache-bj-199.121|app-chinacache-bj-199.43|
|:::|:::|:::|app-chinacache-bj-199.44|
|:::|:::|apphost-chinacache-bj-199.122|app-chinacache-bj-199.45|
|:::|:::|:::|app-chinacache-bj-199.46|
|:::|:::|apphost-chinacache-bj-199.123|app-chinacache-bj-199.47|
|:::|:::|:::|app-chinacache-bj-199.48|
生成虚拟机mac地址 
登录cobbler服务器(192.168.199.1)的/root/sh目录下
将虚拟机主机列表提出至文件\\
hostname.txt
  app-chinacache-bj-199-49
  app-chinacache-bj-199-64
  app-chinacache-bj-199-68
建立主机名、ip、mac地址对应列表,执行以下脚本
  sh create_vmlist.sh #会生成vmlist文件
create_vmlist.sh

#!/bin/bash
while read line
do
echo $line > /tmp/iptmp
ipt`awk -F'-' '{print $NF}' /tmp/iptmp`
mac`python create_mac.py`
echo "$line.chosk.net|192.168.199.$ipt|$mac" >> vmlist
done < hostname.txt

vmlist文件内容如下

^主机名^ip^mac地址^
|app-chinacache-bj-199-49.chosk.net|192.168.199.49|00:16:3e:04:fb:de|
|app-chinacache-bj-199-64.chosk.net|192.168.199.64|00:16:3e:69:a1:cd|
|app-chinacache-bj-199-68.chosk.net|192.168.199.68|00:16:3e:08:1e:b6|
|app-chinacache-bj-199-70.chosk.net|192.168.199.70|00:16:3e:68:af:53|
|app-chinacache-bj-199-71.chosk.net|192.168.199.71|00:16:3e:0a:37:28|
|app-chinacache-bj-199-72.chosk.net|192.168.199.72|00:16:3e:49:9c:41|
|app-chinacache-bj-199-73.chosk.net|192.168.199.73|00:16:3e:47:a0:30|
|app-chinacache-bj-199-74.chosk.net|192.168.199.74|00:16:3e:73:bd:b4|
|app-chinacache-bj-199-75.chosk.net|192.168.199.75|00:16:3e:7f:04:e5|
|app-chinacache-bj-199-76.chosk.net|192.168.199.76|00:16:3e:48:dd:2d|
|app-chinacache-bj-199-77.chosk.net|192.168.199.77|00:16:3e:7e:53:3f|
|app-chinacache-bj-199-78.chosk.net|192.168.199.78|00:16:3e:3b:32:52|
|app-chinacache-bj-199-79.chosk.net|192.168.199.79|00:16:3e:65:4c:e2|
|app-chinacache-bj-199-91.chosk.net|192.168.199.91|00:16:3e:06:06:8f|
|app-chinacache-bj-199-92.chosk.net|192.168.199.92|00:16:3e:46:73:49|
|app-chinacache-bj-199-93.chosk.net|192.168.199.93|00:16:3e:3f:8c:ec|
|app-chinacache-bj-199-94.chosk.net|192.168.199.94|00:16:3e:6c:61:21|
|app-chinacache-bj-199-95.chosk.net|192.168.199.95|00:16:3e:4a:24:54|
|app-chinacache-bj-199-96.chosk.net|192.168.199.96|00:16:3e:7f:23:98|
|app-chinacache-bj-199-97.chosk.net|192.168.199.97|00:16:3e:72:6f:e8|
|app-chinacache-bj-199-98.chosk.net|192.168.199.98|00:16:3e:20:ca:9e|
|app-chinacache-bj-199-99.chosk.net|192.168.199.99|00:16:3e:72:a1:80|
|app-chinacache-bj-199-100.chosk.net|192.168.199.100|00:16:3e:64:22:c6|
|app-chinacache-bj-199-101.chosk.net|192.168.199.101|00:16:3e:61:32:93|
|app-chinacache-bj-199-102.chosk.net|192.168.199.102|00:16:3e:06:a9:11|
|app-chinacache-bj-199-103.chosk.net|192.168.199.103|00:16:3e:0f:b1:e9|
|app-chinacache-bj-199-104.chosk.net|192.168.199.104|00:16:3e:15:06:6a|
|app-chinacache-bj-199-105.chosk.net|192.168.199.105|00:16:3e:44:68:3f|
|app-chinacache-bj-199-106.chosk.net|192.168.199.106|00:16:3e:24:02:36|
|app-chinacache-bj-199-124.chosk.net|192.168.199.124|00:16:3e:11:3d:51|
|app-chinacache-bj-199-125.chosk.net|192.168.199.125|00:16:3e:03:06:2b|
|app-chinacache-bj-199-126.chosk.net|192.168.199.126|00:16:3e:42:a0:b0|
|app-chinacache-bj-199-30.chosk.net|192.168.199.30|00:16:3e:06:c8:d8|
|app-chinacache-bj-199-31.chosk.net|192.168.199.31|00:16:3e:21:75:e6|
|app-chinacache-bj-199-32.chosk.net|192.168.199.32|00:16:3e:0a:bd:f2|
|app-chinacache-bj-199-34.chosk.net|192.168.199.34|00:16:3e:46:21:50|
|app-chinacache-bj-199-35.chosk.net|192.168.199.35|00:16:3e:7e:60:77|
|app-chinacache-bj-199-36.chosk.net|192.168.199.36|00:16:3e:7c:cd:a7|
|app-chinacache-bj-199-38.chosk.net|192.168.199.38|00:16:3e:7a:a1:4c|
|app-chinacache-bj-199-39.chosk.net|192.168.199.39|00:16:3e:0c:f3:1e|
|app-chinacache-bj-199-41.chosk.net|192.168.199.41|00:16:3e:39:b9:f8|
|app-chinacache-bj-199-42.chosk.net|192.168.199.42|00:16:3e:6c:6d:24|
|app-chinacache-bj-199-43.chosk.net|192.168.199.43|00:16:3e:47:68:8a|
|app-chinacache-bj-199-44.chosk.net|192.168.199.44|00:16:3e:00:01:42|
|app-chinacache-bj-199-45.chosk.net|192.168.199.45|00:16:3e:15:ee:62|
|app-chinacache-bj-199-46.chosk.net|192.168.199.46|00:16:3e:24:f6:e6|
|app-chinacache-bj-199-47.chosk.net|192.168.199.47|00:16:3e:35:3f:a7|
|app-chinacache-bj-199-48.chosk.net|192.168.199.48|00:16:3e:71:99:dd|

将指定的主机名、ip和mac地址的对应关系添加到dhcpd的配置文件中
执行set_host_ip.sh

while read line
do
echo $line > /tmp/vm
hostname`awk -F'|' '{print $2}' /tmp/vm`
ipadd`awk -F'|' '{print $3}' /tmp/vm`
mac`awk -F'|' '{print $4}' /tmp/vm`
echo "host $hostname {" >> /etc/dhcp/dhcpd.conf
echo "option host-name \"$hostname\";" >> /etc/dhcp/dhcpd.conf
echo "fixed-address $ipadd;" >> /etc/dhcp/dhcpd.conf
echo "hardware ethernet $mac;" >> /etc/dhcp/dhcpd.conf
echo "}" >> /etc/dhcp/dhcpd.conf
done < vmlist
/etc/init.d/dhcpd restart

 安装虚拟机方法 
以安装192.168.199.117的虚拟机为例
  wget http://192.168.199.1/briage.sh
  sh briage.sh 117 #建立网桥br0,修改主机名、ip等信息
briage.sh

#!/bin/bash
ip$1
sed -i "s/localhost.localdomain/apphost-chinacache-bj-199-$ip.chosk.net/g" /etc/sysconfig/network
hostname apphost-chinacache-bj-199-$ip.chosk.net
echo 192.168.199.$ip apphost-chinacache-bj-199-$ip.chosk.net >> /etc/hosts
echo BRIDGEbr0 >> /etc/sysconfig/network-scripts/ifcfg-eth0

cat >> /etc/sysconfig/network-scripts/ifcfg-br0 << EOF
DEVICEbr0
BOOTPROTOnone
BROADCAST192.168.199.255
IPADDR192.168.199.$ip
NETMASK255.255.255.0
ONBOOTyes
GATEWAY192.168.199.1
USERCTLno
IPV6INITno
PEERDNSyes
#bridgebr0
TYPEBridge
EOF
service network restart

此时会重启网卡,重新连接修改后的ip地址,执行以下脚本
  wget http://192.168.199.1/create-vm.sh

#!/bin/bash

grep $1.chosk.net vmlist > /tmp/hostip 
mac`awk -F'|' '{print $4}' /tmp/hostip`

qemu-img create -f qcow2 /var/lib/libvirt/images/app-chinacache-bj-199-$1.chosk.net.img 80G
virt-install --name app-chinacache-bj-199.$1.chosk.net --ram 4096 --vcpus2 --pxe --disk path/var/lib/libvirt/images/app-chinacache-bj-199-$1.chosk.net.img --network bridgebr0 -m $mac --hvm --noautoconsole --debug

  wget http://192.168.199.1/vmlist
  sh create-vm.sh 35
  sh create-vm.sh 36
进入virt-manager进行选择安装操作系统
posted @ 2015-06-19 22:09  shantuwqk  阅读(365)  评论(0编辑  收藏  举报