In this guid I will give you the steps to install zabbix-agent 2 offline and how to start using it to collect data and send it to your proxy.
Prerequisites
- Basic knowledge of the terminal
- ansible server
- A smile on your face (Put up that smile friend ?)
Firstly, you need to understand why using Ansible. Because it’s really hard and boring to install and configure each server that why we will use these technologies to make work easy also Ansible doesn’t need a lot of resources, just a host server and we will attack other servers.
code source of playbooks file here
install zabbix agent 2
For many reasons of security, we avoid allowing internet servers so that why we will install a zabbix-agent 2 and put it in /tmp.
On host server:
cd /tmp
wget https://repo.zabbix.com/zabbix/6.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.2-4%2Bubuntu20.04_all.deb
Now in Ansible directory we will set up a playbook to install the agent in other servers:
cd /etc/ansible
nano playbook1.yml
And we will put this script yaml to install the agent:
---
- hosts: all
become: true
tasks:
- name: Copy local zabbix package to target servers
copy:
src: /tmp/zabbix-release_6.2-4+ubuntu20.04_all.deb
dest: /tmp/
- name: Install zabbix repo from local repository
apt:
deb: /tmp/zabbix-release_6.2-4+ubuntu20.04_all.deb
state: present
- name: Update package cache
apt:
update_cache: yes
- name: Install zabbix agent
apt:
name: zabbix-agent2
state: present
- name: Start service zabbix-agent2
become: yes
service:
name: zabbix-agent2
state: started
After that we launch this command to start the installation:
ansible-playbook playbook1.yml
Now we should setup our agent to start collecting information.
So in /etc/zabbix/zabbix_agent2.conf we should put this information to connect the agent to the proxy, but don’t worry all this will be with Ansible.
Let create a file on the host server and put this configuration and send it to all your clients servers:
mkdir /templates
nano zabbix_agent2.conf.j2
#copy and past on zabbix_agent2.conf.j2
PidFile=/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=proxy_IP
ServerActive=127.0.0.1
Hostname={{ ansible_hostname }}
Include=/etc/zabbix/zabbix_agentd.d/*.conf
And now we will create a new playbook in /etc/Ansible to send this configuration and start the service:
nano playbook2.yml
---
- hosts: all
gather_facts: yes
tasks:
- name: Remove zabbix config file
become: yes
file:
path: /etc/zabbix/zabbix_agent2.conf
state: absent
- name: Create new zabbix config file from template
become: yes
template:
src: "/templates/zabbix_agent2.conf.j2"
dest: "/etc/zabbix/zabbix_agent2.conf"
- name: Start service zabbix-agent
become: yes
service:
name: zabbix-agent2
state: started
ansible-playbook playbook2.yml
Now you are done and the agent installed in all your clients servers.
Remember that you could use Ansible with a lot of things and for more examples check here