zabbix客户端安装

/etc/ansible/roles/zabbix_agent/zabbix_agentd.yaml    

---
- hosts: test
  remote_user: root
  vars:
        local_doc: /usr/local/src/zabbix-2.4.7.gz
        remote_doc: /usr/local/src/
  tasks:
  - name: upload file
    copy: src={{local_doc}} dest={{remote_doc}} owner=root mode=0644
  - name: install zabbix_agentd
    script: /etc/ansible/templates/zabbix_agentd.sh

 

zabbix_agentd.sh

#!/bin/bash
# install zabbix_agentd
# 2016/1/7 pdd

PORT=10050
EXEC=/usr/local/zabbix-agent/sbin/zabbix_agentd

exec 1>/tmp/zabbix_install.log 2>&1 # record install log

function Check_running() {
    lsof -i:${PORT} && echo "zabbix agentd is running"
}

function Check_sbin() {
    test -f /usr/local/zabbix-agent/sbin/zabbix_agentd && echo "zabbix has been installed"
}

function Config() {
    id zabbix || useradd -M -s /sbin/nologin zabbix
cat << EOF > /usr/local/zabbix-agent/etc/zabbix_agentd.conf
#LogFile=/tmp/zabbix_agentd.log
Server=172.18.2.196
ServerActive=172.18.2.196
Hostname=$(hostname)
Include=/usr/local/zabbix-agent/etc/zabbix_agentd.conf.d/
EOF
}

function Install() {
    Config
    cd /usr/local/src/ && tar -zx -f zabbix-2.4.7.gz
    cd zabbix-2.4.7 && ./configure --prefix=/usr/local/zabbix-agent --enable-agent && make && make install
    $EXEC
}

Check_running && exit

Check_sbin && $EXEC || Install

你可能感兴趣的:(zabbix客户端安装)