運維部署自動化實踐(二)PXE+Preseed自動安裝Ubuntu16.04 server

上一章:運維部署自動化實踐(一)利用PXE遠程自動化安裝Ubuntu16.04 server

接上文

在上文中,嘗試利用Kickstart工具實現(xiàn)PXE遠程安裝的自動化,但是安裝過程中出現(xiàn)了一個分區(qū)報錯需要人工確認,導(dǎo)致自動化過程中斷。查閱了一些技術(shù)博客和官方文檔,發(fā)現(xiàn)Kickstart主要用于Redhat系的linux系統(tǒng)安裝,而對于Debian系的支持可能不太好。Debian系Linux采用了特有的debian-installer作為系統(tǒng)安裝工具,而運維人員可以通過一個preseed.cfg配置文件,寫入安裝各個階段需要的參數(shù)或指令,這樣就可以避免安裝過程中的人機交互,實現(xiàn)無人值守的自動化安裝。
事實上上一文的過程也利用了preseed配置文件(在上文中ubuntu-server.seed文件),只不過大部分安裝指令都寫在了kickstart配置里。本文在沒有kickstart工具的情況下,完全采用preseed配置實現(xiàn)ubuntu系統(tǒng)安裝。

Install Ubuntu with Preseeding

配置dhcp、tftp、http服務(wù)

這一步可以直接復(fù)制上一章的操作,本文嘗試用dnsmasq來代替isc-dhcp-server和tftpd-hpa,提供集成的dhcp和tftp服務(wù)

  1. dnsmasq

安裝dnsmasq
sudo apt-get install dnsmasq
編輯/etc/dnsmasq.conf,將以下的配置配置激活(去掉注釋)

bogus-priv
filterwin2k
interface=eth0  # 查看本機的網(wǎng)卡名
dhcp-range=192.168.1.50,192.168.1.150,12h  
dhcp-boot=pxelinux.0
enable-tftp
tftp-root=/var/ftpd  # tftp的目錄
dhcp-authoritative

創(chuàng)建tftp目錄
sudo mkdir /var/ftpd

啟動dnsmasq
sudo service dnsmasq start

  1. Http
    安裝apache2, 步驟省略,默認http目錄為/var/www/html/
布置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/ftpd/
  3. 在http根目錄下創(chuàng)建preseed配置文件
    sudo touch /var/www/html/preseed.cfg
  4. 編輯preseed.cfg文件,內(nèi)容如下:
# Locale sets language and country. 
d-i debian-installer/language string en
d-i debian-installer/country string US
d-i debian-installer/locale string en_US #應(yīng)該時zh_CN

# Keyboard selection. 
d-i console-setup/ask_detect boolean false 
d-i console-setup/layoutcode string us 

# Network configuration. #注,在netboot模式下,網(wǎng)絡(luò)設(shè)置不起作用,需要在dhcp中設(shè)定用戶名密碼,
d-i netcfg/choose_interface select eth0 
d-i netcfg/dhcp_timeout string 60 
d-i netcfg/get_hostname string libvert 
d-i netcfg/get_domain string libvert 
d-i netcfg/no_default_route boolean true 

# Clock and time zone setup 
d-i clock-setup/utc boolean false 
d-i time/zone string Asia/Shanghai 


# Mirror settings  #安裝文件鏡像設(shè)置,使用http協(xié)議
#d-i mirror/protocol string http 
#d-i mirror/country manual   #這一步要注釋掉,否則會需要人工選擇鏡像所處地區(qū)
d-i mirror/http/hostname string 192.168.1.101  
d-i mirror/http/directory string /ubuntu  # 鏡像路徑 http://192.168.1.101/ubuntu
d-i mirror/http/proxy string 

# Partitioning ###分區(qū)設(shè)定,這個要注意
d-i partman-auto/disk string/dev/sda
d-i partman-auto/method string regular 
d-i partman-lvm/device_remove_lvm boolean true 
d-i partman-md/device_remove_md boolean true 
d-i partman-auto/choose_recipe select atomic
 # This makes partman automatically partition without confirmation
d-i partman/confirm_write_new_label boolean true 
d-i partman/choose_partition select finish 
d-i partman/confirm boolean true 
d-i partman/confirm_nooverwrite boolean true 

#add new 
d-i partman-lvm/confirm boolean true 
d-i partman-lvm/confirm_nooverwrite boolean true 
d-i partman-auto-lvm/guided_size string max 
# Base system installation 
d-i base-installer/kernel/image string linux-generic 

# Account setup 
#d-i passwd/root-login boolean true 
#d-i passwd/root-password password 123456 
#d-i passwd/root-password-again password 123456 
#d-i passwd/make-user boolean false  
#d-i user-setup/encrypt-home boolean false 
#d-i user-setup/allow-password-weak boolean true  #允許weakpassword,

### Account setup
# Skip creation of a root account (normal user account will be able to
# use sudo). The default is false; preseed this to true if you want to set
# a root password.
d-i passwd/root-login boolean false
# Alternatively, to skip creation of a normal user account.
#d-i passwd/make-user boolean false

# Root password, either in clear text
#d-i passwd/root-password password r00tme
#d-i passwd/root-password-again password r00tme
# or encrypted using a crypt(3)  hash.
#d-i passwd/root-password-crypted password [crypt(3) hash]

# To create a normal user account.
d-i passwd/user-fullname string DeepctrlUser
d-i passwd/username string deepctrl
# Normal user's password, either in clear text
d-i passwd/user-password password deepctrl
d-i passwd/user-password-again password deepctrl
# or encrypted using a crypt(3) hash.
#d-i passwd/user-password-crypted password [crypt(3) hash]
# Create the first user with the specified UID instead of the default.
#d-i passwd/user-uid string 1010
# The installer will warn about weak passwords. If you are sure you know
# what you're doing and want to override it, uncomment this.
d-i user-setup/allow-password-weak boolean true

# The user account will be added to some standard initial groups. To
# override that, use this.
d-i passwd/user-default-groups string audio cdrom video

# Set to true if you want to encrypt the first user's home directory.
d-i user-setup/encrypt-home boolean false

# Package selection 
tasksel tasksel/first multiselect standard, ubuntu-server 
d-i pkgsel/include string openssh-server 
d-i pkgsel/upgrade select none 
d-i pkgsel/language-packs multiselect en, zh 
d-i pkgsel/update-policy select none 

# Boot loader installation 
d-i grub-installer/only_debian boolean true 

# Finishing up the installation 
d-i finish-install/reboot_in_progress note 

#d-i live-installer/net-image string http://192.168.1.101/ubuntu/install/filesystem.squashfs
  1. 修改/var/ftpd/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 1
  1. 修改/var/ftpd/ubuntu-installer/amd64/boot-screens/txt.cfg 為以下內(nèi)容:
default install
label install
    menu label ^Install
    menu default
    kernel ubuntu-installer/amd64/linux
    append initrd=ubuntu-installer/amd64/initrd.gz ramdisk_size=100000 auto=true priority=critical interface=auto netcfg/no_default_route=true preseed/url=http://192.168.1.101/preseed.cfg 
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

注意該步驟配置文件中沒有再指定ks.cfg,后面的安裝過程完全通過preseed.cfg控制

目標機啟動,完成安裝

Dell服務(wù)器進入PXE模式,安裝過程無需再人工介入。

下一步繼續(xù)實踐在Preseed里添加后處理,執(zhí)行自動安裝軟件和配置系統(tǒng)環(huán)境。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容