前言
因?yàn)轫?xiàng)目需要(實(shí)際是沒(méi)有人手。招拙。迫像。)瞳遍,需要搞開(kāi)發(fā)的我自己來(lái)搭建服務(wù)器集群環(huán)境,并完成軟件服務(wù)的自動(dòng)化部署由缆。本文及后續(xù)文章猾蒂,記錄運(yùn)維部署自動(dòng)化實(shí)踐中的每一步工作,便于以后追蹤參考舔箭。
本文先完成第一步工作:遠(yuǎn)程自動(dòng)化安裝Linux系統(tǒng)
目標(biāo)
技術(shù)方案選擇:PXE+dhcp+tftp+kickstart 安裝ubuntu16.04 server
宿主機(jī):ubuntu16.04 desktop
目標(biāo)服務(wù)器:(1)Dell Poweredge R540
(2)VMware虛擬機(jī)
安裝鏡像: ubuntu-16.04.5-server-amd64.iso
安裝步驟:
安裝運(yùn)行 dhcp tftp及 http服務(wù)
- dhcp
安裝isc-dhcp-server
sudo apt-get install isc-dhcp-server
修改/etc/default/isc-dhcp-server
INTERFACES="enp0s31f6" #通過(guò)ifconfig得到網(wǎng)卡名稱
修改/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; #在辦公室實(shí)驗(yàn)烙荷,dns服務(wù)器地址配到了路由器上
option broadcast-address 10.255.255.255;
filename "pxelinux.0";
next-server 192.168.1.110; #宿主機(jī)IP
}
運(yùn)行dhcp服務(wù)
sudo service isc-dhcp-server start
- 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"
創(chuàng)建tftp目錄
sudo mkdir /var/lib/tftpboot
sudo chmod 777 /var/lib/tftpboot
運(yùn)行tftp
sudo service tftp-hpa start
- http
安裝apache2
sudo apt-get install apache2
apache 默認(rèn)的根目錄是/var/www/html ,使用默認(rèn)配置啟動(dòng)apache
sudo service apache2 start
通過(guò)瀏覽器訪問(wèn)http://192.168.1.110 測(cè)試http服務(wù)已開(kāi)啟
布置PXE相關(guān)文件
- 將ubuntu鏡像mount到http目錄下
sudo mkdir /var/www/html/ubuntu
sudo mount ~/Downloads/ubuntu-16.04.5-server-amd64.iso /var/www/html/ubuntu
- 拷貝啟動(dòng)文件到tftp目錄
sudo cp -r /var/www/html/ubuntu/install/netboot/* /var/lib/tftpboot/
- 拷貝seed文件到http根目錄
sudo cp /var/www/html/ubuntu/preseed/ubuntu-server.seed /var/www/html/
- 編輯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
- 修改/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
- 修改/var/lib/tftpboot/ubuntu-installer/amd64/boot-screens/txt.cfg 為以下內(nèi)容:
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
從修改內(nèi)容看出镣屹,主要是為了添加pxe服務(wù)器的地址季率,以便目標(biāo)機(jī)能夠找到對(duì)應(yīng)的ks.cfg以及seed文件。
Kickstart
- 安裝Kickstart工具
sudo apt-get install system-config-kickstart
- 通過(guò)Kickstart工具配置鞭光,生成ks.cfg泞遗,內(nèi)容如下:
#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/
目標(biāo)機(jī)設(shè)置
- Dell服務(wù)器
啟動(dòng)電源后按F2進(jìn)入系統(tǒng)設(shè)置史辙,將啟動(dòng)方式由UEFI修改為BIOS,將PXE啟動(dòng)項(xiàng)打鉤晦毙。同時(shí)確認(rèn)下對(duì)應(yīng)的網(wǎng)卡是否已開(kāi)啟PXE選項(xiàng)耙蔑。然后保存配置重啟 - 虛擬機(jī)
VMware虛擬機(jī)未做額外設(shè)置,只創(chuàng)建了一個(gè)空的虛擬機(jī)然后啟動(dòng)即可
安裝結(jié)果
Dell服務(wù)器與虛擬機(jī)均可自動(dòng)開(kāi)啟安裝過(guò)程须揣,虛擬機(jī)全程無(wú)干擾安裝完畢钱豁。
問(wèn)題
Dell服務(wù)器安裝過(guò)程中報(bào)錯(cuò):
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.
在這一步卡住后安裝程序無(wú)法自動(dòng)執(zhí)行,我手工點(diǎn)擊忽略后系統(tǒng)也能夠繼續(xù)安裝完畢卵酪。
網(wǎng)上各種搜谤碳,看到一些評(píng)論說(shuō)debian系的linux不建議用kickstart安裝,建議直接使用preseed配置來(lái)安裝塑煎,接下來(lái)研究下看看能不能解決問(wèn)題臭蚁。
問(wèn)題鏈接:https://serverfault.com/questions/658070/kickstarting-ubuntu-14-04-how-do-i-create-an-efi-boot-partition-from-my-ks-cf
下一章:運(yùn)維部署自動(dòng)化實(shí)踐(二)PXE+Preseed自動(dòng)安裝Ubuntu16.04 server