美文网首页
运维部署自动化实践(一)利用PXE远程自动化安装Ubuntu16

运维部署自动化实践(一)利用PXE远程自动化安装Ubuntu16

作者: zbharper | 来源:发表于2019-01-09 17:24 被阅读0次

前言

因为项目需要(实际是没有人手。。。),需要搞开发的我自己来搭建服务器集群环境,并完成软件服务的自动化部署。本文及后续文章,记录运维部署自动化实践中的每一步工作,便于以后追踪参考。

本文先完成第一步工作:远程自动化安装Linux系统

目标

技术方案选择:PXE+dhcp+tftp+kickstart 安装ubuntu16.04 server

宿主机:ubuntu16.04 desktop
目标服务器:(1)Dell Poweredge R540
(2)VMware虚拟机
安装镜像: ubuntu-16.04.5-server-amd64.iso

安装步骤:

安装运行 dhcp tftp及 http服务
  1. dhcp

安装isc-dhcp-server
sudo apt-get install isc-dhcp-server

修改/etc/default/isc-dhcp-server

INTERFACES="enp0s31f6" #通过ifconfig得到网卡名称

修改/etc/dhcp/dhcpd.conf,添加如下配置:

subnet 192.168.1.0 netmask 255.255.255.0 {
       range 192.168.1.50 192.168.1.100;
       option subnet-mask 255.255.255.0;
       option routers 192.168.1.1;
       option domain-name-servers 192.168.1.1;  #在办公室实验,dns服务器地址配到了路由器上
       option broadcast-address 10.255.255.255;
       filename "pxelinux.0";
       next-server 192.168.1.110;  #宿主机IP
}

运行dhcp服务
sudo service isc-dhcp-server start

  1. tftp

安装tftpd-hpa
sudo apt-get install tftpd-hpa

修改/etc/default/tftpd-hpa

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/var/lib/tftpboot"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="-l -c -s"

创建tftp目录
sudo mkdir /var/lib/tftpboot
sudo chmod 777 /var/lib/tftpboot
运行tftp
sudo service tftp-hpa start

  1. http

安装apache2
sudo apt-get install apache2
apache 默认的根目录是/var/www/html ,使用默认配置启动apache
sudo service apache2 start
通过浏览器访问http://192.168.1.110 测试http服务已开启

image.png
布置PXE相关文件
  1. 将ubuntu镜像mount到http目录下
    sudo mkdir /var/www/html/ubuntu
    sudo mount ~/Downloads/ubuntu-16.04.5-server-amd64.iso /var/www/html/ubuntu
  2. 拷贝启动文件到tftp目录
    sudo cp -r /var/www/html/ubuntu/install/netboot/* /var/lib/tftpboot/
  3. 拷贝seed文件到http根目录
    sudo cp /var/www/html/ubuntu/preseed/ubuntu-server.seed /var/www/html/
  4. 编辑ubuntu-server.seed文件,在最下方添加如下配置:
d-i live-installer/net-image string http://192.168.1.110/ubuntu/install/filesystem.squashfs
d-i pkgsel/include string openssh-server
  1. 修改/var/lib/tftpboot/pxelinux.cfg/default
# D-I config version 2.0
# search path for the c32 support libraries (libcom32, libutil etc.)
path ubuntu-installer/amd64/boot-screens/
include ubuntu-installer/amd64/boot-screens/menu.cfg
default ubuntu-installer/amd64/boot-screens/vesamenu.c32
prompt 0
timeout 60  
  1. 修改/var/lib/tftpboot/ubuntu-installer/amd64/boot-screens/txt.cfg 为以下内容:
default install
label install
    menu label ^Install
    menu default
    kernel ubuntu-installer/amd64/linux
    append ks=http://192.168.1.110/ks.cfg preseed/url=http://192.168.1.110/ubuntu-server.seed netcfg/get_nameservers=192.168.1.110  vga=788 initrd=ubuntu-installer/amd64/initrd.gz --- quiet 
label cli
    menu label ^Command-line install
    kernel ubuntu-installer/amd64/linux
    append tasks=standard pkgsel/language-pack-patterns= pkgsel/install-language-support=false vga=788 initrd=ubuntu-installer/amd64/initrd.gz --- quiet

从修改内容看出,主要是为了添加pxe服务器的地址,以便目标机能够找到对应的ks.cfg以及seed文件。

Kickstart
  1. 安装Kickstart工具
    sudo apt-get install system-config-kickstart
  2. 通过Kickstart工具配置,生成ks.cfg,内容如下:
#Generated by Kickstart Configurator
#platform=x86

#System language
lang en_US
#Language modules to install
langsupport zh_CN --default=en_US
#System keyboard
keyboard us
#System mouse
mouse
#System timezone
timezone Asia/Shanghai
#Root password
rootpw --disabled
#Initial user
user deepctrl --fullname "deepctrl" --iscrypted --password $1$l/vuHXXI$J0poU17Gk3F7z70sny0bn/
#Reboot after installation
reboot
#Use text mode install
text
#Install OS instead of upgrade
install
#Use Web installation
url --url http://192.168.1.110/ubuntu  # 指定安装文件的路径
#System bootloader configuration
bootloader --location=mbr 
#Clear the Master Boot Record
zerombr yes
#Partition clearing information
clearpart --all --initlabel 
#Disk partitioning information
part /boot --fstype ext4 --size 200 
part /boot/efi --fstype vfat --size 4
part swap --size 2000 
part / --fstype ext4 --size 5000 --grow 
#System authorization infomation
auth  --useshadow  --enablemd5 
#Network information
#network --bootproto=dhcp --device=enp0s31f6
#Firewall configuration
firewall --disabled 
#Do not configure the X Window System
skipx
%package
openssh-server

%post

将ks.cfg文件拷贝至http根目录
sudo cp ks.cfg /var/www/html/

目标机设置
  1. Dell服务器
    启动电源后按F2进入系统设置,将启动方式由UEFI修改为BIOS,将PXE启动项打钩。同时确认下对应的网卡是否已开启PXE选项。然后保存配置重启
  2. 虚拟机
    VMware虚拟机未做额外设置,只创建了一个空的虚拟机然后启动即可
安装结果

Dell服务器与虚拟机均可自动开启安装过程,虚拟机全程无干扰安装完毕。

问题

Dell服务器安装过程中报错:

the partition table format in use on your disks normally requires you to create a separate partition for boot loader code. this partition should de marked for use as a "reserved bios boot area" and should de at least 1 mb in size. note that this is not same as a partition mounted in /boot.

if you do not go back to the partitioning menu and correct,boot loader installation may fail later,although it may still be possible to install the loader to a partition.

在这一步卡住后安装程序无法自动执行,我手工点击忽略后系统也能够继续安装完毕。

网上各种搜,看到一些评论说debian系的linux不建议用kickstart安装,建议直接使用preseed配置来安装,接下来研究下看看能不能解决问题。
问题链接:https://serverfault.com/questions/658070/kickstarting-ubuntu-14-04-how-do-i-create-an-efi-boot-partition-from-my-ks-cf

下一章:运维部署自动化实践(二)PXE+Preseed自动安装Ubuntu16.04 server

相关文章

网友评论

      本文标题:运维部署自动化实践(一)利用PXE远程自动化安装Ubuntu16

      本文链接:https://www.haomeiwen.com/subject/lkdgrqtx.html