Zabbix Server Installation

From Michael's Information Zone
Jump to navigation Jump to search

Server

Amazon Linux 2

In this case I am moving an existing installation to an EC2 instance for testing purposes. Sizing and pricing is the name of the game here. I have a t2.large instance with 20GB SSD boot disk and 200GB magnetic data disk. We will be placing the database on the magnetic volume until AWS RDS is ready to take the load.

Docker

Forget all that, lets use docker and AWS RDS Serverless!

sudo yum -y update
sudo yum -y install docker
sudo docker pull zabbix/zabbix-server-mysql
sudo docker pull zabbix/zabbix-web-apache-mysql

I already had a database, so I wanted to import it into the new database container. Problem I can into was that the latest version of MySQL has some new authentication that needs to be addressed.[1]

  • In the following example I mounted the mysql directory to a host directory for easier management.
  • I also had created a new bridge network so I could take advantage of service discovery.

sudo docker run --name zabbix-db -e MYSQL_ROOT_PASSWORD=<password> -e MYSQL_USER='zabbix' -e MYSQL_PASSWORD='<password>' -v /home/ec2-user/db:/var/lib/mysql -e MYSQL_DATABASE=zabbix --network=newbridge --restart=unless-stopped -d mysql:latest

sudo docker exec -it zabbix-db mysql -uroot -p<password> mysql -e "alter user 'zabbix'@'%' identified with mysql_native_password by '<password>';"

sudo docker run --name zabbix-server -t -e DB_SERVER_HOST='zabbix-db' -e MYSQL_USER='zabbix' -e MYSQL_PASSWORD='<password>' -p 10050:10050 -p 10051:10051 --restart=unless-stopped --network=newbridge -d zabbix/zabbix-server-mysql:latest

sudo docker run --name zabbix-web -t -e DB_SERVER_HOST='zabbix-db' -e MYSQL_USER='zabbix' -e MYSQL_PASSWORD='<password>' -e ZBX_SERVER_HOST='zabbix-server' -e PHP_TZ='America/New_York' -p 80:80 --restart=unless-stopped --network=newdbridge -d zabbix/zabbix-web-apache-mysql:latest

Standard Install

Install Packages
sudo yum -y upgrade
sudo amazon-linux-extras install lamp-mariadb10.2-php7.2
sudo yum -y install mod_ssl yum-cron php-mbstring php-gd php-bcmath php-xml php-session htop firewalld mariadb-server
sudo reboot
Configure data disk

[2]

sudo echo -e "n\n\n\n\n\nw\n" fdisk /dev/sdb
sudo pvcreate /dev/sdb1
sudo vgcreate data /dev/sdb1
sudo lvcreate -L 199G -n data_vol data
sudo mkfs.xfs /dev/data/data_vol
sudo mkdir /data
sudo mount /dev/data/data_vol /data/

Be sure to update fstab with the mount point as well

Configure Database

[3]


CentOS 7

rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
yum install zabbix-server-mysql zabbix-web-mysql
yum install mariadb-server mariadb

Database

The following commands are for database creation, but they are not specific. Needs work

shell> mysql -uroot -p<password>
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by '<password>';
mysql> flush privileges;
mysql> quit;
cd /usr/share/doc/zabbix-server-mysql-3.0.4/create
shell>  cat create.sql | mysql -hxxx.xxx.xxx.xxx -uzabbix -p zabbix
Some packages might combine those three SQL files in one, so you will only have create.sql.gz. You can import it directly as "zcat create.sql.gz | mysql zabbix". If you want to see the SQL file, you can extract it with 'tar -xvf create.sql.gz' in a single step.

Config File

Edit the Zabbix Server configuration file

# vi /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix

Starting Service

Start the zabbix server

systemctl start zabbix-server

Edit the php configuration file to use the correct time zone /etc/httpd/conf.d/zabbix.conf

php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value date.timezone America/New_York

Start http

systemctl start httpd 

SELinus

Configure SELinux to allow the above services network access

setsebool -P zabbix_can_network=true
setsebool -P httpd_can_network_connect=true

Enable all service

=Enable services

systemctl enable mariadb
systemctl enable httpd
systemctl enable zabbix-server

At this point you should be able to access the web interface by going to <IP of host>/zabbix. User/password is admin/zabbix.

If everything is working reboot the server, and test again.

Client

CentOS 7

rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
yum -y install zabbix-agent
sed -i 's/^Server=127.0.0.1/Server=<your server>/'  /etc/zabbix/zabbix_agentd.conf
sed -i 's/^ServerActive=127.0.0.1/ServerActive=<your server>/' /etc/zabbix/zabbix_agentd.conf
sed -i 's/^Hostname=Zabbix server/#Hostname=Zabbix server/' /etc/zabbix/zabbix_agentd.conf
sed -i 's/^#HostnameItem=/HostnameItem=system.hostname/' /etc/zabbix/zabbix_agentd.conf
sed -i 's/^#HostMetadataItem=/HostMetadataItem=system.uname/' /etc/zabbix/zabbix_agentd.conf
systemctl enable zabbix-agent
systemctl start zabbix-agent

Ubuntu 16.04

[4]

wget http://repo.zabbix.com/zabbix/3.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.2-1+xenial_all.deb
sudo dpkg -i zabbix-release_3.2-1+xenial_all.deb
sudo apt-get install zabbix-agent
sudo sed -i 's/^Server=127.0.0.1/Server=<your server>/'  /etc/zabbix/zabbix_agentd.conf
sudo sed -i 's/^ServerActive=127.0.0.1/ServerActive=<your server>/' /etc/zabbix/zabbix_agentd.conf
sudo sed -i 's/^Hostname=Zabbix server/#Hostname=Zabbix server/' /etc/zabbix/zabbix_agentd.conf
sudo sed -i 's/^#HostnameItem=/HostnameItem=system.hostname/' /etc/zabbix/zabbix_agentd.conf
sudo sed -i 's/^#HostMetadataItem=/HostMetadataItem=system.uname/' /etc/zabbix/zabbix_agentd.conf
systemctl enable zabbix-agent
systemctl start zabbix-agent

Windows Server

Using powershell to install to a remote system.[5]

$session=New-PSSession -ComputerName computer2
copy-item -tosession $session -path C:\<local directory>\zabbix_agent.msi -destination C:\<remote directory>\zabbix_agent.msi
enter-pssession -session $session
cd c:\<destination directory from above>
msi /i zabbix_agent.msi /qn SERVER=<zabbix server>
exit
remove-pssession -session $session

Proxy

Docker

sudo docker run --name zabbix-db -e MYSQL_ROOT_PASSWORD=<password> -e MYSQL_USER='zabbix' -e MYSQL_PASSWORD='<password>' -e MYSQL_DATABASE=zabbix_proxy --network=newbridge --restart=unless-stopped -d mysql:latest

sudo docker exec -it zabbix-db mysql -uroot -p<password> mysql -e "alter user 'zabbix'@'%' identified with mysql_native_password by '<password>';"

sudo docker run --name zabbix-proxy -t -e DB_SERVER_HOST='zabbix-db' -e MYSQL_USER='zabbix' -e MYSQL_PASSWORD='<password>' -e ZBX_PROXYMODE=1 -e ZBX_SERVER_HOST='<zabbix server>' \
-e PHP_TZ='America/New_York' -p 10050:10050 -p 10051:10051 --restart=unless-stopped --network=newbridge -d zabbix/zabbix-proxy-mysql:latest

Docker on same host with Zgent

Trying to install on host with agent already running. There was a port conflict on 10050.

  • Update /etc/zabbix/zabbix_agentd.conf with another port (ie 10055)
  • Update selinux
semanage port -a -t zabbix_agent_port_t -p tcp 10055
  • Update zabbix server with new port for the agent on this host
  • Start zabbix-proxy docker container

Troubleshooting

  • Reset the password: use zabbix; update zabbix.users set passwd=md5('newpass') where alias='Admin';

https://www.zabbix.com/documentation/3.0/manual/installation/install_from_packages

https://www.zabbix.com/documentation/3.0/manual/appendix/install/db_scripts

https://www.zabbix.com/forum/showthread.php?p=169500

https://www.rackspace.com/knowledge_center/article/installing-mysql-server-on-centos