Use TFTP, DHCP, and PXE to install servers on a Linux Network (automatically)
Source: Internet
Author: User
Use TFTP, DHCP, and PXE to install the Linux Enterprise Application-Linux server application on a Linux Network (automatically). For more information, see the following. -- Automatically obtains the IP (automatically) Server SETUP instance for installing Red Hat Enterprise Linux 4.0
To automatically obtain the IP address, install linux as follows: start the client PXE Nic --> Use The Bootp protocol --> DHCP server --> obtain the IP --> download pxelinux.0 and vmlinuz and initrd from the TFTP. img --> Start the system --> (go to the specified location to download ks. cfg file --> according to ks. cfg file to NFS/HTTP/FTP server automatically) download the RPM package and install the system --> complete the installation.
Note: All of the following experiments are implemented in RHEL AS4 fully installed in VMWare5.5.1 under WinXP SP2. The basic steps are as follows:
Step 1:
1) mount the ISO file or system installation disc to a directory
[Root @ rhel] # mkdir/media/rhel4
[Root @ rhel] # mount-o loop, ro/root/RHEL4.iso/media/rhel4 # mount the ISO file
[Root @ rhel] # mount-o loop, ro/dev/cdrom/media/rhel4 # attach a cd
2) 8. If it is automatically loaded at startup, add a line in/etc/fstab:
[Root @ rhel] # vi/etc/fstab
/Root/RHEL4.iso/media/rhel4 nfs intr
3) after mounting ISO, copy initrd. img and vmlinuz under the isolinux directory to/tftpboot/linux-install:
4) if there is no rhel as 4 ISO file, you can create a shared directory (such AS rhel) to copy all the content on the first RHEL disc to this directory, copy the rpm packages in the RPMS directory of the second, third, and fourth discs to the/rhel/RedHat/RPMS directory and enable the NFS service. Change the mounted directory/media/rhel4/to the created rhel directory. perform the following operations.
Step 2:
1) install the DHCP server package (use the RPM package to install DHCP ).
2) configure the DHCP server ,. /Etc/dhcpd. conf usually includes three parts: parameters, declarations, and option.
Parameters in the DHCP configuration file ):
Ddns-update-style configure DHCP-DNS interactive update mode.
Default-lease-time specifies the length of the lease time, in seconds.
Max-lease-time specifies the maximum lease time length, in seconds.
Hardware specifies the NIC interface type and MAC address.
Server-name notifies DHCP client server name.
Get-lease-hostnames flag checks the IP address used by the client.
The fixed-address ip address is assigned to the client as a fixed address.
Authritative rejects incorrect IP address requirements.
Declarations (Declaration) in the DHCP configuration file ):
Shared-network is used to tell if some sub-networks share the same network.
Subnet describes whether an IP address belongs to this subnet.
Range: The range in which IP addresses are terminated.
For host names, refer to special hosts.
Group provides a declaration for a group of parameters.
Allow unknown-clients? Whether the deny unknown-client dynamically allocates IP addresses to unknown users.
Allow bootp; whether deny bootp responds to the activation query.
Allow booting? Whether deny booting responds to user queries.
The name of the Start file of filename, which is applied to the diskless workstation.
Next-server: Set the Host Name of the server from the boot file and apply it to the diskless workstation.
Option in the DHCP configuration file ):
Subnet-mask Sets the subnet mask for the client.
Domain-name indicates the DNS name of the client.
Domain-name-servers specifies the IP address of the DNS server for the client.
Host-name specifies the host name of the client.
Routers sets the default gateway for the client.
Broadcast-address: Set the broadcast address for the client.
Ntp-server sets the IP address of the server for the client network time.
Time-offset is the offset time set by the client and Greenwich Mean time, in seconds.
Note: If the client uses a Windows operating system, do not select the "host-name" option, that is, do not specify the host name for it.
To run the DHCP server, you also need a file named dhcpd. leases to keep all the IP addresses that have been distributed. In the Redhat Linux release version, the file is located in the/var/lib/dhcp/directory. If you install isc dhcp through RPM, the directory already exists. The file format of dhcpd. leases is:
Leases address {statement}
The typical file content is as follows:
Lease 192.168.1.255 {# IP address allocated by the DHCP server #
Starts 1 03:02:26; # lease start lease time #
Ends 1 09:02:26; # lease end lease time #
Binding state active;
Next binding state free;
Hardware ethernet 00: 00: e8: a0: 25: 86; # client Nic MAC address #
Uid "\ 001 \ 000 \ 000 \ 350 \ 240% \ 206"; # used to verify the uid id of the Client #
Client-hostname "cjh1"; # client name #
}
Note that the lease start lease time and lease end lease time are Greenwich Mean Time (GMT), not local time.
When the DHCP server is run for the first time, dhcpd. leases is an empty file and does not need to be created manually. If isc dhcp is not installed through RPM, or dhcpd has been installed, you should try to determine where the dhcpd writes its lease file and ensure that the file exists. You can also create an empty file manually:
[Root @ rhel] # touch/var/lib/dhcp/dhcpd. leases
Edit the DHCP server configuration file. Here is an example:
[Root @ rhel] # vi/etc/dhcp. conf
# Global configuration
Ddns-update-style interim;
Ignore client-updates;
Allow booting;
Allow bootp;
# Subnet (multiple) scopes
Subnet 192.168.1.0 netmask 255.255.255.0 {
Option routers 192.168.1.1;
Option subnet-mask limit 255.0;
Option nis-domain "domain.org ";
Option domain-name "domain.org ";
Option domain-name-servers 192.168.1.1;
Filename "/linux-install/pxelinux.0 ";
Range dynamic-bootp 192.168.1.50 192.168.1.100;
Default-lease-time 21600;
Max-lease-time 43200;
Subnet 192.168.1.0 netmask 255.255.255.0 {
Option routers 192.168.1.1;
Option subnet-mask limit 255.0;
Option nis-domain "domain.org ";
Option domain-name "domain.org ";
Option domain-name-servers 192.168.1.1;
Filename "/linux-install/pxelinux.0 ";
Range dynamic-bootp 192.168.1.150 192.168.1.200;
Default-lease-time 21600;
Max-lease-time 43200;
}
3) configure the DHCP client to automatically enable the network connection. You need to modify your network configuration file, add it, or use ntsysv to configure it:
[Root @ rhel] # vi/etc/sysconfig/network
NETWORKING = yes
Enable the Internet connection during the boot, or use:
[Root @ rhel] # echo "NETWORKING = yes">/etc/sysconfig/network
Then modify your Nic configuration file:
[Root @ rhel] # vi/etc/sysconfig/network-scriptes/ifcfg-eth0
These rows should be included
DEVICE = eth0
BOOTPROTO = dhcp
ONBOOT = yes
4) modify the/etc/sysconfig/dhcpd file and configure the device on which the DHCP server is started. In this way, the DHCP server with two NICS is safer:
[Root @ rhel] # vi/etc/sysconfig/dhcpd
DHCPDARGS = eth0
5) automatically start the DHCP service at all normal operation levels.
[Root @ rhel] # chkconfig -- list dhcpd
[Root @ rhel] # chkconfig dhcpd on
6) Start the DHCP service: the purpose of starting the server is to help start the Red Hat Linux installer on the machine to be installed. A DHCP server and a TFTP server must be set up to start the server. The former is to assign an IP address to the machine to be installed, and the latter provides a way for the machine to download the boot image.
Method 1:
[Root @ rhel] # service dhcpd restart
Method 2:
[Root @ rhel] #/etc/rc. d/ini. d/dhcpd restart
7) configure the DHCP relay proxy and edit/etc/sysconfig/dhcrelay
[Root @ rhel] # vi/etc/sysconfig/dhcrelay
INTERFACES = "eth0"
DHCPSERVERS = "192.168.1.65"
Start the DHCP relay agent:
[Root @ rhel] # service dhcrelay restart
Step 3:
This TFTP service does not need to be configured, because most of them are the same! By default.
1) edit the configuration file of the TFTP server. The configuration file is as follows:
[Root @ rhel] # vi/etc/xinetd. d/tftp
Service tftp
{
Socket_type = dgram
Protocol = udp
Wait = yes
User = root
Server =/usr/sbin/in. tftpd
Server_args =-s/tftpboot
Disable = no
}
2) Start the xinetd daemon when starting the TFTP service:
[Root @ rhel] # server xinetd. d restart
Step 4:
1) copy the Boot Image File pxelinux.0 under/usr/lib/syslinux/to the TFTP server/tftpboot/linux-install:
3) name all the names under/isolinux. copy the msg file to the TFTP server/tftpboot/linux-install/: [root @ rhel] # cp/media/rhel4/isolinux /*. msg/tftpboot/linux-install/
4) configure the directory displayed on the client and modify/tftpboot/linux-install/boot. msg as follows:
1) edit the NFS server configuration file/etc/exports to allow other machines to access the/madia/rhel4 directory through NFS. The file content is as follows:
[Root @ rhel] # vi/etc/exports
/Media/rhel4/* (ro, sync)
/Tftpboot/linux-install/* (ro, sync)
2) restart the NFS service to make the new configuration take effect.
[Root @ rhel] # service nfs restart
Step 6:
Copy the anaconda-ks.cfg file under/root to/tftpboot/linux-install/and rename it huang-ks.cfg
Dhcpd requires several library files to run in jail. You can use the ldd (library Dependency Display) command to Display the shared library that an executable program must use.
[Root @ rhel] # ldd dhcpd
[Root @ rhel] # ln? S libc. so.6 =>/lib/tls/libc. so.6 (0x42000000)
[Root @ rhel] # ln? S/lib/ld-linux.so.2 =>/lib/ld-linux.so.2 (0x40000000)
Create the lib directory in "prison" and copy the library files to it. Manual implementation is troublesome. You can use the jail software package to simplify the chroot "prison" establishment process:
1) Compilation and installation of Jail Software
Jail official website is: http://www.jmcresearch.com/, the latest version: 1.9a.
[Root @ rhel] # Wget http://www.jmcresearch.com/static/dwn/projects/jail/jail_1.9a.tar.gz # download jail Software
[Root @ rhel] # tar xzvf jail.tar.gz # decompress the package to the current directory.
[Root @ rhel] # vi jail/READEM; vi jail/doc/INSTALL # view installation instructions
[Root @ rhel] # cd jail/src/Makefiles; # Set the installation path/tmp/jail to/usr/local
[Root @ rhel] # make; make install
2) use jail to create a prison
The jail package provides mkjailenv, addjailuser, and addjailsw Perl scripts as its core commands.
Mkjailenv: Create the chroot "prison" directory and copy the basic software environment from the real file system. Addjailsw: Copies binary executable files and other related files (including library files, auxiliary files, and Device Files) from the real file system to the "prison. Addjailuser: Create a New chroot "prison" user.
Stop the current dhcpd service and create the chroot directory:
[Root @ rhel] #/sbin/service dhcpd start
[Root @ rhel] # mkjailenv/chroot/
[Root @ rhel] # mkjailenv
Add the dhcpd program for "prison:
[Root @ rhel] # addjailsw/var/chroot/-P/usr/sbin/dhcpd
[Root @ rhel] # addjailsw
Copy the related dhcpd files to "prison" (you can do it or not ):
[Root @ rhel] # mkdir-p/chroot/dhcp/etc
[Root @ rhel] # cp/etc/dhcpd. conf/chroot/dhcp/etc/
[Root @ rhel] # mkdir-p/chroot/dhcp/var/state/dhcp
[Root @ rhel] # touch/chroot/dhcp/var/state/dhcp. leases
Restart the dhcpd Server:
[Root @ rhel] #/chroot/usr/sbin/dhcpd
Run the ps command to check the dhcpd process:
[Root @ rhel] # ps-ef | grep dhcpd
Root 2402 1 0? 00:00:00/chroot/usr/sbin/dhcpd
Root 2764 2725 0 00:00:00 pts/2 grep dhcpd
Note that the process name has changed. Check the port running the dhcpd:
[Root @ rhel] # netstat-nutap | grep dhcpd
Udp 0 0 0.0.0.0: 67 0.0.0.0: * 2402/dhcpd
The port number has not changed. Now dhcpd has been successfully run in "prison.
Step 8:
Start the client for testing. You can create a new virtual machine in VMWare5.5.1 under WinXP SP2 and start the installation from the network to test whether the configuration is successful.
For the server, ensure that the NIC works properly and has the broadcast function. For the client, make sure that the NIC of the client works properly. If the dhcpd process is not started, you can browse the message file/var/log/messages.
The client in the network cannot obtain the IP address. Generally, the NIC of the Linux DHCP server does not have the MULTICAST function. To enable the dhcpd (dhcp daemon) to communicate with the DHCP client normally, you need to modify the route table to activate the MULTICAST function;
[Root @ rhel] # route add-host route 255.255.255 dev eth0
If the following error is reported: commandid 255.255: Unkown host
[Root @ rhel] # vi/etc/hosts # add a line:
255.255.255.255 dhcp
The DHCP Client is incompatible with the DHCP server. The DHCP client and the DHCP server are different in different versions. Linux provides four DHCP client programs: pump, dhclient, dhcpxd, and dhcpcd. Understanding the server and client programs of different Linux releases is necessary for troubleshooting common errors. Add a configuration file to the script
Red Hat Linux 9.0 dhclient NONE/sbin/ifup/etc/sysconfig/network,/etc/sysconfig/network-scripts/ifcfg-eth0
Refer to the above method to try out perfect servers.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service