ubuntu下tftp、dhcp、nfs配置"大滿員"
在網(wǎng)絡(luò)構(gòu)建的過程中,我們需要建立多種服務(wù)器來進行網(wǎng)絡(luò)的構(gòu)建。這里我們就來講解一下ubuntu下安裝tftp、dhcp、nfs服務(wù)器的內(nèi)容。首先我們看一下tftp服務(wù)器的建立,之后再來了解一下dhcp服務(wù)器和nfs服務(wù)器的安裝。
第一步 安裝tftp服務(wù)器
1 安裝
root@ubuntu:/# apt-get install tftpd-hpa
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹
Reading state information... 完成
下列新軟件包將被安裝:
tftpd-hpa
共升級了 0 個軟件包,新安裝了 1 個軟件包,要卸載 0 個軟件包,有 0 個軟件未被升級。
需要下載 34.0kB 的軟件包。
解壓縮后會消耗掉 152kB 的額外空間。
獲?。? http://Ubuntu.cn99.com hardy/main tftpd-hpa 0.43-1.1ubuntu1 [34.0kB]
下載 34.0kB,耗時 5s (5921B/s)
正在預(yù)設(shè)定軟件包 ...
選中了曾被取消選擇的軟件包 tftpd-hpa。
(正在讀取數(shù)據(jù)庫 ... 系統(tǒng)當(dāng)前總共安裝有 112536 個文件和目錄。)
正在解壓縮 tftpd-hpa (從 .../tftpd-hpa_0.43-1.1ubuntu1_i386.deb) ...
正在設(shè)置 tftpd-hpa (0.43-1.1ubuntu1) ...
root@ubuntu:/#
2 設(shè)置tftpd
root@ubuntu:~# nano /etc/default/tftpd-hpa
#Defaults for tftpd-hpa
RUN_DAEMON="yes"#上面這句表示啟動守護進程,tftpd工作
OPTIONS="-l -s /var/lib/tftpboot"
#上面這句表示tftp客戶端能取得的文件所存放的位置
3 啟動服務(wù)
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 查看服務(wù)是否開始工作
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:/# #p#
第二步 安裝dhcp服務(wù)器
1 服務(wù)器環(huán)境
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 安裝命令
root@ubuntu:/# apt-get install dhcp3-server
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹
Reading state information... 完成
dhcp3-server 已經(jīng)是最新的版本了。
共升級了 0 個軟件包,新安裝了 0 個軟件包,要卸載 0 個軟件包,有 0 個軟件未被升級。
3 設(shè)置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"
(注*上面一行指明服務(wù)器端通過哪一塊網(wǎng)卡提供dhcp服務(wù))
4 主要設(shè)置
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;
#下面是全局設(shè)置,這里定義的信息全dhcp服務(wù)器生效
#我一般注釋掉了,下面可以分不同的子網(wǎng)進行設(shè)置
# 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設(shè)置一個子網(wǎng)192.168.1.0/24
#range定義可以分配出去的地址為1.50到1.70
#option domain-name-servers定義dns為202.103.0.117等三個,這里注意每個之間要有個逗號
#option domain-name定義域名稱
#option routers定義網(wǎng)關(guān)地址
#broadcast-address定義廣播地址
#default-lease-time默認(rèn)租約時間
#max-lease-time 最大租約時間
(注*下面這一段是生效部分,請按照實際情況修改)
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.50 192.168.1.70;
(注*上行的動態(tài)IP范圍請不要與系統(tǒng)中已有的dhcp服務(wù)器沖突,比如無線路由器上自帶的dhcp,但是也不需要把原有的關(guān)掉,只要范圍不沖突就可以了,因為客戶端在啟動時會自動使用服務(wù)器端的dhcp所分配的地址、而不使用無線路由器上分配的)
option domain-name-servers 202.103.0.117,202.103.24.68,202.103.150.44;
option domain-name "apt-get.cn";
(注*上行的domain-name在聯(lián)網(wǎng)系統(tǒng)里會起作用,所以請選擇一個你肯定不會去訪問的名字、即使你并不知道它是否被注冊成為域名)
option routers 192.168.1.1;
option broadcast-address 192.168.1.255;
default-lease-time 864000;
max-lease-time 86400000;
filename "pxelinux.0";
(注*上面這一行是要手工加的很關(guān)鍵的信息,實際就是啟動無盤工作站網(wǎng)卡的方式,而其中的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 啟動服務(wù)器
root@ubuntu:/# /etc/init.d/dhcp3-server start
* Starting DHCP server dhcpd3 [ OK ]
root@ubuntu:/#
6 查看服務(wù)是否已經(jīng)正常監(jiān)聽
root@ubuntu:/# netstat -aunp|grep dhcp
udp 0 0 0.0.0.0:67 0.0.0.0:* 23011/dhcpd3
已經(jīng)在67號udp口上開始監(jiān)聽了 #p#
第三步 安裝配置nfs服務(wù)器
1 安裝
root@ubuntu:/# apt-get install nfs-common nfs-kernel-server nfs-client
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹
Reading state information... 完成
nfs-common 已經(jīng)是最新的版本了。
nfs-kernel-server 已經(jīng)是最新的版本了。
注意,我選了 nfs-common 而非 nfs-client
nfs-common 已經(jīng)是最新的版本了。
共升級了 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)
(注*上面這一行是服務(wù)器端提供的磁盤空間的位置,可以是服務(wù)器的任一目錄,建議將一個單獨的磁盤分區(qū)掛在這個目錄下。但是請注意:這個服務(wù)器端的/home/cache/netboot并不是將來客戶端的虛擬根目錄,因為在/home/cache/netboot下面將會有一個名為root的子目錄,而這個/home/cache/netboot/root才是本文中的客戶端的虛擬根目錄,在啟動完成后、實際運行過程中,工作就僅局限在/home/cache/netboot/root中了。建立root的問題下文將會講到)
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服務(wù)器,只需要刷新一下,命令如下
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