PVE QEMU-Agent

介绍:

Qemu 代理即 qemu-guest-agent,是一个运行在虚拟机里面的程序 qemu-guest-agent是一个帮助程序,守护程序,它安装在虚拟机中。 它用于在主机和虚拟机之间交换信息,以及在虚拟机中执行命令。

在Proxmox VE中,qemu代理主要用于两件事:

  1. 正确关闭虚拟机,而不是依赖ACPI命令或Windows策略
  2. 在进行备份时冻结来宾文件系统(在Windows上,使用卷影复制服务VSS)。

如果想用,不仅需要在pve里开启这个选项,还需要手动安装

安装:

  1. debain系:sudo apt install -y qemu-guest-agent
  2. centos系:sudo yum install -y qemu-guest-agent

使用:

命令:

qm agent <vmid> <cmd>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fsfreeze-freeze 
fsfreeze-status
fsfreeze-thaw
fstrim #查看ssd——trim
get-fsinfo #查看磁盘信息
get-host-name #查看主机名
get-memory-block-info #查看内存块 信息
get-memory-blocks #查看您内存
get-osinfo #查看系统信息
get-time #查看时间
get-timezone #查看时区
get-users #用户
get-vcpus #查看CPU数量
info #查看支持的命令
network-get-interfaces #查看网络
ping #不明
shutdown #关机
suspend-disk #休眠,储存到硬盘
suspend-hybrid #休眠,混合
suspend-ram #挂起/休眠 内存

qm guest

  1. qm guest cmd

    与qm agent相同

  2. qm guest exec :执行命令
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    1、查看usr目录
    qm guest exec 108 ls /usr
    返回:
    ```json
    {
    "exitcode" : 0,
    "exited" : 1,
    "out-data" : "bin\ngames\ninclude\nlib\nlocal\nsbin\nshare\nsrc\n"
    }


    2.下载一个文件
    root@pve:/# qm guest exec 108 wget https://www.baidu.com
    {
    "err-data" : "--2020-05-18 19:52:09-- https://www.baidu.com/\nResolving www.baidu.com (www.baidu.com)... 61.135.169.121, 61.135.169.125\nConnecting to www.baidu.com (www.baidu.com)|61.135.169.121|:443... connected.\nHTTP request sent, awaiting response... 200 OK\nLength: 2443 (2.4K) [text/html]\nSaving to: ‘index.html’\n\n 0K .. 100% 258M=0s\n\n2020-05-18 19:52:09 (258 MB/s) - ‘index.html’ saved [2443/2443]\n\n",
    "exitcode" : 0,
    "exited" : 1
    }


    3.查看nginx是否在运行
    qm guest exec 108 ps aux|grep nginx
    返回一堆代表在运行,没运行是没有返回的。
  3. qm guest exec-status:查看进程状态
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    用法如下
    qm guest exec-status <vmid> <pid>
    此项可以查看VM的进程PID状态。
    比如,我创建一个ping 的进程
    qm guest exec 108 ping www.baidu.com --synchronous=0
    返回如下。
    {
    "pid" : 2722
    }
    那么我再通过这个命令,看看这个pid是什么状态
    qm guest exec-status 108 2722
    返回
    {
    "exited" : 0
    }
    证明这个进程还在存活。
    如果先杀掉这个进程,再执行查看pid,第一次回返回一长串数据
    {
    "exited" : 1,
    "out-data" : "PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.\n64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=1 ttl=55 time=37.9 ms\n64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=2 ttl=55 time=38.4 ms\n64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=3 ttl=55 time=38.3 ms\n64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=4 ttl=55 time=38.4 ms\n64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=5 ttl=55 time=38.3 ms\n64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=6 ttl=55 time=38.4 ms\n64 bytes from 61.135.1
    ******
    }
    再次执行qm guest exec-status 108 2722
    Agent error: Invalid parameter 'pid'
    这是就提示错误了。
  4. qm guest passwd:直接修改密码
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    ```bash
    #语法如下
    qm guest passwd <vmid> <username> [OPTIONS]

    #[OPTIONS]只有一个 --crypted=<0/1> 是否加密密码 默认0
    实例
    qm guest passwd 108 root
    #直接更改密码
    qm guest passwd 108 administrator
    #适用于更改windows操作系统密码
    #至于后面的--crypted= 一般不加,都是加密了的密码