意见箱
恒创运营部门将仔细参阅您的意见和建议,必要时将通过预留邮箱与您保持联络。感谢您的支持!
意见/建议
提交建议

部署阿里云服务器,linux查看centos系统版本

来源:恒创科技 编辑:恒创科技编辑部
2023-06-07 16:30:09
概述

Alibaba Cloud Linux 3 兼容 CentOS 8、RHEL 8 软件生态, 其最大的优势之一是能作为 CentOS8 的替代方案, 可免费使用该系统镜像, 并免费获得阿里云针对该操作系统的长期支持 Alibaba Cloud Linux 3(Linux Kernel 5.10.84)镜像目前只支持 KVM 虚拟机, 镜像本身不可直接启动虚拟机,需要配置引导镜像

生成引导镜像

本地生成引导镜像 seed.qcow2, 用于虚拟机安装 Alibaba Cloud Linux 3 系统镜像后, 初始化其系统配置参数

1、本地生成引导镜像 seed.qcow2


部署阿里云服务器,linux查看centos系统版本

mkdir -p alinux/seed && cd alinux/seed
touch meta-data user-data

2、cat meta-data

#cloud-config
#vim:syntax=yaml

local-hostname: t3

3、cat user-data

#cloud-config
#vim:syntax=yaml

# 添加一个名为 alinux 的账号,并且可以执行sudo命令
users:
  - default
  - name: root
    sudo: ['ALL=(ALL)   NOPASSWD:ALL']
    plain_text_passwd: rootroot
    lock_passwd: false

# 添加 Alibaba Cloud Linux 3 的 YUM 源
yum_repos:
    alinux3-module:
        name: alinux3-module
        baseurl: https://mirrors.aliyun.com/alinux/$releasever/module/$basearch/
        enabled: 1
        gpgcheck: 1
        gpgkey: https://mirrors.aliyun.com/alinux/$releasever/RPM-GPG-KEY-ALINUX-3
    alinux3-updates:
        name: alinux3-updates
        baseurl: https://mirrors.aliyun.com/alinux/$releasever/updates/$basearch/
        enabled: 1
        gpgcheck: 1
        gpgkey: https://mirrors.aliyun.com/alinux/$releasever/RPM-GPG-KEY-ALINUX-3
    alinux3-plus:
        name: alinux3-plus
        baseurl: https://mirrors.aliyun.com/alinux/$releasever/plus/$basearch/
        enabled: 1
        gpgcheck: 1
        gpgkey: https://mirrors.aliyun.com/alinux/$releasever/RPM-GPG-KEY-ALINUX-3
    alinux3-powertools:
        name: alinux3-powertools
        baseurl: https://mirrors.aliyun.com/alinux/$releasever/powertools/$basearch/
        gpgcheck: 1
        enabled: 1
        gpgkey: https://mirrors.aliyun.com/alinux/$releasever/RPM-GPG-KEY-ALINUX-3
    alinux3-os:
        name: alinux3-os
        baseurl: https://mirrors.aliyun.com/alinux/$releasever/os/$basearch/
        gpgcheck: 1
        enabled: 1
        gpgkey: https://mirrors.aliyun.com/alinux/$releasever/RPM-GPG-KEY-ALINUX-3

4、利用 cloud-utils 生成引导镜像 seed.qcow2

yum install -y cloud-utils
cloud-localds -d qcow2 seed.qcow2 user-data meta-data
cp seed.qcow2   /home/data/vm/seed.qcow2
创建虚拟机

1、下载 Alibaba Cloud Linux 3 镜像, 创建虚拟机 t3

wget https://alinux3.oss-cn-hangzhou.aliyuncs.com/aliyun_3_x64_20G_nocloud_alibase_20211025.qcow2
cp aliyun_3_x64_20G_nocloud_alibase_20211025.qcow2 /home/data/vm/t3.qcow2

2、定义 kvm 虚拟机 virsh define t3.xml

<!-- cat t3.xml -->
<domain type='kvm'>
    <name>t3</name>
    <memory>4194304</memory><!-- 4 GB内存 -->
    <vcpu>2</vcpu>
    <cpu mode='custom' match='exact' check='partial'>
        <model fallback='allow'>Broadwell</model>
    </cpu>
    <os>
        <!-- 如果是ARM64架构的服务器,则需设置为arch='aarch64' -->
        <type arch='x86_64'>hvm</type>
        <boot dev='hd'/>
    </os>
    <clock sync="localtime"/>
    <on_poweroff>destroy</on_poweroff>
    <on_reboot>restart</on_reboot>
    <on_crash>restart</on_crash>
    <devices>
        <!-- 请根据不同的操作系统设置对应的kvm路径。例如:Ubuntu对应的kvm路径是/usr/bin/kvm -->
        <emulator>/usr/libexec/qemu-kvm</emulator>
        <!-- 请根据镜像格式设置下面的type参数:qcow2对应type='qcow2'、vhd对应type='vpc' -->
        <disk type='file' device='disk'>
            <!-- 如果要创建qcow2快照,需要关闭dataplane -->
            <driver name='qemu' type='qcow2' cache='none' dataplane='on' io='native'/>
            <!-- 填写Alibaba Cloud Linux 3镜像的绝对路径 -->
            <source file='/home/data/vm/t3.qcow2'/>
            <target dev='vda' bus='virtio'/>
        </disk>
        <!-- 加入seed.img的信息 -->
        <disk type='file' device='disk'>
            <driver name='qemu' type='raw'/>
            <!-- 填写seed镜像的绝对路径 -->
            <source file='/home/data/vm/seed.img'/>
            <target dev='vdb' bus='virtio'/>
        </disk>
        <interface type='bridge'>
            <!-- 需要提前创建网桥 br2 -->
            <source bridge='br2'/>
            <model type='virtio'/>
            <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
        </interface>
        <console type='pty'>
            <target type='virtio' port='0'/>
        </console>
        <video>
            <model type='cirrus' vram='9216' heads='1'/>
            <alias name='video0'/>
        </video>
        <input type='tablet' bus='usb'/>
        <input type='mouse' bus='ps2'/>
        <graphics type='vnc' port='59163' autoport='no'/>
    </devices>
</domain>
启动虚拟机
# 1、启动并 console 登录 kvm 虚机 t3
virsh start t3
virsh console t3

# 2、初始化, 启用 ssh 连接时的密码验证、网卡静态 IP 地址
vim /etc/ssh/sshd_config  允许 ssh 登录时使用密码验证
PasswordAuthentication yes
上一篇: 云服务器和云虚拟主机虚拟主机和云服务器的区别是什么? 下一篇: 从IslandsArchitecture看前端有多卷