假设有一台服务器装有 Debian GNU/Linux,有两块网卡。
网卡 eth0 (对外) IP 10.0.2.15 netmask 255.255.255.0 gateway 10.0.2.2
网卡 eth1 (对内) IP 192.168.1.1 netmask 255.255.255.0
网络结构如下:
1. 建需要的目录
#mkdir /diskless
#mkdir /diskless/nfsroot
#mkdir /diskless/tftpboot
#mkdir /diskless/tftpboot/pxelinux.cfg
2. 装需要的软件
#apt-get install dhcp3-server
#apt-get install atftpd
#apt-get install nfs-kernel-server
#apt-get install syslinux
#apt-get install debootstrap
3. 建无盘机用的根文件系统
#debootstrap lenny /diskless/nfsroot http://mirrors.163.com/debian
#chroot /diskless/nfsroot
#apt-get install linux-image-2.6.26-2-686
#exit
4. 配置 DHCP 服务
#nano /etc/dhcp3/dhcpd.conf
网卡 eth0 (对外) IP 10.0.2.15 netmask 255.255.255.0 gateway 10.0.2.2
网卡 eth1 (对内) IP 192.168.1.1 netmask 255.255.255.0
网络结构如下:
网卡 IP 客户端以 root 用户登录无盘服务器,执行:
+-----------------------------+
| |
|+-- [eth0] 10.0.2.15 +- to WAN
| |
|+-- [eth1] 192.168.1.1 +- to clients
| | IP from 192.168.1.2 - 192.168.1.254
+-----------------------------+
1. 建需要的目录
#mkdir /diskless
#mkdir /diskless/nfsroot
#mkdir /diskless/tftpboot
#mkdir /diskless/tftpboot/pxelinux.cfg
2. 装需要的软件
#apt-get install dhcp3-server
#apt-get install atftpd
#apt-get install nfs-kernel-server
#apt-get install syslinux
#apt-get install debootstrap
3. 建无盘机用的根文件系统
#debootstrap lenny /diskless/nfsroot http://mirrors.163.com/debian
#chroot /diskless/nfsroot
#apt-get install linux-image-2.6.26-2-686
#exit
4. 配置 DHCP 服务
#nano /etc/dhcp3/dhcpd.conf
加上如下内容:
subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.2 192.168.1.254; next-server 192.168.1.1; filename "pxelinux.0"; option domain-name "diskless.zhuyiqi.com"; option domain-name-servers 202.96.128.166; option routers 192.168.1.1; } |
#/etc/init.d/dhcp3-server restart
5. 配置 TFTP 服务
#cp /diskless/nfsroot /boot/vmlinuz-2.6.26-2-686 /diskless/ tftpboot /vmlinuz
#cp /diskless/nfsroot /boot/initrd.img-2.6.26-2-686 /diskless/ tftpboot /initrd.img
#cp /usr/lib/syslinux/pxelinux.0 /diskless/tftpboot
#nano /diskless/tftpboot/pxelinux.cfg/default
5. 配置 TFTP 服务
#cp /diskless/nfsroot /boot/vmlinuz-2.6.26-2-686 /diskless/ tftpboot /vmlinuz
#cp /diskless/nfsroot /boot/initrd.img-2.6.26-2-686 /diskless/ tftpboot /initrd.img
#cp /usr/lib/syslinux/pxelinux.0 /diskless/tftpboot
#nano /diskless/tftpboot/pxelinux.cfg/default
LABEL linux KERNEL vmlinuz APPEND initrd=initrd.img boot=nfs nfsroot=/diskless/nfsroot ip=dhcp rw |
#nano /etc/inetd.conf
tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /diskless/tftpboot |
#/etc/init.d/openbsd-inetd restart
6. 配置 NFS 服务
#nano /etc/exports
6. 配置 NFS 服务
#nano /etc/exports
/diskless/nfsroot *(rw,async,no_subtree_check,no_root_squash) |
#/etc/init.d/nfs-kernel-server restart
OK! 无盘机可以通过 PXE 启动了。
============= 进一步完善
=============
7.
配置
客户端环境
#nano /diskless/nfsroot/etc/network/interfaces
#nano /diskless/nfsroot/etc/fstab
auto lo iface lo inet loopback |
#nano /diskless/nfsroot/etc/fstab
#[File system] [Mount point] [Type] [Options] [Dump] [Pass] proc /proc proc defaults 0 0 tmpfs /tmp tmpfs defaults 0 0 tmpfs /var/run tmpfs defaults 0 0 tmpfs /var/lock tmpfs defaults 0 0 tmpfs /var/tmp tmpfs defaults 0 0 |
8. 批量创建用户
#chroot /diskless/nfsroot
#nano /root/batch_add_users.sh
#!/bin/sh
PRE="ws"
for (( i = 2; i <= 254; i++ ))
do
useradd -G audio -p abc123 -s /bin/bash -d /home/$PRE$i -m $PRE$i
done
|
#chmod u+x /root/batch_add_users.sh
#/root/batch_add_users.sh
#exit
9. 让无盘机能够自动进入图形界面
#chroot /diskless/nfsroot
#apt-get install x-window-system-core xfce4
#nano /etc/X11/Xwrapper. config
allowed_users=anybody |
#nano /etc/rc.local
WS_NUMBER=`ifconfig eth0 | grep "inet addr" | cut -d. -f4 | cut -d" " -f1` su ws$WS_NUMBER -c startx #如果想退出图形界面就直接关机 #poweroff exit 0 |
#exit
10. 让无盘机能够播放声音
#chroot /diskless/nfsroot
#apt-get install alsa
#alsaconf
#alsamixer
#nano /etc/rc.local
#如果/dev/dsp不能正常出现,加下面的内容。 modprobe snd-pcm-oss |
#exit
11. 增加无盘机的虚拟内存交换空间SWAP(该步骤确有需要才做,并且不适合多用户使用。)
#cd /diskless/nfsroot
#dd if=/dev/zero of=var/cache/swap.ext3 bs=1024 count=550000
#mkfs -t ext3 var/cache/swap.ext3
#mkdir var/cache/swap
#mount -o loop var/cache/swap.ext3 var/cache/swap
#dd if=/dev/zero of=var/cache/swap/swap0 bs=1024 count=512000
#mkswap var/cache/swap/swap0
#echo "/var/cache/swap.ext3 /var/cache/swap ext3 defaults,loop 0 2" >> etc/fstab
#echo "/var/cache/swap/swap0 none swap sw 0 0" >> etc/fstab
12. 无盘机的引导方式
a. 通常是用网卡上的 boot rom;
b. 如果网卡没有boot rom,可从这里下载 http://rom-o-matic.net/ 各种启动映像文件,包括软盘(Floppy
)
,光盘(ISO
)
,USB等。
Modify: 2011-02-23
Author: Loist
QQ: 23375679
QQ: 23375679
Email: loist@163.com