Bạn có chắc chắn muốn xóa bài viết này không ?
Bạn có chắc chắn muốn xóa bình luận này không ?
PXE boot và các bước xây dựng 1 PXE server
Giới thiệu
PXE là cơ chế cho phép khởi động một phần mềm lấy qua mạng. Để có thể khởi động PXE thì máy trạm (client) cần NIC (Network interface controller) có khả năng PXE và hệ thống mạng có máy chủ DHCP và TFPT.
PXE có thể được sử dụng để cài Linux. Chương 30 trong sổ tay sử dụng Redhat Linux có trình bày về cách cài đặt Linux thông qua cơ chế gọi là PXE, cũng như cách cấu hình DHCP và TFPT server. Bài viết này tóm tắt quy trình cài đặt PXE server.
Cơ chế PXE
PXE boot gồm 6 bước tóm tắt như trên hình. Cụ thể:
- Máy trạm broadcast DHCPDISCOVER dùng giao thức UDP đến cổng 67.
- Máy chủ DHCP gửi lại máy chủ DHCPOFFER trong đó chứa địa chỉ IP. Khái lược về DHCP có thể tham khảo Wikipedia
- Máy trạm gửi DHCPREQUEST đến máy chủ DHCP để nhận thông tin boot image.
- Máy chủ Boot trả về DHCPPACK trong đó chứa thông tin chương trình bootstrap.
- Máy trạm gửi thông tin lấy file bootstrap lên máy chủ boot (TFTP)
- Chuong trình bootstrap sẽ được máy chủ boot trả về. Máy trạm chạy chương trình bootstrap này.
Cài đặt Linux tự động qua PXE
Các phần mềm cần thiết
Các bước cài một máy chủ PXE (chạy CentOS)
Copy packages một bản CentOS
Tải package từ http://www.centos.org/download/mirrors/
Dùng script sau để đồng bộ CentOS về. Mình chọn bừa mirror từ ftp.iij.adj.jp
$ mkdir -p /home/repos/centos
#!/bin/sh
MIRROR=rsync://ftp.iij.ad.jp/centos/6.6
LOCALDIR=/home/repos/centos/6.6
for i in os updates do
rsync -aH $MIRROR/$i $LOCALDIR
done
#----------- Sau khi đồng bộ kết thúc, tạo thư mục chứa kickstart file ---------
$ mkdir -p /home/repos/ks
Cài đặt
Cài các package cần thiết
$ yum install http dhcp tftp-server syslinux
Chỉnh sửa setting
$ vim /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
### sửa disable = no
# Khởi động lại xinetd
$ /etc/init.d/xinetd start
Khởi động dhcpd
- Cấu hình dhcp trả về IP
- Cấu hình dhcp trả về tftp bootstrap
$ vim /etc/dhcpd/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
# see 'man 5 dhcpd.conf'
#
default-lease-time 600;
max-lease-time 7200;
# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
# 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;
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
subnet x.x.x.0 netmask 255.255.255.0 {
range x.x.x.x x.x.x.x
option routers GW_IP
next-server TFTP_SERVER_IP
file
$ /etc/init.d/dhcpd start
Cài đặt httpd
Linux sẽ được cài theo kịch bản định nghĩa sẵn trong file kickstart. Trong quá trình này ta sẽ lấy các package về do vậy ta cần một yum server. Httpd ở đây là để trả lại packages.
$ vim /etc/httpd/conf/httpd.conf
# trỏ document root về thư mục chứa package đồng bộ ở bước đầu.
DocumentRoot "/home/repos"
<Directory /home/repos>
...
</Directory>
$ /etc/init.d/httpd start
Copy bootimage và chuẩn bị file kickstart (kịch bản cài đặt)
$ cp /home/repos/centos/6.6/os/x86_64/images/pxeboot/* /var/lib/tftp/linux-install
$ cd /var/lib/tftp/linux-install
$ mkdir -p pxelinux.cfg
$ vim pxelinux.cfg/default
#### File menu có nội dung dưới đây ###
say === PXE BOOT
say -
say -- CentOS
say app ______ Install an app server
say -
default namenode
prompt 1
timeout 9000
label app
kernel vmlinuz
append ks=http://TFTP_Server_IP/ks/linux.ks initrd=initrd.img ksdevice=eth0 devfs=nomount
Khởi động máy tính, chọn menu cài đặt và uống cafe ngồi chờ Linux được cài đặt
Ví dụ một file kịch bản cài đặt
text
install
url --url http://TFTP_SERVER_IP/centos/6/os/x86_64
lang en_US.UTF-8
skipx
network --onboot yes --device eth0 --bootproto static --hostname centosbase
network --onboot yes --device eth1 --bootproto static
# bbdev
rootpw --iscrypted $6$8y01SMVUuuKhvC1d$80sglL4OA2MecyMHfmR5xFNT6Dxzdr0tnC9Hg3kqC4Tk0ThN770SFcLxSrc0qQStoGWTtRe1.8IyVuwCVoX6r/
firewall --disable
authconfig --enableshadow --passalgo=sha512
selinux --disable
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
clearpart --all
part /boot --fstype=ext4 --size=200 --ondisk=sda
part / --fstype=ext4 --grow --size=200 --ondisk=sda
part swap --size=4096 --ondisk=sda
reboot
%packages
@base
@core
@development
@system-management-snmp
@server-platform
@system-management
pax
sgpio
ruby
ruby-devel
unzip
Cách đổi rootpw trong file kickstart
$ grub-crypt --sha-512
Password: # gõ mật khẩu
Retype password: # gõ lại mật khẩu






