View /etc/protocols file
# cat /etc/protocols
View /etc/protocols file
# cat /etc/protocols
在创建 KVM 虚拟机之前要先安装 KVM 并创建 KVM 虚拟网络
在 Rocky Linux 官网上下载安装系统所需要的镜像:
https://rockylinux.org/download
主要用于批量克隆出新的 KVM 机器,节约创建新虚拟机的时间
(只在真机上执行以下步骤)
# qemu-img create -f qcow2 /var/lib/libvirt/images/rockylinux9.qcow2 10G
(补充:这里以创建 10G 大小的 rockylinux9.qcow2 硬盘文件为例)
(只在真机上执行以下步骤)
# ls /var/lib/libvirt/images/ | grep rockylinux9.qcow2
(补充:这里以显示 rockylinux9.qcow2 硬盘文件为例)
(只在真机上执行以下步骤)
# virt-manager
(只在真机上执行以下步骤)
(步骤略)
(只在真机上执行以下步骤)
(图:1)
(只在真机上执行以下步骤)
(图:2)
(补充:这里以使用 Rocky-9.6-x86_6-dvd1.iso 系统镜像为例)
(只在真机上执行以下步骤)
(图:3)
(补充:这里以设置 2048 MiB 内容和 2 核 CPU 为例)
(只在真机上执行以下步骤)
(图:4)
(补充:这里以使用 rockylinux9.qcow2 硬盘文件为例)
(只在真机上执行以下步骤)
(注意:虚拟网络必须提前创建好)
(图:5)
(补充:这里以将虚拟机命名为 rockylinux9 并使用 network 网络为例)
(只在真机上执行以下步骤)
(图:6)
(只在真机上执行以下步骤)
(图:7)
(只在真机上执行以下步骤)
需要手动配置的地方有四个:
1) “INSTALLATION DESTINATION”
2) “KDUMP”
3) “SOFTWARE SELECTION”
4) “Root Password”
分别点击以后就可以配置了
(只在真机上执行以下步骤)
(补充:完成后点击左上角的 “DONE”)
(注意:只分一个分区,只设置一个挂载点挂载到根 “/”,使用标准硬盘类型,硬盘格式设置为 XFS)
(图:8)
(图:9)
(只在真机上执行以下步骤)
(补充:完成后点击左上角的 “DONE”)
(图:10)
(只在真机上执行以下步骤)
(补充:完成后点击左上角的 “DONE”)
(图:11)
(只在真机上执行以下步骤)
(图:12)
(只在真机上执行以下步骤)
(图:13)
(只在真机上执行以下步骤)
(只在真机上执行以下步骤)
1) 一定要使用刚刚创建的 /var/lib/libvirt/images/rockylinux8.qcow2 作为安装虚拟机的硬件文件
2) 虚拟机网络 “0” 要提前创建好
3) 只分一个分区,只设置一个挂载点挂载到根 “/”,使用标准硬盘,硬盘格式是 XFS
4) 取消 “KDUMP”
5) 选择最小化安装系统
6) 设置 root 密码
# vi /etc/ssh/sshd_config
在此行下面:
......
#PermitRootLogin prohibit-password
......
添加:
......
PermitRootLogin yes
......
# systemctl restart ssd
(只在虚拟机上执行以下步骤)
# vi /etc/NetworkManager/system-connections/enp1s0.nmconnection
将全部内容修改如下:
[connection]
id=enp1s0
type=ethernet
autoconnect-priority=-999
interface-name=enp1s0
timestamp=1755516857
[ethernet]
[ipv4]
method=auto
(只在虚拟机上执行以下步骤)
# reboot
(只在虚拟机上执行以下步骤)
# vi /etc/selinux/config
将全部内容修改如下:
# 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.
# See also:
# https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/using_selinux/changing-selinux-states-and-modes_using-selinux#changing-selinux-modes-at-boot-time_changing-selinux-states-and-modes
#
# NOTE: Up to RHEL 8 release included, SELINUX=disabled would also
# fully disable SELinux during boot. If you need a system with SELinux
# fully disabled instead of SELinux running with no policy loaded, you
# need to pass selinux=0 to the kernel command line. You can use grubby
# to persistently set the bootloader to boot with selinux=0:
#
# grubby --update-kernel ALL --args selinux=0
#
# To revert back to SELinux enabled:
#
# grubby --update-kernel ALL --remove-args selinux
#
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
(只在虚拟机上执行以下步骤)
# vi /etc/sysconfig/network
将全部内容修改如下:
# Created by anaconda
NOZEROCONF="yes"
(只在虚拟机上执行以下步骤)
# vi /etc/default/grub
将全部内容修改如下:
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_SERIAL_COMMAND="serial --unit=1 --speed=115200"
GRUB_CMDLINE_LINUX="biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8"
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=true
(只在虚拟机上执行以下步骤)
# grub2-mkconfig -o grub
(只在虚拟机上执行以下步骤)
# blkid
/dev/vda1: UUID="682d9854-9ca6-4272-9adb-dc9bee3098f6" TYPE="xfs" PARTUUID="bf6af362-01"
(补充:这里的 UUID 是: 682d9854-9ca6-4272-9adb-dc9bee3098f6)
(只在虚拟机上执行以下步骤)
# vi /etc/fstab
将以下内容:
......
UUID=682d9854-9ca6-4272-9adb-dc9bee3098f6 / xfs defaults 0 0
(补充:这里的 UUID 是: 682d9854-9ca6-4272-9adb-dc9bee3098f6)
修改为:
/dev/sda1 / xfs defaults 0 0
(只在虚拟机上执行以下步骤)
# yum -y remove firewalld-* python-firewall
(只在虚拟机上执行以下步骤)
# yum -y update
(只在虚拟机上执行以下步骤)
# yum install -y cloud-utils-growpart
# chmod 755 /etc/rc.local
(只在虚拟机上执行以下步骤)
# vi /etc/rc.local
添加以下内容:
......
/usr/bin/growpart /dev/sda1
/usr/sbin/xfs_growfs /
(只在虚拟机上执行以下步骤)
# vi /etc/hostname
将全部内容修改如下:
rockylinux9
(只在虚拟机上执行以下步骤)
# systemctl start serial-getty@ttyS0
# systemctl enable serial-getty@ttyS0
(只在虚拟机上执行以下步骤)
# history -c
(只在虚拟机上执行以下步骤)
# poweroff
(只在真机上执行以下步骤)
# sudo virt-sysprep -d rockylinux9
(补充:这里以清理 rockylinux9 虚拟机为例)
(
注意:如果此命令不存在
1) Rocky Linux 系统的话需要安装 libguestfs-tools
2) openSUSE 系统的话需要安装 guestfs-tools
)
(只在真机上执行以下步骤)
(步骤略)
# sudo dpkg --configure -a
# sudo apt install --fix-broken
# sudo apt remove --purge postfix
(补充:这里以删除报错的 postfix 软件包为例)
# sudo apt clean
# sudo apt autoremove
# sudo apt update
# sudo apt upgrade
# sudo apt-get install postfix
(补充:这里以重新安装前面报错并删除的 postfix 软件包为例)
# cat /etc/apt/sources.list
# Ubuntu sources have moved to /etc/apt/sources.list.d/ubuntu.sources
# vim /etc/apt/sources.list.d/ubuntu.sources
创建以下内容:
Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# cat /etc/apt/sources.list
# Ubuntu sources have moved to /etc/apt/sources.list.d/ubuntu.sources
# vim /etc/apt/sources.list.d/ubuntu.sources
创建以下内容:
Types: deb
URIs: http://mirrors.aliyun.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
(补充:这里以添加阿里云的软件源为例)
记录需要使用的网络端口的网卡机器码 (MAC) 地址
(步骤略)
(
注意:
1) 只有物理机才需要完成这步
2) 当物理机 1 个网络模块上有 2 个网络端口时,要特别注意 2 个网络端口各自的网卡机器码 (MAC) 地址,例如:戴尔服务器网络端口的网卡机器码 (MAC) 地址在页面的最下方
)
# ip a s
或者:
# ip address show
(补充:当出现 ”UP“ 字样时代表网卡已经启动)
(注意:nmcli device show 命令不能确认此时网卡是否联通)
# ethtool eth0
(注意:nmcli device show 命令不能确认此时网卡是否联通)
# ifconfig eth0 192.168.0.2/24
或者:
# ip a add 192.168.0.2/24 dev eth0
(补充:这里以给 eth0 网卡添加临时 IP 地址 192.168.0.2/24 为例)
(注意:只有当确认网卡是联通的时候才进行此操作)
# route add default gw 192.168.0.1
或者:
# ip route add default via 192.168.0.1
(注意:只有当确认网卡是联通的时候才进行此操作)
# ip a s
# route -n