设为首页 收藏本站
查看: 695|回复: 0

[经验分享] PXE和Cobble实现自动装机

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-5-24 11:16:00 | 显示全部楼层 |阅读模式
t    :PXE:
     预启动执行环境,是由Intel开发的最新技术,工作于Client/Server的网络模式,支持终端通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,在启动过程中,终端要求服务器分配IP地址,再用TFTP(trivial file transfer protocol)协议下载一个启动软件包到本机内存中执行,由这个启动软件包完成终端基本软件设置,从而引导预先安装在服务器中的终端操作系统。

一、安装DHCP服务,实现动态地址分配  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
~]# yum -y install dhcp
~]# vim /etc/dhcp/dhcpd.conf

option domain-name-servers 172.18.0.1;    //指明分配的DNS
#
default-lease-time 3600;                  
max-lease-time 7200;
#
# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;                                
#
subnet 192.168.100.0 netmask 255.255.255.0 {       //地址分配池
        range 192.168.100.20 192.168.100.99;       //地址分配范围  
        filename "pxelinux.0";                     //引导文件名称
        next-server 192.168.100.10;                //引导文件所在的IP地址  
}



测试有无语法错误,并启动dhcp服务:
1
2
3
4
5
]# service dhcpd configtest
Syntax: OK
~]# service dhcpd start
Starting dhcpd:                                            [  OK  ]
   //注意:启动dhcp服务时,会去读取网卡的配置,如果网卡没能配置192.168.100.10,会报错



查看监听端口:
1
2
3
~]# ss -uan
State       Recv-Q Send-Q      Local Address:Port     Peer Address:Port   
UNCONN      0      0           *:67                   *:*



二、安装tftp服务,实现文件传输
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
]# yum -y install tftp-server
]# vim /etc/xinetd.d/tftp
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        disable                 = no        //改为no就行
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}



启动tftp,并查看监听端口:
1
2
3
4
5
6
]# service xinetd restart
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]
]# ss -uan
State       Recv-Q Send-Q      Local Address:Port     Peer Address:Port   
UNCONN      0      0           *:69                  *:*




三、安装httpd,提供远程下载仓库
1
2
]# yum -y install httpd
]# service httpd start




四、挂载虚拟光盘到虚拟机上
1
2
3
4
5
]# mkdir /media/cdrom
]# mount /dev/cdrom /media/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only
]# mkdir /var/www/html/centos
]# mount --bind /media/cdrom/ /var/www/html/centos/




五、下载pxe引导文件
1
]# yum -y install syslinux



复制引导安装文件到tftp服务的目录下:

1
2
3
4
5
6
7
8
]# cp /usr/share/syslinux/pxelinux.0  /var/lib/tftpboot/         //引导文件
]# cp /media/cdrom/images/pxeboot/{vmlinuz,initrd.img}  /var/lib/tftpboot/
                                    //内核和ramdisk
]# cp /media/cdrom/isolinux/{boot.msg,vesamenu.c32,splash.jpg}  /var/lib/tftpboot
                                    //背景图片
]# mkdir /var/lib/tftpboot/pxelinux.cfg/      
]# cp /media/cdrom/isolinux/isolinux.cfg  /var/lib/tftpboot/pxelinux.cfg/default
                                    //菜单



修改default文件,符合自己的要求:

1
2
3
4
5
6
7
]# vim /var/lib/tftpboot/pxelinux.cfg/default
timeout 100        //修改为10秒
label autoinst
    menu label CentOS 6.5 INSTALL
    menu default
    kernel vmlinuz
    append initrd=initrd.img ks=http://192.168.100.10/centos6.5_x86_64.cfg  //自动装机文件




五:配置自动装机文件kickstart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
]# vim /var/www/html/centos6.5_x86_64.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --enable
# Install OS instead of upgrade
install
# Use network installation
url --url="http://192.168.100.10/centos"
# Root password
rootpw 123456                        
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info --host=192.168.100.10
# Reboot after installation
reboot
# System timezone
timezone  Asia/Shanghai
# System bootloader configuration
bootloader --append="rhgb crashkernel=auto quiet" --location=mbr --driveorder="sda"
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all  
# Disk partitioning information

part / --bytes-per-inode=4096 --fstype="ext4" --grow --size=1
part /boot --bytes-per-inode=4096 --fstype="ext4" --size=200
part swap --bytes-per-inode=4096 --fstype="swap" --size=8192

%packages --nobase                 //最小化安装
@core                        
%end



测试能否远程读取CentOS仓库及装机文件:

wKioL1dBLODiRi4rAAA5tAjPXDA700.jpg
wKioL1dBLPvzSU6wAABEDxpUduk832.jpg

六:开启虚拟机测试能否自动装机
wKiom1dBLcnj-vo-AARY-UyHLJ8537.jpg
wKioL1dBL0iiDGpDAAAF7wQS6TU418.jpg
wKiom1dBLqmiVEBwAAASrPn-l6w411.jpg


Cobbler:
    Red Hat根据PXE二次封装的网络工具,使用更为简单:
1
]#  yum -y install cobbler dhcp tftp-server syslinux httpd



启动cobbler并检测运行环境:
1
2
3
4
5
6
7
8
9
10
11
12
13
]# service cobblerd start
]# cobbler check
]# cobbler check
Traceback (most recent call last):
  File "/usr/bin/cobbler", line 36, in <module>
    sys.exit(app.main())      
#报错,修改配置文件:
]# vim /etc/cobbler/settings
server: 192.168.100.10               //把这两项修改为虚拟机的IP地址
next_server: 192.168.100.10   
]# service cobblerd restart
]# service httpd  start             //启动httpd
]# service xinetd start             //启动tftp



再一次cobbler check:
wKioL1dBeZni93UKAABHrE_rOWc635.jpg 1、如果当前节点可以访问互联网,执行“cobbler get-loaders”命令即可;否则,需要安装syslinux程序包,而后复制/usr/share/syslinux/目录下所有文件至/var/lib/cobbler/loaders/目录中;
2、执行  chkconfig rsync on 命令
3、执行  yum -y install debmirror 命令
4、执行  yum -y install pykickstart 命令
5、执行“openssl passwd -1 -salt $(openssl rand -hex 4)”生成密码,并用其替换/etc/cobbler/settings文件中default_password_crypted参数的值;
6、执行  yum -y install cman fence-agents 命令
修改完后执行重启cobblerb并cobbler sync,在次执行cobbler check
1
]# cobbler check



wKioL1dBewOQo59TAAAlt3c6mLs687.jpg
1、可以不用管,只要复制了syslinux目录下的文件过去就行;
2、注释/etc/debmirror.conf文件中的“@dists="sid";”一行;
3、注释/etc/debmirror.conf文件中的“@arches="i386";”一行;
1
2
3
4
]# service cobblerd restart
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:                                   [  OK  ]
]# cobbler sync                        //在次同步配置文件



导入光盘到虚拟机里,生成cobbler的distro和profile文件:
1
2
3
4
5
6
7
]# mount /dev/cdrom /media/cdrom
]# cobbler import --name="Centos6.5-x86_64" --path=/media/cdrom  //定义distro
]# cobbler distro list
   Centos6.5-x86_64
]# cobbler profile list
   Centos6.5-x86_64
]# cobbler profile remove --name Centos6.5-x86_64    //定义distro时会自动生成一个profile文件,不符合我们的要求,删除



编辑kickstart文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
vim /var/lib/cobbler/kickstarts/centos6.cfg

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --enable
# Install OS instead of upgrade
install
# Use network installation
url --url="http://172.18.250.76/cobbler/ks_mirror/Centos6.5-x86_64/"
# Root password
rootpw 123456                 
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info --host=192.168.100.10
# Reboot after installation
reboot
# System timezone
timezone  Asia/Shanghai
# System bootloader configuration
bootloader --append="rhgb crashkernel=auto quiet" --location=mbr --driveorder="sda"
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all  
# Disk partitioning information

part / --bytes-per-inode=4096 --fstype="ext4" --grow --size=1
part /boot --bytes-per-inode=4096 --fstype="ext4" --size=200
part swap --bytes-per-inode=4096 --fstype="swap" --size=8192

%packages --nobase                //最小化安装
@core
%end



生成符合要求的profile:

1
2
3
4
5
6
7
8
9
10
]# cobbler profile add --name=centos6.5-x86 --distro=Centos6.5-x86_64  --kickstart=/var/lib/cobbler/kickstarts/centos6.cfg  
]# cobbler profile list
   centos6.5-x86
]# vim /var/lib/tftpboot/pxelinux.cfg/default     //可以修改默认菜单
DEFAULT menu
#PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.com
TIMEOUT 100
TOTALTIMEOUT 6000
ONTIMEOUT centos6.5-x86



执行cobbler sync,一定不要忘了。。。。。

1
2
3
4
]# cobbler sync
]# service cobblerd restart
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:                                   [  OK  ]



测试能否正常装机:
wKiom1dBfQbC7DXFAAALx0p4ccA814.jpg
wKioL1dBfjXxJof_AAAHBxnjZwU780.jpg
wKioL1dBfk7wDy7qAAAWxvQkkdU592.jpg


三、cobbler重装系统之koan
   koan是cobbler的一个辅助工具,koan是kickstart-over-a-network的缩写安装在客户端的使用,koan配合cobbler实现快速重装linux。
1
2
3
4
5
6
7
8
9
10
]# yum -y install koan
]# koan --server=192.168.100.10 --list=profiles        //列出cobbler中有哪些profile
- looking for Cobbler at http://192.168.100.10:80/cobbler_api
centos6.5-x86
]# koan --replace-self --server=192.168.100.10 --profile=centos6.5-x86   //重装系统
- looking for Cobbler at http://192.168.100.10:80/cobbler_api
- reading URL:
........ '--title=kick1463906560']
- reboot to apply changes
]# reboot               //输入此命令重启后,不能再中止重装,重启后自动进入pxe装机。



和--title=kick1463906560一样
wKiom1dBgFvg0PoxAAAFTNQ4IbE229.jpg
wKioL1dBgVihyfuhAAAWE6m4jvc346.jpg
wKiom1dBgIOxHofaAAAWlQNsdGM561.jpg


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-221123-1-1.html 上篇帖子: 基于TCP协议下的socket编程 下篇帖子: Linux系统下的find指令操作
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表