centos7安装kvm 再安装aliyun linux cloud,应对centos 停更问题, 解决aliyun linux 支持远程密码登录

注意事项

# 1. 确保cpu 能开启虚拟化, 没有开启的boss 开启
# 2. 不要远程控制物理机,最好能直接操作物理机,不然安装桥接网卡的时候,链接不上物理机

安装kvm

curl -o /etc/yum.repos.d/Centos-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo

systemctl stop firewalld.service

systemctl disable firewalld.service

yum install autoconf gcc gcc-c++ automake libtool glib*   zlib*  -y

yum -y group install virtualization-platform virtualization-client

yum -y install tigervnc-server tigervnc vnc vnc-server

yum install qemu-kvm -y

yum install qemu-img -y

yum -y install qemu-kvm-tools

yum -y install virt-install

 yum -y install bridge-utils

yum -y install libvirt

systemctl start libvirtd

systemctl enable libvirtd

yum install libguestfs-tools -y

yum install libvirt-python python-virtinst libvirt-client virt-install virt-viewer –y

# 查看安装结果
lsmod | grep kvm

绑定网卡

# 查看网卡名称
ip add

# 假如我查结果 enp3s0
# 关键一步来了,绑定桥接网卡,我取名为 br0 ,这时候绑定的过程就断网,需要直接操作物理机
# 格式  virsh iface-bridge 桥接网卡名 实际网卡名
virsh iface-bridge br0 enp3s0

# 有人不使用 virsh iface-bridge 绑定, 而是直接按照格式来修改网卡内容,bctl 绑定 然后重启网卡。
# 这个我没有试过
# 直接操作物理机,查看网卡情况
ip add

# 如果发现没有br0 先重启网卡,如果报错,用命令查看是否绑定了网卡
brctl show

# 结果
#bridge name	bridge id		STP enabled	interfaces
#br0		8000.7824af8d88be	yes		

# 发现 interfaces 为空 不是 enp3s0
# 这时添加绑定
brctl addif br0	enp3s0

# 再重启网卡
systemctl restart network

# 这一步几乎不会再报错了,如果再报错,关闭 NetworkManager
systemctl disable NetworkManager
systemctl stop NetworkManager
# 再重启网卡
systemctl restart network
# 再重启网卡还可以使用
service network restart
 
 # 再看ip
 ip add

# enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 0
#    link/ether  :ff:ff
#br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueu 
#    link/ether   ff:ff:ff:ff:ff:ff
#    inet 192.168.0.35/24 brd 192.168.0.255 scope global dynamic br0

这样桥接网卡成功, 安装aliyun linux cloud, 官网:https://help.aliyun.com/document_detail/215519.html

参照官网下载好镜像,我使用的是 qcow2, uname -a 看cpu 架构, 我的是x86_64

master.xml

<domain type='kvm'>
    <name>master</name>
    <memory>3145728</memory><!-- 3 GB内存。 -->
    <vcpu>2</vcpu>
    <cpu mode='host-passthrough'><!-- 需要在对应架构的服务器上启动实例。 -->
    </cpu>
    <os>
        <type arch='x86_64'>hvm</type><!-- 如果是ARM64架构的服务器,则需设置为arch='aarch64'。 -->
        <boot dev='hd'/>
    </os>
    <clock sync="localtime"/>
    <on_poweroff>destroy</on_poweroff>
    <on_reboot>restart</on_reboot>
    <on_crash>restart</on_crash>
    <devices>
        <emulator>/usr/libexec/qemu-kvm</emulator><!-- 请根据不同的操作系统设置对应的kvm路径。例如:Ubuntu对应的kvm路径是/usr/bin/kvm。 -->
        <disk type='file' device='disk'><!-- 请根据镜像格式设置下面的type参数:qcow2对应type='qcow2'、vhd对应type='vpc'。 -->
            <driver name='qemu' type='qcow2' cache='none' dataplane='on' io='native'/> <!-- 如果要创建qcow2快照,需要关闭dataplane。 -->
            <source file='/vm/master.qcow2'/> <!-- 填写Alibaba Cloud Linux 3镜像的绝对路径。 -->
            <target dev='vda' bus='virtio'/>
        </disk>
        <!-- 加入seed.img的信息。 -->
        <disk type='file' device='disk'>
            <driver name='qemu' type='raw'/>
            <source file='/vm/seed.img'/> <!-- 填写seed镜像的绝对路径。 -->
            <target dev='vdb' bus='virtio'/>
        </disk>
        <interface type='bridge'>
            <source bridge='br0'/>
            <model type='virtio'/>
        </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='-1' autoport='yes' listen='0.0.0.0'/>
    </devices>
</domain>

部署虚拟机,并启动

virsh define master.xml

# 启动
virsh start master

# 要是报错记得查看是否开启的虚拟化,除外几乎没有报错
# 登录系统
virsh console master

# 如果卡住,直接回车就能进入系统
#Escape character is ^]

#Alibaba Cloud Linux 3 (Soaring Falcon)
#Kernel 5.10.134-12.al8.x86_64 on an x86_64

#db-master login: 

# 账号密码 是你/vm/seed.img 这个文件设置的
# 登录进去先修改root 账号密码
sudo passwd root

# 切换root
su root

# 修改ssh,保证远程用密码登录
vim /etc/ssh/sshd_config

# 最后一行 PasswordAuthentication no, 改成yes
PasswordAuthentication yes

# 重启 sshd
systemctl restart sshd

#一定要注意是修改 sshd_config 不是  ssh_config

谢谢观看

end

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值