我是靠谱客的博主 着急枫叶,最近开发中收集的这篇文章主要介绍如何在KVM环境中使用网络安装部署多台虚拟服务器,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

这是KVM系列的第二部分,我们在这里讨论如何在KVM环境中使用网络安装部署Linux虚拟机。我们将讨论三种类型的网络安装(FTP, NFS和HTTP),它们中每一种有它特殊的前提条件。

使用FTP的网络安装

1、在开始前,我们应该安装ftp服务软件包。

[root@localhost images]# yum install vsftpd

2、在安装了vsftpd后,介质启动并且使得这个服务永久启用。

[root@localhost images]# systemctl start vsftpd
[root@localhost images]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

3、出于安全考虑,你需要添加FTP服务到防火墙。

[root@localhost images]# firewall-cmd --permanent --add-service=ftp
success
[root@localhost images]# firewall-cmd --reload
success

4、现在该选取你想要使用的首选Linux ISO,在这里我们使用CentOS7 ISO。让我们在/var/ftp/pub下创建一个目录CentOS7作为这个ISO文件的挂载点进行挂载。

[root@localhost images]# mkdir /var/ftp/pub/CentOS7
[root@localhost images]# mount -t iso9660 -o ro /mnt/CentOS-7-x86_64-2009.iso  /var/ftp/pub/CentOS7
[root@localhost images]# ls /var/ftp/pub/CentOS7
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL

5、最终重启vsftpd服务并且检查这个服务的状态。

[root@localhost images]# systemctl restart vsftpd
[root@localhost images]# systemctl enable vsftpd
[root@localhost images]# systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-07-15 15:26:59 CST; 6s ago
  Process: 25619 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
 Main PID: 25620 (vsftpd)
    Tasks: 1
   CGroup: /system.slice/vsftpd.service
           └─25620 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

6、用ftp软件进行验证:主机IP地址,用户名为anonymous,密码为空

 7、现在是时候启动我们的GUI工具virt-manager了。

[root@localhost images]# virt-manager

8、在启动"virt-manager"后,创建新的虚拟机,接着从这个窗口选择网络安装。 

 9、当你首先安装了KVM软件包时,创建了虚拟桥来连接虚拟机和物理主机。你可以使用ifconfig命令显示它的配置。

[root@localhost images]# ifconfig virbr0
virbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:b7:8a:74  txqueuelen 1000  (Ethernet)
        RX packets 5690  bytes 304012 (296.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 9466  bytes 531767312 (507.1 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

你将注意到IP:192.168.122.1被分配给了虚拟桥virbr0。虚拟机使用这个IP来连接物理主机。所以,我们说这个IP地址表示物理机在虚拟网络环境中。

我们将使用以下IP提供到我们FTP目录的URL路径,这个FTP目录包含我们ISO的文件。如果你在另一台/远程主机上部署了你的FTP,只要输入其它服务器的IP地址替代先前的IP。

 10、接着将与教程的先前部分相同,询问你资源和存储。在最后,你将到达这个窗口。

11、 按下Finish后,进入了新虚拟机安装界面:

使用NFS的网络安装

1、我们有几乎相同的步骤,安装nfs服务软件包。

[root@localhost images]# yum install nfs-utils

2、接着,启动nfs服务并且永久地添加它到防火墙

[root@localhost images]# systemctl start nfs
[root@localhost images]# systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@localhost images]# firewall-cmd --permanent --add-service=nfs
success
[root@localhost images]# firewall-cmd --reload
success

3、创建挂载点,并进行挂载。

[root@localhost images]# mkdir -p /mnt/nfs/CentOS7
[root@localhost images]# mount -t iso9660 -o ro /mnt/CentOS-7-x86_64-2009.iso /mnt/nfs/CentOS7

4、我们应该通过编辑/etc/exports共享挂载点使用NFS共享。

[root@areadetector etc]# vim /etc/exports
[root@areadetector etc]# cat /etc/exports
/mnt/nfs/CentOS7      192.168.3.0/24(rw,sync)

[root@areadetector etc]# exportfs -av
exporting 192.168.3.0/24:/mnt/nfs/CentOS7

5、启动virt-manager,并选择从网络安装,填入nfs共享地址

 6、按提示地操作步骤,完成虚拟机地创建

使用HTTP的网络安装

1、我们基本也有相同的步骤,安装http服务软件包,启动它并且使它在防火墙上悠久使能。

[root@areadetector blctrl]# dnf install httpd
Last metadata expiration check: 1:36:16 ago on Mon 18 Jul 2022 11:59:33 AM CST.
Dependencies resolved.
...

Complete!
[root@areadetector blctrl]# systemctl start httpd
[root@areadetector blctrl]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@areadetector blctrl]# firewall-cmd --permanent --add-service=http
success
[root@areadetector blctrl]# firewall-cmd --reload
success

2、接着,创建一个挂载点var/www/html/CentOS7,并且把光盘镜像挂载到这个位置:

 mkdir /var/www/html/CentOS7
 1014  mount -t iso9660 -o ro harddisk/CentOS-7-x86_64-Everything-2009.iso /var/www/html/CentOS7

3、重启http服务器,并且查看其运行状态

[root@areadetector mnt]# systemctl restart httpd
[root@areadetector mnt]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2022-07-18 13:55:26 CST; 9s ago
     Docs: man:httpd.service(8)
 Main PID: 734280 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 213 (limit: 820636)
   Memory: 18.3M
   CGroup: /system.slice/httpd.service
           ├─734280 /usr/sbin/httpd -DFOREGROUND
           ├─734282 /usr/sbin/httpd -DFOREGROUND
           ├─734283 /usr/sbin/httpd -DFOREGROUND
           ├─734284 /usr/sbin/httpd -DFOREGROUND
           └─734285 /usr/sbin/httpd -DFOREGROUND

4、在以下界面中,填写http服务器中安装镜像的地址,

5、出现以下安装界面:

 6、按提示地操作步骤进行安装。

最后

以上就是着急枫叶为你收集整理的如何在KVM环境中使用网络安装部署多台虚拟服务器的全部内容,希望文章能够帮你解决如何在KVM环境中使用网络安装部署多台虚拟服务器所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(52)

评论列表共有 0 条评论

立即
投稿
返回
顶部