如何在 Debian 和 Ubuntu 上使用 vzwatchd 监控 OpenVZ 限制如何在 Debian 和 Ubuntu 上使用 vzwatchd 监控 OpenVZ 限制如何在 Debian 和 Ubuntu 上使用 vzwatchd 监控 OpenVZ 限制如何在 Debian 和 Ubuntu 上使用 vzwatchd 监控 OpenVZ 限制
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

如何在 Debian 和 Ubuntu 上使用 vzwatchd 监控 OpenVZ 限制

在此页

  1. 1 我的虚拟服务器是否使用 OpenVZ
  2. 2 安装 vzwatchd
    1. 安装先决条件

    Vzwatchd 是一个 OpenVZ 监控守护进程,当达到容器的限制时,它会通过电子邮件通知服务器管理员。 OpenVZ 是虚拟主机服务经常使用的 Linux 内核虚拟化技术,它是商业 virtuozzo 虚拟化应用程序的免费核心。 OpenVZ 是一种轻量级虚拟化,其开销低于 KVM 或 XEN,它更像是 Linux LXC 监狱,但具有高级限制选项来定义虚拟机可以使用多少资源,并且它支持文件系统配额。

    本教程介绍了在 Debian 和 Ubuntu 上安装和配置 vzwatchd 守护进程。

    1 我的虚拟服务器是否使用 OpenVZ

    您是否从托管公司租用了一台虚拟服务器,却不知道它使用的是哪种虚拟化技术?运行以下命令来测试它是否使用 OpenVZ:

    cat /proc/user_beancounters

    如果输出类似于下面的输出,那么您的服务器使用 OpenVZ 或兼容技术,您可以使用 vzwatchd 来监控虚拟服务器。

    :/# cat /proc/user_beancounters
    Version: 2.5
    uid resource held maxheld barrier limit failcnt
    101: kmemsize 190939926 274194432 9223372036854775807 9223372036854775807 0
    lockedpages 0 3211 1048576 1048576 0
    privvmpages 749006 781311 9223372036854775807 9223372036854775807 0
    shmpages 22506 30698 9223372036854775807 9223372036854775807 0
    dummy 0 0 9223372036854775807 9223372036854775807 0
    numproc 237 312 9223372036854775807 9223372036854775807 0
    physpages 486543 804959 0 1048576 0
    vmguarpages 0 0 3145728 9223372036854775807 0
    oomguarpages 233498 242378 1048576 9223372036854775807 0
    numtcpsock 111 298 9223372036854775807 9223372036854775807 0
    numflock 253 294 9223372036854775807 9223372036854775807 0
    numpty 1 12 9223372036854775807 9223372036854775807 0
    numsiginfo 0 33 9223372036854775807 9223372036854775807 0
    tcpsndbuf 7083944 11209000 9223372036854775807 9223372036854775807 0
    tcprcvbuf 3300832 10792248 9223372036854775807 9223372036854775807 0
    othersockbuf 261256 1008400 9223372036854775807 9223372036854775807 0
    dgramrcvbuf 0 5152 9223372036854775807 9223372036854775807 0
    numothersock 166 526 1024 1024 0
    dcachesize 168291899 247843839 9223372036854775807 9223372036854775807 0
    numfile 3098 5205 9223372036854775807 9223372036854775807 0
    dummy 0 0 9223372036854775807 9223372036854775807 0
    dummy 0 0 9223372036854775807 9223372036854775807 0
    dummy 0 0 9223372036854775807 9223372036854775807 0
    numiptent 28 35 9223372036854775807 9223372036854775807 0

    输出显示虚拟机的限制,每行描述一个限制,vzwatchd 监视的列是计算达到限制的频率的最后一列。

    2 安装 vzwatchd

    Vzwatchd 是用 Perl 编写的,它是使用 CPAN 命令从 Perl CPAN 存档下载和安装的。

    安装先决条件

    我将以 root 用户身份执行以下步骤,在 Ubuntu 上运行 sudo -s 以成为 root:

    sudo -s

    首先,我将安装 make 工具和 nano 编辑器,CPAN 使用 make 来构建 vzwatchd,稍后我将使用 nano 来编辑配置文件:

    apt-get install make nano

    接下来,我将使用以下命令从 CPAN 安装 vzwatchd:

    cpan -i App::OpenVZ::BCWatch

    如果这是您第一次在服务器上使用 CPAN,该脚本会询问您几个关于基本 CPAN 配置的问题:

    Would you like to configure as much as possible automatically? [yes]
    Would you like me to automatically choose some CPAN mirror sites for you? (This means connecting to the Internet) [yes]

    用“是”回答这两个问题。

    安装程序现在将下载、编译和安装许多 Perl 模块:

    :~# cpan -i App::OpenVZ::BCWatch

    CPAN.pm requires configuration, but most of it can be done automatically.
    If you answer 'no' below, you will enter an interactive dialog for each
    configuration option instead.

    Would you like to configure as much as possible automatically? [yes] yes

    Autoconfigured everything but 'urllist'.

    Now you need to choose your CPAN mirror sites. You can let me
    pick mirrors for you, you can select them from a list or you
    can enter them by hand.

    Would you like me to automatically choose some CPAN mirror
    sites for you? (This means connecting to the Internet) [yes] yes
    Trying to fetch a mirror list from the Internet
    Fetching with LWP:
    http://www.perl.org/CPAN/MIRRORED.BY

    Looking for CPAN mirrors near you (please be patient)
    .............................. done!

    New urllist
    http://www.planet-elektronik.de/CPAN/
    http://cpan.noris.de/
    http://cpan.lnx.sk/

    Autoconfiguration complete.

    commit: wrote '/root/.cpan/CPAN/MyConfig.pm'

    You can re-run configuration any time with 'o conf init' in the CPAN shell
    Fetching with LWP:
    http://www.planet-elektronik.de/CPAN/authors/01mailrc.txt.gz
    Going to read '/root/.cpan/sources/authors/01mailrc.txt.gz'
    ............................................................................DONE
    Fetching with LWP:
    http://www.planet-elektronik.de/CPAN/modules/02packages.details.txt.gz
    Going to read '/root/.cpan/sources/modules/02packages.details.txt.gz'
    Database was generated on Mon, 13 Apr 2015 23:29:02 GMT
    ..............
    New CPAN.pm version (v2.10) available.
    [Currently running version is v1.960001]
    You might want to try
    install CPAN
    reload cpan
    to both upgrade CPAN.pm and run the new version without leaving
    the current session.

    [... snip ...]

    CPAN.pm: Going to build G/GW/GWOLF/Config-File-1.50.tar.gz

    Building Config-File
    GWOLF/Config-File-1.50.tar.gz
    ./Build -- OK
    Running Build test
    t/pod.t ........... Subroutine main::all_pod_files_ok redefined at /usr/local/share/perl/5.14.2/Test/Pod.pm line 90.
    t/pod.t ........... ok
    t/pod_coverage.t .. ok
    t/test.t .......... 1/11 Invalid characters in key to'be^ignored at line 10 - Ignoring at /root/.cpan/build/Config-File-1.50-NjLxod/blib/lib/Config/File.pm line 41, <GEN0> line 10.
    Line format invalid at line 11: 'malformed line that should be also dropped (no equal sign)' at /root/.cpan/build/Config-File-1.50-NjLxod/blib/lib/Config/File.pm line 35, <GEN0> line 11.
    t/test.t .......... ok
    All tests successful.
    Files=3, Tests=13, 0 wallclock secs ( 0.03 usr 0.00 sys + 0.13 cusr 0.02 csys = 0.18 CPU)
    Result: PASS
    GWOLF/Config-File-1.50.tar.gz
    ./Build test -- OK
    Running Build install
    Building Config-File
    Installing /usr/local/share/perl/5.14.2/Config/File.pm
    Installing /usr/local/man/man3/Config::File.3pm
    GWOLF/Config-File-1.50.tar.gz
    ./Build install -- OK
    Running Build for S/SC/SCHUBIGER/App-OpenVZ-BCWatch-0.04.tar.gz
    Has already been unwrapped into directory /root/.cpan/build/App-OpenVZ-BCWatch-0.04-4Al97O

    CPAN.pm: Going to build S/SC/SCHUBIGER/App-OpenVZ-BCWatch-0.04.tar.gz

    Building App-OpenVZ-BCWatch
    SCHUBIGER/App-OpenVZ-BCWatch-0.04.tar.gz
    ./Build -- OK
    Running Build test
    t/00-load.t ....... ok
    t/basic.t ......... ok
    t/pod-coverage.t .. ok
    t/pod.t ........... ok
    All tests successful.
    Files=4, Tests=6, 0 wallclock secs ( 0.04 usr 0.01 sys + 0.27 cusr 0.04 csys = 0.36 CPU)
    Result: PASS
    SCHUBIGER/App-OpenVZ-BCWatch-0.04.tar.gz
    ./Build test -- OK
    Running Build install
    Building App-OpenVZ-BCWatch
    Installing /usr/local/man/man1/vzwatchd.1p
    Installing /usr/local/share/perl/5.14.2/App/OpenVZ/BCWatch.pm
    Installing /usr/local/man/man3/App::OpenVZ::BCWatch.3pm
    Installing /usr/local/bin/vzwatchd
    SCHUBIGER/App-OpenVZ-BCWatch-0.04.tar.gz
    ./Build install -- OK

    看到这条线很重要

    ./Build install -- OK

    在编译输出的末尾。如果您收到错误,请重新运行该命令。我必须运行命令两次才能成功编译所有模块。

    检查是否安装成功,运行命令:

    vzwatchd check

    这将检查安装并创建示例配置文件。

    :~# vzwatchd check
    /etc/vzwatchd.conf does not exist, creating one with defaults.
    Edit /etc/vzwatchd.conf to suit your needs and then start /usr/local/bin/vzwatchd again.

    3 配置并激活vzwatchd

    现在我将编辑 vzwatchd.conf 文件并设置通知消息的电子邮件地址。

    nano /etc/vzwatchd.conf

    配置文件在您编辑后应如下所示,当然只是您自己的电子邮件地址。

    mail[from] = 
    mail[subject] = vzwatchd on server.example.com: NOTICE
    sleep = 60
    verbose = 0
    monitor_fields = failcnt
    _active = 1

    变化是:

    • \mail[from]\ 行包含通知电子邮件的发件人地址。
    • “mail[to]”行包含接收通知的电子邮件地址。
    • 必须将 \_active\ 行中的值更改为 1 才能激活 vzwatchd。
    • 当您运行多个 OpenVZ 服务器时,更改 \mail[subject]\ 以包含服务器名称可能会很方便。

    将 vzwatchd 配置为在服务器启动时自动启动:

    vzwatchd install
    :~# vzwatchd install
    + /usr/sbin/update-rc.d vzwatchd defaults
    update-rc.d: warning: /etc/init.d/vzwatchd missing LSB information
    update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
    Adding system startup for /etc/init.d/vzwatchd ...
    /etc/rc0.d/K20vzwatchd -> ../init.d/vzwatchd
    /etc/rc1.d/K20vzwatchd -> ../init.d/vzwatchd
    /etc/rc6.d/K20vzwatchd -> ../init.d/vzwatchd
    /etc/rc2.d/S20vzwatchd -> ../init.d/vzwatchd
    /etc/rc3.d/S20vzwatchd -> ../init.d/vzwatchd
    /etc/rc4.d/S20vzwatchd -> ../init.d/vzwatchd
    /etc/rc5.d/S20vzwatchd -> ../init.d/vzwatchd

    并启动 vzwatchd 监控守护进程:

    vzwatchd start
    :~# vzwatchd start
    Starting /usr/local/bin/vzwatchd server

    现在,当您的 OpenVZ 虚拟服务器达到 OpenVZ 容器的限制之一时,您将收到电子邮件通知。

    链接

    • OpenVZ
    • Vzwatchd

©2015-2025 艾丽卡 support@alaica.com