Article Directory
- Project requirements:
-
- Project requirement one:
- PXE (Project Requirements 2 and 3)
-
- 1) Configure the local yum source warehouse
- 2) Install, configure and enable TFTP
- 3) Install and enable DHCP service
- 4) Prepare the Linux kernel and initialize the image file
- 5) PXE boot program
- 6) Install FTP service, prepare CentOS7 installation source
- 7) Configure the boot menu
- 8) Turn off the firewall and open the new virtual machine to verify the PXE network installation
- Verification project requirements 2
- Configure forward analysis (project requirement 4)
-
- 1) Turn off the firewall and security options (it has been turned off and no longer operate), install the bind package
- 2) Modify the main configuration file
- 3) Modify the zone configuration file
- 4) Configure the forward zone data file
- 5) Turn on the dns service and turn off the firewall
- 6) Test DNS resolution
- NFS
- Operate on server2
-
- 1) First confirm server2 as the IP address of the NFS server, and use ifconfig to view
- 2) Install the nfs-utils and rpcbind software packages
- 3) Set up a shared directory
- 4) Start the NFS service program
- 5) Create and edit files in the /opt/share directory
- 6) View the NFS shared directory published by this machine
- Operate on server1
Project requirements:
1) Prepare 3 virtual machines, a Windows virtual machine PC1 (not limited to win7 or win10), a Linux server server1 (IP is 172.16.100.100/24) and an empty virtual machine server2. The virtual machine network uses host-only mode.
2) Server1 provides DHCP service to assign IP addresses of corresponding network segments to PC1 and server2.
3) Server1 provides PXE service, which enables server2 to automatically install Centos7 Linux operating system.
4) Install and start the httpd service on server1 to provide external Web services, and build a DNS service to resolve the address www.mhh.com, so that PC1 can use the domain name www.mhh.com to access the Web server.
5) Install the NFS service on server2, provide the shared directory /share, create the file index.html in the /share directory, and customize the file content. Mount the /share directory of server2 to the /var/www/html directory of server1 through NFS, so that PC1 can display customized content when accessing the Web service.
Project requirement one:
1) Modify the server server1 virtual machine IP
vim /etc/sysconfig/network-scripts/ifcfg-ens33 #编辑网卡配置文件
systemctl restart network #重启网卡令更改后配置生效
ifconfig #查看网卡配置详情
Restart and see if the change is successful
2) Configure the virtual machine network to use host-only mode
Edit→Virtual Network Editor→click to change settings, and then change to "host only mode", turn off the use of local DHCP in the circle, because the local DHCP and the network segment to be configured later are not in the same network segment, which will cause conflicts. Then "Apply" and then "OK".
3) Steps to create a new virtual machine
compatibility
Installation source
Operating system selection
Choose a location to install
Processor settings
The virtual machine memory must be at least 2G, otherwise the installer will prompt that the memory space is insufficient, and the error will be stuck
Network type select host mode
I/O controller type default
Disk type default
Select disk default
Customize the capacity
Specify the disk default
Custom hardware
Sound card and printer do not need to be removed
Network adapter select only host mode
Use physical drive selection to automatically detect
Configuration complete
PXE (Project Requirements 2 and 3)
1) Configure the local yum source warehouse
mount /dev/cdrom /mnt/ #把光盘挂载到/mnt目录下
cd /etc/yum.repos.d/ #切换到yum.repos.d目录下
mkdir repos.bak #新建一个目录,用于备份里面原有的文件或目录
mv *.repo repos.bak #将所有的里面所有的文件移动到刚创建的目录中
vim local.repo
[local] #仓库类别
name=local #仓库名称
baseurl=file:///mnt #指定URL 访问路径为光盘挂载目录
enabled=1 #开启此yum源,此为默认项,可省略
gpgcheck=0 #不验证软件包的签名
yum clean all #删除yum缓存
yum makecache #更新yum缓存
After the configuration is complete: wq save and exit
2) Install, configure and enable TFTP
yum -y install tftp-server xinetd
vim /etc/xinetd.d/tftp
:wq After saving the configuration file, start the service and set it to start automatically after booting
systemctl start tftp
systemctl enable tftp
systemctl start xinetd
systemctl enable xinetd
3) Install and enable DHCP service
yum -y install dhcp #安装dhcp服务
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf #用实例模板覆盖主配置文件
vim /etc/dhcp/dhcpd.conf #编辑dhcp配置文件
ddns-update-style none; #禁用 DNS 动态更新
next-server 172.16.100.100; #指定 TFTP 服务器的地址
filename "pxelinux.0"; #指定要下载的 PXE 引导程序的文件
subnet 172.16.100.0 netmask 255.255.255.0 { #声明要分配的网段地址
range 172.16.100.100 172.16.100.200; #设置地址池
option routers 172.16.100.100; #默认网关地址指向TFTP服务器的IP地址
}
systemctl start dhcpd
systemctl enable dhcpd
Edit the dhcp configuration file through vim /etc/dhcp/dhcpd.conf
:wq Save the configuration file, then turn on the dhcp service and set it to start automatically after booting
4) Prepare the Linux kernel and initialize the image file
mount /dev/sr0 /mnt #挂载光盘
cd /mnt/images/pxeboot #切换到光盘的pxeboot目录下
cp vmlinuz /var/lib/tftpboot/ #复制 Linux系统的内核文件到TFTP根目录下
cp initrd.img /var/lib/tftpboot/ #复制初始化镜像文件(linux引导加载模块)到TFTP根目录下
5) PXE boot program
yum -y install syslinux #PXE引导程序由软件包 syslinux 提供
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ #复制 PXE引导程序 到TFTP根目录下
ls /var/lib/tftpboot/ #查看是否已经复制过来
6) Install FTP service, prepare CentOS7 installation source
yum -y install vsftpd #安装ftp服务
mkdir /var/ftp/centos7 #创建安装源目录
cp -rf /mnt/* /var/ftp/centos7/ #将挂载的光盘里的镜像文件强行复制到刚创建的目录里
After copying, check that it has been copied successfully
systemctl start vsftpd #启动ftp服务
systemctl enable vsftpd #设置开机自启ftp服务
7) Configure the boot menu
The default boot menu file is in the pxelinux.cfg subdirectory of the TFTP root directory, and the file name is default
cd /var/lib/tftpboot #切换到tftp根目录下
ls #查看有没有pxelinux.cfg,没有就创建一个
mkdir /var/lib/tftpboot/pxelinux.cfg #创建一个pxelinux.cfg目录
vim /var/lib/tftpboot/pxelinux.cfg/default
default auto #指定默认入口名称
prompt 0 #设置是否等待用户选择,“1”表示等待用户控制
label auto #图形安装(默认)引导入口,label 用来定义启动项
kernel vmlinuz #kernel 和 append用来定义引导参数
append initrd=initrd.img method=ftp://192.168.163.5/centos7
label linux text #文本安装引导入口
kernel vmlinuz
append text initrd=initrd.img method=ftp://192.168.163.5/centos7
label linux rescue #救援模式引导入口
kernel vmlinuz
append rescue initrd=initrd.img method=ftp://192.168.163.5/centos7
8) Turn off the firewall and open the new virtual machine to verify the PXE network installation
systemctl stop firewalld.service #关闭防火墙服务
setenforce 0 #关闭安全选项
Start the newly created virtual machine (loading in the picture below)
PXE network installation is complete
Verification project requirements 2
1) Verify on the virtual machine win10 (PC1)
2) Boot verification on the newly installed virtual machine (server2)
Configure forward analysis (project requirement 4)
1) Turn off the firewall and security options (it has been turned off and no longer operate), install the bind package
yum install -y bind #安装bind软件包
rpm -qc bind #查询bind软件包配置文件所在路径
/etc/named.conf #主配置文件
/etc/named.rfc1912.zones #区域配置文件
/var/named/named.localhost #区域数据配置文件
2) Modify the main configuration file
vim /etc/named.conf
options {
listen-on port 53 { any; }; #监听53端口,ip地址使用提供服务的本地IP,也可用any表示所有
#######listen-on-v6 port 53 { : : 1; }; #ipv6行如不使用可以注释掉或者删除
directory "/var/named"; #区域数据文件的默认存放位置
dump-file "/var/named/data/cache_dump.db"; #域名缓存数据库文件的位置
statistics-file "/var/named/data/named_stats.txt"; #状态统计文件的位置
memstatistics-file "/var/named/data/named_mem_stats.txt"; #内存统计文件的位置
allow-query { any; }; #允许使用本DNS解析服务的网段,也可用any代表所有
......
}
zone "." IN { #正向解析"."根区域
type hint; #类型为根区域
file "named.ca"; #区域数据文件为named.ca,记录了13台根域服务器的域名和IP地址等信息
};
include "/etc/named.rfc1912.zones"; #包含区域配置文件里的所有配置
3) Modify the zone configuration file
vim /etc/named.rfc1912.zones #可在文件里有模版, 可复制粘贴后修改
zone "mhh.com" IN { #正向解析"benet.com"区域
type master; #类型为主区域
file "mhh.com.zone"; #指定区域数据文件为benet.com.zone
allow-update { none; };
}
4) Configure the forward zone data file
cd /var/named/
cp -p named.localhost mhh.com.zone #保留源文件的权限和属主的属性复制
vim /var/named/mhh.com.zone
$TTL 1D #设置缓存解析结果的有效时间,就是一条域名解析记录在DNS服务器中的存留时间为1天
@ IN SOA mhh.com. admin.mhh.com. ( #admin.mhh.com这里也可以用原文件里的地址,表示管理员邮箱
0 ;serial
1D ;refresh 1H ;retry
1W ;expire
3H ) ;minimum
NS mhh.com. #记录当前区域的DNS服务器的名称
A 172.16.100.100 #记录主机IP地址
www IN A 172.16.100.100 #记录正向解析www.benet.com对应的IP
#"@"这里是一个变量,当前DNS区域名
#SOA标记用于同步主从服务器的区域数据,如更新序列号相同则不会更新
#"benet.com."此为完全合格域名(FQDN),后面有个"."不能漏掉
"#"admin.benet.com."表示管理员邮箱,这里的"@"是变量,所以用"."代替
Enter the zone data configuration file through vim /var/named/mhh.com.zone
5) Turn on the dns service and turn off the firewall
6) Test DNS resolution
Verify on PC1
Verify on the server
NFS
Operate on server2
1) First confirm server2 as the IP address of the NFS server, and use ifconfig to view
2) Install the nfs-utils and rpcbind software packages
rpm -q rpcbind nfs-utils
yum -y install nfs-utils rpcbind
3) Set up a shared directory
mkdir -p /opt/share
chmod 777 /opt/share/
vim /etc/exports
/opt/share 172.16.100.102/24(rw,sync,no_root_squash)
The client address can be a host name, IP address, or network segment address, and wildcards "*" and "?" are allowed.
The commonly used option "rw" means read and write is allowed, and "ro" means read-only;
sync: Means synchronous writing to the memory and hard disk.
async: Save the data in the memory buffer first, and then write it to disk when necessary.
no_root_squash: Indicates that the local root authority is granted when the client is accessed as root (the default is root_squash).
root_squash: indicates that when the client uses the root user to access the shared directory, the root user is mapped to an anonymous user.
all_squash: All access users are mapped to anonymous users or user groups.
subtree_check (default): If the output directory is a subdirectory, the nfs server will check the permissions of its parent directory.
no_subtree_check: Even if the output directory is a subdirectory, the nfs server does not check the permissions of its parent directory, which can improve efficiency.
4) Start the NFS service program
Start rpcbind first, then nfs
systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind
systemctl enable nfs
netstat -anpt | grep 111 #查看rpcbind端口111是否开启, rpcbind默认使用tcp的111端口
5) Create and edit files in the /opt/share directory
6) View the NFS shared directory published by this machine
exportfs -rv #发布共享
showmount -e #查看共享
Operate on server1
7) Client access to NFS shared resources
First, like server2, query and install the nfs-utils and rpcbind packages
rpm -q rpcbind nfs-utils
yum -y install nfs-utils rpcbind
systemctl start rpcbind
systemctl enable rpcbind
systemctl stop firewalld.service
setenforce 0
showmount -e 172.16.100.102 #查看 NFS 服务器端共享了哪些目录
8) Mount the NFS shared directory
cd /var/www/html #切换到要挂载的目录下
ls #查看是否有index.html文件
touch index.html #创建index.html文件
mount 172.16.100.102:/opt/share /var/www/html #挂载共享目录
9) Verify that the sharing is successful
Check the index.html content and find that it has been implemented on server1
Open the virtual machine win10 (PC1) and find that it cannot be accessed
Then reinstall and start the http service on server1
Check again on PC1, PC1 can display customized content when accessing the Web service.