最近机房要上线几个机柜的机器,必须实现自动化装机。

一、安装

系统环境是centos6.4,采用yum安装:

rpm -Uvh http://mirrors.hustunique.com/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum -y install cobbler  cobbler-web  httpd rsync tftp-server xinetd dhcp python-ctypes debmirror pykickstart

二、配置

1、关闭防火墙和SELinux 后重启系统:

/etc/init.d/iptables stop         #关闭防火墙
chkconfig iptables off
sed -i '/SELINUX=/d' /etc/selinux/config &&  echo "SELINUX=disabled">> /etc/selinux/config  #关闭SELINUX

2、修改cobbler配置文件:

'next_server: 127.0.0.1' 替换成 'next_server:172.28.26.188'    #DHCP服务地址
'server: 127.0.0.1' 替换成 'server: 172.28.26.188'   #cobbler服务地址
'manage_dhcp: 0' 替换成 'manage_dhcp: 1'      #cobbler管理dhcp
'manage_rsync: 0' 替换成 'manage_rsync: 1'     #cobbler管理rsync功能
default_password_crypted: "$1$cobber$yV9XfOuaaiVDvImopK7o.1"  
sed -i 's/next_server: 127.0.0.1/next_server: 172.28.26.188/g' /etc/cobbler/settings
sed -i 's/server: 127.0.0.1/server: 172.28.26.188/g' /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
sed -i 's/http_port: 80/http_port: 9080/g' /etc/cobbler/settings

openssl passwd -1 -salt "cobber" "123456 #把生成的密码填到/etc/cobbler/settings配置里default_password_crypted:生成的新密码,这个密码就是装完系统后的root密码。

3、修改tftp服务和rsync服务配置 :

sed -i '/disable/c disable = no' /etc/xinetd.d/tftp    #设置 'disable' 为 'no'
sed -i -e 's/= yes/= no/g' /etc/xinetd.d/rsync        #设置 'disable' 为 'no'

4、修改dhcp模板 :

subnet 192.168.66.0 netmask 255.255.255.0 {
     option routers             192.168.66.87;
     option domain-name-servers 202.106.0.20;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.66.100 192.168.66.102;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
     class "pxeclients" {
     .....

5、修改cobbler-web配置 

sed -i 's/module = authn_denyall/module = authn_configfile/g' /etc/cobbler/modules.conf   #修改认证
htdigest  /etc/cobbler/users.digest "Cobbler" cobbler  #修改cobbler WEB页面管理密码

6、启动相关的服务

/etc/init.d/httpd start
/etc/init.d/xinetd start
/etc/init.d/dhcpd start
/etc/init.d/cobblerd start
chkconfig --level 35 httpd on
chkconfig --level 35 xinetd on
chkconfig --level 35 dhcpd on
chkconfig --level 35 cobblerd on

7、效验cobbler安装条件:

service cobblerd restart
cobbler get-loaders       #修复cobbler check时出现的错误信息
cobbler check

三、导入镜配置:

1:使用光盘镜像
挂载ISO镜像到/mnt目录
mount -o loop /data/CentOS_6.4_vm.iso /mnt/
导入ISO,并设置为“x86_64”,并将其命名为Centos6.4
cobbler import --path=/mnt/   --name=CentOS_6.4  --arch=x86_64

2:挂载linux光盘:
mount /dev/cdrom /media/
cobbler import --path=/media/CentOS_6.4_Final --name=Centos6.4
查看导入结果
cobbler distro list
完成后同步所有配置
cobbler sync

这时,我们就可以访问cobbler的web界面了:

cobbler 安装部署_cobbler 自动化部署 linux系

cobbler 安装部署_cobbler 自动化部署 linux系_02



四、需要装系统的机器从网卡启动:

cobbler 安装部署_cobbler 自动化部署 linux系_03

cobbler 安装部署_cobbler 自动化部署 linux系_04

cobbler 安装部署_cobbler 自动化部署 linux系_05

ks.cfg:

#set $swap= $getVar('$swap', '2000')
autostep --autoscreenshot
install
url --url=$tree
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
text
skipx
lang en_US.UTF-8
keyboard us
network --onboot yes --bootproto dhcp --noipv6 --nodns
#rootpw  --iscrypted \$6\$Qz7FvhTWfC2yTdb1\$qNF1o.fpE44l/F1ROzJ.bXRKeB4OVQ.maYCY3tMZKDS7tDLrHthIAREXZFvW1G08tOqptkLMxfvyW4wA.vPOz1
rootpw 123456
firewall --disabled
firstboot --disabled
authconfig --enableshadow --passalgo=sha512
selinux --disabled
#timezone --isUtc Asia/Shanghai
timezone --utc Asia/Shanghai
# 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
logging --level=info
#bootloader --append="nohz=off" --location=mbr
bootloader --location=mbr --driveorder=sda --append="biosdevname=0 nohz=off thash_entries=1048576 rhash_entries=1048576 selinux=0"
zerombr yes
# clearpart --all --initlabel --drives=sda
clearpart --all --initlabel
# ignoredisk --only-use=sda
part / --fstype=ext4 --asprimary --size=1 --grow --label=/
part swap --asprimary --size=$swap --maxsize=2000 --label=2000
%pre
$SNIPPET('pre_install_network_config')
# Add Pre-Installation Script here
date
%end
%packages --excludedocs --ignoremissing
@base
@core
@development
@server-policy
ftp
nc
telnet
cmake
compat-gcc-34
compat-gcc-34-c++
sgpio
libXtst
#yum-plugin-priorities
koan
openssl
tengine
-lvm2
-acpid
-biosdevname
-hunspell-en
-abrt-cli
-man-pages-overrides
-blktrace
-words
-abrt-addon-kerneloops
-abrt-addon-ccpp
-bridge-utils
-nano
-mtr
-hunspell
-abrt-addon-python
-man-pages
-byacc
-indent
-diffstat
-doxygen
-intltool
-git
-ctags
-cscope
-iptables
-system-config-firewall-base
-iptables-ipv6
-system-config-firewall-tui
-subversion
%end
$SNIPPET('services_disable_enable')
%post
$SNIPPET('post_install_network_config')
$SNIPPET('env_init')
$SNIPPET('kis_cobbler_api')
$SNIPPET('cactirelease')
$SNIPPET('kisyum_install')
%post 
--interpreter /bin/sh
chkconfig NetworkManager off
chkconfig NetworkManagerDispatcher off
chkconfig acpid off
chkconfig anacron off
chkconfig atd off
chkconfig autofs off
chkconfig avahi-daemon off
chkconfig avahi-dnsconfd off
chkconfig bluetooth off
chkconfig conman off
chkconfig cups off
chkconfig dhcdbd off
chkconfig dund off
chkconfig firstboot off
chkconfig funcd on
chkconfig gpm off
chkconfig haldaemon off
chkconfig hidd off
chkconfig httpd off
chkconfig ibmasm off
chkconfig ip6tables off
chkconfig ipmi off
chkconfig iptables off
chkconfig irda off
chkconfig irqbalance off
chkconfig kdump off
chkconfig kudzu off
chkconfig lvm2-monitor off
chkconfig mcstrans off
chkconfig mdmpd off
chkconfig microcode_ctl off
chkconfig multipathd off
chkconfig netconsole off
chkconfig netfs off
chkconfig netplugd off
chkconfig nfs off
chkconfig nfslock off
chkconfig nscd off
chkconfig ntpd off
chkconfig oddjobd off
chkconfig pand off
chkconfig pcscd off
chkconfig portmap off
chkconfig psacct off
chkconfig rdisc off
chkconfig restorecond off
chkconfig rpcgssd off
chkconfig rpcidmapd off
chkconfig rpcsvcgssd off
chkconfig saslauthd off
chkconfig sendmail off
chkconfig setroubleshoot off
chkconfig winbind off
chkconfig wpa_supplicant off
chkconfig xfs off
chkconfig ypbind off
chkconfig yum-updatesd off
chkconfig rpcbind on
chkconfig snmpd on
# file descriptors
ulimit -HSn 65535
#sysctl
echo -ne "
* soft nofile 65536
* hard nofile 65536
" >>/etc/security/limits.conf
cat>>/etc/sysctl.conf<<eof
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.ip_local_port_range = 1024 65535
eof
/sbin/sysctl -p
cat >> /etc/hosts <<eof
192.168.1.200 front_baby_sqs
eof
#/usr/sbin/eject -rv /dev/sr* # eject P cdrom
echo 'v1.3' > ~root/VERSION
%end
# finish
reboot
重装系统:
rpm -ivh http://mirrors.zju.edu.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm
# 在要重装的机器安装koan  
yum install koan  
#查看cobbler服务器有哪些安装盘  
koan --list=profiles --server=192.168.66.87
#选择要重装的系统并重启  
koan --replace-self --server=192.168.66.87 --profile=Centos6.4-x86_64
#重启,便进入安装界面。
reboot