利用saltstack批量安装clamav杀毒软件

源码包安装:
clamav_source:
  file.managed:
    - name: /tmp/clamav-0.99.2.tar.gz
    - unless: test -f /tmp/clamav-0.99.2.tar.gz  //如果没有这个文件,才会执行。
    - source: salt://clamav/package/clamav-0.99.2.tar.gz
clamav_unzip:
  cmd.run:
    - cwd: /tmp
    - name: tar -zxf clamav-0.99.2.tar.gz
    - unless: test -f /tmp/clamav-0.99.2
    - require:
      - file: clamav_source
clamav_pkg:
  pkg.installed:
    - names:
      - gcc  //源码安装需要编译器
      - make
clamav_install:
  cmd.run:
    - cwd: /tmp/clamav-0.99.2
    - unless: test
    - name: ./configure --prefix=/usr/local/clamav && make && make install
    - require:
      - cmd: clamav_unzip
      - pkg: clamav_pkg

同步配置文件:
conf_file1:
  file.managed:
    - name: /usr/local/clamav/etc/clamd.conf
    - source: salt://clamav/conf_file/clamd.conf
    - unless: test -f /usr/local/clamav/etc/clamd.conf
conf_file2:
  file.managed:
    - name: /usr/local/clamav/etc/freshclam.conf
    - source: salt://clamav/conf_file/freshclam.conf
    - unless: test -f /usr/local/clamav/etc/freshclam.conf

创建用户:
create_user:
  user.present:
    - name: clamav
    - require:
      - group: creat_group
    - groups:
      - clamav
creat_group:
  group.present:
    - name: clamav


创建目录和文件:
create_dir:
  cmd.run:
    - name: mkdir /usr/local/clamav/logs && mkdir /usr/local/clamav/updata
create_log:
  cmd.run:
    - name: touch /usr/local/clamav/logs/clamd.log && touch /usr/local/clamav/logs/freshclam.log
    - require:
      - cmd: create_dir

文件授权:
change_perm:
  cmd.run:
    - name: chown clamav.clamav /usr/local/clamav/logs/clamd.log && chown clamav.clamav /usr/local/clamav/logs/freshclam.log && chown clamav.clamav /usr/local/clamav/updata
    - require:
      - cmd: create_log
      - cmd: create_user
 

  注:应把所需要的文件,复制到对应文件夹中。

posted @ 2017-12-04 11:33  houyongchong  阅读(314)  评论(0编辑  收藏  举报