歡迎您光臨本站 註冊首頁

無盤ubuntu詳細筆記

←手機掃碼閱讀     火星人 @ 2014-03-26 , reply:0

作者:情滅緣盡

第一步 安裝tftp伺服器
tftpd

1 安裝

root@ubuntu:/# apt-get install tftpd-hpa
正在讀取軟體包列表... 完成
正在分析軟體包的依賴關係樹
Reading state information... 完成
下列【新】軟體包將被安裝:
tftpd-hpa
共升級了 0 個軟體包,新安裝了 1 個軟體包,要卸載 0 個軟體包,有 0 個軟體未被升級。
需要下載 34.0kB 的軟體包。
解壓縮後會消耗掉 152kB 的額外空間。
獲取:1 http://Ubuntu.cn99.com gutsy/main tftpd-hpa 0.43-1.1ubuntu1 [34.0kB]
下載 34.0kB,耗時 5s (5921B/s)
正在預設定軟體包 ...
選中了曾被取消選擇的軟體包 tftpd-hpa。
(正在讀取資料庫 ... 系統當前總共安裝有 112536 個文件和目錄。)
正在解壓縮 tftpd-hpa (從 .../tftpd-hpa_0.43-1.1ubuntu1_i386.deb) ...
正在設置 tftpd-hpa (0.43-1.1ubuntu1) ...

root@ubuntu:/#

2 設置tftpd
root@ubuntu:~# nano /etc/default/tftpd-hpa
#Defaults for tftpd-hpa
RUN_DAEMON="yes"

#上面這句表示啟動守護進程,tftpd工作
OPTIONS="-l -s /var/lib/tftpboot"
#上面這句表示tftp客戶端能取得的文件所存放的位置

3 啟動服務

root@ubuntu:/# /etc/init.d/tftpd-hpa start
Starting HPA's tftpd: in.tftpd.
root@ubuntu:/# ps aux|grep tftp
root 26853 0.0 0.1 2196 288 ? Ss 17:26 0:00 /usr/sbin/in.tftpd -l -s /var/lib/tftpboot
root 26862 0.0 0.2 3180 748 pts/1 R+ 17:27 0:00 grep tftp
root@ubuntu:/#

4 查看服務是否開始工作

root@ubuntu:/# netstat -pna|grep tft
udp 0 0 0.0.0.0:69 0.0.0.0:* 26853/in.tftpd
unix 2 [ ] DGRAM 164700 26853/in.tftpd
root@ubuntu:/#

情滅緣盡
2007.12.21

第二步 安裝dhcp伺服器
dhcpd

1 伺服器環境

root@ubuntu:/# uname -a
Linux ubuntu 2.6.22-14-generic #1 SMP Sun Oct 14 23:05:12 GMT 2007 i686 GNU/Linux
root@ubuntu:/#

2 安裝命令 ---我下面是已經安裝好了的,如果沒有安裝好的輸入命令apt-get install dhcp3-server 就可以了
root@ubuntu:/# apt-get install dhcp3-server
正在讀取軟體包列表... 完成
正在分析軟體包的依賴關係樹
Reading state information... 完成
dhcp3-server 已經是最新的版本了。
共升級了 0 個軟體包,新安裝了 0 個軟體包,要卸載 0 個軟體包,有 0 個軟體未被升級。

3 設置dhcpd工作介面

root@ubuntu:~# nano /etc/default/dhcp3-server
# Defaults for dhcp initscript
# sourced by /etc/init.d/dhcp
# installed at /etc/default/dhcp3-server by the maintainer scripts

#
# This is a POSIX shell fragment
#

# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".

# 下面這句用來定義工作介面,如果是多個就中間空格
# 比如INTERFACES="eth0 eth1 eth2"
INTERFACES="eth0"

4 主要設置

root@ubuntu:~# nano /etc/dhcp3/dhcpd.conf

#
# Sample configuration file for ISC dhcpd for Debian
#
# $Id: dhcpd.conf,v 1.1.1.1 2002/05/21 00:07:44 peloy Exp $
#

# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;


#下面是全局設置,這裡定義的信息全dhcp伺服器生效
#我一般註釋掉了,下面可以分不同的子網進行設置
# option definitions common to all supported networks...
#option domain-name "apt-get.cn";
#option domain-name-servers 202.103.0.117, 202.103.24.68;
#default-lease-time 600;
#max-lease-time 7200;

# 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 10.152.187.0 netmask 255.255.255.0 {
#}

# This is a very basic subnet declaration.

#subnet 10.254.239.0 netmask 255.255.255.224 {
# range 10.254.239.10 10.254.239.20;
# option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
#}

# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.

#subnet 10.254.239.32 netmask 255.255.255.224 {
# range dynamic-bootp 10.254.239.40 10.254.239.60;
# option broadcast-address 10.254.239.31;
# option routers rtr-239-32-1.example.org;
#}

# A slightly different configuration for an internal subnet.
#subnet設置一個子網192.168.1.0/24
#range定義可以分配出去的地址為1.50到1.70
#option domain-name-servers定義dns為202.103.0.117等三個,這裡注意每個之間要有個逗號
#option domain-name定義域名稱
#option routers定義網關地址
#broadcast-address定義廣播地址
#default-lease-time默認租約時間
#max-lease-time 最大租約時間
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.50 192.168.1.70;
option domain-name-servers 202.103.0.117,202.103.24.68,202.103.150.44;
option domain-name "apt-get.cn";
option routers 192.168.1.1;
option broadcast-address 192.168.1.255;
default-lease-time 864000;
max-lease-time 86400000;
filename "pxelinux.0";
}

# Hosts which require special configuration options can be listed in
# host statements. If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.

#host passacaglia {
# hardware ethernet 0:0:c0:5d:bd:95;
# filename "vmunix.passacaglia";
# server-name "toccata.fugue.com";
#}

# Fixed IP addresses can also be specified for hosts. These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP. Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
#host fantasia {
# hardware ethernet 08:00:07:26:c0:a5;
# fixed-address fantasia.fugue.com;
#}

# You can declare a class of clients and then do address allocation
# based on that. The example below shows a case where all clients
# in a certain class get addresses on the 10.17.224/24 subnet, and all
# other clients get addresses on the 10.0.29/24 subnet.

#class "foo" {
# match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
#}

#shared-network 224-29 {
# subnet 10.17.224.0 netmask 255.255.255.0 {
# option routers rtr-224.example.org;
# }
# subnet 10.0.29.0 netmask 255.255.255.0 {
# option routers rtr-29.example.org;
# }
# pool {
# allow members of "foo";
# range 10.17.224.10 10.17.224.250;
# }
# pool {
# deny members of "foo";
# range 10.0.29.10 10.0.29.230;
# }
#}



5 啟動伺服器

root@ubuntu:/# /etc/init.d/dhcp3-server start
* Starting DHCP server dhcpd3 [ OK ]
root@ubuntu:/#
如果原來啟動了的就restart

6 查看服務是否已經正常監聽

root@ubuntu:/# netstat -aunp|grep dhcp
udp 0 0 0.0.0.0:67 0.0.0.0:* 23011/dhcpd3

已經在67號udp口上開始監聽了



7 使用客戶端看能否獲取ip


結束語

這只是一個最基本的dhcp伺服器設置,滿足基本的ip地址分配沒什麼大問題,但是如果需要netboot等服務,還需要更加詳細的設置,待續

情滅緣盡
2007.12.21

第三步 安裝配置nfs伺服器
1 安裝
root@ubuntu:/# apt-get install nfs-common nfs-kernel-server nfs-client
正在讀取軟體包列表... 完成
正在分析軟體包的依賴關係樹
Reading state information... 完成
nfs-common 已經是最新的版本了。
nfs-kernel-server 已經是最新的版本了。
注意,我選了 nfs-common 而非 nfs-client
nfs-common 已經是最新的版本了。
共升級了 0 個軟體包,新安裝了 0 個軟體包,要卸載 0 個軟體包,有 0 個軟體未被升級。

2 配置
root@ubuntu:~# nano /etc/exports

# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync) hostname2(ro,sync)
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt)
# /srv/nfs4/homes gss/krb5i(rw,sync)
#暫時只為弄清楚安裝方法,安全問題以後再慢慢說
/home/cache/netboot 192.168.1.0/24(rw,no_root_squash,sync)

3 啟動nfs或者重新載入
啟動nfs
root@ubuntu:/# /etc/init.d/nfs-kernel-server start
* Exporting directories for NFS kernel daemon...
exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "192.168.1.0/24:/home/cache/netboot".
Assuming default behaviour ('no_subtree_check').
NOTE: this default has changed since nfs-utils version 1.0.x
...done.
* Starting NFS kernel daemon
...done.
如果是修改了/etc/exports 配置文件,不需要重新啟動nfs伺服器,只需要刷新一下,命令如下
root@ubuntu:/# exportfs -r
exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "192.168.1.0/24:/home/cache/netboot".
Assuming default behaviour ('no_subtree_check').
NOTE: this default has changed since nfs-utils version 1.0.x
情滅緣盡
2007.12.21

第四步 安裝syslinux
1 安裝syslinux,其實也就是為了要裡面的pxelinux部分的文件
root@ubuntu:/# apt-get install syslinux
正在讀取軟體包列表... 完成
正在分析軟體包的依賴關係樹
Reading state information... 完成
syslinux 已經是最新的版本了。
共升級了 0 個軟體包,新安裝了 0 個軟體包,要卸載 0 個軟體包,有 0 個軟體未被升級。

2 拷貝pxelinux.0文件到tftpboot目錄
root@ubuntu:/# cp /usr/lib/syslinux/pxelinux.0 /var/lib/tftpboot/
root@ubuntu:/#

3 在tftpboot目錄建立pxelinux.cfg目錄,然後在pxelinux.cfg目錄下建立default文件
也可以是以某個ip地址為文件名稱
root@ubuntu:/# nano /var/lib/tftpboot/pxelinux.cfg/default

DEFAULT ubuntu
LABEL ubuntu
kernel linux
append initrd=initrd.nfs root=/dev/nfs nfsroot=192.168.1.88:/home/cache/netboot/root ip=dhcp rw
PROMPT 1
TIMEOUT 3


第五步 安裝一個新的將來用來在無盤機器上運行的linux,我這裡安裝的是一個ubuntu 7的伺服器版本
1 安裝ubuntu 伺服器,你也可以安裝你需要的linux版本
注意的是
1> 安裝好nfs的client
root@netfs:~# apt-get install nfs-client
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting nfs-common instead of nfs-client
nfs-common is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 14 not upgraded.

2> ip分配需要修改為手動,因為開機器的時候已經分配了ip
root@netfs:~# nano /etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet manual

3> 編輯fstab文件,把除了proc外的所有都註釋掉,udev會自動完成這個工作

4> 編輯udev的rules中關於網路借口記錄的文件,去掉已經定義了的網路介面,否則無盤啟動了有個報錯
root@netfs:~# :>/etc/udev/rules.d/70-persistent-net.rules


2 安裝initramfs-tools
root@netfs:~# apt-get install initramfs-tools
Reading package lists... Done
Building dependency tree
Reading state information... Done
initramfs-tools is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 14 not upgraded.
root@netfs:~#

3 編輯initramfs.conf把BOOT=local改為BOOT=nfs
#
# initramfs.conf
# Configuration file for mkinitramfs(. See initramfs.conf(5).
#

#
# MODULES: [ most | netboot | dep | list ]
#
# most - Add all framebuffer, acpi, filesystem, and harddrive drivers.
#
# dep - Try and guess which modules to load.
#
# netboot - Add the base modules, network modules, but skip block devices.
#
# list - Only include modules from the 'additional modules' list
#

MODULES=most

# BUSYBOX: [ y | n ]
#
# Use busybox if available.
#

BUSYBOX=y

#
# NFS Section of the config.
#

#
# BOOT: [ local | nfs ]
#
# local - Boot off of local media (harddrive, USB stick).
#
# nfs - Boot using an NFS drive as the root of the drive.
#

BOOT=nfs

#
# DEVICE: ...
#
# Specify the network interface, like eth0
#

DEVICE=eth0

#
# NFSROOT: [ auto | HOST:MOUNT ]
#

NFSROOT=auto


4 創建支持nfs的initrd.img文件
首先我們把nfs掛上來,創建的文件直接丟到nfs伺服器上去
root@netfs:/# mkdir /netfs
root@netfs:/# mount -t nfs 192.168.1.88:/home/cache/netboot /netfs
建立兩目錄
root@netfs:/# cd /netfs/;mkdir root tftpboot
創建支持nfs啟動的initrd.img文件
root@netfs:/# mkinitramfs -o /netfs/tftpboot/initrd.nfs
拷貝內核到tftpboot目錄
root@netfs:/# cp /boot/vmlinuz-2.6.22-14-server /netfs/tftpboot/linux

5 打包ubuntu伺服器版本的/為tgz文件並且放到nfs上保存,您可以不需要這樣,我這樣做的目的是創建了一個拷貝,如果出問題了,可以在nfs伺服器上快速的恢復無盤客戶機的系統,先apt-get update一下,然後apt-get clean
一下,打包的時候請排除掉proc等目錄
root@netfs:/etc# apt-get clean
root@netfs:/etc# apt-get autoclean
Reading package lists... Done
Building dependency tree
Reading state information... Done
#用下面的命令打包
root@netfs:/# tar zcvfp /netfs/root/netfs.tgz / --exclude=/sys/* --exclude=/netfs --exclude=mnt/* \
--exclude=/lost+found --exclude=/var/cache/* --exclude=/var/tmp/* --exclude=/proc/*

OK,打包完成了以後,關掉這個機器,到nfs伺服器上那個機器去

第六步
1> 在nfs伺服器上拷貝內核和initrd.img到到/var/lib/tfptboot/
root@ubuntu:~# cp /home/cache/netboot/tftpboot/* /var/lib/tftpboot/

2> 把剛才壓縮的netfs.tgz文件移動到我們準備長期保存的地方,然後把他解壓縮一份到
/home/cache/netboot/root/
root@ubuntu:/home/cache/netboot/root# ls -lh netfs.tgz
-rw-r--r-- 1 root root 96M 2007-12-22 06:03 netfs.tgz

root@ubuntu:/home/cache/netboot/root# cp netfs.tgz /home/cache/
root@ubuntu:/home/cache/netboot/root#

root@ubuntu:/home/cache/netboot/root# tar zxvf netfs.tgz && rm -fr netfs.tgz
root@ubuntu:/home/cache/netboot/root# ls
bin dev home initrd.img media opt root srv tmp var
cdrom etc initrd lib mnt proc sbin sys usr vmlinuz
刪除mtab文件
root@ubuntu:/# cd /home/cache/netboot/root/etc/
root@ubuntu:/home/cache/netboot/root/etc# rm mtab
root@ubuntu:/home/cache/netboot/root/etc#

第七步 設置一個虛擬機從網卡啟動,或者找一個真實的客戶機設置從網卡啟動
當然你的機器一定要支持網路啟動,並且網卡的驅動已經在內核裡面了,如果沒在,請重新編譯內核,找到對應的網卡驅動,然後敲空格選擇星號表示把驅動編譯到內核裡面

[火星人 ] 無盤ubuntu詳細筆記已經有605次圍觀

http://coctec.com/docs/linux/show-post-181302.html