美文网首页zabbix监控
ansbile批量部署zabbix agent5.0的脚本

ansbile批量部署zabbix agent5.0的脚本

作者: 青纹刀狼 | 来源:发表于2021-04-16 09:00 被阅读0次

    这个是zabbix_agent.yaml的脚本

    - hosts: zabbix_agent_docker(自定义)

     remote_user: root

     tasks:

      -name: mkdir

       file: path=/tmp/zabbix state=directory

      -name: touch Logfile

       file: path=/tmp/zabbix/zabbix.log state=touch

      -name: copy repo(确保本地源yum可以用)

       copy: src=/etc/yum.repos.d/CentOS-Base1.repo   dest=/etc/yum.repos.d/CentOS-Base1.repo backup=yes

    #  -name: yum install gcc

    #   yum: state=installed name=gcc*

    #  -name: yum install pcre*

    #   yum: state=installed name=pcre*

      -name: copy zabbix.tar to clien

       copy: src=/usr/local/src/zabbix-5.0.9.tar.gz     dest=/tmp/ mode=777

      -name: copy install_shell to client

       copy: src=/etc/ansible/zabbix_agent.sh     dest=/tmp/zabbix/install_zabbix_client.sh

       notify: install shell

     handlers:

      -name: install shell

    script:/bin/bash      /tmp/zabbix/install_zabbix_client.sh

    下面是install_zabbix_client.sh

    #!/bin/bash

    HOST=`/bin/hostname`

    ##########################createuser

    groupadd   zabbix

    useradd   -g   zabbix zabbix -s /sbin/nologin

    #########################make  install

    cd /tmp/

    tar -xvf    zabbix-5.0.9.tar.gz

    cd    /tmp/zabbix-5.0.9/

    yum clean  all  &&  yum makecache

    yum -y install    gcc pcre*

    ./configure  --prefix=/usr/local/zabbix-5.0    --enable-agent

    make  && make install

    #############################start   zabbix-agent

    cp  /tmp/zabbix-5.0.9/misc/init.d/tru64/zabbix_agentd   /etc/init.d/

    chmod a+x       /etc/init.d/zabbix_agentd

    sed -i      's#DAEMON=/usr/local/sbin/zabbix_agentd#DAEMON=/usr/local/zabbix-5.0/sbin/zabbix_agentd#g'      /etc/init.d/zabbix_agentd

    #echo chkconfig:345 95 95 >> /etc/init.d/zabbix_agentd

    #chkconfigzabbix_agentd on

    sed -i    's#Server=127.0.0.1#Server=192.168.43.129#g'   /usr/local/zabbix-5.0/etc/zabbix_agentd.conf

    sed -i    's#ServerActive=127.0.0.1#ServerActive=192.168.43.129#g'    /usr/local/zabbix-5.0/etc/zabbix_agentd.conf

    sed -i    's#LogFile=/tmp/zabbix_agentd.log#LogFile=/var/log/zabbix/zabbix_agentd.log#g'     /usr/local/zabbix-5.0/etc/zabbix_agentd.conf

    sed -i   "s#Zabbix server#$HOST#g"      /usr/local/zabbix-5.0/etc/zabbix_agentd.conf

    mkdir/var/log/zabbix

    touch    /var/log/zabbix/zabbix_agentd.log

    chown -R    zabbix.zabbix /var/log/zabbix/

    chown -R   zabbix.zabbix /usr/local/zabbix-5.0

    /etc/init.d/zabbix_agentdstart

    相关文章

      网友评论

        本文标题:ansbile批量部署zabbix agent5.0的脚本

        本文链接:https://www.haomeiwen.com/subject/xpcvkltx.html