<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Virtualization (虚拟化) &#8211; Eternal Center</title>
	<atom:link href="https://eternalcenter-sep-2022.github.io/category/virtualization/feed/" rel="self" type="application/rss+xml" />
	<link>https://eternalcenter-sep-2022.github.io/</link>
	<description></description>
	<lastBuildDate>Tue, 23 Aug 2022 17:26:55 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>[步骤] KVM 虚拟机模板的创建 （Rocky Linux 8 版）</title>
		<link>https://eternalcenter-sep-2022.github.io/kvm-template-install-rocky-linux-8/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sun, 06 Feb 2022 09:08:24 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[KVM]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Computer & System Hardware & System Installation & System Upgradation (系统电脑 & 系统硬件 & 系统安装 & 系统升级)]]></category>
		<category><![CDATA[System Installation (系统安装)]]></category>
		<category><![CDATA[Virtualization (虚拟化)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=21850</guid>

					<description><![CDATA[注意： 在创建 KVM 虚拟机之前要先安装 KVM 并创建 KVM 虚拟网络 软件准备： 在 Rocky Linux 官网上下载安装系统所需要的镜像： https://rockylinux.org/download 正文： 步骤一：理解创建 KVM 虚拟机模板的目的 主要用于批量克隆出新的 KVM 机器，节约创建新虚拟机的时间 步骤二：为这个虚拟机创建硬盘文件 2.1 创建硬盘文件 （只在真机上执行以下步骤） （补充：这里以创建 10G 大小的 rockylinux8.qcow2 硬盘文件为例） 2.2 确认硬盘文件已创建 （只在真机上执行以下步骤） （补充：这里以显示 rockylinux8.qcow2 硬盘文件为例） 步骤三：使用 KVM 和刚刚创建的硬盘文件新安装一台虚拟机 3.1 启动 KVM 的 virt-manager （只在真机上执行以下步骤） 3.2 在 virt-manager 上的左上角点击文件之后点击 “新建虚拟机” （只在真机上执行以下步骤） （步骤略） 3.2.1 选择以本地安装介质的方式安装系统 （只在真机上执行以下步骤） &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/kvm-template-install-rocky-linux-8/" class="more-link">Continue reading<span class="screen-reader-text"> "[步骤] KVM 虚拟机模板的创建 （Rocky Linux 8 版）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h1 id="注意">注意：</h1>



<p>在创建 KVM 虚拟机之前要先安装 KVM 并创建 KVM 虚拟网络</p>



<div class="wp-container-1 is-content-justification-center wp-block-buttons">
<div class="wp-block-button is-style-outline"><a class="wp-block-button__link no-border-radius" href="https://eternalcenter-sep-2022.github.io/kvm-install/">KVM 的安装</a></div>



<div class="wp-block-button is-style-outline"><a class="wp-block-button__link no-border-radius" href="https://eternalcenter-sep-2022.github.io/kvm-network-install/">KVM 虚拟网络的创建</a></div>
</div>



<h1 id="软件准备">软件准备：</h1>



<p>在 Rocky Linux 官网上下载安装系统所需要的镜像：</p>



<p class="has-text-align-center"><a href="https://rockylinux.org/download">https://rockylinux.org/download</a></p>



<h1 id="正文">正文：</h1>



<h3 id="步骤一-理解创建-kvm-虚拟机模板的目的">步骤一：理解创建 KVM 虚拟机模板的目的</h3>



<p>主要用于批量克隆出新的 KVM 机器，节约创建新虚拟机的时间</p>



<h3 id="步骤二-为这个虚拟机创建硬盘文件-template-centos-8-10g-qcow22-1-创建硬盘文件-template-centos-8-10g-qcow2">步骤二：为这个虚拟机创建硬盘文件</h3>



<h4 id="步骤二-为这个虚拟机创建硬盘文件-template-centos-8-10g-qcow22-1-创建硬盘文件-template-centos-8-10g-qcow2">2.1 创建硬盘文件</h4>



<p>（只在真机上执行以下步骤）</p>



<pre class="wp-block-code"><code># qemu-img create -f qcow2 /var/lib/libvirt/images/rockylinux8.qcow2 10G</code></pre>



<p>（补充：这里以创建 10G 大小的 rockylinux8.qcow2 硬盘文件为例）</p>



<h4 id="2-2-确认硬盘文件已创建">2.2 确认硬盘文件已创建</h4>



<p>（只在真机上执行以下步骤）</p>



<pre class="wp-block-code"><code># ls /var/lib/libvirt/images/ | grep rockylinux8.qcow2</code></pre>



<p>（补充：这里以显示 rockylinux8.qcow2 硬盘文件为例）</p>



<h3 id="步骤三-使用-kvm-和刚刚创建的硬盘文件新安装一台虚拟机3-1-启动-kvm-的-virt-manager">步骤三：使用 KVM 和刚刚创建的硬盘文件新安装一台虚拟机</h3>



<h4 id="步骤三-使用-kvm-和刚刚创建的硬盘文件新安装一台虚拟机3-1-启动-kvm-的-virt-manager">3.1 启动 KVM 的 virt-manager</h4>



<p>（只在真机上执行以下步骤）</p>



<pre class="wp-block-code"><code># virt-manager</code></pre>



<h4 id="3-2-在-virt-manager-上的左上角点击文件之后点击-新建虚拟机">3.2 在 virt-manager 上的左上角点击文件之后点击 “新建虚拟机”</h4>



<p>（只在真机上执行以下步骤）</p>



<p>（步骤略）</p>



<h5 id="3-2-1-选择以本地安装介质的方式安装系统">3.2.1 选择以本地安装介质的方式安装系统</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img width="494" height="530" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-1.png" alt="" class="wp-image-21851" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-1.png 494w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-1-280x300.png 280w" sizes="(max-width: 494px) 100vw, 494px" /><figcaption><em>（图：1）</em></figcaption></figure></div>


<h5 id="3-2-2-选择安装系统的系统镜像">3.2.2 选择安装系统的系统镜像</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="494" height="530" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-2.png" alt="" class="wp-image-21852" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-2.png 494w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-2-280x300.png 280w" sizes="(max-width: 494px) 100vw, 494px" /><figcaption><em>（图：2）</em></figcaption></figure></div>


<p>（补充：这里以使用 Rocky-8.5-x86_6-dvd1.iso 系统镜像为例）</p>



<h5 id="3-2-3-设置内存大小和处理器数量">3.2.3 设置内存大小和 CPU 核心数</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="494" height="530" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-3.png" alt="" class="wp-image-21853" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-3.png 494w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-3-280x300.png 280w" sizes="(max-width: 494px) 100vw, 494px" /><figcaption><em>（图：3）</em></figcaption></figure></div>


<p>（补充：这里以设置 2048 MiB 内容和 2 核 CPU 为例）</p>



<h5 id="3-2-4-选择用刚刚创建的硬盘文件来安装系统">3.2.4 选择用刚刚创建的硬盘文件来安装系统</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="494" height="530" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-4.png" alt="" class="wp-image-21854" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-4.png 494w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-4-280x300.png 280w" sizes="(max-width: 494px) 100vw, 494px" /><figcaption><em>（图：4）</em></figcaption></figure></div>


<p>（补充：这里以使用 rockylinux8.qcow2 硬盘文件为例）</p>



<h5 id="3-2-5-给虚拟机命名并选择虚拟网络">3.2.5 给虚拟机命名并选择虚拟网络</h5>



<p>（只在真机上执行以下步骤）</p>



<p>（注意：虚拟网络必须提前创建好）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="494" height="533" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-5.png" alt="" class="wp-image-21855" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-5.png 494w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-5-278x300.png 278w" sizes="(max-width: 494px) 100vw, 494px" /><figcaption><em>（图：5）</em></figcaption></figure></div>


<p>（补充：这里以将虚拟机命名为 rockylinux8 并使用 0 网络为例）</p>



<h5 id="3-2-6-开始安装系统">3.2.6 开始安装系统</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="794" height="630" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-6.png" alt="" class="wp-image-21856" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-6.png 794w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-6-300x238.png 300w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-6-768x609.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption><em>（图：6）</em></figcaption></figure></div>


<h5 id="3-2-7-选择系统语言">3.2.7 选择系统语言</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="1016" height="762" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-7.png" alt="" class="wp-image-21857" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-7.png 1016w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-7-300x225.png 300w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-7-768x576.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption><em>（图：7）</em></figcaption></figure></div>


<h5 id="3-2-8-之后进行系统配置界面">3.2.8 之后进行系统配置界面</h5>



<p>（只在真机上执行以下步骤）</p>



<p>需要手动配置的地方有四个：<br>1) “INSTALLATION DESTINATION”<br>2) “KDUMP”<br>3) “SOFTWARE SELECTION”<br>4) “Root Password”<br>分别点击以后就可以配置了</p>



<h5 id="3-2-8-1-通过-installation-destination-对硬盘进行分区">3.2.8.1 通过 “INSTALLATION DESTINATION” 对硬盘进行分区</h5>



<p>（只在真机上执行以下步骤）</p>



<p>（补充：完成后点击左上角的 “DONE”）</p>



<p>（注意：只分一个分区，只设置一个挂载点挂载到根，使用标准硬盘类型，硬盘格式设置为 XFS）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="1016" height="762" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-8.png" alt="" class="wp-image-21858" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-8.png 1016w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-8-300x225.png 300w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-8-768x576.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption><em>（图：8）</em></figcaption></figure></div>

<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="1016" height="762" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-9.png" alt="" class="wp-image-21859" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-9.png 1016w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-9-300x225.png 300w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-9-768x576.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption><em>（图：9）</em></figcaption></figure></div>


<h5 id="3-2-8-2-取消-kdump">3.2.8.2 取消 “KDUMP”</h5>



<p>（只在真机上执行以下步骤）</p>



<p>（补充：完成后点击左上角的 “DONE”）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="1016" height="762" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-10.png" alt="" class="wp-image-21860" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-10.png 1016w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-10-300x225.png 300w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-10-768x576.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption><em>（图：10）</em></figcaption></figure></div>


<h5 id="3-2-8-3-选择最小化安装系统">3.2.8.3 选择最小化安装系统</h5>



<p>（只在真机上执行以下步骤）</p>



<p>（补充：完成后点击左上角的 “DONE”）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="1016" height="762" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-11.png" alt="" class="wp-image-21861" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-11.png 1016w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-11-300x225.png 300w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-11-768x576.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption><em>（图：11）</em></figcaption></figure></div>


<h5 id="3-2-8-4-设置-root-密码">3.2.8.4 设置 root 密码</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="1016" height="762" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-12.png" alt="" class="wp-image-21862" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-12.png 1016w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-12-300x225.png 300w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-12-768x576.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption><em>（图：12）</em></figcaption></figure></div>


<h5 id="3-2-9-之后点击右下角的-begin-installation">3.2.9 之后点击右下角的 “Begin installation”</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="1016" height="762" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-13.png" alt="" class="wp-image-21863" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-13.png 1016w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-13-300x225.png 300w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-13-768x576.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption><em>（图：13）</em></figcaption></figure></div>


<h5 id="3-2-10-安装完成后重启">3.2.10 安装完成后重启</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="1016" height="762" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-14.png" alt="" class="wp-image-21864" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-14.png 1016w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-14-300x225.png 300w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2022/02/KVM-template-Rocky-Linux-8-14-768x576.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption><em>（图：14）</em></figcaption></figure></div>


<h5 id="3-2-11-在安装系统的过程中需要注意的内容总结">3.2.11 在安装系统的过程中需要注意的内容总结</h5>



<p>（只在真机上执行以下步骤）</p>



<p>1) 一定要使用刚刚创建的 /var/lib/libvirt/images/rockylinux8.qcow2 作为安装虚拟机的硬件文件<br>2) 虚拟机网络 “0” 要提前创建好<br>3) 只分一个分区，只设置一个挂载点挂载到根，使用标准硬盘，硬盘格式是 XFS<br>4) 取消 “KDUMP”<br>5) 选择最小化安装系统<br>6) 设置 root 密码</p>



<h3 id="步骤四-进入新创建虚拟机修改配置4-1-修改网卡个性化设置4-1-1-修改网卡配置文件">步骤四：进入新创建虚拟机修改配置</h3>



<h4 id="步骤四-进入新创建虚拟机修改配置4-1-修改网卡个性化设置4-1-1-修改网卡配置文件">4.1 修改网卡个性化设置</h4>



<h5 id="步骤四-进入新创建虚拟机修改配置4-1-修改网卡个性化设置4-1-1-修改网卡配置文件">4.1.1 修改网卡配置文件</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/sysconfig/network-scripts/ifcfg-enp1s0</code></pre>



<p>将全部内容修改如下：</p>



<pre class="wp-block-code"><code>TYPE=Ethernet
BOOTPROTO=dhcp
NAME=enp1s0
DEVICE=enp1s0
ONBOOT=yes</code></pre>



<h5 id="4-1-2-使修改的网卡配置生效">4.1.2 使修改的网卡配置生效</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># reboot</code></pre>



<h4 id="4-2-禁用-selinux">4.2 禁用 SELinux</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/selinux/config</code></pre>



<p>将全部内容修改如下：</p>



<pre class="wp-block-code"><code># This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted</code></pre>



<h4 id="4-3-禁用空路由">4.3 禁用空路由</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/sysconfig/network</code></pre>



<p>将全部内容修改如下：</p>



<pre class="wp-block-code"><code># Created by anaconda
NOZEROCONF="yes"</code></pre>



<h4 id="4-4-添加-console-配置4-4-1-修改-grub-内核配置文件">4.4 添加 Console 配置</h4>



<h5 id="4-4-添加-console-配置4-4-1-修改-grub-内核配置文件">4.4.1 修改 grub 内核配置文件</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/default/grub</code></pre>



<p>将全部内容修改如下：</p>



<pre class="wp-block-code"><code>GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL="serial console"
GRUB_SERIAL_COMMAND="serial --unit=1 --speed=115200"
GRUB_CMDLINE_LINUX="biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8"
GRUB_DISABLE_LINUX_UUID="true"
GRUB_ENABLE_LINUX_LABEL="true"
GRUB_DISABLE_RECOVERY="true"</code></pre>



<h5 id="4-4-2-使修改的-grub-内核配置生效">4.4.2 使修改的 grub 内核配置生效</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># grub2-mkconfig -o grub</code></pre>



<h4 id="4-5-将系统自动挂载的硬盘从使用-uuid-换成硬件路径4-5-1-显示根分区的-uuid">4.5 将系统自动挂载的硬盘从使用 UUID 换成硬件路径</h4>



<h5 id="4-5-将系统自动挂载的硬盘从使用-uuid-换成硬件路径4-5-1-显示根分区的-uuid">4.5.1 显示根分区的 UUID</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># blkid
/dev/sda1: UUID="e76ed189-6d0f-49d5-8586-c5aae4bdc9b5" TYPE="xfs" PARTUUID="3d8377ef-01"</code></pre>



<p>（补充：这里的 UUID 是： e76ed189-6d0f-49d5-8586-c5aae4bdc9b5）</p>



<h5 id="4-5-2-在自动挂载文件里将根分区的-uuid-换成硬件路径">4.5.2 在自动挂载文件里将根分区的 UUID 换成硬件路径</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/fstab</code></pre>



<p>将以下内容：</p>



<pre class="wp-block-code"><code>......
UUID=e76ed189-6d0f-49d5-8586-c5aae4bdc9b5 /                   xfs     defaults        0 0</code></pre>



<p>（补充：这里的 UUID 是： e76ed189-6d0f-49d5-8586-c5aae4bdc9b5）</p>



<p>修改为：</p>



<pre class="wp-block-code"><code>/dev/sda1 /                   xfs     defaults        0 0</code></pre>



<h4 id="4-6-删除不用的程序">4.6 删除不用的程序</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum -y remove firewalld-* python-firewall</code></pre>



<h4 id="4-7-对虚拟系统进行升级">4.7 对虚拟系统进行升级</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum -y update</code></pre>



<h4 id="4-9-进行分区扩展4-9-1-安装分区扩展软件">4.8 进行分区扩展</h4>



<h5 id="4-9-进行分区扩展4-9-1-安装分区扩展软件">4.8.1 安装分区扩展软件</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum install -y cloud-utils-growpart</code></pre>



<h5 id="4-8-2-给开机自启配置文件相应的权限">4.8.2 给开机自启配置文件相应的权限</h5>



<pre class="wp-block-code"><code># chmod 755 /etc/rc.local</code></pre>



<h5 id="4-8-3-设置开机自动扩容根目录">4.8.3 设置开机自动扩容根目录</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/rc.local</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
/usr/bin/growpart /dev/sda1
/usr/sbin/xfs_growfs /</code></pre>



<h4 id="4-9-修改虚拟机系统的名称">4.9 修改虚拟机系统的名称</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/hostname</code></pre>



<p>将全部内容修改如下：</p>



<pre class="wp-block-code"><code>rockylinux8</code></pre>



<h4 id="4-10-启用-serial-服务实现通过-virsh-console-命令控制虚拟机">4.10 启用 serial 服务实现通过 virsh console 命令控制虚拟机</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># systemctl start serial-getty@ttyS0
# systemctl enable serial-getty@ttyS0</code></pre>



<h4 id="4-11-清除虚拟系统的历史命令">4.11 清除虚拟系统的历史命令</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># history -c</code></pre>



<h4 id="4-12-关闭虚拟机">4.12 关闭虚拟机</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># poweroff</code></pre>



<h4 id="步骤五-在真机上对虚拟机进行清理优化">步骤五：在真机上对虚拟机进行清理优化</h4>



<p>（只在真机上执行以下步骤）</p>



<pre class="wp-block-code"><code># sudo virt-sysprep -d rockylinux8</code></pre>



<p>（补充：这里以清理 rockylinux8 虚拟机为例）</p>



<p>（<br>注意：如果此命令不存在<br>1) Rocky Linux 系统的话需要安装 libguestfs-tools<br>2) openSUSE 系统的话需要安装 guestfs-tools<br>）</p>



<h4 id="步骤六-此时就可以将此虚拟机的硬件文件作为模板进行批量克隆虚拟机了">步骤六：此时就可以将此虚拟机的硬件文件作为模板进行批量克隆虚拟机了</h4>



<p>（只在真机上执行以下步骤）</p>



<p>（步骤略）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[排错] 解决 KVM 开启虚拟机时报错 “failed to set MSR 0xe1 to 0x0”</title>
		<link>https://eternalcenter-sep-2022.github.io/debug-failed-to-set-msr-0xe1-to-0x0/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sun, 22 Aug 2021 14:09:42 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[KVM]]></category>
		<category><![CDATA[Virtualization (虚拟化)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=17549</guid>

					<description><![CDATA[报错代码 AMD CPU 在使用 KVM 开启虚拟机时可能会出现此类报错： 解决方法]]></description>
										<content:encoded><![CDATA[
<h4>报错代码</h4>



<p>AMD CPU 在使用 KVM 开启虚拟机时可能会出现此类报错：</p>



<pre class="wp-block-code"><code>failed to set MSR 0xe1 to 0x0</code></pre>



<h4>解决方法</h4>



<pre class="wp-block-code"><code># echo Y &gt; /sys/module/kvm/parameters/ignore_msrs</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] VMware 命令行启动 （Linux 版）</title>
		<link>https://eternalcenter-sep-2022.github.io/vmware-command-start-linux/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sun, 22 Aug 2021 11:34:44 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Virtualization (虚拟化)]]></category>
		<category><![CDATA[VMware]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=17547</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-code"><code># /etc/init.d/vmware start
# vmplayer</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] KVM 虚拟机模板的创建 （openSUSE Leap 15 版）</title>
		<link>https://eternalcenter-sep-2022.github.io/kvm-template-install-opensuse-leap-15/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 06 Feb 2021 14:23:47 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[KVM]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Computer & System Hardware & System Installation & System Upgradation (系统电脑 & 系统硬件 & 系统安装 & 系统升级)]]></category>
		<category><![CDATA[System Installation (系统安装)]]></category>
		<category><![CDATA[Virtualization (虚拟化)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=13283</guid>

					<description><![CDATA[注意： 在创建 KVM 虚拟机之前要先安装 KVM 并创建 KVM 虚拟网络 软件准备： 在 openSUSE 官网上下载安装系统所需要的镜像： https://software.opensuse.org/distributions/leap 正文： 步骤一：理解创建 KVM 虚拟机模板的目的 主要用于批量克隆出新的 KVM 机器，节约创建新虚拟机的时间 步骤二：为这个虚拟机创建硬盘文件 1.1 创建硬盘文件 （只在真机上执行以下步骤） （补充：这里以创建 10G 大小的 template_opensuse_leap_15_10g.qcow2 硬盘文件为例） 1.2 确认硬盘文件已创建 （只在真机上执行以下步骤） （补充：这里以确认 template_opensuse_leap_15_10g.qcow2 硬盘文件为例） 步骤三：使用 KVM 和刚刚创建的硬盘文件新安装一台虚拟机 3.1 启动 KVM 的 virt-manager （只在真机上执行以下步骤） 3.2 在 virt-manager 上的左上角点击文件之后 “点击新建虚拟机” （只在真机上执行以下步骤） （步骤略） 3.2.1 选择以本地安装介质的方式安装系统 （只在真机上执行以下步骤） 3.2.2 &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/kvm-template-install-opensuse-leap-15/" class="more-link">Continue reading<span class="screen-reader-text"> "[步骤] KVM 虚拟机模板的创建 （openSUSE Leap 15 版）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h1 id="注意">注意：</h1>



<p>在创建 KVM 虚拟机之前要先安装 KVM 并创建 KVM 虚拟网络</p>



<div class="wp-container-2 is-horizontal is-content-justification-center wp-block-buttons">
<div class="wp-block-button is-style-outline"><a class="wp-block-button__link no-border-radius" href="https://eternalcenter-sep-2022.github.io/kvm-install/">KVM 的安装</a></div>



<div class="wp-block-button is-style-outline"><a class="wp-block-button__link no-border-radius" href="https://eternalcenter-sep-2022.github.io/kvm-network-installation/">KVM 虚拟网络的创建</a></div>
</div>



<h1 id="软件准备">软件准备：</h1>



<p>在 openSUSE 官网上下载安装系统所需要的镜像：</p>



<p class="has-text-align-center"><a href="https://software.opensuse.org/distributions/leap" target="_blank" rel="noreferrer noopener">https://software.opensuse.org/distributions/leap</a></p>



<h1 id="正文">正文：</h1>



<h3 id="步骤一-理解创建-kvm-虚拟机模板的目的">步骤一：理解创建 KVM 虚拟机模板的目的</h3>



<p>主要用于批量克隆出新的 KVM 机器，节约创建新虚拟机的时间</p>



<h3 id="步骤二-为这个虚拟机创建硬盘文件-template-opensuse-leap-15-10g-qcow21-1-创建硬盘文件-template-opensuse-leap-15-10g-qcow2">步骤二：为这个虚拟机创建硬盘文件</h3>



<h4 id="步骤二-为这个虚拟机创建硬盘文件-template-opensuse-leap-15-10g-qcow21-1-创建硬盘文件-template-opensuse-leap-15-10g-qcow2">1.1 创建硬盘文件</h4>



<p>（只在真机上执行以下步骤）</p>



<pre class="wp-block-code"><code># qemu-img create -f qcow2 /var/lib/libvirt/images/template_opensuse_leap_15_10g.qcow2 10G</code></pre>



<p>（补充：这里以创建 10G 大小的 template_opensuse_leap_15_10g.qcow2 硬盘文件为例）</p>



<h4 id="1-2-确认硬盘文件已创建">1.2 确认硬盘文件已创建</h4>



<p>（只在真机上执行以下步骤）</p>



<pre class="wp-block-code"><code># ls /var/lib/libvirt/images/ | grep template_opensuse_leap_15_10g.qcow2</code></pre>



<p>（补充：这里以确认 template_opensuse_leap_15_10g.qcow2 硬盘文件为例）</p>



<h3 id="步骤三-使用-kvm-和刚刚创建的硬盘文件新安装一台虚拟机3-1-启动-kvm-的-virt-manager">步骤三：使用 KVM 和刚刚创建的硬盘文件新安装一台虚拟机</h3>



<h4 id="步骤三-使用-kvm-和刚刚创建的硬盘文件新安装一台虚拟机3-1-启动-kvm-的-virt-manager">3.1 启动 KVM 的 virt-manager</h4>



<p>（只在真机上执行以下步骤）</p>



<pre class="wp-block-code"><code># virt-manager</code></pre>



<h4 id="3-2-在-virt-manager-上的左上角点击文件之后-点击新建虚拟机">3.2 在 virt-manager 上的左上角点击文件之后 “点击新建虚拟机”</h4>



<p>（只在真机上执行以下步骤）</p>



<p>（步骤略）</p>



<h5 id="3-2-1-选择以本地安装介质的方式安装系统">3.2.1 选择以本地安装介质的方式安装系统</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="502" height="539" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-1.png" alt="" class="wp-image-19725" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-1.png 502w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-1-279x300.png 279w" sizes="(max-width: 502px) 100vw, 502px" /><figcaption>（图：1）</figcaption></figure></div>


<h5 id="3-2-2-选择安装系统的系统镜像">3.2.2 选择安装系统的系统镜像</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="502" height="539" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-2.png" alt="" class="wp-image-19726" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-2.png 502w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-2-279x300.png 279w" sizes="(max-width: 502px) 100vw, 502px" /><figcaption>（图：2）</figcaption></figure></div>


<p>（补充：这里以使用 openSUSE-Leap-15.2-DVD-x86_64.iso 系统镜像为例）</p>



<h5 id="3-2-3-设置内存大小和处理器数量">3.2.3 设置内存大小和 CPU 核心数</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="502" height="539" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-3.png" alt="" class="wp-image-19727" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-3.png 502w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-3-279x300.png 279w" sizes="(max-width: 502px) 100vw, 502px" /><figcaption>（图：3）</figcaption></figure></div>


<p>（补充：这里以设置 2048 MiB 内容和 2 核 CPU 为例）</p>



<h5 id="3-2-4-选择用刚刚创建的硬盘文件来安装系统">3.2.4 选择用刚刚创建的硬盘文件来安装系统</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="502" height="539" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-4.png" alt="" class="wp-image-19728" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-4.png 502w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-4-279x300.png 279w" sizes="(max-width: 502px) 100vw, 502px" /><figcaption>（图：4）</figcaption></figure></div>


<p>（补充：这里以使用 template_opensuse_leap_15_10g.qcow2 硬盘文件为例）</p>



<h5 id="3-2-5-给虚拟机命名并选择虚拟网络">3.2.5 给虚拟机命名并选择虚拟网络</h5>



<p>（只在真机上执行以下步骤）</p>



<p>（注意：虚拟网络必须提前创建好）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="502" height="539" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-5.png" alt="" class="wp-image-19729" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-5.png 502w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-5-279x300.png 279w" sizes="(max-width: 502px) 100vw, 502px" /><figcaption>（图：5）</figcaption></figure></div>


<p>（补充：这里以将虚拟机命名为 template_opensuse_leap_15_10g 并使用 0 网络为例）</p>



<h5 id="3-2-6-开始安装系统">3.2.6 开始安装系统</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="613" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-6.png" alt="" class="wp-image-19730" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-6.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-6-300x239.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：6）</figcaption></figure></div>


<h5 id="3-2-7-进入-language-keyboard-and-license-agreement-后选择系统语言-再点击-next">3.2.7 进入 “Language, Keyboard and License Agreement” 后选择系统语言，再点击 “Next”</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-7.png" alt="" class="wp-image-19731" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-7.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-7-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：7）</figcaption></figure></div>


<h5 id="3-2-8-当出现-activate-online-repositories-now-时-点击-no">3.2.8 当出现 &#8220;Activate online repositories now?&#8221; 时，点击 “No”</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-8.png" alt="" class="wp-image-19733" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-8.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-8-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：8）</figcaption></figure></div>


<h5 id="3-2-9-进入-system-role-后选择-server-再点击-next">3.2.9 进入 “System Role” 后选择 “Server”，再点击 “Next”</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-9.png" alt="" class="wp-image-19734" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-9.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-9-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：9）</figcaption></figure></div>


<h5 id="3-2-10-进入-suggested-partitioning-后点击-guided-setup">3.2.10 进入 “Suggested Partitioning” 后点击 “Guided Setup”</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-10.png" alt="" class="wp-image-19735" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-10.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-10-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：10）</figcaption></figure></div>


<h5 id="3-2-11-进入-partitioning-scheme-后点击-next">3.2.11 进入 “Partitioning Scheme” 后点击 “Next”</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-11.png" alt="" class="wp-image-19736" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-11.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-11-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：11）</figcaption></figure></div>


<h5 id="3-2-12-进入-filesystem-options-后-file-system-type-选择-xfs-再点击-next">3.2.12 进入 “Filesystem Options” 后 “File System Type“ 选择 “XFS”，再点击 “Next”</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-12.png" alt="" class="wp-image-19737" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-12.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-12-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：12）</figcaption></figure></div>


<h5 id="3-2-13-回到-suggested-partitioning-后点击-next">3.2.13 回到 “Suggested Partitioning” 后点击 “Next”</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-13.png" alt="" class="wp-image-19738" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-13.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-13-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：13）</figcaption></figure></div>


<h5 id="3-2-14-进入-clock-and-time-zone-后选择时区-再点击-next">3.2.14 进入 “Clock and Time Zone” 后选择时区，再点击 “Next”</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="266" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-14.png" alt="" class="wp-image-19739" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-14.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-14-300x104.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：14）</figcaption></figure></div>


<h5 id="3-2-15-进入-local-user-后选择-skip-user-creation-并点击-next">3.2.15 进入 “Local User” 后选择 “Skip User Creation” 并点击 “Next”</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-15.png" alt="" class="wp-image-19740" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-15.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-15-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：15）</figcaption></figure></div>


<h5 id="3-2-16-进入-authentication-for-the-system-administrator-root-后给-root-设置密码-再点击-next">3.2.16 进入 “Authentication for the System Administrator &#8220;root&#8221;” 后给 root 设置密码，再点击 “Next”</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-16.png" alt="" class="wp-image-19741" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-16.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-16-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：16）</figcaption></figure></div>


<h5 id="3-2-17-如果出现-yast2-the-password-is-too-simple-则点击-yes">3.2.17 如果出现 “YaST2 The password is too simple” 则点击 “Yes”</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-17.png" alt="" class="wp-image-19742" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-17.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-17-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：17）</figcaption></figure></div>


<h5 id="3-2-18-进入-installation-settings-后点击-next">3.2.18 进入 “Installation Settings” 后点击 “Next”</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-18.png" alt="" class="wp-image-19743" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-18.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-18-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：18）</figcaption></figure></div>


<h5 id="3-2-19-当出现-confirm-installation-时点击-install">3.2.19 当出现 “Confirm Installation” 时点击 “Install”</h5>



<p>（只在真机上执行以下步骤）</p>



<figure class="wp-block-image size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-19.png" alt="" class="wp-image-19744" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-19.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-19-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：19）</figcaption></figure>



<h5 id="3-2-20-当出现-the-system-will-reboot-now-时-点击-ok">3.2.20 当出现 “The system will reboot now…” 时，点击 “Ok”</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-20.png" alt="" class="wp-image-19745" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-20.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-openSUSE-15-20-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：20）</figcaption></figure></div>


<h5 id="3-2-21-在安装系统的过程中需要注意的内容总结">3.2.21 在安装系统的过程中需要注意的内容总结</h5>



<p>（只在真机上执行以下步骤）</p>



<p>1)  一定要使用刚刚创建的 template_opensuse_leap_15_10g.qcow2 作为安装虚拟机的硬件文件<br>2)  虚拟机网络 “0” 要提前创建好<br>3)  只分一个分区，只设置一个挂载点挂载到根，使用标准硬盘，硬盘格式是 XFS<br>4)  选择最小化安装系统</p>



<h3 id="步骤四-进入新创建虚拟机修改配置4-1-添加-console-配置4-1-1-修改-grub-内核配置文件">步骤四：进入新创建虚拟机修改配置</h3>



<h4 id="步骤四-进入新创建虚拟机修改配置4-1-添加-console-配置4-1-1-修改-grub-内核配置文件">4.1 添加 Console 配置</h4>



<h5 id="步骤四-进入新创建虚拟机修改配置4-1-添加-console-配置4-1-1-修改-grub-内核配置文件">4.1.1 修改 grub 内核配置文件</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/default/grub</code></pre>



<p>将全部内容修改如下：</p>



<pre class="wp-block-code"><code># If you change this file, run 'grub2-mkconfig -o /boot/grub2/grub.cfg' afterwards to update
# /boot/grub2/grub.cfg.

# Uncomment to set your own custom distributor. If you leave it unset or empty, the default
# policy is to determine the value from /etc/os-release
GRUB_DISTRIBUTOR=
GRUB_DEFAULT=saved
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=8
GRUB_CMDLINE_LINUX_DEFAULT="splash=silent mitigations=auto quiet"
GRUB_SERIAL_COMMAND="serial --unit=1 --speed=115200"
GRUB_CMDLINE_LINUX="biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8"
GRUB_DISABLE_LINUX_UUID="true"
GRUB_ENABLE_LINUX_LABEL="true"
GRUB_DISABLE_RECOVERY="true"

# Uncomment to automatically save last booted menu entry in GRUB2 environment

# variable `saved_entry'
# GRUB_SAVEDEFAULT="true"
#Uncomment to enable BadRAM filtering, modify to suit your needs

# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
# GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"
#Uncomment to disable graphical terminal (grub-pc only)

GRUB_TERMINAL="gfxterm"
# The resolution used on graphical terminal
#note that you can use only modes which your graphic card supports via VBE

# you can see them in real GRUB with the command `vbeinfo'
GRUB_GFXMODE="auto"
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
# GRUB_DISABLE_LINUX_UUID=true
#Uncomment to disable generation of recovery mode menu entries

# GRUB_DISABLE_RECOVERY="true"
#Uncomment to get a beep at grub start

# GRUB_INIT_TUNE="480 440 1"
GRUB_BACKGROUND=
GRUB_THEME=/boot/grub2/themes/openSUSE/theme.txt
SUSE_BTRFS_SNAPSHOT_BOOTING="true"
GRUB_DISABLE_OS_PROBER="false"
GRUB_ENABLE_CRYPTODISK="n"
GRUB_CMDLINE_XEN_DEFAULT="vga=gfx-1024x768x16"</code></pre>



<h5 id="4-1-2-使修改的-grub-内核配置生效">4.1.2 使修改的 grub 内核配置生效</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># grub2-mkconfig -o grub</code></pre>



<h4 id="4-2-将系统自动挂载的硬盘从使用-uuid-换成硬件路径4-2-1-显示根分区的-uuid">4.2 将系统自动挂载的硬盘从使用 uuid 换成硬件路径</h4>



<h5 id="4-2-将系统自动挂载的硬盘从使用-uuid-换成硬件路径4-2-1-显示根分区的-uuid">4.2.1 显示根分区的 UUID</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># blkid
/dev/vda1: UUID="53ee2f87-89b8-4cd7-a4dc-0957d28f4831" TYPE="xfs" PARTUUID="3d8377ef-01"</code></pre>



<p>（补充：这里的 UUID 是： 53ee2f87-89b8-4cd7-a4dc-0957d28f4831）</p>



<h5 id="4-2-2-在自动挂载文件里将根分区的-uuid-换成硬件路径">4.2.2 在自动挂载文件里将根分区的 UUID 换成硬件路径</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/fstab</code></pre>



<p>将以下内容：</p>



<pre class="wp-block-code"><code>......
UUID=53ee2f87-89b8-4cd7-a4dc-0957d28f4831 /                   xfs     defaults        0 0</code></pre>



<p>（补充：这里的 UUID 是： 53ee2f87-89b8-4cd7-a4dc-0957d28f4831）</p>



<p>修改为：</p>



<pre class="wp-block-code"><code>......
/dev/vda1 /                   xfs     defaults        0 0</code></pre>



<h4 id="4-3-删除不用的软件">4.3 删除不用的软件</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># zypper -n rm firewalld-*</code></pre>



<h4 id="4-4-进行分区扩展4-4-1-安装分区扩展软件">4.4 进行分区扩展</h4>



<h5 id="4-4-进行分区扩展4-4-1-安装分区扩展软件">4.4.1 安装分区扩展软件</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># zypper -n in growpart</code></pre>



<h5 id="4-4-2-设置开机自动扩容根目录-4-4-2-1-创建开机自动扩容根目录的配置文件">4.4.2 设置开机自动扩容根目录</h5>



<h5 id="4-4-2-设置开机自动扩容根目录-4-4-2-1-创建开机自动扩容根目录的配置文件">4.4.2.1 创建开机自动扩容根目录的配置文件</h5>



<pre class="wp-block-code"><code># vim /etc/init.d/after.local</code></pre>



<p>创建以下内容：</p>



<pre class="wp-block-code"><code>/usr/bin/growpart /dev/sda1
/usr/sbin/xfs_growfs /</code></pre>



<h5 id="4-4-2-2-给开机自启配置文件相应的权限">4.4.2.2 给开机自启配置文件相应的权限</h5>



<pre class="wp-block-code"><code># chmod 755 /etc/init.d/after.local</code></pre>



<h4 id="4-5-只使用本地软件源-选做-4-5-1-禁用所有软件源-选做">4.5 只使用本地软件源（选做）</h4>



<h5 id="4-5-只使用本地软件源-选做-4-5-1-禁用所有软件源-选做">4.5.1 禁用所有软件源（选做）</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># zypper mr -da</code></pre>



<h5 id="4-5-2-添加本地软件源-选做">4.5.2 添加本地软件源（选做）</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># zypper ar -fcg http://10.0.0.254/openSUSE-Leap-15/ lan</code></pre>



<p>(注意： http://10.0.0.254/openSUSE-Leap-15/ 需要根据真实环境的情况进行更改)</p>



<h5 id="4-5-3-添加本地软件源-选做">4.5.3 添加本地软件源（选做）</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># zypper ref</code></pre>



<h4 id="4-6-修改虚拟机系统的名称">4.6 修改虚拟机系统的名称</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># hostnamectl set-hostname template_opensuse_leap_15_10g</code></pre>



<h4 id="4-7-启用-serial-服务实现通过-virsh-console-命令控制虚拟机">4.7 启用 serial 服务实现通过 virsh console 命令控制虚拟机</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># systemctl start serial-getty@ttyS0
# systemctl enable serial-getty@ttyS0</code></pre>



<h4 id="4-8-清除虚拟系统的历史命令">4.8 清除虚拟系统的历史命令</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># history -c</code></pre>



<h4 id="4-9-关闭虚拟机">4.9 关闭虚拟机</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># poweroff</code></pre>



<h3 id="步骤五-修改新创建的虚拟机配置文件">步骤五：修改新创建的虚拟机配置文件</h3>



<p>删除配置文件里 cdrom 相关的部分</p>



<pre class="wp-block-code"><code># vim /etc/libvirt/qemu/template_opensuse_leap_15_10g.xml</code></pre>



<p>删除以下内容：</p>



<pre class="wp-block-code"><code>......
    &lt;disk type='file' device='cdrom'&gt;
      &lt;driver name='qemu' type='raw'/&gt;
      &lt;source file='/test/iso/openSUSE-Leap-15.2-DVD-x86_64.iso'/&gt;
      &lt;target dev='sda' bus='sata'/&gt;
      &lt;readonly/&gt;
      &lt;address type='drive' controller='0' bus='0' target='0' unit='0'/&gt;
    &lt;/disk&gt;
......</code></pre>



<h3 id="步骤五-此时就可以将此虚拟机的硬件文件作为模板进行批量克隆虚拟机了">步骤六：此时就可以将此虚拟机的硬件文件作为模板进行批量克隆虚拟机了</h3>



<p>（只在真机上执行以下步骤）</p>



<p>（步骤略）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] 远程虚拟化平台的搭建</title>
		<link>https://eternalcenter-sep-2022.github.io/remote-virtual-platform/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 26 Sep 2020 10:10:37 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[KVM]]></category>
		<category><![CDATA[Other Service (其它服务)]]></category>
		<category><![CDATA[Service (服务)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Computer (系统电脑)]]></category>
		<category><![CDATA[System Computer & System Hardware & System Installation & System Upgradation (系统电脑 & 系统硬件 & 系统安装 & 系统升级)]]></category>
		<category><![CDATA[Virtualization (虚拟化)]]></category>
		<category><![CDATA[VNC]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=10587</guid>

					<description><![CDATA[步骤一：规划拓扑 1.1 电脑列表 1) 一台可以联接公网的电脑2) 一个 CentOS 8.2 系统的安装 U 盘3) 一台可以联接公网并且有公网 IP 地址的 VPS4) 一个可以联接公网并使用 SSH 和 VNC 的客户端 1.2 服务器列表简介 1) 电脑通过 SSH 建立联接到 VPS 的隧道，此操作会占用 VPS 的一个端口2) VPS 通过 SSH 将联接电脑的隧道端口映射到一个新的端口3) 客户端通过 SSH 联接到 VPS 映射出来的新端口，通过 SSH 或远程桌面使用虚拟化平台4) 客户端和电脑如果在同一内网里则可以通过 Samba 互传数据 步骤二：CentOS 8.2 系统的安装 U 盘给电脑安装系统 （只在电脑上执行以下步骤）（步骤略） （补充：安装系统时可选择以下选项：1) 系统起动方式：BIOS2) Keyboard：English(US)3) Language Support：English(United &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/remote-virtual-platform/" class="more-link">Continue reading<span class="screen-reader-text"> "[步骤] 远程虚拟化平台的搭建"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h3 id="步骤一-规划拓扑1-1-电脑列表">步骤一：规划拓扑</h3>



<h4 id="步骤一-规划拓扑1-1-电脑列表">1.1 电脑列表</h4>



<p>1) 一台可以联接公网的电脑<br>2) 一个 CentOS 8.2 系统的安装 U 盘<br>3) 一台可以联接公网并且有公网 IP 地址的 VPS<br>4) 一个可以联接公网并使用 SSH 和 VNC 的客户端</p>



<h4 id="1-2-服务器列表简介">1.2 服务器列表简介</h4>



<p>1) 电脑通过 SSH 建立联接到 VPS 的隧道，此操作会占用 VPS 的一个端口<br>2) VPS 通过 SSH 将联接电脑的隧道端口映射到一个新的端口<br>3) 客户端通过 SSH 联接到 VPS 映射出来的新端口，通过 SSH 或远程桌面使用虚拟化平台<br>4) 客户端和电脑如果在同一内网里则可以通过 Samba 互传数据</p>



<h3 id="步骤二-centos-8-2-系统的安装-u-盘给电脑安装系统">步骤二：CentOS 8.2 系统的安装 U 盘给电脑安装系统</h3>



<p>（只在电脑上执行以下步骤）<br>（步骤略）</p>



<p>（<br>补充：<br>安装系统时可选择以下选项：<br>1) 系统起动方式：BIOS<br>2) Keyboard：English(US)<br>3) Language Support：English(United States)<br>4) Time &amp; Date：Asia/ShangHai<br>5) Installation Source：Local media<br>6) Software Selection：Minial Install<br>7) Installation Destination：将主硬盘里的所有空间都分配给根分区<br>8) KDUMP：Kdump is disabled<br>9) Network &amp; Host Name：开启网络联接并设置好固定 DNS<br>10) SECURITY POLICY：No controller found<br>）</p>



<p>（这里以将 IP 地址设置为固定 IP 地址 192.168.0.1，DNS 设置为固定 DNS 8.8.8.8 为例）</p>



<h3 id="步骤三-安装图形系统桌面">步骤三：安装图形系统桌面</h3>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum groupinstall -y "Server with GUI"</code></pre>



<h3 id="步骤四-安装中文输入法4-1-安装中文库">步骤四：安装中文输入法</h3>



<h4 id="步骤四-安装中文输入法4-1-安装中文库">4.1 安装中文库</h4>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum -y install langpacks-zh_CN</code></pre>



<h4 id="4-2-确认中文库已经安装">4.2 确认中文库已经安装</h4>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># locale -a</code></pre>



<h4 id="4-3-安装中文输入法">4.3 安装中文输入法</h4>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum -y install ibus ibus-libpinyin</code></pre>



<h3 id="步骤五-创建用户用户5-1-创建用户用户">步骤五：创建用户用户</h3>



<h4 id="步骤五-创建用户用户5-1-创建用户用户">5.1 创建用户用户</h4>



<p>（分别在电脑、VPS 和客户端上执行以下步骤）</p>



<pre class="wp-block-code"><code># useradd zhumingyu</code></pre>



<p>（补充：这里创建用户 zhumingyu 为例）</p>



<h4 id="5-2-给用户用户设置密码">5.2 给用户用户设置密码</h4>



<p>（分别在电脑、VPS 和客户端上执行以下步骤）</p>



<pre class="wp-block-code"><code># passwd zhumingyu</code></pre>



<p>（补充：这里创建用户 zhumingyu 为例）</p>



<h3 id="步骤六-增加-centos-系统的稳定性6-1-延长看门狗喂狗间隔以减少系统被软锁出现-softlockup-的几率6-1-1-临时延长看门狗喂狗间隔的时间">步骤六：增加 CentOS 系统的稳定性</h3>



<h4 id="步骤六-增加-centos-系统的稳定性6-1-延长看门狗喂狗间隔以减少系统被软锁出现-softlockup-的几率6-1-1-临时延长看门狗喂狗间隔的时间">6.1 延长看门狗喂狗间隔以减少系统被软锁出现 softlockup 的几率</h4>



<h5 id="步骤六-增加-centos-系统的稳定性6-1-延长看门狗喂狗间隔以减少系统被软锁出现-softlockup-的几率6-1-1-临时延长看门狗喂狗间隔的时间">6.1.1 临时延长看门狗喂狗间隔的时间</h5>



<p>（分别在电脑和 VPS 上执行以下步骤）</p>



<pre class="wp-block-code"><code># sysctl -w kernel.watchdog_thresh=60</code></pre>



<h5 id="6-1-2-永久延长看门狗喂狗间隔的时间6-1-2-1-添加延长看门狗喂狗间隔的设置">6.1.2 永久延长看门狗喂狗间隔的时间</h5>



<h5 id="6-1-2-永久延长看门狗喂狗间隔的时间6-1-2-1-添加延长看门狗喂狗间隔的设置">6.1.2.1 添加延长看门狗喂狗间隔的设置</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># vim /etc/sysctl.conf</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
kernel.watchdog_thresh=60</code></pre>



<h5 id="6-1-2-2-让添加延长看门狗喂狗间隔的设置生效">6.1.2.2 让添加延长看门狗喂狗间隔的设置生效</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># sysctl -p</code></pre>



<h5 id="6-1-3-让-softlockup-触发后直接宕机">6.1.3 让 softlockup 触发后直接宕机</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># echo 1 &gt; /proc/sys/kernel/softlockup_panic</code></pre>



<h4 id="6-2-禁止图形系统桌面的-dns-和路由以避免系统崩溃6-2-1-添加禁止图形系统桌面的-dns-和路由的设置">6.2 禁止图形系统桌面的 DNS 和路由以避免系统崩溃</h4>



<h5 id="6-2-禁止图形系统桌面的-dns-和路由以避免系统崩溃6-2-1-添加禁止图形系统桌面的-dns-和路由的设置">6.2.1 添加禁止图形系统桌面的 DNS 和路由的设置</h5>



<p>（分别在电脑和 VPS 上执行以下步骤）</p>



<pre class="wp-block-code"><code># vim /etc/sysconfig/network-scripts/ifcfg-enp9s0</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
PEERDNS=no
PEERROUTES=no</code></pre>



<p>（补充：这里的 ifcfg-enp9s0 是指网卡对应的配置文件，不同的网卡对应的配置文件不同，这里以网卡名 ifcfg-enp9s0 为例，需要给所有网卡添加此参数，这一步也可以在系统图形系统桌面上设置）</p>



<h5 id="6-2-2-让禁止图形系统桌面的-dns-和路由的设置生效">6.2.2 让禁止图形系统桌面的 DNS 和路由的设置生效</h5>



<p>（分别在电脑和 VPS 上执行以下步骤）</p>



<pre class="wp-block-code"><code># systemctl restart NetworkManager</code></pre>



<h4 id="6-3-禁止图形系统界面自动黑屏或自动挂起">6.3 禁止图形系统界面自动黑屏或自动挂起</h4>



<p>（只在电脑上执行以下步骤）</p>



<h4 id="6-4-让-ssh-联接永久不超时6-4-1-让-ssh-服务端的连接不超时">6.4 让 SSH 联接永久不超时</h4>



<h5 id="6-4-让-ssh-联接永久不超时6-4-1-让-ssh-服务端的连接不超时">6.4.1 让 SSH 服务端的连接不超时</h5>



<p>（分别在电脑和 VPS 上执行以下步骤）</p>



<pre class="wp-block-code"><code># vim /etc/ssh/sshd_config</code></pre>



<p>将以下内容：</p>



<pre class="wp-block-code"><code>......
#ClientAliveInterval 0
#ClientAliveCountMax 3
......</code></pre>



<p>修改为：</p>



<pre class="wp-block-code"><code>......
ClientAliveInterval 60
ClientAliveCountMax 525600
......</code></pre>



<p>（补充：这样设置会让 SSH 服务端每 60s 就会尝试连接一次客户端，如果 525600 次后没有回应，则断开）</p>



<h5 id="6-4-2-让用户登陆永不超时6-4-2-1-在系统文件里添加让用户登陆永不超时的设置">6.4.2 让用户登录永不超时</h5>



<h5 id="6-4-2-让用户登陆永不超时6-4-2-1-在系统文件里添加让用户登陆永不超时的设置">6.4.2.1 在系统文件里添加让用户登录永不超时的设置</h5>



<p>（分别在电脑和 VPS 上执行以下步骤）</p>



<pre class="wp-block-code"><code># vim /etc/bashrc</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
export TMOUT=0</code></pre>



<pre class="wp-block-code"><code># vim /etc/profile</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
export TMOUT=0</code></pre>



<h5 id="6-4-2-2-让用户登陆永不超时的设置立刻生效">6.4.2.2 让用户登录永不超时的设置立刻生效</h5>



<p>（分别在电脑和 VPS 上执行以下步骤）</p>



<pre class="wp-block-code"><code># source /etc/bashrc
# source /etc/profile</code></pre>



<h4 id="6-5-删除不需要的软件包以避免-cpu-占用过高而崩溃-选做">6.5 删除不需要的软件包以避免 CPU 占用过高而崩溃（选做）</h4>



<p>（步骤略）</p>



<h3 id="步骤七-搭建虚拟化平台">步骤七：搭建虚拟化平台</h3>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum -y install qemu-kvm libvirt-daemon libvirt-client libvirt-daemon-driver-qemu virt-install virt-manager virt-viewer virt-v2v</code></pre>



<h3 id="步骤八-实现文件共享8-1-安装-samba-服务">步骤八：实现文件共享</h3>



<h4 id="步骤八-实现文件共享8-1-安装-samba-服务">8.1 安装 Samba 服务</h4>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum -y install samba
</code></pre>



<h4 id="8-2-配置-samba-服务的配置文件">8.2 配置 Samba 服务的配置文件</h4>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># vim /etc/samba/smb.conf</code></pre>



<p>将全部内容修改如下：</p>



<pre class="wp-block-code"><code># See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.

&#91;global]
workgroup = WORKGROUP
realm = zhumingyu
netbios name = zhumingyu
#encrypt passwords = yes
map to guest = NEVER
security = user
password server = *
name resolve order = bcast host
restrict anonymous = 2
#null passwords = no
#guest account = smb_nobody
#use spnego = yes
client use spnego = yes
server string = ""
host msdfs = no
msdfs root = no
domain master = no
preferred master = no
local master = no
os level = 0
browse list = no
browseable = no
dns proxy = no
wide links = no
public= no
guest ok = no
hosts deny = ALL EXCEPT 192.168.0.2

&#91;share]
valid users = zhumingyu
write list = zhumingyu
read list = zhumingyu
path = /share
guest ok = no
read only = no
browseable = no
writable = yes
public = no
create mask = 0755
directory mask = 0755</code></pre>



<p>（<br>补充：<br>1) 这里以 Samba 服务器的 IP 地址是 192.168.0.1 为例<br>2) 这里的 workgroup = WORKGROUP 是让 Samba 服务属于 WORKGROUP<br>3) 这里的 hosts deny = ALL EXCEPT 192.168.0.2 是只让客户端 192.168.0.3 能够访问服务端的 Samba<br>4) 这里的 sharetest 是这个 Samba 挂载点的名称，挂载这个挂载点的格式就是：//192.168.0.1/share<br>5) 这里的 valid users = zhumingyu 是 Samba 服务共享用户需要手动生成<br>6) 这里的 path = /share 是 Samba 服务共享目录需要手动生成<br>）</p>



<h4 id="8-3-设置-samba-服务共享用户8-3-1-给-samba-服务共享用户设置-samba-共享密码">8.3 设置 Samba 服务共享用户</h4>



<h5 id="8-3-设置-samba-服务共享用户8-3-1-给-samba-服务共享用户设置-samba-共享密码">8.3.1 给 Samba 服务共享用户设置 Samba 共享密码</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># smbpasswd -a zhumingyu</code></pre>



<p>（补充：这里以用户 zhumingyu 为例）</p>



<h5 id="8-3-2-显示-samba-服务共享用户是否可用">8.3.2 显示 Samba 服务共享用户是否可用</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># pdbedit -L</code></pre>



<h4 id="8-4-生成-samba-服务共享目录8-4-1-生成-samba-服务共享目录">8.4 生成 Samba 服务共享目录</h4>



<h5 id="8-4-生成-samba-服务共享目录8-4-1-生成-samba-服务共享目录">8.4.1 生成 Samba 服务共享目录</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># mkdir /share</code></pre>



<h5 id="8-4-2-给-samba-服务共享目录设置权限">8.4.2 给 Samba 服务共享目录设置权限</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># chmod 755 /share/</code></pre>



<h5 id="8-4-3-给-samba-服务共享目录设置所属主和所属组">8.4.3 给 Samba 服务共享目录设置所属主和所属组</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># chown zhumingyu:zhumingyu /share/</code></pre>



<p>（补充：这里以用户 zhumingyu 为例）</p>



<h5 id="8-4-4-给-samba-服务共享目录设置-selinux-标签">8.4.4 给 Samba 服务共享目录设置 selinux 标签</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># semanage fcontext -a -t samba_share_t '/share(/.*)?'</code></pre>



<h5 id="8-4-5-让-samba-服务共享目录上的-selinux-标签立刻生效">8.4.5 让 Samba 服务共享目录上的 selinux 标签立刻生效</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># restorecon -RFvv /share/</code></pre>



<h4 id="8-5-启动-samba-服务并设置为开机自动启动">8.5 启动 Samba 服务并设置为开机自动启动</h4>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># systemctl enable --now smb</code></pre>



<h4 id="8-6-在系统防火墙开放-samba-的端口8-6-1-在系统防火墙开放-samba-的端口">8.6 在系统防火墙开放 Samba 的端口</h4>



<h5 id="8-6-在系统防火墙开放-samba-的端口8-6-1-在系统防火墙开放-samba-的端口">8.6.1 在系统防火墙开放 Samba 的端口</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># firewall-cmd --add-service=samba --permanent</code></pre>



<h5 id="8-6-2-让系统防火墙重新加载">8.6.2 让系统防火墙重新加载</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># firewall-cmd --reload</code></pre>



<h3 id="步骤九-实现远程桌面9-1-安装-vnc-服务">步骤九：实现远程桌面</h3>



<h4 id="步骤九-实现远程桌面9-1-安装-vnc-服务">9.1 安装 vnc 服务</h4>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum -y install tigervnc tigervnc-server</code></pre>



<h4 id="9-2-设置-vnc-服务共享用户9-2-1-进入用户">9.2 设置 VNC 服务共享用户</h4>



<h5 id="9-2-设置-vnc-服务共享用户9-2-1-进入用户">9.2.1 进入用户</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># su - zhumingyu</code></pre>



<p>（补充：这里以用户 zhumingyu 为例）</p>



<h5 id="9-2-2-给-vnc-服务共享用户设置-vnc-远程密码">9.2.2 给 VNC 服务共享用户设置 VNC 远程密码</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ vncpasswd</code></pre>



<h5 id="9-2-3-退出用户">9.2.3 退出用户</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ exit</code></pre>



<h4 id="9-3-启动-vnc-并设置为开机自动启动9-3-1-创建开启-vnc-的脚本-vnc-sh9-3-1-1-进入到用户">9.3 启动 VNC 并设置为开机自动启动</h4>



<h5 id="9-3-启动-vnc-并设置为开机自动启动9-3-1-创建开启-vnc-的脚本-vnc-sh9-3-1-1-进入到用户">9.3.1 创建开启 VNC 的脚本 ~/vnc.sh</h5>



<h5 id="9-3-启动-vnc-并设置为开机自动启动9-3-1-创建开启-vnc-的脚本-vnc-sh9-3-1-1-进入到用户">9.3.1.1 进入到用户</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># su - zhumingyu</code></pre>



<p>（补充：这里以用户 zhumingyu 为例）</p>



<h5 id="9-3-1-2-创建开启-vnc-的脚本-vnc-sh">9.3.1.2 创建开启 VNC 的脚本 ~/vnc.sh</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ vim ~/vnc.sh</code></pre>



<p>创建以下内容：</p>



<pre class="wp-block-code"><code>#!/bin/bash

vncserver -list | grep :1 &amp;&gt; /dev/null || vncserver :1 -localhost -nolisten tcp</code></pre>



<p>（补充：此命令会检查 vncserver :1 会话是否存在，如果不存在，就以禁止非安全远程登录的方式创建一个）</p>



<h5 id="9-3-1-3-退出用户">9.3.1.3 退出用户</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ exit</code></pre>



<h5 id="9-3-2-执行开启-vnc-的脚本9-3-2-1-开机执行开启-vnc-的脚本9-3-2-1-1-配置开机执行的文件">9.3.2 执行开启 VNC 的脚本</h5>



<h5 id="9-3-2-执行开启-vnc-的脚本9-3-2-1-开机执行开启-vnc-的脚本9-3-2-1-1-配置开机执行的文件">9.3.2.1 开机执行开启 VNC 的脚本</h5>



<h5 id="9-3-2-执行开启-vnc-的脚本9-3-2-1-开机执行开启-vnc-的脚本9-3-2-1-1-配置开机执行的文件">9.3.2.1.1 配置开机执行的文件</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># vim /etc/rc.local</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
su - zhumingyu -c '/home/zhumingyu/vnc.sh'</code></pre>



<p>（补充：这里以用户 zhumingyu 的身份运行）</p>



<p>或者：</p>



<pre class="wp-block-code"><code>......
su - zhumingyu -c 'vncserver -list | grep :1' &amp;&gt; /dev/null || su - zhumingyu -c 'vncserver :1 -localhost -nolisten tcp'</code></pre>



<p>（<br>补充：<br>1) 如果前面没有创建脚本的话，可以只添加上面“或者”后面的这一行<br>2) 以用户 zhumingyu 的身份运行<br>3) 此命令会检查 vncserver :1 会话是否存在，如果不存在，就以禁止非安全远程登录的方式创建一个<br>）</p>



<h5 id="9-3-2-1-2-给开机执行的文件执行权限">9.3.2.1.2 给开机执行的文件执行权限</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># chmod u+x /home/zhumingyu/vnc.sh</code></pre>



<h5 id="9-3-2-2-定期执行开启-vnc-的脚本9-3-2-2-1-进入到用户">9.3.2.2 定期执行开启 VNC 的脚本</h5>



<h5 id="9-3-2-2-定期执行开启-vnc-的脚本9-3-2-2-1-进入到用户">9.3.2.2.1 进入到用户</h5>



<pre class="wp-block-code"><code># su - zhumingyu</code></pre>



<p>（补充：这里以用户 zhumingyu 为例）</p>



<h5 id="9-3-2-2-2-配置定期执行的文件">9.3.2.2.2 配置定期执行的文件</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ crontab -e</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
0 */1 * * * /home/zhumingyu/vnc.sh</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code>......
0 */1 * * * vncserver -list | grep :1' &amp;&gt; /dev/null || su - zhumingyu -c 'vncserver :1 -localhost -nolisten tcp</code></pre>



<p>（<br>补充：<br>1) 这里以用户 zhumingyu 的身份运行<br>2) 如果前面没有创建脚本的话，可以只添加上面“或者”后面的这一行<br>3) 此命令会检查 vncserver :1 会话是否存在，如果不存在，就以禁止非安全远程登录的方式创建一个<br>）</p>



<h5 id="9-3-2-2-3-退出用户">9.3.2.2.3 退出用户</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ exit</code></pre>



<h3 id="步骤十-设置-ssh-内网穿透10-1-生成-ssh-密钥10-1-1-进入到用户">步骤十：设置 SSH 内网穿透</h3>



<h5 id="步骤十-设置-ssh-内网穿透10-1-生成-ssh-密钥10-1-1-进入到用户">10.1 生成 SSH 密钥</h5>



<h5 id="步骤十-设置-ssh-内网穿透10-1-生成-ssh-密钥10-1-1-进入到用户">10.1.1 进入到用户</h5>



<p>（分别在电脑、VPS 和客户端上执行以下步骤）</p>



<pre class="wp-block-code"><code># su - zhumingyu</code></pre>



<p>（补充：这里以用户 zhumingyu 为例）</p>



<h5 id="10-1-2-生成-ssh-密钥">10.1.2 生成 SSH 密钥</h5>



<p>（分别在电脑、VPS 和客户端上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ ssh-keygen -b 2048 -t rsa</code></pre>



<p>（补充：建议在创建 SSH 密钥时为 SSH 密钥添加一个密码）</p>



<h5 id="10-1-3-退出用户">10.1.3 退出用户</h5>



<p>（分别在电脑、VPS 和客户端上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ exit</code></pre>



<h4 id="10-2-实现无密钥-ssh10-2-1-进入到用户">10.2 实现无密钥 SSH</h4>



<h5 id="10-2-实现无密钥-ssh10-2-1-进入到用户">10.2.1 进入到用户</h5>



<p>（分别在电脑、VPS 和客户端上执行以下步骤）</p>



<pre class="wp-block-code"><code># su - zhumingyu</code></pre>



<p>（补充：这里以用户 zhumingyu 为例）</p>



<h5 id="10-2-2-让电脑可以无密钥-ssh-vps">10.2.2 让电脑可以无密钥 SSH VPS</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ ssh-copy-id &lt;public IP address of VPS&gt;</code></pre>



<h5 id="10-2-3-让-vps-可以无密钥-ssh-自己">10.2.3 让 VPS 可以无密钥 SSH 自己</h5>



<p>（只在 VPS 上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ ssh-copy-id localhost</code></pre>



<h5 id="10-2-4-让客户端可以远程-vps-和电脑">10.2.4 让客户端可以远程 VPS 和电脑</h5>



<pre class="wp-block-code"><code>$ ssh-copy-id &lt;IP address of computer&gt;
$ ssh-copy-id &lt;public IP address of VPS&gt;</code></pre>



<h5 id="10-2-5-退出用户">10.2.5 退出用户</h5>



<p>（分别在电脑、VPS 和客户端上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ exit</code></pre>



<h4 id="10-3-建立电脑到-vps-的-ssh-隧道并设置为开机自启10-3-1-创建建立电脑到-vps-的-ssh-隧道的脚本-ssh-sh10-3-1-1-进入到用户">10.3 建立电脑到 VPS 的 SSH 隧道并设置为开机自启</h4>



<h5 id="10-3-建立电脑到-vps-的-ssh-隧道并设置为开机自启10-3-1-创建建立电脑到-vps-的-ssh-隧道的脚本-ssh-sh10-3-1-1-进入到用户">10.3.1 创建建立电脑到 VPS 的 SSH 隧道的脚本 ～/ssh.sh<br>10.3.1.1 进入到用户</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># su - zhumingyu</code></pre>



<p>（补充：这里以用户 zhumingyu 为例）</p>



<h5 id="10-3-1-2-创建建立电脑到-vps-的-ssh-隧道的脚本-ssh-sh">10.3.1.2 创建建立电脑到 VPS 的 SSH 隧道的脚本 ～/ssh.sh</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ vim ～/ssh.sh</code></pre>



<p>创建以下内容：</p>



<pre class="wp-block-code"><code>ps -aux | grep -v grep | grep "11000:localhost:22 &lt;IP address of computer&gt;" &amp;&gt; /dev/null || ssh -X -fCNR 11000:localhost:22 &lt;IP address of computer&gt;</code></pre>



<p>（<br>补充：<br>1) 这里以用户 zhumingyu 的身份运行<br>2) 如果 11000 端口没有影射到 22 端口则影射<br>）</p>



<h5 id="10-3-1-3-退出用户">10.3.1.3 退出用户</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ exit</code></pre>



<h5 id="10-3-2-执行电脑到-vps-的-ssh-隧道的脚本10-3-2-1-开机执行开启电脑到-vps-的-ssh-隧道的脚本10-3-2-1-1-配置开机执行的文件">10.3.2 执行电脑到 VPS 的 SSH 隧道的脚本</h5>



<h5 id="10-3-2-执行电脑到-vps-的-ssh-隧道的脚本10-3-2-1-开机执行开启电脑到-vps-的-ssh-隧道的脚本10-3-2-1-1-配置开机执行的文件">10.3.2.1 开机执行开启电脑到 VPS 的 SSH 隧道的脚本</h5>



<h5 id="10-3-2-执行电脑到-vps-的-ssh-隧道的脚本10-3-2-1-开机执行开启电脑到-vps-的-ssh-隧道的脚本10-3-2-1-1-配置开机执行的文件">10.3.2.1.1 配置开机执行的文件</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># vim /etc/rc.local</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
su - zhumingyu -c '/home/zhumingyu/ssh.sh'</code></pre>



<p>（补充：这里以用户 zhumingyu 的身份运行）</p>



<p>或者：</p>



<pre class="wp-block-code"><code>......
ps -aux | grep -v grep | grep "11000:localhost:22 &lt;IP address of computer&gt;" &amp;&gt; /dev/null || su - zhumingyu -c 'ssh -X -fCNR 11000:localhost:22 &lt;IP address of computer&gt;'</code></pre>



<p>（<br>补充：<br>1) 如果前面没有创建脚本的话，可以只添加上面“或者”后面的这一行<br>2) 这里以用户 zhumingyu 的身份运行<br>3) 如果 11000 端口没有影射到 22 端口则影射<br>）</p>



<h5 id="10-3-2-1-2-给开机执行的文件执行权限">10.3.2.1.2 给开机执行的文件执行权限</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># chmod +x /etc/rc.local</code></pre>



<h5 id="10-3-3-定期执行电脑到-vps-的-ssh-隧道的脚本10-3-3-1-进入到用户">10.3.3 定期执行电脑到 VPS 的 SSH 隧道的脚本</h5>



<h5 id="10-3-3-定期执行电脑到-vps-的-ssh-隧道的脚本10-3-3-1-进入到用户">10.3.3.1 进入到用户</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># su - zhumingyu</code></pre>



<p>（补充：这里以 zhumingyu 为例）</p>



<h5 id="10-3-3-2-配置定期执行的文件">10.3.3.2 配置定期执行的文件</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ crontab -e</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
0 */1 * * * /home/zhumingyu/ssh.sh</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code>......
0 */1 * * * ps -aux | grep -v grep | grep "11000:localhost:22 &lt;IP address of computer&gt;" &amp;&gt; /dev/null || ssh -X -fCNR 11000:localhost:22 &lt;IP address of computer&gt;</code></pre>



<p>（补充：如果 11000 端口影射到 22 端口则影射）</p>



<h5 id="10-3-3-3-退出用户">10.3.3.3 退出用户</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ exit</code></pre>



<h4 id="10-4-建立-vps-的-ssh-隧道端口映射并设置为开机自启10-4-1-创建建立-vps-的-ssh-隧道端口映射的脚本10-4-1-1-进入到用户">10.4 建立 VPS 的 SSH 隧道端口映射并设置为开机自启</h4>



<h5 id="10-4-建立-vps-的-ssh-隧道端口映射并设置为开机自启10-4-1-创建建立-vps-的-ssh-隧道端口映射的脚本10-4-1-1-进入到用户">10.4.1 创建建立 VPS 的 SSH 隧道端口映射的脚本</h5>



<h5 id="10-4-建立-vps-的-ssh-隧道端口映射并设置为开机自启10-4-1-创建建立-vps-的-ssh-隧道端口映射的脚本10-4-1-1-进入到用户">10.4.1.1 进入到用户</h5>



<p>（只在 VPS 上执行以下步骤）</p>



<pre class="wp-block-code"><code># su - zhumingyu</code></pre>



<p>（补充：这里以用户 zhumingyu 为例）</p>



<h5 id="10-4-1-2-创建建立-vps-的-ssh-隧道端口映射的脚本">10.4.1.2 创建建立 VPS 的 SSH 隧道端口映射的脚本</h5>



<p>（只在 VPS 上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ vim ~/sshd.sh</code></pre>



<p>创建以下内容：</p>



<pre class="wp-block-code"><code>#!/bin/bash

ps -aux | grep -v grep | grep "*:10000:localhost:11000 localhost" || ssh -X -fCNL *:10000:localhost:11000 localhost</code></pre>



<p>（补充：如果 11000 端口没有影射成 10000 端口则影射）</p>



<h5 id="10-4-1-3-退出用户">10.4.1.3 退出用户</h5>



<p>（只在 VPS 上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ exit</code></pre>



<h5 id="10-4-2-执行电脑到-vps-的-ssh-隧道的脚本10-4-2-1-开机执行开启电脑到-vps-的-ssh-隧道的脚本10-4-2-1-1-配置开机执行的文件">10.4.2 执行电脑到 VPS 的 SSH 隧道的脚本</h5>



<h5 id="10-4-2-执行电脑到-vps-的-ssh-隧道的脚本10-4-2-1-开机执行开启电脑到-vps-的-ssh-隧道的脚本10-4-2-1-1-配置开机执行的文件">10.4.2.1 开机执行开启电脑到 VPS 的 SSH 隧道的脚本</h5>



<h5 id="10-4-2-执行电脑到-vps-的-ssh-隧道的脚本10-4-2-1-开机执行开启电脑到-vps-的-ssh-隧道的脚本10-4-2-1-1-配置开机执行的文件">10.4.2.1.1 配置开机执行的文件</h5>



<p>（只在 VPS 上执行以下步骤）</p>



<pre class="wp-block-code"><code># vim /etc/rc.local</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
su - zhumingyu -c '/home/zhumingyu/sshd.sh'</code></pre>



<p>（补充：这里以用户 zhumingyu 为例）</p>



<p>或者：</p>



<pre class="wp-block-code"><code>......
ps -aux | grep -v grep | grep "*:10000:localhost:11000 localhost" || su - zhumingyu -c 'ssh -X -fCNL *:10000:localhost:11000 localhost'</code></pre>



<p>（<br>补充：<br>1) 如果前面没有创建脚本的话，可以只添加上面“或者”后面的这一行<br>2) 以用户 zhumingyu 的身份运行<br>3) 如果 11000 端口没有影射成 10000 端口则影射<br>）</p>



<h5 id="10-4-2-1-2-给开机执行的文件执行权限">10.4.2.1.2 给开机执行的文件执行权限</h5>



<p>（只在 VPS 上执行以下步骤）</p>



<pre class="wp-block-code"><code># chmod +x /etc/rc.local</code></pre>



<h5 id="10-4-3-定期执行电脑到-vps-的-ssh-隧道的脚本10-4-3-1-进入到用户用户">10.4.3 定期执行电脑到 VPS 的 SSH 隧道的脚本</h5>



<h5 id="10-4-3-定期执行电脑到-vps-的-ssh-隧道的脚本10-4-3-1-进入到用户用户">10.4.3.1 进入到用户用户</h5>



<p>（只在 VPS 上执行以下步骤）</p>



<pre class="wp-block-code"><code># su - zhumingyu</code></pre>



<p>（补充：这里以用户 zhumingyu 为例）</p>



<h5 id="10-4-3-2-配置定期执行的文件">10.4.3.2 配置定期执行的文件</h5>



<p>（只在 VPS 上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ crontab -e</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
0 */1 * * * /home/zhumingyu/sshd.sh</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code>......
0 */1 * * * ps -aux | grep -v grep | grep "*:10000:localhost:11000 localhost" || ssh -X -fCNL *:10000:localhost:11000 localhost</code></pre>



<p>（<br>补充：<br>1) 如果前面没有创建脚本的话，可以只添加上面“或者”后面的这一行<br>2) 如果 11000 端口没有影射成 10000 端口则影射<br>）</p>



<h5 id="10-4-4-退出用户">10.4.4 退出用户</h5>



<p>（只在 VPS 上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ exit</code></pre>



<h5 id="10-4-5-打开外网-vps-对应端口的防火墙10-4-5-1-打开外网-vps-对应端口的防火墙">10.4.5 打开外网 VPS 对应端口的防火墙</h5>



<h5 id="10-4-5-打开外网-vps-对应端口的防火墙10-4-5-1-打开外网-vps-对应端口的防火墙">10.4.5.1 打开外网 VPS 对应端口的防火墙</h5>



<p>（只在 VPS 上执行以下步骤）</p>



<pre class="wp-block-code"><code># firewall-cmd --add-port=10000/tcp --permanent</code></pre>



<p>（补充：这里打开的端口号，是根据前面的设置而定的）</p>



<h5 id="10-4-5-2-让刚刚外网-vps-刚刚配置的防火墙生效">10.4.5.2 让刚刚外网 VPS 刚刚配置的防火墙生效</h5>



<p>（只在 VPS 上执行以下步骤）</p>



<pre class="wp-block-code"><code># firewall-cmd --reload</code></pre>



<h3 id="步骤十一-加强-ssh-的安全性-选做-11-1-禁止-root-被-ssh-选做">步骤十一：加强 SSH 的安全性（选做）</h3>



<h4 id="步骤十一-加强-ssh-的安全性-选做-11-1-禁止-root-被-ssh-选做">11.1 禁止 root 被 SSH（选做）</h4>



<p>（分别在电脑和 VPS 上执行以下步骤）</p>



<pre class="wp-block-code"><code># vim /etc/ssh/sshd_config</code></pre>



<p>将以下内容：</p>



<pre class="wp-block-code"><code>......
PermitRootLogin no
......</code></pre>



<p>修改为：</p>



<pre class="wp-block-code"><code>......
PermitRootLogin yes
......</code></pre>



<h4 id="11-2-禁止使用密码被-ssh-选做">11.2 禁止使用密码被 SSH（选做）</h4>



<p>（分别在电脑和 VPS 上执行以下步骤）</p>



<pre class="wp-block-code"><code># vim /etc/ssh/sshd_config</code></pre>



<p>将以下内容：</p>



<pre class="wp-block-code"><code>......
# PasswordAuthentication yes
......</code></pre>



<p>修改为：</p>



<pre class="wp-block-code"><code>......
PasswordAuthentication no
......</code></pre>



<h3 id="步骤十二-私有远程桌面和虚拟化平台的使用12-1-客户端-ssh-联接电脑的方法12-1-1-客户端和电脑不在同一内网时">步骤十二：私有远程桌面和虚拟化平台的使用</h3>



<h4 id="步骤十二-私有远程桌面和虚拟化平台的使用12-1-客户端-ssh-联接电脑的方法12-1-1-客户端和电脑不在同一内网时">12.1 客户端 SSH 联接电脑的方法</h4>



<h5 id="步骤十二-私有远程桌面和虚拟化平台的使用12-1-客户端-ssh-联接电脑的方法12-1-1-客户端和电脑不在同一内网时">12.1.1 客户端和电脑不在同一内网时</h5>



<p>（只在客户端上执行以下步骤）</p>



<pre class="wp-block-code"><code># ssh -X -p &lt;SSH non standard port number&gt; &lt;user of computer&gt;@&lt;public IP address of VPS&gt;</code></pre>



<p>（<br>补充：<br>1) 如果按照前面的步骤操作，这里的 VPS 每小时会生成一个新的 SSH 非标准端口号以用于联接电脑，比如说现在是 14 点，那就会自动生成一个 11014 的 SSH 非标准端口号<br>2) 如果按照前面的步骤操作，这里的用户是 zhumingyu<br>）</p>



<h5 id="12-1-2-客户端和电脑在同一内网时">12.1.2 客户端和电脑在同一内网时</h5>



<p>（只在客户端上执行以下步骤）</p>



<pre class="wp-block-code"><code># ssh -X &lt;user of computer&gt;@&lt;IP address of computer&gt;</code></pre>



<p>（<br>补充：<br>1) 如果按照前面的步骤操作，这里的用户用户是 zhumingyu<br>2) 如果按照前面的步骤操作，这里的电脑的 IP 地址是 192.168.0.1<br>）</p>



<h4 id="12-2-客户端使用电脑虚拟化平台的的方法12-2-1-客户端和电脑不在同一内网时12-2-1-1-在客户端上联接电脑">12.2 客户端使用电脑虚拟化平台的的方法</h4>



<h5 id="12-2-客户端使用电脑虚拟化平台的的方法12-2-1-客户端和电脑不在同一内网时12-2-1-1-在客户端上联接电脑">12.2.1 客户端和电脑不在同一内网时</h5>



<h5 id="12-2-客户端使用电脑虚拟化平台的的方法12-2-1-客户端和电脑不在同一内网时12-2-1-1-在客户端上联接电脑">12.2.1.1 在客户端上联接电脑</h5>



<p>（只在客户端上执行以下步骤）</p>



<pre class="wp-block-code"><code># ssh -X -p &lt;SSH non standard port number&gt; &lt;user of computer&gt;@&lt;public IP address of VPS&gt;</code></pre>



<p>（<br>补充：<br>1) 如果按照前面的步骤操作，这里的 VPS 每小时会生成一个新的 SSH 非标准端口号以用于联接电脑，比如说现在是 14 点，那就会自动生成一个 11014 的 SSH 非标准端口号<br>2) 如果按照前面的步骤操作，这里的用户用户是 zhumingyu<br>）</p>



<h5 id="12-2-1-2-通过-ssh-开启虚拟化图形管理平台">12.2.1.2 通过 ssh 开启虚拟化图形管理平台</h5>



<p>（只在客户端上执行以下步骤）</p>



<pre class="wp-block-code"><code># virt-manager</code></pre>



<p>（注意：网络带宽很小则远程桌面会比较卡，建议电脑、客户端和 VPS 的带宽 2m 以上）</p>



<h5 id="12-2-2-客户端和电脑在同一内网时12-2-2-1-在客户端上联接电脑">12.2.2 客户端和电脑在同一内网时</h5>



<h5 id="12-2-2-客户端和电脑在同一内网时12-2-2-1-在客户端上联接电脑">12.2.2.1 在客户端上联接电脑</h5>



<p>（只在客户端上执行以下步骤）</p>



<pre class="wp-block-code"><code># ssh -X &lt;user of computer&gt;@&lt;IP address of computer&gt;</code></pre>



<p>（<br>补充：<br>1) 如果按照前面的步骤操作，这里的用户用户是 zhumingyu<br>2) 如果按照前面的步骤操作，这里的电脑的 IP 地址是 192.168.0.1<br>）</p>



<h5 id="12-2-2-2-通过-ssh-开启虚拟化图形管理平台">12.2.2.2 通过 ssh 开启虚拟化图形管理平台</h5>



<p>（只在客户端上执行以下步骤）</p>



<pre class="wp-block-code"><code># virt-manager</code></pre>



<p>（注意：网络带宽很小则远程桌面会比较卡，建议电脑、客户端和 VPS 的带宽 2m 以上）</p>



<h4 id="12-3-客户端使用私有远程桌面的方法12-3-1-客户端和电脑不在同一内网时">12.3 客户端使用私有远程桌面的方法</h4>



<h5 id="12-3-客户端使用私有远程桌面的方法12-3-1-客户端和电脑不在同一内网时">12.3.1 客户端和电脑不在同一内网时</h5>



<p>（只在客户端上执行以下步骤）</p>



<pre class="wp-block-code"><code># ssh -p &lt;SSH non standard port number&gt; -L &lt;port number of VNC&gt;:localhost:&lt;port number of VNC&gt; -l &lt;user of computer&gt; &lt;public IP address of VPS&gt;</code></pre>



<p>（<br>补充：<br>1) 如果按照前面的步骤操作，这里的 VPS 每小时会生成一个新的 SSH 非标准端口号以用于联接电脑，比如说现在是 14 点，那就会自动生成一个 11014 的 SSH 非标准端口号<br>2) 如果按照前面的步骤操作，这里的 VNC 的端口号是 5901<br>3) 如果按照前面的步骤操作，这里的电脑的用户用户是 zhumingyu<br>）</p>



<p>另开启一个命令行终端：</p>



<pre class="wp-block-code"><code># vncviewer localhost :&lt;number of VNC service&gt;</code></pre>



<p>（补充：如果按照前面的步骤操作，这里的 VNC 服务的编号是 1）</p>



<p>（注意：网络带宽很小则远程桌面会比较卡，建议电脑、客户端和 VPS 的带宽 2m 以上）</p>



<h5 id="12-3-2-客户端和电脑在同一内网时">12.3.2 客户端和电脑在同一内网时</h5>



<p>（只在客户端上执行以下步骤）</p>



<pre class="wp-block-code"><code># vncviewer -via &lt;user of computer&gt;@&lt;IP address of computer&gt; localhost :&lt;number of VNC service&gt;</code></pre>



<p>（<br>补充：<br>1) 如果按照前面的步骤操作，这里的电脑的用户是 zhumingyu<br>2) 如果按照前面的步骤操作，这里的电脑的 IP 地址是 192.168.0.1<br>3) 如果按照前面的步骤操作，这里的 VNC 服务的编号是 1<br>）</p>



<h4 id="12-4-客户端在内网和电脑互传数据的方法12-4-1-在-windows-图形客户端上和电脑互传数据的方法">12.4 客户端在内网和电脑互传数据的方法</h4>



<h5 id="12-4-客户端在内网和电脑互传数据的方法12-4-1-在-windows-图形客户端上和电脑互传数据的方法">12.4.1 在 Windows 图形客户端上和电脑互传数据的方法</h5>



<p>（只在客户端上执行以下步骤）</p>



<p>在文件目录下栏输入以下内容：</p>



<pre class="wp-block-code"><code>\\&lt;IP address of computer&gt;\&lt;samba directory&gt;</code></pre>



<p>（<br>补充：<br>1) 如果按照前面的步骤操作，这里的电脑的 IP 地址是 192.168.0.1<br>2) 如果按照前面的步骤操作，这里的 Samba 项目是 share<br>）</p>



<p>（<br>注意：<br>1) 如果按照前面的步骤操作，只有 IP 地址是 192.168.0.2 和 192.168.0.3 的客户端才能够执行以上步骤<br>2) Windows 客户端建议安装 SecureCRT、Xmanager 和 VNC 客户端以实现 ssh、ssh 调用 virt-manager 和 VNC<br>）</p>



<h5 id="12-4-2-在-linux-图形客户端上和电脑互传数据的方法">12.4.2 在 Linux 图形客户端上和电脑互传数据的方法</h5>



<p>（只在客户端上执行以下步骤）</p>



<p>在文件 &#8211;&gt; 其他位置 &#8211;&gt; 连接到服务器的地址栏里输入以下内容：</p>



<pre class="wp-block-code"><code>smb://&lt;IP address of computer&gt;/&lt;samba directory&gt;</code></pre>



<p>（<br>补充：<br>1) 如果按照前面的步骤操作，这里的电脑的 IP 地址是 192.168.0.1<br>2) 如果按照前面的步骤操作，这里的 Samba 项目是 share<br>）</p>



<p>（注意：如果按照前面的步骤操作，只有 IP 地址是 192.168.0.2 和 192.168.0.3 的客户端才能够执行以上步骤）</p>



<h3 id="步骤十三-客户端直接使用公网-ip-地址联接电脑13-1-实现此步骤所需环境">步骤十三：客户端直接使用公网 IP 地址联接电脑</h3>



<h4 id="步骤十三-客户端直接使用公网-ip-地址联接电脑13-1-实现此步骤所需环境">13.1 实现此步骤所需环境</h4>



<p>网关路由器拥有 IP 地址（可以通过给宽带申请公网 IP 地址并将光纤盒设置为桥接模式，在路由器上添加用户和密码实现）</p>



<h4 id="13-2-在路由器上将电脑上的-22-端口映射到路由器上的公网-ip-地址上-这样路由器上的公网-ip-地址就变成电脑的公网-ip-地址了">13.2 在路由器上将电脑上的 22 端口映射到路由器上的公网 IP 地址上，这样路由器上的公网 IP 地址就变成电脑的公网 IP 地址了</h4>



<p>（步骤略）</p>



<h4 id="13-3-将电脑的公网-ip-地址放到-vps-上13-3-1-将电脑的公网-ip-地址放到-vps-上的意义">13.3 将电脑的公网 IP 地址放到 VPS 上</h4>



<h5 id="13-3-将电脑的公网-ip-地址放到-vps-上13-3-1-将电脑的公网-ip-地址放到-vps-上的意义">13.3.1 将电脑的公网 IP 地址放到 VPS 上的意义</h5>



<p>由于大多数的公网 IP 地址都是动态，定期会变，所以可以通过此方法知道近期的公网 IP 地址是多少</p>



<h5 id="13-3-2-创建将电脑的公网-ip-地址放到-vps-上的脚本13-3-2-1-进入到用户">13.3.2 创建将电脑的公网 IP 地址放到 VPS 上的脚本</h5>



<h5 id="13-3-2-创建将电脑的公网-ip-地址放到-vps-上的脚本13-3-2-1-进入到用户">13.3.2.1 进入到用户</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># su - zhumingyu</code></pre>



<p>（补充：这里以用户 zhumingyu 为例）</p>



<h5 id="13-3-2-2-创建将电脑的公网-ip-地址放到-vps-上的脚本">13.3.2.2 创建将电脑的公网 IP 地址放到 VPS 上的脚本</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ vim /root/computerip.sh</code></pre>



<p>创建以下内容：</p>



<pre class="wp-block-code"><code>#!/bin/bash

computerip=`curl ifconfig.me`
domain=&lt;public IP address of VPS&gt;

ssh athenadb.com \"echo `curl ifconfig.me` &gt; /home/zhumingyu/serverip.txt\"</code></pre>



<p>（补充：这里以将电脑的公网 IP 地址拷贝到 VPS 的 /tmp/computerip.txt 文件里为例）</p>



<h5 id="13-3-2-3-退出用户用户">13.3.2.3 退出用户用户</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ exit</code></pre>



<h5 id="13-3-3-执行将电脑的公网-ip-地址放到-vps-上的脚本13-3-3-1-进入到用户用户">13.3.3 执行将电脑的公网 IP 地址放到 VPS 上的脚本</h5>



<h5 id="13-3-3-执行将电脑的公网-ip-地址放到-vps-上的脚本13-3-3-1-进入到用户用户">13.3.3.1 进入到用户用户</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code># su - zhumingyu</code></pre>



<p>（补充：这里以用户 zhumingyu 为例）</p>



<h5 id="13-3-3-2-配置定期执行的文件">13.3.3.2 配置定期执行的文件</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ crontab -e</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
0 */10 * * * /home/zhumingyu/.crontab/computerip.txt</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code>......
ssh &lt;public IP address of VPS&gt; \"echo `curl ifconfig.me` &gt; /home/zhumingyu/serverip.txt\"</code></pre>



<p>（<br>补充：<br>1) 如果前面没有创建脚本的话，可以只添加上面“或者”后面的这一行<br>2) 将电脑的公网 IP 地址拷贝到 VPS 的 /home/zhumingyu/serverip.txt 文件里<br>）</p>



<h5 id="13-3-3-3-退出用户用户">13.3.3.3 退出用户用户</h5>



<p>（只在电脑上执行以下步骤）</p>



<pre class="wp-block-code"><code>$ exit</code></pre>



<h4 id="13-4-通过-ddns-服务显示电脑的公网-ip13-4-1-通过-ddns-服务显示电脑的公网-ip">13.4 通过 DDNS 服务显示电脑的公网 IP 地址</h4>



<h5 id="13-4-通过-ddns-服务显示电脑的公网-ip13-4-1-通过-ddns-服务显示电脑的公网-ip">13.4.1 通过 DDNS 服务显示电脑的公网 IP 地址</h5>



<p>由于大多数的公网 IP 地址都是动态，定期会变，所以可以通过此方法知道近期的公网 IP 地址是多少</p>



<h5 id="13-4-2-有些-ddns-服务可以在网关路由器上设置-并且通过手机-app-显示现在的公网-ip-地址">13.4.2 有些 DDNS 服务可以在网关路由器上设置，并且通过手机 APP 显示现在的公网 IP 地址</h5>



<p>（步骤略）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] VMware Workstation Player 的安装 （CentOS Linux &#038; RHEL 版）</title>
		<link>https://eternalcenter-sep-2022.github.io/vmware-workstation-player-install-centos-linux-rhel/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 19 Sep 2020 07:09:07 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Virtualization (虚拟化)]]></category>
		<category><![CDATA[VMware]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=10565</guid>

					<description><![CDATA[软件准备： 在 VMware 的官网上下载软件 VMware Workstation Player（本次使用的是 VMware-Player-15.5.6-16341506.x86_64.bundle）： https://my.vmware.com/cn/web/vmware/downloads/info/slug/desktop_end_user_computing/vmware_workstation_player/16_0 正文： 步骤一：系统环境要求 服务器系统要配置好可用的软件源 步骤二：安装 VMware 虚拟化平台的依赖软件 步骤三：给 VMware 安装包执行权限 （补充：本次添加权限的是 VMware-Player-15.5.6-16341506.x86_64.bundle） 步骤四：安装 VMware 虚拟化平台 （补充：本次安装的是 VMware-Player-15.5.6-16341506.x86_64.bundle）]]></description>
										<content:encoded><![CDATA[
<h1>软件准备：</h1>



<p>在 VMware 的官网上下载软件 VMware Workstation Player（本次使用的是 VMware-Player-15.5.6-16341506.x86_64.bundle）：</p>



<p class="has-text-align-center"><a href="https://my.vmware.com/cn/web/vmware/downloads/info/slug/desktop_end_user_computing/vmware_workstation_player/16_0" target="_blank" rel="noreferrer noopener">https://my.vmware.com/cn/web/vmware/downloads/info/slug/desktop_end_user_computing/vmware_workstation_player/16_0</a></p>



<h1>正文：</h1>



<h3>步骤一：系统环境要求</h3>



<p>服务器系统要配置好可用的软件源</p>



<h3>步骤二：安装 VMware 虚拟化平台的依赖软件</h3>



<pre class="wp-block-code"><code># yum -y install perl gcc kernel-devel libX11 libXinerama libXcursor libXtst elfutils-libelf-devel</code></pre>



<h3>步骤三：给 VMware 安装包执行权限</h3>



<pre class="wp-block-code"><code># chmod u+x VMware-Player-15.5.6-16341506.x86_64.bundle</code></pre>



<p>（补充：本次添加权限的是 VMware-Player-15.5.6-16341506.x86_64.bundle）</p>



<h3>步骤四：安装 VMware 虚拟化平台</h3>



<pre class="wp-block-code"><code># ./VMware-Player-15.5.6-16341506.x86_64.bundle</code></pre>



<p>（补充：本次安装的是 VMware-Player-15.5.6-16341506.x86_64.bundle）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] KVM  虚拟机模板的创建 （CentOS Linux 8 版）</title>
		<link>https://eternalcenter-sep-2022.github.io/kvm-template-install-centos-linux-8/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Thu, 31 Oct 2019 14:21:44 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[KVM]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Computer & System Hardware & System Installation & System Upgradation (系统电脑 & 系统硬件 & 系统安装 & 系统升级)]]></category>
		<category><![CDATA[System Installation (系统安装)]]></category>
		<category><![CDATA[Virtualization (虚拟化)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=6392</guid>

					<description><![CDATA[注意： 在创建 KVM 虚拟机之前要先安装 KVM 并创建 KVM 虚拟网络 软件准备： 在 CentOS 官网上下载安装系统所需要的镜像： https://centos.org/download/ 正文： 步骤一：理解创建 KVM 虚拟机模板的目的 主要用于批量克隆出新的 KVM 机器，节约创建新虚拟机的时间 步骤二：为这个虚拟机创建硬盘文件 2.1 创建硬盘文件 （只在真机上执行以下步骤） （补充：这里以创建 10G 大小的 template_centos_8_10g.qcow2 硬盘文件为例） 2.2 确认硬盘文件已创建 （只在真机上执行以下步骤） （补充：这里以确认 template_centos_8_10g.qcow2 硬盘文件为例） 步骤三：使用 KVM 和刚刚创建的硬盘文件新安装一台虚拟机 3.1 启动 KVM 的 virt-manager （只在真机上执行以下步骤） 3.2 在 virt-manager 上的左上角点击文件之后点击 “新建虚拟机” （只在真机上执行以下步骤） （步骤略） 3.2.1 选择以本地安装介质的方式安装系统 （只在真机上执行以下步骤） 3.2.2 &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/kvm-template-install-centos-linux-8/" class="more-link">Continue reading<span class="screen-reader-text"> "[步骤] KVM  虚拟机模板的创建 （CentOS Linux 8 版）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h1 id="注意">注意：</h1>



<p>在创建 KVM 虚拟机之前要先安装 KVM 并创建 KVM 虚拟网络</p>



<div class="wp-container-3 is-horizontal is-content-justification-center wp-block-buttons">
<div class="wp-block-button is-style-outline"><a class="wp-block-button__link no-border-radius" href="https://eternalcenter-sep-2022.github.io/kvm-install/">KVM 的安装</a></div>



<div class="wp-block-button is-style-outline"><a class="wp-block-button__link no-border-radius" href="https://eternalcenter-sep-2022.github.io/kvm-network-install/">KVM 虚拟网络的创建</a></div>
</div>



<h1 id="软件准备">软件准备：</h1>



<p>在 CentOS 官网上下载安装系统所需要的镜像：</p>



<p class="has-text-align-center"><a href="https://centos.org/download/" target="_blank" rel="noreferrer noopener">https://centos.org/download/</a></p>



<h1 id="正文">正文：</h1>



<h3 id="步骤一-理解创建-kvm-虚拟机模板的目的">步骤一：理解创建 KVM 虚拟机模板的目的</h3>



<p>主要用于批量克隆出新的 KVM 机器，节约创建新虚拟机的时间</p>



<h3 id="步骤二-为这个虚拟机创建硬盘文件-template-centos-8-10g-qcow22-1-创建硬盘文件-template-centos-8-10g-qcow2">步骤二：为这个虚拟机创建硬盘文件</h3>



<h4 id="步骤二-为这个虚拟机创建硬盘文件-template-centos-8-10g-qcow22-1-创建硬盘文件-template-centos-8-10g-qcow2">2.1 创建硬盘文件</h4>



<p>（只在真机上执行以下步骤）</p>



<pre class="wp-block-code"><code># qemu-img create -f qcow2 /var/lib/libvirt/images/template_centos_8_10g.qcow2 10G</code></pre>



<p>（补充：这里以创建 10G 大小的 template_centos_8_10g.qcow2 硬盘文件为例）</p>



<h4 id="2-2-确认硬盘文件已创建">2.2 确认硬盘文件已创建</h4>



<p>（只在真机上执行以下步骤）</p>



<pre class="wp-block-code"><code># ls /var/lib/libvirt/images/ | grep template_centos_8_10g.qcow2</code></pre>



<p>（补充：这里以确认 template_centos_8_10g.qcow2 硬盘文件为例）</p>



<h3 id="步骤三-使用-kvm-和刚刚创建的硬盘文件新安装一台虚拟机3-1-启动-kvm-的-virt-manager">步骤三：使用 KVM 和刚刚创建的硬盘文件新安装一台虚拟机</h3>



<h4 id="步骤三-使用-kvm-和刚刚创建的硬盘文件新安装一台虚拟机3-1-启动-kvm-的-virt-manager">3.1 启动 KVM 的 virt-manager</h4>



<p>（只在真机上执行以下步骤）</p>



<pre class="wp-block-code"><code># virt-manager</code></pre>



<h4 id="3-2-在-virt-manager-上的左上角点击文件之后点击-新建虚拟机">3.2 在 virt-manager 上的左上角点击文件之后点击 “新建虚拟机”</h4>



<p>（只在真机上执行以下步骤）</p>



<p>（步骤略）</p>



<h5 id="3-2-1-选择以本地安装介质的方式安装系统">3.2.1 选择以本地安装介质的方式安装系统</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="448" height="482" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-1.png" alt="" class="wp-image-19710" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-1.png 448w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-1-279x300.png 279w" sizes="(max-width: 448px) 100vw, 448px" /><figcaption>（图：1）</figcaption></figure></div>


<h5 id="3-2-2-选择安装系统的系统镜像">3.2.2 选择安装系统的系统镜像</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="458" height="448" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-2.png" alt="" class="wp-image-19711" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-2.png 458w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-2-300x293.png 300w" sizes="(max-width: 458px) 100vw, 458px" /><figcaption>（图：2）</figcaption></figure></div>


<p>（补充：这里以使用 CentOS-8-x86_64-1905-dvd1.iso 系统镜像为例）</p>



<h5 id="3-2-3-设置内存大小和处理器数量">3.2.3 设置内存大小和 CPU 核心数</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="448" height="448" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-3.png" alt="" class="wp-image-19712" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-3.png 448w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-3-300x300.png 300w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-3-150x150.png 150w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-3-100x100.png 100w" sizes="(max-width: 448px) 100vw, 448px" /><figcaption>（图：3）</figcaption></figure></div>


<p>（补充：这里以设置 2048 MiB 内容和 2 核 CPU 为例）</p>



<h5 id="3-2-4-选择用刚刚创建的硬盘文件来安装系统">3.2.4 选择用刚刚创建的硬盘文件来安装系统</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="448" height="448" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-4.png" alt="" class="wp-image-19713" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-4.png 448w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-4-300x300.png 300w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-4-150x150.png 150w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-4-100x100.png 100w" sizes="(max-width: 448px) 100vw, 448px" /><figcaption>（图：4）</figcaption></figure></div>


<p>（补充：这里以使用 template_centos_8_10g.qcow2 硬盘文件为例）</p>



<h5 id="3-2-5-给虚拟机命名并选择虚拟网络">3.2.5 给虚拟机命名并选择虚拟网络</h5>



<p>（只在真机上执行以下步骤）</p>



<p>（注意：虚拟网络必须提前创建好）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="448" height="499" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-5.png" alt="" class="wp-image-19714" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-5.png 448w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-5-269x300.png 269w" sizes="(max-width: 448px) 100vw, 448px" /><figcaption>（图：5）</figcaption></figure></div>


<p>（补充：这里以将虚拟机命名为 template_centos_8_10g 并使用 vlan001 网络为例）</p>



<h5 id="3-2-6-开始安装系统">3.2.6 开始安装系统</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="612" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-6.png" alt="" class="wp-image-19715" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-6.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-6-300x239.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：6）</figcaption></figure></div>


<h5 id="3-2-7-选择系统语言">3.2.7 选择系统语言</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-7.png" alt="" class="wp-image-19717" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-7.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-7-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：7）</figcaption></figure></div>


<h5 id="3-2-8-之后进行系统配置界面">3.2.8 之后进行系统配置界面</h5>



<p>（只在真机上执行以下步骤）</p>



<p>需要手动配置的地方有三个：<br>1) “INSTALLATION DESTINATION”<br>2) “KDUMP”<br>3) “SOFTWARE SELECTION”<br>分别点击以后就可以配置了</p>



<h5 id="3-2-8-1-通过-installation-destination-对硬盘进行分区">3.2.8.1 通过 “INSTALLATION DESTINATION” 对硬盘进行分区</h5>



<p>（只在真机上执行以下步骤）</p>



<p>（补充：完成后点击左上角的 “DONE”）</p>



<p>（注意：只分一个分区，只设置一个挂载点挂载到根，使用标准硬盘类型，硬盘格式设置为 XFS）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-8.png" alt="" class="wp-image-19718" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-8.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-8-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：8）</figcaption></figure></div>

<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-9.png" alt="" class="wp-image-19719" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-9.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-9-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：9）</figcaption></figure></div>


<h5 id="3-2-8-2-取消-kdump">3.2.8.2 取消 “KDUMP”</h5>



<p>（只在真机上执行以下步骤）</p>



<p>（补充：完成后点击左上角的 “DONE”）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-10.png" alt="" class="wp-image-19720" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-10.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-10-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：10）</figcaption></figure></div>


<h5 id="3-2-8-3-选择最小化安装系统">3.2.8.3 选择最小化安装系统</h5>



<p>（只在真机上执行以下步骤）</p>



<p>（补充：完成后点击左上角的 “DONE”）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-11.png" alt="" class="wp-image-19721" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-11.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-11-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：11）</figcaption></figure></div>


<h5 id="3-2-9-之后点击右下角的-begin-installation">3.2.9 之后点击右下角的 “Begin installation”</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-12.png" alt="" class="wp-image-19722" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-12.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-12-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：12）</figcaption></figure></div>


<h5 id="3-2-10-在安装的过程中设置-root-密码-安装完成后重启">3.2.10 在安装的过程中设置 root 密码，安装完成后重启</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-13.png" alt="" class="wp-image-19723" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-13.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-8-13-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：13）</figcaption></figure></div>


<h5 id="3-2-11-在安装系统的过程中需要注意的内容总结">3.2.11 在安装系统的过程中需要注意的内容总结</h5>



<p>（只在真机上执行以下步骤）</p>



<p>1) 一定要使用刚刚创建的 /var/lib/libvirt/images/template_centos_8_10g.qcow2 作为安装虚拟机的硬件文件<br>2) 虚拟机网络 “vlan001” 要提前创建好<br>3) 只分一个分区，只设置一个挂载点挂载到根，使用标准硬盘，硬盘格式是 XFS<br>4) 取消 “KDUMP”<br>5) 选择最小化安装系统</p>



<h3 id="步骤四-进入新创建虚拟机修改配置4-1-修改网卡个性化设置4-1-1-修改网卡配置文件">步骤四：进入新创建虚拟机修改配置</h3>



<h4 id="步骤四-进入新创建虚拟机修改配置4-1-修改网卡个性化设置4-1-1-修改网卡配置文件">4.1 修改网卡个性化设置</h4>



<h5 id="步骤四-进入新创建虚拟机修改配置4-1-修改网卡个性化设置4-1-1-修改网卡配置文件">4.1.1 修改网卡配置文件</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/sysconfig/network-scripts/ifcfg-ens3</code></pre>



<p>将全部内容修改如下：</p>



<pre class="wp-block-code"><code>TYPE=Ethernet
BOOTPROTO=dhcp
NAME=ens3
DEVICE=ens3
ONBOOT=yes</code></pre>



<h5 id="4-1-2-使修改的网卡配置生效">4.1.2 使修改的网卡配置生效</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># reboot</code></pre>



<h4 id="4-2-禁用-selinux">4.2 禁用 SELinux</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/selinux/config</code></pre>



<p>将全部内容修改如下：</p>



<pre class="wp-block-code"><code># This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted</code></pre>



<h4 id="4-3-禁用空路由">4.3 禁用空路由</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/sysconfig/network</code></pre>



<p>将全部内容修改如下：</p>



<pre class="wp-block-code"><code># Created by anaconda
NOZEROCONF="yes"</code></pre>



<h4 id="4-4-添加-console-配置4-4-1-修改-grub-内核配置文件">4.4 添加 Console 配置</h4>



<h5 id="4-4-添加-console-配置4-4-1-修改-grub-内核配置文件">4.4.1 修改 grub 内核配置文件</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/default/grub</code></pre>



<p>将全部内容修改如下：</p>



<pre class="wp-block-code"><code>GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL="serial console"
GRUB_SERIAL_COMMAND="serial --unit=1 --speed=115200"
GRUB_CMDLINE_LINUX="biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8"
GRUB_DISABLE_LINUX_UUID="true"
GRUB_ENABLE_LINUX_LABEL="true"
GRUB_DISABLE_RECOVERY="true"</code></pre>



<h5 id="4-4-2-使修改的-grub-内核配置生效">4.4.2 使修改的 grub 内核配置生效</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># grub2-mkconfig -o grub</code></pre>



<h4 id="4-5-将系统自动挂载的硬盘从使用-uuid-换成硬件路径4-5-1-显示根分区的-uuid">4.5 将系统自动挂载的硬盘从使用 UUID 换成硬件路径</h4>



<h5 id="4-5-将系统自动挂载的硬盘从使用-uuid-换成硬件路径4-5-1-显示根分区的-uuid">4.5.1 显示根分区的 UUID</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># blkid
/dev/sda1: UUID="e76ed189-6d0f-49d5-8586-c5aae4bdc9b5" TYPE="xfs" PARTUUID="3d8377ef-01"</code></pre>



<p>（补充：这里的 UUID 是： e76ed189-6d0f-49d5-8586-c5aae4bdc9b5）</p>



<h5 id="4-5-2-在自动挂载文件里将根分区的-uuid-换成硬件路径">4.5.2 在自动挂载文件里将根分区的 UUID 换成硬件路径</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/fstab</code></pre>



<p>将以下内容：</p>



<pre class="wp-block-code"><code>......
UUID=e76ed189-6d0f-49d5-8586-c5aae4bdc9b5 /                   xfs     defaults        0 0</code></pre>



<p>（补充：这里的 UUID 是： e76ed189-6d0f-49d5-8586-c5aae4bdc9b5）</p>



<p>修改为：</p>



<pre class="wp-block-code"><code>/dev/sda1 /                   xfs     defaults        0 0</code></pre>



<h4 id="4-6-删除不用的程序">4.6 删除不用的程序</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum -y remove firewalld-* python-firewall</code></pre>



<h4 id="4-7-配置虚拟系统的-yum-源4-7-1-备份旧-yum-源4-7-1-1-创建备份目录">4.7 配置虚拟系统的 yum 源</h4>



<h5 id="4-7-配置虚拟系统的-yum-源4-7-1-备份旧-yum-源4-7-1-1-创建备份目录">4.7.1 备份旧 yum 源</h5>



<h5 id="4-7-配置虚拟系统的-yum-源4-7-1-备份旧-yum-源4-7-1-1-创建备份目录">4.7.1.1 创建备份目录</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># mkdir /etc/yum.repos.d/backup</code></pre>



<h5 id="4-7-1-2-备份旧-yum-源">4.7.1.2 备份旧 yum 源</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup</code></pre>



<h5 id="4-7-2-创建新的-yum-源文件">4.7.2 创建新的 yum 源文件</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/yum.repos.d/lan.repo</code></pre>



<p>创建以下内容：</p>



<pre class="wp-block-code"><code>&#91;CentOS8BaseOS]
name=CentOS8BaseOS
baseurl=http://192.168.100.254/CentOS8/BaseOS/
enabled=1
gpgcheck=0

&#91;CentOS8AppStream]
name=CentOS8AppStream
baseurl=http://192.168.100.254/CentOS8/AppStream/
enabled=1
gpgcheck=0</code></pre>



<p>(注意：http://192.168.1.250/centos8/ 需要根据真实环境的情况进行更改)</p>



<h5 id="4-7-3-删除旧的-yum-源数据">4.7.3 删除旧的 yum 源数据</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum clean all</code></pre>



<h5 id="4-7-4-刷新新的-yum-源">4.7.4 刷新新的 yum 源</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum repolist</code></pre>



<h4 id="4-8-对虚拟系统进行升级">4.8 对虚拟系统进行升级</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum -y update</code></pre>



<h4 id="4-9-进行分区扩展4-9-1-安装分区扩展软件">4.9 进行分区扩展</h4>



<h5 id="4-9-进行分区扩展4-9-1-安装分区扩展软件">4.9.1 安装分区扩展软件</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum install -y cloud-utils-growpart</code></pre>



<h5 id="4-9-2-给开机自启配置文件相应的权限">4.9.2 给开机自启配置文件相应的权限</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># chmod 755 /etc/rc.local</code></pre>



<h5 id="4-9-3-设置开机自动扩容根目录">4.9.3 设置开机自动扩容根目录</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/rc.local</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>......
/usr/bin/growpart /dev/sda1
/usr/sbin/xfs_growfs /</code></pre>



<h4 id="4-10-修改虚拟机系统的名称">4.10 修改虚拟机系统的名称</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/hostname</code></pre>



<p>将全部内容修改如下：</p>



<pre class="wp-block-code"><code>template_centos_8_10g
</code></pre>



<h4 id="4-11-启用-serial-服务实现通过-virsh-console-命令控制虚拟机">4.11 启用 serial 服务实现通过 virsh console 命令控制虚拟机</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># systemctl start serial-getty@ttyS0
# systemctl enable serial-getty@ttyS0</code></pre>



<h4 id="4-12-清除虚拟系统的历史命令">4.12 清除虚拟系统的历史命令</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># history -c</code></pre>



<h4 id="4-13-关闭虚拟机">4.13 关闭虚拟机</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># poweroff</code></pre>



<h3 id="步骤五-在真机上对虚拟机进行清理优化">步骤五：在真机上对虚拟机进行清理优化</h3>



<p>（只在真机上执行以下步骤）</p>



<pre class="wp-block-code"><code># sudo virt-sysprep -d template_centos_8_10g</code></pre>



<p>（补充：这里以清理 template_centos_8_10g 虚拟机为例）</p>



<p>（<br>注意：如果此命令不存在<br>1) CentOS 系统的话需要安装 libguestfs-tools<br>2) openSUSE 系统的话需要安装 guestfs-tools<br>）</p>



<h3 id="步骤六-此时就可以将此虚拟机的硬件文件作为模板进行批量克隆虚拟机了">步骤六：此时就可以将此虚拟机的硬件文件作为模板进行批量克隆虚拟机了</h3>



<p>（只在真机上执行以下步骤）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[命令] KVM 命令 qemu （管理系统镜像文件）</title>
		<link>https://eternalcenter-sep-2022.github.io/qemu/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 24 Aug 2019 14:22:31 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[KVM]]></category>
		<category><![CDATA[Virtualization (虚拟化)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=5498</guid>

					<description><![CDATA[注意： 在使用 qemu 命令之前要先安装 KVM ，并且需要 root 权限 正文： 内容一：系统镜像文件显示 （补充：这里以显示镜像文件 disk.img 的信息为例） 内容二：创建系统镜像文件 （补充：这里以创建一个最大大小是 50G，格式为 qcow2 ，名为 disk.img 的镜像为例） （注意：1) 这个系统镜像是空的，还需要往里面装系统2) 克隆的系统镜像的容量一点要大于被克隆系统镜像的大小，显示镜像设置的大小的命令是：# qemu-img info disk.img，不是 # ls -l） 内容三：克隆系统镜像文件 （补充：这里以 qcow2 格式的镜像文件 disk.qcow2 作为模版，克隆出一个格式为 qcow2 的名为 newdisk.img 的镜像文件，大小为 10 G 为例） （注意：这里的的镜像文件 disk.qcow2 必须不大于 10G，否则新克隆出来的镜像文件无法使用）]]></description>
										<content:encoded><![CDATA[
<h1 id="注意">注意：</h1>



<p>在使用 qemu 命令之前要先安装 KVM ，并且需要 root 权限</p>



<div class="wp-container-4 is-horizontal is-content-justification-center wp-block-buttons">
<div class="wp-block-button is-style-outline"><a class="wp-block-button__link no-border-radius" href="https://eternalcenter-sep-2022.github.io/kvm-install/">KVM 的安装</a></div>
</div>



<h1 id="正文">正文：</h1>



<h3 id="内容一-系统镜像文件显示">内容一：系统镜像文件显示</h3>



<pre class="wp-block-code"><code># qemu-img info disk.img </code></pre>



<p>（补充：这里以显示镜像文件 disk.img 的信息为例）</p>



<h3 id="内容二-创建系统镜像文件">内容二：创建系统镜像文件</h3>



<pre class="wp-block-code"><code># qemu-img create -f qcow2 disk.img 50G </code></pre>



<p>（补充：这里以创建一个最大大小是 50G，格式为 qcow2 ，名为 disk.img 的镜像为例）</p>



<p>（<br>注意：<br>1) 这个系统镜像是空的，还需要往里面装系统<br>2) 克隆的系统镜像的容量一点要大于被克隆系统镜像的大小，显示镜像设置的大小的命令是：# qemu-img info disk.img，不是 # ls -l<br>）</p>



<h3 id="内容三-克隆系统镜像文件">内容三：克隆系统镜像文件</h3>



<pre class="wp-block-code"><code># qemu-img create -b disk.qcow2 -f qcow2 -F qcow2 newdisk.img 10G</code></pre>



<p>（补充：这里以 qcow2 格式的镜像文件  disk.qcow2 作为模版，克隆出一个格式为 qcow2 的名为 newdisk.img 的镜像文件，大小为 10 G 为例）</p>



<p>（注意：这里的的镜像文件 disk.qcow2 必须不大于 10G，否则新克隆出来的镜像文件无法使用）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[命令] KVM 命令 virsh （管理虚拟机和虚拟网络）</title>
		<link>https://eternalcenter-sep-2022.github.io/virsh/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 24 Aug 2019 14:13:10 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[KVM]]></category>
		<category><![CDATA[Virtualization (虚拟化)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=5496</guid>

					<description><![CDATA[注意： 在使用 virsh 命令之前要先安装 KVM ，并且需要 root 权限 正文： 内容一：virsh 命令所有选项的显示方法 内容二：虚拟机显示 2.1 显示所有虚拟机 2.2 显示所有正在运行的虚拟机 2.3 显示某台虚拟机 2.4 显示某台虚拟机的网卡情况 内容三：虚拟机管理 3.1 启动某台虚拟机 3.2 重启某台虚拟机 3.3 正常关闭某台虚拟机 3.4 强制关闭某台虚拟机 3.5 让某台虚拟机自动启动 3.6 取消某台虚拟机的自动启动 3.7 定义某台虚拟机（也就是把虚拟机加入 KVM 虚拟机中） （注意：要先生成好对应的系统镜像 host.img 和镜像配置文件 host.xml） 3.8 取消定义某台虚拟机（也就是把虚拟机从 KVM 软件删除） 3.9 修改名某台虚拟机的配置文件 （注意：要先关闭此虚拟机再进行修改） 3.10 通过 console 口登录某台虚拟机 内容四：虚拟网络显示 4.1 显示所有虚拟网络 &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/virsh/" class="more-link">Continue reading<span class="screen-reader-text"> "[命令] KVM 命令 virsh （管理虚拟机和虚拟网络）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h1 id="注意">注意：</h1>



<p>在使用 virsh 命令之前要先安装 KVM ，并且需要 root 权限</p>



<div class="wp-container-5 is-horizontal is-content-justification-center wp-block-buttons">
<div class="wp-block-button is-style-outline"><a class="wp-block-button__link no-border-radius" href="https://eternalcenter-sep-2022.github.io/kvm-install/">KVM 的安装</a></div>
</div>



<h1 id="正文">正文：</h1>



<h3 id="内容一-virsh-命令所有选项的查看方法">内容一：virsh 命令所有选项的显示方法</h3>



<pre class="wp-block-code"><code># virsh --help</code></pre>



<h3 id="内容二-虚拟机显示2-1-显示所有虚拟机">内容二：虚拟机显示</h3>



<h4 id="内容二-虚拟机显示2-1-显示所有虚拟机">2.1 显示所有虚拟机</h4>



<pre class="wp-block-code"><code># virsh list --all</code></pre>



<h4 id="2-2-显示所有正在运行的虚拟机">2.2 显示所有正在运行的虚拟机</h4>



<pre class="wp-block-code"><code># virsh list</code></pre>



<h4 id="2-3-显示某一台虚拟机">2.3 显示某台虚拟机</h4>



<pre class="wp-block-code"><code># virsh dominfo &lt;host&gt;</code></pre>



<h4 id="2-4-显示某一台虚拟机的网卡情况">2.4 显示某台虚拟机的网卡情况</h4>



<pre class="wp-block-code"><code># visrsh domiflist &lt;host&gt;</code></pre>



<h3 id="内容三-虚拟机管理3-1-启动某一台虚拟机">内容三：虚拟机管理</h3>



<h4 id="内容三-虚拟机管理3-1-启动某一台虚拟机">3.1 启动某台虚拟机</h4>



<pre class="wp-block-code"><code># virsh start &lt;host&gt;</code></pre>



<h4 id="3-2-重启某一台虚拟机">3.2 重启某台虚拟机</h4>



<pre class="wp-block-code"><code># virsh reboot &lt;host&gt;</code></pre>



<h4 id="3-3-正常关闭某一台虚拟机">3.3 正常关闭某台虚拟机</h4>



<pre class="wp-block-code"><code># virsh shutdown &lt;host&gt;</code></pre>



<h4 id="3-4-强制关闭某一台虚拟机">3.4 强制关闭某台虚拟机</h4>



<pre class="wp-block-code"><code># virsh destroy &lt;host&gt;</code></pre>



<h4 id="3-5-让某一台虚拟机自动启动">3.5 让某台虚拟机自动启动</h4>



<pre class="wp-block-code"><code># virsh autostart &lt;host&gt;</code></pre>



<h4 id="3-6-取消某一台虚拟机的自动启动">3.6 取消某台虚拟机的自动启动</h4>



<pre class="wp-block-code"><code># virsh autostart --disable &lt;host&gt;</code></pre>



<h4 id="3-7-定义某一台虚拟机-也就是把虚拟机加入-kvm-虚拟机中">3.7 定义某台虚拟机（也就是把虚拟机加入 KVM 虚拟机中）</h4>



<pre class="wp-block-code"><code># virsh define &lt;host.xml&gt;</code></pre>



<p>（注意：要先生成好对应的系统镜像 host.img 和镜像配置文件 host.xml）</p>



<h4 id="3-8-取消定义某一台虚拟机-也就是把虚拟机从-kvm-软件删除">3.8 取消定义某台虚拟机（也就是把虚拟机从 KVM 软件删除）</h4>



<pre class="wp-block-code"><code># virsh undefine &lt;host&gt;</code></pre>



<h4 id="3-9-修改名某一台虚拟机的配置文件">3.9 修改名某台虚拟机的配置文件</h4>



<pre class="wp-block-code"><code># virsh edit &lt;host&gt;</code></pre>



<p>（注意：要先关闭此虚拟机再进行修改）</p>



<h4 id="3-10-通过-console-口登陆某一台虚拟机">3.10 通过 console 口登录某台虚拟机</h4>



<pre class="wp-block-code"><code># virsh console &lt;host&gt;</code></pre>



<h3 id="内容四-虚拟网络显示4-1-显示所有虚拟网络">内容四：虚拟网络显示</h3>



<h4 id="内容四-虚拟网络显示4-1-显示所有虚拟网络">4.1 显示所有虚拟网络</h4>



<pre class="wp-block-code"><code># virsh net-list --all</code></pre>



<h4 id="4-2-显示所有正在运行的虚拟网络">4.2 显示所有正在运行的虚拟网络</h4>



<pre class="wp-block-code"><code># virsh net-list</code></pre>



<h4 id="4-3-显示某一个虚拟网络">4.3 显示某个虚拟网络</h4>



<pre class="wp-block-code"><code># virsh net-info &lt;network&gt;</code></pre>



<h3 id="内容五-虚拟网络管理5-1-启动某一个虚拟网络">内容五：虚拟网络管理</h3>



<h4 id="内容五-虚拟网络管理5-1-启动某一个虚拟网络">5.1 启动某个虚拟网络</h4>



<pre class="wp-block-code"><code># virsh net-start &lt;network&gt;</code></pre>



<h4 id="5-2-强制关闭某一个虚拟网络">5.2 强制关闭某个虚拟网络</h4>



<pre class="wp-block-code"><code># virsh net-destroy &lt;network&gt;</code></pre>



<h4 id="5-3-让某一个虚拟网络自动启动">5.3 让某个虚拟网络自动启动</h4>



<pre class="wp-block-code"><code># virsh net-autostart &lt;network&gt;</code></pre>



<h4 id="5-4-取消某一个虚拟网络的自动启动">5.4 取消某个虚拟网络的自动启动</h4>



<pre class="wp-block-code"><code># virsh net-autostart --disable &lt;network&gt;</code></pre>



<h4 id="5-5-定义某一个虚拟网络-也就是把虚拟网络加入-kvm-软件">5.5 定义某个虚拟网络（也就是把虚拟网络加入 KVM 软件）</h4>



<pre class="wp-block-code"><code># virsh net-define &lt;network.xml&gt;</code></pre>



<p>（注意：要先生成好虚拟网络配置文件 network.xml）</p>



<h4 id="5-6-取消定义某一台虚拟网络-也就是把虚拟网络从-kvm-软件删除">5.6 取消定义某台虚拟网络（也就是把虚拟网络从 KVM 软件删除）</h4>



<pre class="wp-block-code"><code># virsh net-undefine &lt;network&gt;</code></pre>



<h3 id="内容六-虚拟机快照6-1-给某一个台虚拟机创建虚拟机快照">内容六：虚拟机快照</h3>



<h4 id="内容六-虚拟机快照6-1-给某一个台虚拟机创建虚拟机快照">6.1 给某台虚拟机创建虚拟机快照</h4>



<pre class="wp-block-code"><code># virsh snapshot-create-as &lt;host&gt; &lt;snapshot&gt;</code></pre>



<h4 id="6-2-显示某一台虚拟机的所有快照">6.2 显示某台虚拟机的所有快照</h4>



<pre class="wp-block-code"><code># virsh snapshot-list &lt;host&gt;</code></pre>



<h4 id="6-3-删除某一台虚拟机的某一个快照">6.3 删除某台虚拟机的某个快照</h4>



<pre class="wp-block-code"><code># virsh snapshot-delete &lt;host&gt; &lt;snapshot&gt;</code></pre>



<h4 id="6-4-恢复某一台虚拟机的某一个快照">6.4 恢复某台虚拟机的某个快照</h4>



<pre class="wp-block-code"><code># virsh snapshot-revert &lt;host&gt; &lt;snapshot&gt; --current</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[工具] Shell 批量克隆 KVM 虚拟机 （中文版）</title>
		<link>https://eternalcenter-sep-2022.github.io/shell-kvm-clone-cn/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 24 Aug 2019 13:31:26 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[KVM]]></category>
		<category><![CDATA[Language (语言)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Deployment (部署)]]></category>
		<category><![CDATA[Shell Others (其它)]]></category>
		<category><![CDATA[Shell Tools (工具)]]></category>
		<category><![CDATA[Virtualization (虚拟化)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=5487</guid>

					<description><![CDATA[注意： 在克隆 KVM 虚拟机之前要先安装 KVM 、创建 KVM 虚拟网络和 KVM 模板机 正文： 介绍 基本信息 作者：朱明宇名称：批量克隆 KVM 虚拟机（中文版）作用：批量克隆 KVM 虚拟机（中文版） 使用方法 1. 在此脚本的分割线内写入相应的内容2. 给此脚本添加执行权限3. 执行此脚本 脚本分割线里的变量 1. templatedisk=&#8221;/test/kvm/images/rockylinux8.qcow2&#8243; #模板机硬盘文件2. templatexml=&#8221;/test/kvm/qemu/rockylinux8.xml&#8221; #模板机 xml 文件3. templatename=&#8221;rockylinux8&#8243; #模板机在 KVM 域中的名称4. newdiskpath=&#8221;/test/kvm/images/&#8221; #新模版机硬盘文件目录5. newxmlpath=&#8221;/test/kvm/qemu/&#8221; #新模版机硬盘文件目录 注意 1. 在执行此脚本之前要先安装 KVM2. 在执行此脚本之前要先准备好模板机的硬盘文件和 xml 文件3. 请以 root 的权限执行次脚本 脚本]]></description>
										<content:encoded><![CDATA[
<h1 id="注意">注意：</h1>



<p>在克隆 KVM 虚拟机之前要先安装 KVM 、创建 KVM 虚拟网络和 KVM 模板机</p>



<div class="wp-container-6 is-horizontal is-content-justification-center wp-block-buttons">
<div class="wp-block-button is-style-outline"><a class="wp-block-button__link no-border-radius" href="https://eternalcenter-sep-2022.github.io/kvm-install/">KVM 的安装</a></div>



<div class="wp-block-button is-style-outline"><a class="wp-block-button__link no-border-radius" href="https://eternalcenter-sep-2022.github.io/kvm-network-install/">KVM 虚拟网络的创建</a></div>



<div class="wp-block-button is-style-outline"><a class="wp-block-button__link no-border-radius" href="https://eternalcenter-sep-2022.github.io/kvm-template-install-centos-7/">KVM 虚拟机模板的创建 <br>（CentOS 7 版）</a></div>



<div class="wp-block-button is-style-outline"><a class="wp-block-button__link no-border-radius" href="https://eternalcenter-sep-2022.github.io/kvm-template-install-centos-8/">KVM 虚拟机模板的创建 <br>（CentOS 8 版）</a></div>
</div>



<h1>正文：</h1>



<h2 id="介绍">介绍</h2>



<h3>基本信息</h3>



<p>作者：朱明宇<br>名称：批量克隆 KVM 虚拟机（中文版）<br>作用：批量克隆 KVM 虚拟机（中文版）</p>



<h3>使用方法</h3>



<p>1. 在此脚本的分割线内写入相应的内容<br>2. 给此脚本添加执行权限<br>3. 执行此脚本</p>



<h3>脚本分割线里的变量</h3>



<p>1. templatedisk=&#8221;/test/kvm/images/rockylinux8.qcow2&#8243; #模板机硬盘文件<br>2. templatexml=&#8221;/test/kvm/qemu/rockylinux8.xml&#8221; #模板机 xml 文件<br>3. templatename=&#8221;rockylinux8&#8243; #模板机在 KVM 域中的名称<br>4. newdiskpath=&#8221;/test/kvm/images/&#8221; #新模版机硬盘文件目录<br>5. newxmlpath=&#8221;/test/kvm/qemu/&#8221; #新模版机硬盘文件目录</p>



<h3>注意</h3>



<p>1. 在执行此脚本之前要先安装 KVM<br>2. 在执行此脚本之前要先准备好模板机的硬盘文件和 xml 文件<br>3. 请以 root 的权限执行次脚本</p>



<h2 id="脚本">脚本</h2>



<pre class="wp-block-code"><code>#!/bin/bash
#作者:朱明宇
#名称:批量克隆 KVM 虚拟机
#作用:批量克隆 KVM 虚拟机
#使用方法:
#1.在此脚本的分割线内写入相应的内容
#2.给此脚本增加执行权限
#3.执行此脚本
#注意:
#1.在执行此脚本之前要先安装 KVM
#2.在执行此脚本之前要先准备好模板机的硬盘文件和 xml 文件
#3.请以 root 的权限执行次脚本

###此为分割线，分割线里的内容可让懂 Shell 用户自行修改，如果你不懂 Shell 请勿修改###

templatedisk="/test/kvm/images/rockylinux8.qcow2" #模板机硬盘文件
templatexml="/test/kvm/qemu/rockylinux8.xml" #模板机 xml 文件
templatename="rockylinux8" #模板机在 KVM 域中的名称
newdiskpath="/test/kvm/images/" #新模版机硬盘文件目录
newxmlpath="/test/kvm/qemu/" #新模版机硬盘文件目录

###此为分割线，分割线里的内容可让懂 Shell 用户自行修改，如果你不懂 Shell 请勿修改###

echo

mkdir $newdiskpath &amp;&gt; /dev/null

sudo systemctl start libvirtd &amp;&gt; /dev/null
if &#91; $? -ne 0 ];then
	echo
	echo -e "\033&#91;31m你没有安装 KVM 或者你没有以 root 权限执行次脚本，脚本无法执行\033&#91;0m"
	exit
fi

ls $templatedisk &amp;&gt; /dev/null
if &#91; $? -ne 0 ];then
        echo
        echo -e "\033&#91;31m模版机硬盘文件不存在，脚本无法执行\033&#91;0m"
        exit
fi

ls $templatexml &amp;&gt; /dev/null
if &#91; $? -ne 0 ];then
        echo
        echo -e "\033&#91;31m模版机配置文件不存在，脚本无法执行\033&#91;0m"
        exit
fi

sudo virsh destroy $templatename &amp;&gt; /dev/null
sudo virt-sysprep -d $templatename &amp;&gt; /dev/null
dnet=`sudo virsh net-list | sed -n 3p  | awk '{print $1}'`

read -p "将要克隆虚拟机，单独克隆一台请输入 1，批量克隆请输入任意其他字符 " cloneway
if &#91; ! $cloneway ];then
	echo
	echo -e "\033&#91;31m你没有输入任何值，立刻退出\033&#91;0m"
	exit
fi

if &#91; $cloneway == 1 ];then
	read -p "要克隆产生的主机名称，没有默认值必须输入一个 " onename

	echo $onename | grep '\ ' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                echo
                echo -e "\033&#91;31m要克隆产生的主机名 '$onename' 不能有空格，停止克隆\033&#91;0m"
                exit
        fi

        if &#91; ! $onename ];then
		echo
                echo -e "\033&#91;31m你没有输入要克隆产生的主机名，停止克隆\033&#91;0m"
                exit
        fi

	sudo virsh list --all | egrep -w $onename &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
		echo
                echo -e "\033&#91;31m要克隆产生的主机名 '$onename' 已经存在了，停止克隆\033&#91;0m"
                exit
        fi

        read -p "要克隆的主机所属的虚拟网络，直接回车则是选择已创建的网络中排名最靠前的 $dnet " net

        echo $net | grep '\ ' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                echo
                echo -e "\033&#91;31m网络名 '$net' 不能有空格，停止克隆\033&#91;0m"
                exit
        fi

	read -p "要克隆产生的主机 CPU 核心数,请只输入数字，最小为 1，单位个,直接回车则是使用默认值 1 " cpu

	echo $cpu | grep '\ ' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                echo
                echo -e "\033&#91;31m CPU 核心数 '$cpu' 不能有空格，停止克隆\033&#91;0m"
                exit
        fi

	read -p "要克隆产生的主机内存大小,请只输入数字，单位 K，直接回车则是使用默认值 1048576 " mem

        echo $mem | grep '\ ' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                echo
                echo -e "\033&#91;31m内存大小 '$mem' 不能有空格，停止克隆\033&#91;0m"
                exit
        fi

	read -p "要克隆产生的主机硬盘大小,请只输入数字，单位 G，直接回车则是使用默认值 10 " disk

        echo $disk | grep '\ ' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                echo
                echo -e "\033&#91;31m硬盘大小 '$disk' 不能有空格，停止克隆\033&#91;0m"
                exit
        fi

	echo
	echo "名称："
	echo "使用主机名 '$onename'"

else
	read -p "要批量克隆产生的主机名称的前缀名称，没有默认值必须输入一个 " name

	echo $name | grep '\ ' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                echo
                echo -e "\033&#91;31m要批量克隆产生的主机名称前缀 '$name' 不能有空格，停止克隆\033&#91;0m"
                exit
        fi


        if &#91; ! $name ];then
		echo
                echo -e "\033&#91;31m你没有输入要批量克隆产生的主机名称前缀，停止克隆\033&#91;0m"
                exit
        fi

	read -p "要批量克隆产生的主机名后缀起始编号，没有默认值必须输入一个，请只输入数字 " snum

        if &#91; ! $snum ];then
		echo
                echo -e "\033&#91;31m你没有输入要批量克隆产生的主机名后缀起始编号，停止克隆\033&#91;0m"
                exit
        fi

        echo $snum | grep '\-' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
		snum=${snum##*-}
                echo -e "\033&#91;33m你输入的要批量克隆产生的主机名后缀起始编号可能是一个负数，将只使用整数部分 $snum\033&#91;0m"
        fi

        echo $snum | grep '\.' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                snum=${snum%%.*}
                echo -e "\033&#91;33m你输入的要批量克隆产生的主机名后缀起始编号可能是一个小数，将只使用数字部分 $snum\033&#91;0m"
        fi

        let snum+0 &amp;&gt; /dev/null
        if &#91; $? -ne 0 ];then
                echo
                echo -e "\033&#91;31m你输入的要批量克隆产生的主机名后缀起始编号 $snum 不是数字，无法克隆\033&#91;0m"
        exit
        fi

	read -p "要批量克隆产生的主机名后缀结束编号，没有默认值必须输入一个，请只输入数字 " enum

        if &#91; ! $enum ];then
                echo -e "\033&#91;31m你没有输入要批量克隆产生的主机名后缀结束编号，停止克隆\033&#91;0m"
        fi

	echo $enum | grep '\-' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                enum=${enum##*-}
                echo -e "\033&#91;33m你输入的要批量克隆产生的主机名后缀结束编号可能是一个负数，将只使用数字部分 $enum\033&#91;0m"
        fi

        echo $enum | grep '\.' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                enum=${enum%%.*}
                echo -e "\033&#91;33m你输入的要批量克隆产生的主机名后缀结束编号可能是一个小数，将只使用整数部分 $enum\033&#91;0m"
        fi

        let enum+0 &amp;&gt; /dev/null
        if &#91; $? -ne 0 ];then
                echo -e "\033&#91;31m你输入的要批量克隆产生的主机名后缀结束编号 $enum 不是数字，无法克隆\033&#91;0m"
                exit
        fi

        read -p "要批量克隆的主机所属的虚拟网络，直接回车则是选择已创建的网络中排名最靠前的 $dnet " net

        echo $net | grep '\ ' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                echo
                echo -e "\033&#91;31m网络名 '$net' 不能有空格，停止克隆\033&#91;0m"
                exit
        fi

	read -p "要批量克隆产生的主机 CPU 核心数，请只输入数字，最小为 1，单位个，直接回车则是使用默认值 1 " cpu

        echo $cpu | grep '\ ' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                echo
                echo -e "\033&#91;31m CPU 核心数 '$cpu' 不能有空格，停止克隆\033&#91;0m"
                exit
        fi

	read -p "要批量克隆产生的主机内存大小，请只输入数字，单位 K，直接回车则是使用默认值 1048576 " mem

        echo $mem | grep '\ ' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                echo
                echo -e "\033&#91;31m内存大小 '$mem' 不能有空格，停止克隆\033&#91;0m"
                exit
        fi

	read -p "要批量克隆产生的主机硬盘大小，请只输入数字，单位 G，直接回车则是使用默认值 10 " disk

        echo $disk | grep '\ ' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                echo
                echo -e "\033&#91;31m硬盘大小 '$disk' 不能有空格，停止克隆\033&#91;0m"
                exit
        fi

	echo
	echo "名称："
	for i in `seq $snum $enum`
	do
	sudo virsh list --all | egrep -w $name$i &amp;&gt; /dev/null
	if &#91; $? -eq 0 ];then
		echo -e "\033&#91;33m使用主机名 '$name$i' ，已经存在了，将跳过不克隆它\033&#91;0m"
	else
		echo "使用主机名 '$name$i' "
	fi
        done
fi

echo

echo "网络："

sudo virsh net-list | grep $net &amp;&gt; /dev/null
if &#91; $? -eq 0 ];then
        echo "使用网络 $net"
fi

if &#91; ! $net ];then
        net=`sudo virsh net-list | sed -n 3p  | awk '{print $1}'`
	echo -e "\033&#91;33m你没有输入网络，将使用默认网络 $net\033&#91;0m"
	echo "使用网络 $net"
fi

sudo virsh net-list | grep $net &amp;&gt; /dev/null
if &#91; $? -ne 0 ];then
        net=`sudo virsh net-list | sed -n 3p  | awk '{print $1}'`
        echo -e "\033&#91;33m你输入的要克隆主机的所属的网络不存在，将使用默认网络 $net\033&#91;0m"
	echo "使用网络 $net"
fi

echo

echo "CPU："

if &#91; ! $cpu ];then
	cpu=1
	echo -e "\033&#91;33m你没有输入 CPU 核心数，将使用默认 CPU 核心数 1\033&#91;0m"
else

        echo $cpu | grep '\-' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                cpu=${cpu##*-}
                echo -e "\033&#91;33m你输入的 CPU 核心数可能是一个负数，将只使用数字部分 $cpu\033&#91;0m"
        fi

        echo $cpu | grep '\.' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                cpu=${cpu%%.*}
                echo -e "\033&#91;33m你输入的 CPU 核心数可能是一个小数，将只使用整数部分 $cpu\033&#91;0m"
        fi

	let cpu=cpu+0 &amp;&gt; /dev/null
	if &#91; $? -ne 0 ];then
		echo -e "\033&#91;33m你输入的 CPU 核心数不是数字，将使用默认值 1\033&#91;0m"
                cpu=1
	fi

	if &#91; $cpu -lt 1 ];then
                echo -e "\033&#91;33m你输入的 CPU 核心数小于 1，将使用默认值 1\033&#91;0m"
		cpu=1
	fi
fi

echo "CPU 核心数 $cpu"

echo

echo "内存："

if &#91; ! $mem ];then
	mem=1048576
        echo -e "\033&#91;33m你没有输入内存大小，将使用默认内存大小 1048576 K\033&#91;0m"

else

        echo $mem | grep '\-' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                mem=${mem##*-}
                echo -e "\033&#91;33m你输入的内存大小可能是一个负数，将只使用数字部分 $mem\033&#91;0m"
        fi

        echo $mem | grep '\.' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                mem=${mem%%.*}
                echo -e "\033&#91;33m你输入的内存大小可能是一个小数，将只使用整数部分 $mem\033&#91;0m"
        fi

	let mem=mem+0 &amp;&gt; /dev/null
	if &#91; $? -ne 0 ];then
		echo -e "\033&#91;33m你输入的内存大小不是数字，将使用默认值 1048576\033&#91;0m"
                mem=1048576
	fi

	if &#91; $mem -lt 1048576 ];then
                echo -e "\033&#91;33m你输入的内存大小小于 1048576，将使用默认值 1048576\033&#91;0m"
		mem=1048576
	fi
fi

echo "内存大小 $mem K"

echo

echo "硬盘："

if &#91; ! $disk ];then
	disk=10
        echo -e "\033&#91;33m你没有输入硬盘大小，将使用默认硬盘大小 10 G\033&#91;0m"

else

        echo $disk | grep '\-' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                disk=${disk##*-}
                echo -e "\033&#91;33m你输入的硬盘大小可能是一个负数，将只使用数字部分 $disk\033&#91;0m"
        fi

        echo $disk | grep '\.' &amp;&gt; /dev/null
        if &#91; $? -eq 0 ];then
                disk=${disk%%.*}
                echo -e "\033&#91;33m你输入的硬盘大小可能是一个小数，将只使用整数部分 $disk\033&#91;0m"
        fi

	let disk=disk+0 &amp;&gt; /dev/null
	if &#91; $? -ne 0 ];then
		echo -e "\033&#91;33m你输入的硬盘大小不是数字，将使用默认值 10\033&#91;0m"
	fi

	if &#91; $disk -lt 10 ];then
		echo -e "\033&#91;33m你输入的硬盘大小小于 10，将使用默认值 10\033&#91;0m"
		disk=10
	fi
fi

echo "硬盘大小 $disk G"

echo

echo "备注（可能没有任何信息）："

if &#91; $cloneway -eq 1 ];then
	sudo qemu-img create -f qcow2 -F qcow2 -b $templatedisk $newdiskpath$onename.qcow2 ${disk}G &amp;&gt; /dev/null
	sudo cp $templatexml $newxmlpath$onename.xml
	sudo sed -i "/uuid/d" $newxmlpath$onename.xml
	sudo sed -i "/mac address/d" $newxmlpath$onename.xml
	sudo sed -i "s:&lt;name&gt;.*&lt;/name&gt;:&lt;name&gt;$onename&lt;/name&gt;:" $newxmlpath$onename.xml
	sudo sed -i "s:&lt;source file=.*/&gt;:&lt;source file=\'$newdiskpath$onename.qcow2\'/&gt;:" $newxmlpath$onename.xml
	sudo sed -i "s:&lt;vcpu placement='static'&gt;.*&lt;/vcpu&gt;:&lt;vcpu placement='static'&gt;$cpu&lt;/vcpu&gt;:" $newxmlpath$onename.xml
	sudo sed -i "s:.*&lt;/memory&gt;:&lt;memory unit='KB'&gt;$mem&lt;/memory&gt;:" $newxmlpath$onename.xml
	sudo sed -i "s:.*&lt;/currentMemory&gt;:&lt;currentMemory unit='KB'&gt;$mem&lt;/currentMemory&gt;:" $newxmlpath$onename.xml
        sudo sed -i "s:&lt;source network=.*:&lt;source network=\'$net\'/&gt;:" $newxmlpath$onename.xml
	sudo virsh define $newxmlpath$onename.xml &amp;&gt; /dev/null
        sudo virsh start $onename &amp;&gt; /dev/null
	echo
	sudo virsh list --all
else
	for i in `seq $snum $enum`
	do
                sudo virsh list --all | egrep -w $name$i &amp;&gt; /dev/null
                if &#91; $? -eq 0 ];then
		      echo -e "\033&#91;33m$name$i 没有被克隆\033&#91;0m"
	       	      continue
                fi
		sudo qemu-img create -f qcow2 -F qcow2 -b $templatedisk $newdiskpath$name$i.qcow2 $&#91;disk]G &amp;&gt; /dev/null
		sudo cp $templatexml $newxmlpath$name$i.xml
		sudo sed -i "/uuid/d" $newxmlpath$name$i.xml
		sudo sed -i "/mac address/d" $newxmlpath$name$i.xml
		sudo sed -i "s:&lt;name&gt;.*&lt;/name&gt;:&lt;name&gt;$name$i&lt;/name&gt;:" $newxmlpath$name$i.xml
		sudo sed -i "s:&lt;source file=.*/&gt;:&lt;source file=\'$newdiskpath$name$i.qcow2\'/&gt;:" $newxmlpath$name$i.xml
		sudo sed -i "s:&lt;vcpu placement='static'&gt;.*&lt;/vcpu&gt;:&lt;vcpu placement='static'&gt;$cpu&lt;/vcpu&gt;:" $newxmlpath$name$i.xml
		sudo sed -i "s:.*&lt;/memory&gt;:&lt;memory unit='KB'&gt;$mem&lt;/memory&gt;:" $newxmlpath$name$i.xml
		sudo sed -i "s:.*&lt;/currentMemory&gt;:&lt;currentMemory unit='KB'&gt;$mem&lt;/currentMemory&gt;:" $newxmlpath$name$i.xml
                sudo sed -i "s:&lt;source network=.*:&lt;source network=\'$net\'/&gt;:" $newxmlpath$name$i.xml
	        sudo virsh define $newxmlpath$name$i.xml &amp;&gt; /dev/null
                sudo virsh start $name$i &amp;&gt; /dev/null
      done
      echo
      sudo virsh list --all
fi</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] KVM 的安装</title>
		<link>https://eternalcenter-sep-2022.github.io/kvm-install/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 24 Aug 2019 13:16:03 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[KVM]]></category>
		<category><![CDATA[Virtualization (虚拟化)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=5476</guid>

					<description><![CDATA[步骤一：系统环境要求 服务器系统要配置好可用的软件源 步骤二：安装 KVM 2.1 安装 KVM 服务端软件 如果是 CentOS Linux 7 &#38; RHEL 7： 如果是 Rocky Linux 8 &#38; RHEL 8： 如果是 openSUSE &#38; SLE： 2.2 安装 KVM 客户端软件 如果是 CentOS Linux 7 &#38; RHEL 7： 如果是 Rocky Linux 8 &#38; RHEL 8： 如果是 openSUSE &#38; SLE： 步骤三：启动 KVM 步骤四：使用 KVM （补充：1) qemu-kvm libvirt-daemon &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/kvm-install/" class="more-link">Continue reading<span class="screen-reader-text"> "[步骤] KVM 的安装"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h3>步骤一：系统环境要求</h3>



<p>服务器系统要配置好可用的软件源</p>



<h3>步骤二：安装 KVM</h3>



<h4>2.1 安装 KVM 服务端软件</h4>



<p>如果是 CentOS Linux 7 &amp; RHEL 7：</p>



<pre class="wp-block-code"><code># yum -y install qemu-kvm libvirt-daemon libvirt-client libvirt-daemon-driver-qemu</code></pre>



<p>如果是 Rocky Linux 8 &amp; RHEL 8：</p>



<pre class="wp-block-code"><code># dnf groupinstall 'Virtualization Host'</code></pre>



<p>如果是 openSUSE &amp; SLE：</p>



<pre class="wp-block-code"><code># zypper in -t pattern kvm_server</code></pre>



<h4>2.2 安装 KVM 客户端软件</h4>



<p>如果是 CentOS Linux 7 &amp; RHEL 7：</p>



<pre class="wp-block-code"><code># yum -y install virt-install virt-manager virt-viewer virt-v2v</code></pre>



<p>如果是 Rocky Linux 8 &amp; RHEL 8：</p>



<pre class="wp-block-code"><code># dnf -y install virt-install virt-manager virt-viewer virt-v2v</code></pre>



<p>如果是 openSUSE &amp; SLE：</p>



<pre class="wp-block-code"><code># zypper in -t pattern kvm_tools</code></pre>



<h3>步骤三：启动 KVM</h3>



<pre class="wp-block-code"><code># systemctl start libvirtd-manager</code></pre>



<h3>步骤四：使用 KVM</h3>



<pre class="wp-block-code"><code># virt-manager</code></pre>



<p>（<br>补充：<br>1) qemu-kvm libvirt-daemon libvirt-client libvirt-daemon-driver-qemu 是必选安装项<br>2) virt-install（虚拟机命令行安装器） virt-manager（虚拟机图形界面安装和管理器） virt-v2v（虚拟机导入器） 是可选安装项<br>）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] KVM  虚拟机模板的创建 （CentOS Linux 7 版）</title>
		<link>https://eternalcenter-sep-2022.github.io/kvm-template-install-centos-linux-7/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Thu, 22 Aug 2019 15:45:01 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[KVM]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Computer & System Hardware & System Installation & System Upgradation (系统电脑 & 系统硬件 & 系统安装 & 系统升级)]]></category>
		<category><![CDATA[System Installation (系统安装)]]></category>
		<category><![CDATA[Virtualization (虚拟化)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=5435</guid>

					<description><![CDATA[注意： 在创建 KVM 虚拟机之前要先安装 KVM 并创建 KVM 虚拟网络 软件准备： 在 CentOS 官网上下载安装系统所需要的镜像： https://centos.org/download/ 正文： 步骤一：理解创建 KVM 虚拟机模板的目的 主要用于批量克隆出新的 KVM 机器，节约创建新虚拟机的时间 步骤二：为这个虚拟机创建硬盘文件 2.1 创建硬盘文件 （只在真机上执行以下步骤） （补充：这里以创建 10G 大小的 template_centos_7_10g.qcow2 硬盘文件为例） 2.2 确认硬盘文件已创建 （只在真机上执行以下步骤） （补充：这里以确认 template_centos_7_10g.qcow2 硬盘文件为例） 步骤三：使用 KVM 和刚刚创建的硬盘文件新安装一台虚拟机 3.1 启动 KVM 的 virt-manager （只在真机上执行以下步骤） 3.2 在 virt-manager 上的左上角点击文件之后 “点击新建虚拟机” （只在真机上执行以下步骤） （步骤略） 3.2.1 选择以本地安装介质的方式安装系统 （只在真机上执行以下步骤） 3.2.2 &#8230; <p class="link-more"><a href="https://eternalcenter-sep-2022.github.io/kvm-template-install-centos-linux-7/" class="more-link">Continue reading<span class="screen-reader-text"> "[步骤] KVM  虚拟机模板的创建 （CentOS Linux 7 版）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h1 id="注意">注意：</h1>



<p>在创建 KVM 虚拟机之前要先安装 KVM 并创建 KVM 虚拟网络</p>



<div class="wp-container-7 is-horizontal is-content-justification-center wp-block-buttons">
<div class="wp-block-button is-style-outline"><a class="wp-block-button__link no-border-radius" href="https://eternalcenter-sep-2022.github.io/kvm-install/">KVM 的安装</a></div>



<div class="wp-block-button is-style-outline"><a class="wp-block-button__link no-border-radius" href="https://eternalcenter-sep-2022.github.io/kvm-network-install/">KVM 虚拟网络的创建</a></div>
</div>



<h1 id="软件准备">软件准备：</h1>



<p>在 CentOS 官网上下载安装系统所需要的镜像：</p>



<p class="has-text-align-center"><a href="https://centos.org/download/" target="_blank" rel="noreferrer noopener">https://centos.org/download/</a></p>



<h1 id="正文">正文：</h1>



<h3 id="步骤一-理解创建-kvm-虚拟机模板的目的">步骤一：理解创建 KVM 虚拟机模板的目的</h3>



<p>主要用于批量克隆出新的 KVM 机器，节约创建新虚拟机的时间</p>



<h3 id="步骤二-为这个虚拟机创建硬盘文件-template-centos-7-10g-qcow22-1-创建硬盘文件-template-centos-7-10g-qcow2">步骤二：为这个虚拟机创建硬盘文件</h3>



<h4 id="步骤二-为这个虚拟机创建硬盘文件-template-centos-7-10g-qcow22-1-创建硬盘文件-template-centos-7-10g-qcow2">2.1 创建硬盘文件</h4>



<p>（只在真机上执行以下步骤）</p>



<pre class="wp-block-code"><code># qemu-img create -f qcow2 /var/lib/libvirt/images/template_centos_7_10g.qcow2 10G</code></pre>



<p>（补充：这里以创建 10G 大小的 template_centos_7_10g.qcow2 硬盘文件为例）</p>



<h4 id="2-2-确认硬盘文件已创建">2.2 确认硬盘文件已创建</h4>



<p>（只在真机上执行以下步骤）</p>



<pre class="wp-block-code"><code># ls /var/lib/libvirt/images/ | grep template_centos_7_10g.qcow2</code></pre>



<p>（补充：这里以确认 template_centos_7_10g.qcow2 硬盘文件为例）</p>



<h3 id="步骤三-使用-kvm-和刚刚创建的硬盘文件新安装一台虚拟机3-1-启动-kvm-的-virt-manager">步骤三：使用 KVM 和刚刚创建的硬盘文件新安装一台虚拟机</h3>



<h4 id="步骤三-使用-kvm-和刚刚创建的硬盘文件新安装一台虚拟机3-1-启动-kvm-的-virt-manager">3.1 启动 KVM 的 virt-manager</h4>



<p>（只在真机上执行以下步骤）</p>



<pre class="wp-block-code"><code># virt-manager</code></pre>



<h4 id="3-2-在-virt-manager-上的左上角点击文件之后-点击新建虚拟机">3.2 在 virt-manager 上的左上角点击文件之后 “点击新建虚拟机”</h4>



<p>（只在真机上执行以下步骤）</p>



<p>（步骤略）</p>



<h5 id="3-2-1-选择以本地安装介质的方式安装系统">3.2.1 选择以本地安装介质的方式安装系统</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="448" height="482" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-1.png" alt="" class="wp-image-19696" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-1.png 448w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-1-279x300.png 279w" sizes="(max-width: 448px) 100vw, 448px" /><figcaption>（图：1）</figcaption></figure></div>


<h5 id="3-2-2-选择安装系统的系统镜像">3.2.2 选择安装系统的系统镜像</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="458" height="448" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-2.png" alt="" class="wp-image-19697" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-2.png 458w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-2-300x293.png 300w" sizes="(max-width: 458px) 100vw, 458px" /><figcaption>（图：2）</figcaption></figure></div>


<p>（补充：这里以使用 centos-7.6-x86_64-everythin-1810.iso 系统镜像为例）</p>



<h5 id="3-2-3-设置内存大小和处理器数量">3.2.3 设置内存大小和 CPU 核心数</h5>



<pre id="block-2faa27f0-e4ae-4ad6-8dd9-28ff620e19c8" class="wp-block-code"><code>（只在真机上执行以下步骤）</code></pre>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="448" height="448" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-3.png" alt="" class="wp-image-19698" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-3.png 448w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-3-300x300.png 300w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-3-150x150.png 150w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-3-100x100.png 100w" sizes="(max-width: 448px) 100vw, 448px" /><figcaption>（图：3）</figcaption></figure></div>


<p>（补充：这里以设置 2048 MiB 内容和 2 核 CPU 为例）</p>



<h5 id="3-2-4-选择用刚刚创建的硬盘文件来安装系统">3.2.4 选择用刚刚创建的硬盘文件来安装系统</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="448" height="448" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-4.png" alt="" class="wp-image-19699" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-4.png 448w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-4-300x300.png 300w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-4-150x150.png 150w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-4-100x100.png 100w" sizes="(max-width: 448px) 100vw, 448px" /><figcaption>（图：4）</figcaption></figure></div>


<p>（补充：这里以使用 template_centos_7_10g.qcow2 硬盘文件为例）</p>



<h5 id="3-2-5-给虚拟机命名为并选择虚拟网络">3.2.5 给虚拟机命名为并选择虚拟网络</h5>



<p>（注意：虚拟网络必须提前创建好）</p>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="448" height="499" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-5.png" alt="" class="wp-image-19700" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-5.png 448w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-5-269x300.png 269w" sizes="(max-width: 448px) 100vw, 448px" /><figcaption>（图：5）</figcaption></figure></div>


<p>（补充：这里以将虚拟机命名为 template_centos_7_10g 并使用 vlan001 网络为例）</p>



<h5 id="3-2-6-开始安装系统">3.2.6 开始安装系统</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="612" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-6.png" alt="" class="wp-image-19702" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-6.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-6-300x239.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：6）</figcaption></figure></div>


<h5 id="3-2-7-选择系统语言">3.2.7 选择系统语言</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-7.png" alt="" class="wp-image-19703" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-7.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-7-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：7）</figcaption></figure></div>


<h5 id="3-2-8-之后进行系统配置界面">3.2.8 之后进行系统配置界面</h5>



<p>（只在真机上执行以下步骤）</p>



<p>需要手动配置的地方有两个：<br>1) “INSTALLATION DESTINATION”<br>2) “KDUMP”<br>分别点击以后就可以配置了</p>



<h5 id="3-2-8-1-通过-installation-destination-对硬盘进行分区">3.2.8.1 通过 “INSTALLATION DESTINATION” 对硬盘进行分区</h5>



<p>（只在真机上执行以下步骤）</p>



<p>（补充：完成后点击左上角的 “DONE”）</p>



<p>（注意：只分一个分区，只设置一个挂载点挂载到根，使用标准硬盘类型，硬盘格式设置为 XFS）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-8.png" alt="" class="wp-image-19704" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-8.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-8-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：8）</figcaption></figure></div>

<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-9.png" alt="" class="wp-image-19705" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-9.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-9-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：9）</figcaption></figure></div>


<h5 id="3-2-8-2-取消-kdump">3.2.8.2 取消 “KDUMP”</h5>



<p>（只在真机上执行以下步骤）</p>



<p>（补充：完成后点击左上角的 “DONE”）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-10.png" alt="" class="wp-image-19706" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-10.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-10-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：10）</figcaption></figure></div>


<h5 id="3-2-9-设置完成之后点击右下角的-begin-installation">3.2.9 设置完成之后点击右下角的 “Begin installation”</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-11.png" alt="" class="wp-image-19707" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-11.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-11-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：11）</figcaption></figure></div>


<h5 id="3-2-10-在安装的过程中设置-root-密码-安装完成后重启">3.2.10 在安装的过程中设置 root 密码，安装完成后重启</h5>



<p>（只在真机上执行以下步骤）</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" width="768" height="466" src="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-12.png" alt="" class="wp-image-19708" srcset="https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-12.png 768w, https://eternalcenter-sep-2022.github.io/wp-content/uploads/2021/12/KVM-template-CentOS-7-12-300x182.png 300w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>（图：12）</figcaption></figure></div>


<h5 id="3-2-11-在安装系统的过程中需要注意的内容总结">3.2.11 在安装系统的过程中需要注意的内容总结</h5>



<p>1)  一定要使用刚刚创建的 /var/lib/libvirt/images/template_centos_7_10g.qcow2 作为安装虚拟机的硬件文件<br>2)  虚拟机网络 “vlan001” 要提前创建好<br>3)  只分一个分区，只设置一个挂载点挂载到根，使用标准硬盘，硬盘格式是 XFS<br>4)  取消 “KDUMP”</p>



<h3 id="步骤四-进入新创建虚拟机修改配置4-1-修改网卡个性化设置4-1-1-修改网卡配置文件">步骤四：进入新创建虚拟机修改配置</h3>



<h4 id="步骤四-进入新创建虚拟机修改配置4-1-修改网卡个性化设置4-1-1-修改网卡配置文件">4.1 修改网卡个性化设置</h4>



<h5 id="步骤四-进入新创建虚拟机修改配置4-1-修改网卡个性化设置4-1-1-修改网卡配置文件">4.1.1 修改网卡配置文件</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/sysconfig/network-scripts/ifcfg-eth0</code></pre>



<p>将全部内容进行如下修改：</p>



<pre class="wp-block-code"><code>BOOTPROTO=dhcp
NAME=eth0
DEVICE=eth0
ONBOOT=yes
TYPE=Ethernet</code></pre>



<h5 id="4-1-2-使修改的网卡配置生效">4.1.2 使修改的网卡配置生效</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># service network restart</code></pre>



<h4 id="4-2-禁用-selinux">4.2 禁用 selinux</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/selinux/config</code></pre>



<p>将全部内容进行如下修改：</p>



<pre class="wp-block-code"><code># This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted</code></pre>



<h4 id="4-3-禁用空路由">4.3 禁用空路由</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/sysconfig/network</code></pre>



<p>将全部内容修改如下：</p>



<pre class="wp-block-code"><code># Created by anaconda
NOZEROCONF="yes"</code></pre>



<h4 id="4-4-添加-console-配置4-4-1-修改-grub-内核配置文件">4.4 添加 Console 配置</h4>



<h5 id="4-4-添加-console-配置4-4-1-修改-grub-内核配置文件">4.4.1 修改 grub 内核配置文件</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/default/grub</code></pre>



<p>将全部内容修改如下：</p>



<pre class="wp-block-code"><code>GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL="serial console"
GRUB_SERIAL_COMMAND="serial --unit=1 --speed=115200"
GRUB_CMDLINE_LINUX="biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8"
GRUB_DISABLE_LINUX_UUID="true"
GRUB_ENABLE_LINUX_LABEL="true"
GRUB_DISABLE_RECOVERY="true"</code></pre>



<h5 id="4-4-2-使修改的-grub-内核配置生效">4.4.2 使修改的 grub 内核配置生效</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># grub2-mkconfig -o grub</code></pre>



<h4 id="4-5-将系统自动挂载的硬盘从使用-uuid-换成硬件路径4-5-1-显示根分区的-uuid">4.5 将系统自动挂载的硬盘从使用 UUID 换成硬件路径</h4>



<h5 id="4-5-将系统自动挂载的硬盘从使用-uuid-换成硬件路径4-5-1-显示根分区的-uuid">4.5.1 显示根分区的 UUID</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># blkid
/dev/vda1: UUID="84ccf593-a924-4949-b7ef-584be43deef5" TYPE="xfs"</code></pre>



<p>（补充：这里的 UUID 是： 84ccf593-a924-4949-b7ef-584be43deef5）</p>



<h5 id="4-5-2-在自动挂载文件里将根分区的-uuid-换成硬件路径">4.5.2 在自动挂载文件里将根分区的 UUID 换成硬件路径</h5>



<pre class="wp-block-code"><code># vi /etc/fstab</code></pre>



<p>将以下内容：</p>



<pre class="wp-block-code"><code>......
UUID=84ccf593-a924-4949-b7ef-584be43deef5 /                   xfs     defaults        0 0</code></pre>



<p>（补充：这里的 UUID 是： 84ccf593-a924-4949-b7ef-584be43deef5）</p>



<p>修改为：</p>



<pre class="wp-block-code"><code>......
/dev/vda1 /                   xfs     defaults        0 0</code></pre>



<h4 id="4-6-删除不用的程序">4.6 删除不用的程序</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum -y remove NetworkManager-* firewalld-* python-firewall</code></pre>



<h4 id="4-7-配置虚拟系统的-yum-源4-7-1-备份旧-yum-源4-7-1-1-创建备份目录">4.7 配置虚拟系统的 yum 源</h4>



<h5 id="4-7-配置虚拟系统的-yum-源4-7-1-备份旧-yum-源4-7-1-1-创建备份目录">4.7.1 备份旧 yum 源</h5>



<h5 id="4-7-配置虚拟系统的-yum-源4-7-1-备份旧-yum-源4-7-1-1-创建备份目录">4.7.1.1 创建备份目录</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># mkdir /etc/yum.repos.d/backup</code></pre>



<h5 id="4-7-1-2-备份旧-yum-源">4.7.1.2 备份旧 yum 源</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup</code></pre>



<h5 id="4-7-2-创建新的-yum-源文件">4.7.2 创建新的 yum 源文件</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/yum.repos.d/lan.repo</code></pre>



<p>创建以下内容：</p>



<pre class="wp-block-code"><code>&#91;CentOS7]
name=CentOS7
baseurl=http://192.168.100.254/CentOS7/
enabled=1
gpgcheck=0</code></pre>



<p>(注意：这里的 http://192.168.1.250/centos7/ 需要根据真实环境的情况进行更改)</p>



<h5 id="4-7-3-删除旧的-yum-源数据">4.7.3 删除旧的 yum 源数据</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum clean all</code></pre>



<h5 id="4-7-4-刷新新的-yum-源">4.7.4 刷新新的 yum 源</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum repolist</code></pre>



<h4 id="4-8-对虚拟系统进行升级">4.8 对虚拟系统进行升级</h4>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum -y update</code></pre>



<h4 id="4-9-进行分区扩展4-9-1-安装分区扩展软件">4.9 进行分区扩展</h4>



<h5 id="4-9-进行分区扩展4-9-1-安装分区扩展软件">4.9.1 安装分区扩展软件</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># yum install -y cloud-utils-growpart</code></pre>



<h5 id="4-9-2-给开机自启配置文件相应的权限">4.9.2 给开机自启配置文件相应的权限</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># chmod 755 /etc/rc.local</code></pre>



<h5 id="4-9-3-设置开机自动扩容根目录">4.9.3 设置开机自动扩容根目录</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/rc.local</code></pre>



<p>添加以下内容：</p>



<pre class="wp-block-code"><code>/usr/bin/growpart /dev/vda1 
/usr/sbin/xfs_growfs /</code></pre>



<h5 id="4-10-修改虚拟机系统的名称">4.10 修改虚拟机系统的名称</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># vi /etc/hostname</code></pre>



<p>将全部内容修改如下：</p>



<pre class="wp-block-code"><code>template_centos_7_10g</code></pre>



<h5 id="4-11-启用-serial-服务实现通过-virsh-console-命令控制虚拟机">4.11 启用 serial 服务实现通过 virsh console 命令控制虚拟机</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># systemctl start serial-getty@ttyS0
# systemctl enable serial-getty@ttyS0</code></pre>



<h5 id="4-12-清除虚拟系统的历史命令">4.12 清除虚拟系统的历史命令</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># history -c</code></pre>



<h5 id="4-13-关闭虚拟机">4.13 关闭虚拟机</h5>



<p>（只在虚拟机上执行以下步骤）</p>



<pre class="wp-block-code"><code># poweroff</code></pre>



<h3 id="步骤五-在真机上对虚拟机进行清理优化">步骤五：在真机上对虚拟机进行清理优化</h3>



<p>（只在真机上执行以下步骤）</p>



<pre class="wp-block-code"><code># sudo virt-sysprep -d template_centos_7_10g</code></pre>



<p>（补充：这里以清理 template_centos_7_10g 虚拟机为例）</p>



<p>（<br>注意：如果此命令不存在<br>1) CentOS 系统的话需要安装 libguestfs-tools<br>2) openSUSE 系统的话需要安装 guestfs-tools<br>）</p>



<h3 id="步骤六-此时就可以将此虚拟机的硬件文件作为模块进行批量克隆虚拟机了">步骤六：此时就可以将此虚拟机的硬件文件作为模块进行批量克隆虚拟机了</h3>



<p>（只在真机上执行以下步骤）</p>



<p>（步骤略）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] KVM 虚拟网络的创建</title>
		<link>https://eternalcenter-sep-2022.github.io/kvm-network-install/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Wed, 21 Aug 2019 08:14:31 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[KVM]]></category>
		<category><![CDATA[Virtualization (虚拟化)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=5389</guid>

					<description><![CDATA[注意： 在创建 KVM 虚拟机网络之前要先安装 KVM 正文： 步骤一：制作 1 个 KVM 虚拟网络的配置文件 创建以下内容： （补充：这里以创建1) 名为 vlan0012) dhcp 是 192.168.1.100 到 192.168.1.1003) 子网掩码是 255.255.255.04) 本机 IP 地址是 192.168.1.2545) 配置文件是 /etc/libvirt/qemu/networks/vlan001.xml 为例） 步骤二：将刚刚制作的虚拟网络配置文件定义到 KVM 里 （补充：这里的虚拟网络配置文件是 /etc/libvirt/qemu/networks/vlan001.xml） 步骤三：启动刚刚定制的虚拟网络 （补充：这里的虚拟网络名是 vlan001） 步骤四：确认刚刚定制的虚拟网络 步骤五：将刚刚定制的虚拟网络设置为开机自动启动 （补充：这里的虚拟网络名是 vlan001）]]></description>
										<content:encoded><![CDATA[
<h1>注意：</h1>



<p>在创建 KVM 虚拟机网络之前要先安装 KVM</p>



<div class="wp-container-8 is-horizontal is-content-justification-center wp-block-buttons">
<div class="wp-block-button is-style-outline"><a class="wp-block-button__link no-border-radius" href="https://eternalcenter-sep-2022.github.io/kvm-install/">KVM 的安装</a></div>
</div>



<h1>正文：</h1>



<h3>步骤一：制作 1 个 KVM 虚拟网络的配置文件</h3>



<pre class="wp-block-code"><code># vim /etc/libvirt/qemu/networks/vlan001.xml</code></pre>



<p>创建以下内容：</p>



<pre class="wp-block-code"><code>&lt;network&gt;
  &lt;name&gt;vlan001&lt;/name&gt;
  &lt;bridge name="vlan001"/&gt;
  &lt;forward mode="nat"/&gt;
  &lt;ip address="192.168.1.254" netmask="255.255.255.0"&gt;
    &lt;dhcp&gt;
      &lt;range start="192.168.1.100" end="192.168.1.200"/&gt;
    &lt;/dhcp&gt;
  &lt;/ip&gt;
&lt;/network&gt;</code></pre>



<p>（<br>补充：这里以创建<br>1) 名为 vlan001<br>2) dhcp 是 192.168.1.100 到 192.168.1.100<br>3) 子网掩码是 255.255.255.0<br>4) 本机 IP 地址是 192.168.1.254<br>5) 配置文件是 /etc/libvirt/qemu/networks/vlan001.xml 为例<br>）</p>



<h3>步骤二：将刚刚制作的虚拟网络配置文件定义到 KVM 里</h3>



<pre class="wp-block-code"><code># virsh net-define /etc/libvirt/qemu/networks/vlan001.xml</code></pre>



<p>（补充：这里的虚拟网络配置文件是 /etc/libvirt/qemu/networks/vlan001.xml）</p>



<h3>步骤三：启动刚刚定制的虚拟网络</h3>



<pre class="wp-block-code"><code># virsh net-start vlan001</code></pre>



<p>（补充：这里的虚拟网络名是 vlan001）</p>



<h3>步骤四：确认刚刚定制的虚拟网络</h3>



<pre class="wp-block-code"><code># ifconfig</code></pre>



<h3>步骤五：将刚刚定制的虚拟网络设置为开机自动启动</h3>



<pre class="wp-block-code"><code># virsh net-autostart vlan001</code></pre>



<p>（补充：这里的虚拟网络名是 vlan001）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[模板] KVM 虚拟机的 XML 模板</title>
		<link>https://eternalcenter-sep-2022.github.io/kvm-template-node-xml/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Fri, 15 Feb 2019 03:13:50 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[KVM]]></category>
		<category><![CDATA[Virtualization (虚拟化)]]></category>
		<guid isPermaLink="false">https://eternalcenter-sep-2022.github.io/?p=3056</guid>

					<description><![CDATA[注意： 此模板只用于参考 创建以下内容： （补充：这里以给 template_centos_7_10g 创建一个虚拟机模板为例）]]></description>
										<content:encoded><![CDATA[
<h2>注意：</h2>



<p>此模板只用于参考</p>



<pre class="wp-block-code"><code># vi /etc/libvirt/qemu/template_centos_7_10g.xml</code></pre>



<p>创建以下内容：</p>



<pre class="wp-block-code"><code>&lt;domain type='kvm'&gt;
  &lt;name&gt;node&lt;/name&gt;
  &lt;memory unit='KB'&gt;1524000&lt;/memory&gt;
  &lt;currentMemory unit='KB'&gt;1524000&lt;/currentMemory&gt;
  &lt;vcpu placement='static'&gt;1&lt;/vcpu&gt;
  &lt;os&gt;
    &lt;type arch='x86_64' machine='template_centos_7_10g'&gt;hvm&lt;/type&gt;
    &lt;boot dev='hd'/&gt;
    &lt;bootmenu enable='yes'/&gt;
    &lt;bios useserial='yes'/&gt;
  &lt;/os&gt;
  &lt;features&gt;
    &lt;acpi/&gt;
    &lt;apic/&gt;
  &lt;/features&gt;
  &lt;cpu mode='host-passthrough'&gt;
  &lt;/cpu&gt;
  &lt;clock offset='localtime'/&gt;
  &lt;on_poweroff&gt;destroy&lt;/on_poweroff&gt;
  &lt;on_reboot&gt;restart&lt;/on_reboot&gt;
  &lt;on_crash&gt;restart&lt;/on_crash&gt;
  &lt;devices&gt;
    &lt;emulator&gt;/usr/bin/qemu-kvm&lt;/emulator&gt;
    &lt;disk type='file' device='disk'&gt;
      &lt;driver name='qemu' type='qcow2'/&gt;
      &lt;source file='/var/lib/libvirt/images/template_centos_7_10g.img'/&gt;
      &lt;target dev='vda' bus='virtio'/&gt;
    &lt;/disk&gt;
    &lt;interface type='bridge'&gt;
      &lt;source bridge='vlan001'/&gt;
      &lt;model type='virtio'/&gt;
    &lt;/interface&gt;
    &lt;channel type='unix'&gt;
      &lt;target type='virtio' name='org.qemu.guest_agent.0'/&gt;
    &lt;/channel&gt;
    &lt;serial type='pty'&gt;&lt;/serial&gt;
    &lt;console type='pty'&gt;
      &lt;target type='serial'/&gt;
    &lt;/console&gt;
    &lt;memballoon model='virtio'&gt;&lt;/memballoon&gt;
  &lt;/devices&gt;
&lt;/domain&gt;</code></pre>



<p>（补充：这里以给 template_centos_7_10g 创建一个虚拟机模板为例）</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
