AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 718239
Accepted
quanta
quanta
Asked: 2015-09-02 01:23:53 +0800 CST2015-09-02 01:23:53 +0800 CST 2015-09-02 01:23:53 +0800 CST

有没有办法知道为什么重新启动服务以及是谁做的?

  • 772
  • Ubuntu 14.04
  • 克拉玛夫 0.98.7

该问题clamav-daemon几乎每天都会重新启动:

Sep  1 06:30:00 x-master clamd[6778]: Pid file removed.
clamd[6778]: --- Stopped at Tue Sep  1 06:30:00 2015
clamd[5979]: clamd daemon 0.98.7 (OS: linux-gnu, ARCH: x86_64, CPU: x86_64)
clamd[5979]: Running as user root (UID 0, GID 0)
clamd[5979]: Log file size limited to 4294967295 bytes.
clamd[5979]: Reading databases from /var/lib/clamav
clamd[5979]: Not loading PUA signatures.
clamd[5979]: Bytecode: Security mode set to "TrustSigned".

如果clamdscan正在运行,则会导致问题:

/etc/cron.daily/clamav_scan:
ERROR: Could not connect to clamd on x.x.x.x: Connection refused

请注意,我在开头说“几乎”:

/var/log/syslog:Sep  1 06:30:00 x-master clamd[6778]: Pid file removed.
/var/log/syslog.1:Aug 31 06:27:54 x-master clamd[20128]: Pid file removed.
/var/log/syslog.4.gz:Aug 28 06:28:34 x-master clamd[4475]: Pid file removed.
/var/log/syslog.5.gz:Aug 27 06:27:47 x-master clamd[21466]: Pid file removed.

如你看到的:

  • 它没有发生在 8 月 29 日和 30 日
  • 它经常在 06:27 左右重新启动,这cron.daily是运行时间

    27 6 * * * root nice -n 19 ionice -c3 run-parts --report /etc/cron.daily
    

的内容/etc/cron.daily/clamav_scan:

find / $exclude_string ! \( -path "/tmp/clamav-*.tmp" -prune \) ! \( -path "/var/lib/elasticsearch" -prune \) ! \( -path "/var/lib/mongodb" -prune \) ! \( -path "/var/lib/graylog-server" -prune \) -mtime -1 -type f -print0 | xargs -0 clamdscan --quiet -l "$status_file" || retval=$?

clamav-daemon 有一个 logrotate 文件:

/var/log/clamav/clamav.log {
     rotate 12
     weekly
     compress
     delaycompress
     create 640  clamav adm
     postrotate
     /etc/init.d/clamav-daemon reload-log > /dev/null
     endscript
     }

但它只是重新加载日志:

Sep  1 02:30:24 uba-master clamd[6778]: SIGHUP caught: re-opening log file.

我知道我们可以auditd用来监控二进制文件,这是一个示例日志:

ausearch -f /usr/sbin/clamd                                                                                                        [2/178]
----
time->Tue Sep  1 07:56:44 2015
type=PATH msg=audit(1441094204.559:15): item=1 name=(null) inode=2756458 dev=fc:00 mode=0100755 ouid=0 ogid=0 rdev=00:00
type=PATH msg=audit(1441094204.559:15): item=0 name="/usr/sbin/clamd" inode=3428628 dev=fc:00 mode=0100755 ouid=0 ogid=0 rdev=00:00
type=CWD msg=audit(1441094204.559:15):  cwd="/"
type=EXECVE msg=audit(1441094204.559:15): argc=1 a0="/usr/sbin/clamd"
type=SYSCALL msg=audit(1441094204.559:15): arch=c000003e syscall=59 success=yes exit=0 a0=7ffd277e03dc a1=7ffd277dfa78 a2=7ffd277dfa88 a3=7ffd277df570 items=2
 ppid=5708 pid=5946 auid=4294967295 uid=109 gid=114 euid=109 suid=109 fsuid=109 egid=114 sgid=114 fsgid=114 tty=pts1 ses=4294967295 comm="clamd" exe="/usr/sbin/clamd" key=(null)

109 是...clamav用户的 UID:

getent passwd clamav clamav:x:109:114::/var/lib/clamav:/bin/false

在这种情况下是否有另一种解决方法?


回复@HBrijn:

更新 AV 定义后可能是新鲜蛤蜊?

我想过这个问题。这是日志:

Sep  1 05:31:04 x-master freshclam[16197]: Received signal: wake up
Sep  1 05:31:04 x-master freshclam[16197]: ClamAV update process started at Tue Sep  1 05:31:04 2015
Sep  1 05:31:04 x-master freshclam[16197]: main.cvd is up to date (version: 55, sigs: 2424225, f-level: 60, builder: neo)
Sep  1 05:31:05 x-master freshclam[16197]: Downloading daily-20865.cdiff [100%]
Sep  1 05:31:09 x-master freshclam[16197]: daily.cld updated (version: 20865, sigs: 1555338, f-level: 63, builder: neo)
Sep  1 05:31:10 x-master freshclam[16197]: bytecode.cvd is up to date (version: 268, sigs: 47, f-level: 63, builder: anvilleg)
Sep  1 05:31:13 x-master freshclam[16197]: Database updated (3979610 signatures) from db.local.clamav.net (IP: 168.143.19.95)
Sep  1 05:31:13 x-master freshclam[16197]: Clamd successfully notified about the update.
Sep  1 05:31:13 x-master freshclam[16197]: --------------------------------------
Sep  1 04:34:10 x-master clamd[6778]: SelfCheck: Database status OK.
Sep  1 05:31:13 x-master clamd[6778]: Reading databases from /var/lib/clamav
Sep  1 05:31:22 x-master clamd[6778]: Database correctly reloaded (3974071 signatures)

我不确定这一点,但看起来freshclam 有一个“内部机制”来通知clamd 更新。之后它可以重新加载数据库,无需重新启动进程。你确定吗?

此外,从时间戳中,我看到在freshclam 更新数据库一小时后clamav-daemon 重新启动。正常吗?


更新 9 月 1 日星期二 22:10:49 ICT 2015

但看起来freshclam有一个“内部机制”来通知clamd有关更新。之后它可以重新加载数据库,无需重新启动进程。

我可以通过测试来确认这是正确的:

  • 编辑freshclam.conf 文件以将时间间隔更改为一分钟(Checks 1440)
  • 重启clamav-freshclam
  • cd /var/lib/clamav
  • rm daily.cvd
  • 等一分钟

    Sep  1 14:49:25 p freshclam[7654]: Downloading daily.cvd [100%]
    Sep  1 14:49:28 p freshclam[7654]: daily.cvd updated (version: 19487, sigs: 1191913, f-level: 63, builder: neo)
    Sep  1 14:49:28 p freshclam[7654]: Reading CVD header (bytecode.cvd):
    Sep  1 14:49:28 p freshclam[7654]: OK
    Sep  1 14:49:28 p freshclam[7654]: bytecode.cvd is up to date (version: 245, sigs: 43, f-level: 63, builder: dgoddard)
    Sep  1 14:49:31 p freshclam[7654]: Database updated (3616181 signatures) from clamav.local (IP: 10.0.2.2)
    Sep  1 14:49:31 p freshclam[7654]: Clamd successfully notified about the update.
    Sep  1 14:49:31 p freshclam[7654]: --------------------------------------
    Sep  1 14:49:32 p clamd[6693]: Reading databases from /var/lib/clamav
    Sep  1 14:49:39 p clamd[6693]: Database correctly reloaded (3610621 signatures)
    

并且 clamav-daemon 没有重新启动。

ubuntu
  • 2 2 个回答
  • 813 Views

2 个回答

  • Voted
  1. Best Answer
    Soumyadip DM
    2015-09-02T08:23:01+08:002015-09-02T08:23:01+08:00

    请检查您是否正在使用任何配置管理系统,例如 Puppet、Chef、CFEngine 等。它们可能会定期干扰服务。为纠正此问题而采取的具体行动取决于该服务在配置管理系统中的使用方式。

    • 7
  2. quanta
    2015-09-04T07:45:44+08:002015-09-04T07:45:44+08:00

    自己注意。

    作业缓存的输出:

    ----------
              ID: clamav-daemon
        Function: service.running
          Result: True
         Comment: Service restarted
         Started: 06:27:52.736890
        Duration: 12997.632 ms
         Changes:
                  ----------
                  clamav-daemon:
                      True
    

    看clamav公式:

      clamav-daemon:
        service:
          - running
          - order: 50
          - require:
            - service: clamav-freshclam
          - watch:
            - pkg: clamav-daemon
            - file: clamav-daemon
            - user: clamav
    

    watched 状态中的任何内容都没有改变:

    ----------
              ID: clamav-daemon
        Function: pkg.latest
          Result: True
         Comment: Package clamav-daemon is already up-to-date.
         Started: 06:27:51.531415
        Duration: 53.224 ms
         Changes:
    
    ----------
              ID: clamav-daemon
        Function: file.managed
            Name: /etc/clamav/clamd.conf
          Result: True
         Comment: File /etc/clamav/clamd.conf is in the correct state
         Started: 06:27:51.760019
        Duration: 625.075 ms
         Changes:
    
    ----------
              ID: clamav
        Function: user.present
          Result: True
         Comment: User clamav is present and up to date
         Started: 06:27:51.590214
        Duration: 2.455 ms
         Changes:
    

    为什么服务已重新启动?

    寻找watch_in,我发现管理 pid 文件的状态,如果 pid 文件发生更改,服务将重新启动:

    {%- macro manage_pid(path, user, group, watch_in_service, mode=644) -%}
        {%- if salt['file.file_exists'](path) %}
    {{ path }}:
      file:
        - managed
        - user: {{ user }}
        - group: {{ group }}
        - mode: {{ mode }}
        - replace: False
            {%- if caller is defined -%}
                {%- for line in caller().split("\n") -%}
                    {%- if loop.first %}
        - require:
                    {%- endif %}
    {{ line|trim|indent(6, indentfirst=True) }}
                {%- endfor -%}
            {%- endif %}
        - watch_in:
          - service: {{ watch_in_service }}
        {%- else %}
    # {{ path }} does not exist, no need to manage
        {%- endif -%}
    {%- endmacro -%}
    
    {%- call manage_pid('/var/run/clamav/clamd.pid', 'clamav', 'clamav', 'clamav-daemon', 664) %}
    - pkg: clamav-daemon
    {%- endcall %}
    

    在 的输出中salt-run jobs.lookup_jid <job id number>,我看到了这个:

    ----------
              ID: /var/run/clamav/clamd.pid
        Function: file.managed
          Result: True
         Comment:
         Started: 06:27:52.392555
        Duration: 2.364 ms
         Changes:
                  ----------
                  group:
                      clamav
                  user:
                      clamav
    

    因此,该 pid 文件的所有者/组已更改为clamav. 最后,我发现原因是 clamav 守护进程是以root用户身份在网络模式下运行的。因此,pid 文件被创建为root. 因此,管理 pid 文件的状态必须更改为:

    {%- call manage_pid('/var/run/clamav/clamd.pid', 'root', 'root', 'clamav-daemon', 664) %}
    - pkg: clamav-daemon
    {%- endcall %}
    
    • 5

相关问题

  • 无法通过 Ubuntu VPN 访问外部网络

  • ubuntu apt-get upgrade - 如何在 shell 中单击确定?

  • VirtualBox 上 Ubuntu 的访客优化技巧 [关闭]

  • 外部硬盘上的 virtualbox 虚拟硬盘驱动器(Vista 主机上的 ubuntu 客户机)

  • 如何在 Ubuntu 上挂载 LVM 分区?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve