批量Linux 网络安装环境建立工具
网络安装服务器套件:
Cobbler(Red Hat 2008年发布的项目)
Kickstart(Red Hat08年前项目,相关脚本令人望而却步,现今应用渐移cobbler,在cobbler中仅遗骨架,事件类似于perl用户遗向pythno)
相关名词ruiy哥就真不想解释了,很明显这个 baidu/google是专家 ruiy哥不是,再说了ruiy哥也就那两板斧子哈,;
技术细节=> PXE(Pre-boot Execution Environment),DHCP,TFTP
在此问看管们个ruiy哥所不解之谜题?为什么赵高可以指鹿为马?
ruiy哥为事遵循,严谨高效,务实实干;
凡是开心就好,朋友交的是真心,不是假意;
1,epel
wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm #CentOS 5.x 64位
wget http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm #CentOS 5.x 32位
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm #CentOS6.x 64位
wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm #CentOS6.x 32位
2,安装cobbler
yum install cobbler tftp tftp-server xinetd dhcp httpd rsync #安装cobbler
yum install pykickstart debmirror python-ctypes cman #安装运行cobbler需要的软件包
Python Web Server Gateway Interface (wsgi,wsgi.conf)
3,cobbler配置
设置http服务
vi /etc/httpd/conf.d/wsgi.conf
LoadModule wsgi_module modules/mod_wsgi.so #取消前面的注释
设置tftp服务开机启动
vi /etc/cobbler/tftpd.template
设置rsync服务开机启动
vi /etc/xinetd.d/rsync
/etc/init.d/xinetd start #启动(CentOS中是以xinetd 来管理Rsync和tftp服务的)
配置cobbler相关参数
vi /etc/debmirror.conf #注释掉 @dists 和 @arches 两行
#@dists="sid";
#@arches="i386";
openssl passwd -1 -salt 'ruiy' '123456' #生成默认模板下系统安装完成之后root账号登录密码
vi /etc/cobbler/settings
修改与下几行成
default_password_crypted: "添加上面生成的秘钥,这里填写你自己的哈"
next_server: 192.168.1.109
server: 192.168.1.109
manage_dhcp: 1
default_kickstart: /var/lib/cobbler/kickstarts/default.ks
配置dhcp服务器
vi /etc/cobbler/dhcp.template #编辑,修改
subnet 192.168.1.0 netmask 255.255.255.0 { #设置网段
option routers 192.168.1.109; #设置网关
option domain-name-servers 8.8.8.8,8.8.4.4; #设置dns服务器地址
option subnet-mask 255.255.255.0; #设置子网掩码
range dynamic-bootp 192.168.1.110 192.168.1.150; #设置dhcp服务器IP地址租用的范围
vi /etc/sysconfig/dhcpd #指定DHCP服务的网络接口
DHCPDARGS=eth0
dhcpd #测试dhcp服务器配置是否正确
chkconfig dhcpd on #设置开机启动
chkconfig cobblerd on #设置开机启动
service cobblerd start #启动cobbler
cobbler get-loaders #安装cobbler相关工具包,否则检查cobbler配置会报错
cobbler sync #同步配置文件到dhcp服务器
service dhcpd start #启动dhcp服务
设置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 #重启cobbler
cobbler check #检查cobbler配置
4,挂载系统安装镜像到http服务器站点目录
mount -t iso9660 -o rw,loop /usr/local/src/CentOS-6.5-x86_64-bin-DVD1.iso /var/www/html/os/CentOS-6.5-x86_64-bin-DVD1 #挂载系统镜像(自行确保相关目录已存在)
vi /etc/fstab #添加以下代码。实现开机自动挂载
/usr/local/src/CentOS-6.5-x86_64-bin-DVD1.iso /var/www/html/os/CentOS-6.5-x86_64-bin-DVD1 iso9660 defaults,ro,loop 0 0
5,创建kickstarts自动安装脚本
/var/lib/cobbler/kickstarts/CentOS-5.10-x86_64.ks #创建CentOS6安装脚本可下载从如下链接
vi /var/www/cobbler/ks_mirror/config/autoip.sh #创建脚本,自动设置Linux系统静态IP地址、DNS、网关、计算机名称
#!/bin/sh
ROUTE=$(route -n|grep "^0.0.0.0"|awk '{print $2}')
BROADCAST=$(/sbin/ifconfig eth0|grep -i bcast|awk '{print $3}'|awk -F":" '{print $2}')
HWADDR=$(/sbin/ifconfig eth0|grep -i HWaddr|awk '{print $5}')
IPADDR=$(/sbin/ifconfig eth0|grep "inet addr"|awk '{print $2}'|awk -F":" '{print $2}')
NETMASK=$(/sbin/ifconfig eth0|grep "inet addr"|awk '{print $4}'|awk -F":" '{print $2}')
cat >/etc/sysconfig/network-scripts/ifcfg-eth0<<EOF
DEVICE=eth0
BOOTPROTO=static
BROADCAST=$BROADCAST
HWADDR=$HWADDR
IPADDR=$IPADDR
NETMASK=$NETMASK
GATEWAY=$ROUTE
ONBOOT=yes
EOF
IPADDR1=$(echo $IPADDR|awk -F"." '{print $4}')
cat >/etc/sysconfig/network-scripts/ifcfg-eth1<<EOF
DEVICE=eth1
BOOTPROTO=static
BROADCAST=10.0.0.255
HWADDR=$(/sbin/ifconfig eth1|grep -i HWaddr|awk '{print $5}')
IPADDR=10.0.0.$IPADDR1
NETMASK=255.255.255.0
ONBOOT=yes
EOF
HOSTNAME=ruiy_$(echo $IPADDR|awk -F"." '{print $4}')
cat >/etc/sysconfig/network<<EOF
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=$HOSTNAME
GATEWAY=$ROUTE
EOF
echo "127.0.0.1 $HOSTNAME" >> /etc/hosts
hostname=$HOSTNAME
echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
6,导入系统镜像到cobbler
cobbler import --path=/var/www/html/os/Centos/ --name=CentOS --arch=x86_64
系统镜像导入目录/var/www/cobbler/ks_mirror
导入镜像有点小消耗,务必请你耐心等候,毕竟镜像size =4.2G左右;
命令格式:cobbler import --path=镜像路径 -- name=安装引导名 --arch=32位或64位
重复上面的操作,把其他的系统镜像文件导入到cobbler
八、设置profile,按照操作系统版本分别关联系统镜像文件和kickstart自动安装文件
在第一次导入系统镜像时,cobbler会给安装镜像指定一个默认的kickstart自动安装文件
例如:CentOS6-x86_64版本的kickstart自动安装文件为:/var/lib/cobbler/kickstarts/sample.ks
查看profile
cobbler profile report --name CentOS6-x86_64 #查看profile设置
cobbler distro report --name CentOS6-x86_64 #查看安装镜像文件信息
cobbler profile remove --name=CentOS6-x86_64 #移除profile
cobbler profile remove --name=CentOS6-x86_64
cobbler profile add --name=CentOS6-x86_64 --distro=CentOS6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/Centos6.ks
要是虚拟机的话,请设置网络桥接
有点小问题,Repairing;