debian_pxe安装部署

该文详细介绍了如何搭建DebianPXE服务器,包括安装和配置缓存服务器apt-cacher-ng和Apache,设置TFTP服务,配置DHCP以分配IP地址,启用selinux无盘启动镜像,以及利用preseed.cfg进行无人值守安装,整个过程旨在实现自动化部署。
摘要由CSDN通过智能技术生成

# **Debian PXE服务器搭建**

## 1、安装缓存及镜像源

**apt-get install apt-cacher-ng apache2**

**vim /etc/apt-cacher-ng/backends_debian**
http://mirrors.163.com/debian/   **#修改缓存软件包**

## 2、TFTP服务

cat /etc/default/tftpd-hpa    **#安装tftp-hpa**
\# /etc/default/tftpd-hpa   **#编辑tftp配置文件**
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/var/lib/tftpboot"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="--secure"    

/etc/init.d/tftpd-hpa restart  **#重启tftp-hpa服务**

/etc/init.d/tftpd-hpa status   **#查看tftp-hpa服务**

chown tftp:tftp /var/lib/tftpboot  **#修改用户组所有者权限**  

## 3、DHCP服务

vi /etc/dhcp/dhcpd.conf    **#配置dhcp服务**
subnet 192.88.50.0 netmask 255.255.255.0 {
 range 192.88.50.200 192.88.50.253;
 option domain-name-servers 192.88.50.42;
 option routers 192.88.50.1;
 default-lease-time 600;
 max-lease-time 7200;
 next-server 192.88.50.46;
 filename  "pxelinux.0";
}

**nano /etc/default/isc-dhcp-server**  (重要配置文件)

INTERFACESv4=“自己网卡名字”   

`dhcpd -t`(查看配置是否正确)

systemctl start isc-dhcp-server  #开启DHCP服务

netstat -uap | grep 'dhcp*'  查看服务是否开启

出现错误,执行如下操作:

执行`sudo rm -rf /var/run/dhcpd.pid`在重启dhcp服务就行了

**DHCP配置文件**

vi /etc/dhcp/dhcpd.conf
subnet 192.168.1.0  netmask 255.255.255.0 {
 range 192.168.1.200 192.168.1.220;
 option domain-name-servers 192.168.1.1;

option routers 192.168.1.1;
 option broadcast-address 192.168.1.255;
 default-lease-time 600;
 max-lease-time 7200;
 next-server 192.168.1.160;
 filename  "pxelinux.0";

}

## 4、Apache服务

nano /etc/apache2/sites-enabled/000-default   **#修改Apache配置文件000-default**

ServerAdmin webmaster@localhost

\#DocumentRoot /var/www

DocumentRoot /var/www

Options FollowSymLinks Indexes

AllowOverride All

**nano /etc/apache2/apache2.conf**     **#修改Apache配置文件apache2.conf**

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>
DocumentRoot "/var/www/"
<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
        Allow from all
</Directory>

/etc/init.d/apache2 start   **#开启apache服务**

注意:将站点下index.html文件删除,否则访问不到preseed,preseed.cfg放到var/www/html文件下。

apt-get install -y ufw

ufw allow 80/udp

ufw allow 67/udp

ufw allow 69/udp  **#打开防火墙端口**

## 5、安装selinux

apt install syslinux-utils syslinux  **#selinux无盘启动镜像**

wget http://ftp.nl.debian.org/debian/dists/stretch/main/installer-amd64/current/images/netboot/netboot.tar.gz;

tar zxvf netboot.tar.gz -C /var/lib/tftpboot   **#下载镜像归档**

cp /usr/lib/syslinux/memdisk /var/lib/tftpboot   **#将Syslinux软件包提供的memdisk文件复制到TFTP根路径**

cd /var/lib/tftpboot

**vim /var/lib/tftpboot/pxelinux.cfg/default**

#D-I config version 2.0

#search path for the c32 support libraries (libcom32, libutil etc.)

path debian-installer/amd64/boot-screens/
include debian-installer/amd64/boot-screens/menu.cfg
default debian-installer/amd64/boot-screens/vesamenu.c32
prompt 0
timeout 5

DEFAULT wheezy_amd64
LABEL wheezy_amd64
kernel debian-installer/amd64/linux
append vga=normal initrd=debian-installer/amd64/initrd.gz auto=true interface=auto netcfg/dhcp_timeout=60 netcfg/choose_interface=auto priority=critical url=http://10.16.228.114/html/preseed.cfg
        IPAPPEND 2

## 6、preseed.cfg配置文件

**vim /var/www/html/preseed.cfg** 

d-i debian-installer/locale string en_US
d-i console-keymaps-at/keymap select us
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/xkb-keymap select us
d-i keyboard-configuration/layoutcode string us
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string unassigned-domain
d-i netcfg/get_domain string unassigned-domain
d-i netcfg/no_default_route boolean true
d-i mirror/country string manual
#d-i mirror/protocol string http
d-i mirror/http/hostname string 10.16.228.114:3142
d-i mirror/http/directory string /debian/
d-i mirror/http/proxy string
#d-i mirror/suite string wheezy

#**设置时区**

d-i time/zone string Asia/Shanghai
d-i clock-setup/utc boolean true
d-i clock-setup/ntp boolean true

**#设置分区 分别为swap 8G /home 2G / 10G /tmp 10G /use 5G /var 5G 剩余的全部分给 /www**

d-i partman-auto/disk string /dev/sda
###需要分区的磁盘文件,默认为/dev/sda
d-i partman-auto/method string lvm
d-i partman-auto/choose_recipe select fsm
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-auto-lvm/no_boot boolean true
d-i partman-auto-lvm/new_vg_name string vg0

d-i partman-auto/expert_recipe string \
fsm :: \
1024 100% 8192 linux-swap method{ swap } \
format{ } $lvmok{ } lv_name{ swap } \
. \
2048 2048 2048 ext4 method{ lvm } \
$lvmok{ } mountpoint{ /home } lv_name{ home } \
format{ } use_filesystem{ } filesystem{ ext4 } \
. \
10240 10240 10240 ext4 method{ lvm } \
$lvmok{ } mountpoint{ / } lv_name{ root } \
format{ } use_filesystem{ } filesystem{ ext4 } \
options/relatime{ relatime } \
. \
768 1024 1024 ext4 method{ lvm } \
$lvmok{ } mountpoint{ /tmp } lv_name{ tmp } \
format{ } use_filesystem{ } filesystem{ ext4 } \
options/relatime{ relatime } \
. \
10240 40960 40960 ext4 method{ lvm } \
$lvmok{ } mountpoint{ /usr } lv_name{ usr } \
format{ } use_filesystem{ } filesystem{ ext4 } \
options/relatime{ relatime } \
. \
7680 10240 10240 ext4 method{ lvm } \
$lvmok{ } mountpoint{ /var } lv_name{ var } \
format{ } use_filesystem{ } filesystem{ ext4 } \
options/relatime{ relatime } \
. \

1 2048 1000000000 ext4 method{ lvm } \
$lvmok{ } mountpoint{ /www } lv_name{ www } \
format{ } use_filesystem{ } filesystem{ ext4 } \
options/relatime{ relatime } \
. \
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-lvm/confirm boolean true
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/confirm boolean true

**保存磁盘分区信息**

d-i partman/choose_partition \
select Finish partitioning and write changes to disk

**#设置root 用户密码**

#Alternatively, create a normal user account.

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

**#安装的软件包** 

tasksel tasksel/first multiselect standard,debian-servr

#d-i pkgsel/include string ruby openssh-server sysstat xinetd build-essential curl tcpdump chkconfig lrzsz atop htop iotop dstat ethtool vim screen curl dmidecode lsb-release ntp ipmitool   可以后期安装

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
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev  string default

**#完成安装重启**

d-i finish-install/reboot_in_progress note

然后pxe引导后自己安装,无需手工干预。完成后记得修改机器名与Ip地址即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值