【ansible自动化运维之部署zabbix-agent】

惯例,自用。。。。。。。

一、主控机安装配置ansible

    1、安装

        yum install -y ansible

    2、配置hosts文件,添加目标主机

        

    3、主控机生成ssh公钥,并发送请求到目标主机

        ssh-keygen

        ssh-copy-id 目标主机IP

    4、测试

        ansible all -m ping

        

二、通过ansible向目标主机部署zabbix-agent

    1、修改zabbix_agent.sh文件

    2、运行zabbix_agent.yaml剧本

        ansible-playbook zabbix-agent.yaml

    3、zabbix_agent.yaml文件内容如下:        

- hosts: zabbix_agent
  remote_user: root
  tasks:
  - name: close firewall
    command: systemctl stop firewalld.service
  - name: disable firewall
    command: systemctl disable firewalld.service
  - name: close selinux
    command: setenforce 0
  - name: disable selinux
    command: sed -i 's\SELINUX=enforcing\SELINUX=disabled\g' /etc/selinux/config
  - name: copy sh
    copy: src=/etc/ansible/zabbix-agent/zabbix_agent.sh dest=/usr/local/src/zabbix_agent.sh mode=0700
  - name: copy yum
    copy: src=/etc/ansible/zabbix-agent/CentOS-Base.repo dest=/usr/local/src/CentOS-Base.repo
  - name: sent tar
    copy: src=/etc/ansible/zabbix-agent/zabbix-3.4.10.tar.gz dest=/usr/local/src/zabbix-3.4.10.tar.gz
    notify: install shell
  handlers:
  - name: install shell
    shell: /usr/local/src/zabbix_agent.sh

    4、zabbix_agent.sh内容如下:

#!/bin/bash
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.back
cp /usr/local/src/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo
yum clean all

yum install -y gcc*
yum install -y pcre*

groupadd zabbix
useradd -g zabbix zabbix

cd /usr/local/src/
tar -zxvf zabbix-3.4.10.tar.gz

cd zabbix-3.4.10
./configure --enable-agent
make && make install

cp misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/
chmod 700 /etc/init.d/zabbix_agentd
sed -i  's\Server=127.0.0.1\Server=10.0.0.7\g' /usr/local/etc/zabbix_agentd.conf
sed -i  's\ServerActive=127.0.0.1\Server=10.0.0.7\g' /usr/local/etc/zabbix_agentd.conf
sed -i  's\Hostname=127.0.0.1\Server=10.0.0.7\g' /usr/local/etc/zabbix_agentd.conf

/etc/init.d/zabbix_agentd start    ##启动
chkconfig zabbix_agentd on         ##设为开机启动

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值