DevOps

通过Saltstack安装filebeat

2016-12-08  本文已影响56人  ly93
  1. 拷贝rpm包
  2. 安装rpm
  3. 替换配置文件
  4. 启动服务

结构

[root@Test-01 filebeat]# tree
.
├── conf.sls                                   ----替换配置文件,重启服务
├── files                                      ----存放文件的目录
│   ├── filebeat-1.2.2-x86_64.rpm              ----filebeat的rpm
│   └── filebeat.yml                           ----filebeat配置文件
├── init.sls                                   ----入口文件
├── install.sls                                ----拷贝加安装

1、init.sls

include:
  - filebeat.install
  - filebeat.conf

2、install.sls

filebeat_source:
  file.managed:
    - name: /tmp/filebeat-1.2.2-x86_64.rpm
    - unless: test -e /tmp/filebeat-1.2.2-x86_64.rpm
    - source: salt://filebeat/files/filebeat-1.2.2-x86_64.rpm
filebeat_install:
  cmd.run:
    - cwd: /tmp
    - names:
      - rpm -ivh filebeat-1.2.2-x86_64.rpm
    - unless: test -e /etc/filebeat/filebeat.yml
    - requires:
      - file: filebeat_source
filebeat_rm:
  cmd.run:
    - cwd: /tmp
    - names:
      - rm -rf filebeat-1.2.2-x86_64.rpm
    - unless: test -e ! /tmp/filebeat-1.2.2-x86_64.rpm
    - requires:
      - files: filebeat_install

conf.sls

filebeat_conf:
  file.managed:
    - name: /etc/filebeat/filebeat.yml
    #- unless: test -e /etc/filebeat/filebeat.yml
    - source: salt://filebeat/files/filebeat.yml
filebeat_restart:
  cmd.run:
    - names:
      - /etc/init.d/filebeat restart
    - requires:
      - files: filebeat_conf

执行

[root@Test-01 filebeat]# salt '*02' state.sls filebeat
Test-02:
----------
          ID: filebeat_source
    Function: file.managed
        Name: /tmp/filebeat-1.2.2-x86_64.rpm
      Result: True
     Comment: File /tmp/filebeat-1.2.2-x86_64.rpm updated
     Started: 19:21:43.161849
    Duration: 888.519 ms
     Changes:   
              ----------
              diff:
                  New file
              mode:
                  0644
----------
          ID: filebeat_install
    Function: cmd.run
        Name: rpm -ivh filebeat-1.2.2-x86_64.rpm
      Result: True
     Comment: unless execution succeeded
     Started: 19:21:44.050721
    Duration: 26.608 ms
     Changes:   
----------
          ID: filebeat_rm
    Function: cmd.run
        Name: rm -rf filebeat-1.2.2-x86_64.rpm
      Result: True
     Comment: Command "rm -rf filebeat-1.2.2-x86_64.rpm" run
     Started: 19:21:44.077776
    Duration: 54.082 ms
     Changes:   
              ----------
              pid:
                  7076
              retcode:
                  0
              stderr:
              stdout:
----------
          ID: filebeat_conf
    Function: file.managed
        Name: /etc/filebeat/filebeat.yml
      Result: True
     Comment: File /etc/filebeat/filebeat.yml is in the correct state
     Started: 19:21:44.132225
    Duration: 39.827 ms
     Changes:   
----------
          ID: filebeat_restart
    Function: cmd.run
        Name: /etc/init.d/filebeat restart
      Result: True
     Comment: Command "/etc/init.d/filebeat restart" run
     Started: 19:21:44.172250
    Duration: 188.96 ms
     Changes:   
              ----------
              pid:
                  7077
              retcode:
                  0
              stderr:
              stdout:
                  Stopping filebeat: ?[60G[?[0;32m  OK  ?[0;39m]
                  Starting filebeat: ?[60G[?[0;32m  OK  ?[0;39m]
Summary for Test-02
------------
Succeeded: 5 (changed=3)
Failed:    0
------------
Total states run:     5

ok!

上一篇下一篇

猜你喜欢

热点阅读