# Zabbix :grinning_face_with_one_large_and_one_small_eye: ###### tags: `zabbix` `zabbix agent` `mariadb` `certbot` ### links [Zabbix](https://www.zabbix.com/download?zabbix=6.4&os_distribution=ubuntu&os_version=22.04&components=server_frontend_agent&db=mysql&ws=nginx) [Zabbix install](https://bestmonitoringtools.com/how-to-install-zabbix-server-on-ubuntu/) [Zabbix agent](https://www.zabbix.com/download?zabbix=6.4&os_distribution=ubuntu&os_version=22.04&components=agent&db=&ws=) [DigitalOcean](https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-zabbix-to-securely-monitor-remote-servers-on-ubuntu-20-04) ## add repo and install zabbix components `wget https://repo.zabbix.com/zabbix/6.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.2-4%2Bubuntu22.04_all.deb` `dpkg -i zabbix-release_6.2-4+ubuntu22.04_all.deb` `apt update` `apt -y install zabbix-server-mysql zabbix-frontend-php zabbix-nginx-conf zabbix-sql-scripts zabbix-agent` `apt -y install nginx` ## setup mariadb `sudo apt install software-properties-common -y` `curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup` `sudo bash mariadb_repo_setup --mariadb-server-version=10.6` `sudo apt update` `sudo apt -y install mariadb-common mariadb-server-10.6 mariadb-client-10.6` `sudo systemctl start mariadb` `sudo systemctl enable mariadb` ### mariadb secure install :secret: `sudo mysql_secure_installation` ``` Enter current password for root (enter for none): Press Enter Switch to unix_socket authentication [Y/n] y Change the root password? [Y/n] y New password: <root DB password> Re-enter new password: <Repeat root DB password> Remove anonymous users? [Y/n]: Y Disallow root login remotely? [Y/n]: Y Remove test database and access to it? [Y/n]: Y Reload privilege tables now? [Y/n]: Y ``` ### create database ``` sudo mysql -uroot -p'<root DB password>' -e "create database zabbix character set utf8mb4 collate utf8mb4_bin;" sudo mysql -uroot -p'<root DB password>' -e "grant all privileges on zabbix.* to zabbix@localhost identified by '<zabbix DB password>;" ``` ## zabbix conection setup `sudo zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p'<zabbix DB password>' zabbix` `sudo nano /etc/zabbix/zabbix_server.conf` `DBPassword=<zabbix DB password>` ## nginx setup `apt install nginx -y` `nano /etc/zabbix/nginx.conf` ``` server { allow 1.1.1.1.; allow 2.2.2.2; allow 3.3.3.3; deny all; listen localhost:8888; server_name zabbix.domain.com; ``` `sudo systemctl restart zabbix-server zabbix-agent` `sudo systemctl enable zabbix-server zabbix-agent` ### setup nginx proxy `nano /etc/nginx/sites-available/zabbix.domain.com` ``` server { listen 80; server_name zabbix.domain.com; location / { proxy_pass http://127.0.0.1:8888; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } ``` - create symbolic link `ln -s /etc/nginx/sites-available/zabbix.domain.com /etc/nginx/sites-enabled/` `nginx -t systemctl restart nginx` ## Setup zabbix - go to http://zabbix.domain.com/ ![](https://i.imgur.com/xOiP1D4.png) ## install cerbot `apt install certbot python3-certbot-nginx` - add DNS A to your domain hosting `certbot --nginx -d zabbix.domain.ru` `import template to zabbix and setup zabbix agent https://github.com/cryptage21/wireguard-zabbix` ## Setup zabbix agent - Install Zabbix repository ``` wget https://repo.zabbix.com/zabbix/6.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.4-1+ubuntu22.04_all.deb dpkg -i zabbix-release_6.4-1+ubuntu22.04_all.deb apt update ``` - Install Zabbix agent `apt install zabbix-agent` - Start Zabbix agent process and make it start at system boot. `systemctl restart zabbix-agent` `systemctl enable zabbix-agent` - generate psk key `sudo sh -c "openssl rand -hex 32 > /etc/zabbix/zabbix_agentd.psk"` `cat zabbix_agentd.psk` `bf5d1e411b9160000000000000005143d10a9584823b02f2` - add info to zabbix agent conf `nano /etc/zabbix/zabbix_agentd.conf` ``` Server=1.1.1.1 # ip v4 only ListenIP=0.0.0.0 ServerActive=1.1.1.1 Hostname=<Your Host Name> TLSConnect=psk TLSAccept=psk TLSPSKFile=/etc/zabbix/zabbix_agentd.psk TLSPSKIdentity=PSKbillsrv1 ```