笔记:How to Install Zabbix Server 4.0 on Ubuntu 18.04 & Ubuntu 16.04 LTS

832 阅读2分钟

computingforgeeks.com/how-to-inst…

Zabbix is an enterprise-grade open source monitoring tool used for monitoring applications, systems, Network devices, IOT devices, e.t.c. Zabbix server backend is written in C and Java, and the frontend interface written in PHP.

Zabbix Architecture

Zabbix works in a Client/Server model. The server communicates to the native software agents available for various Operating systems like Linux, NIX, and Windows.

For systems without an agent, generic monitoring protocols such as Simple Network Management Protocol (SNMP) or Intelligent Platform Management Interface (IPMI) can be used.

Install Zabbix Server 4.0 on Ubuntu 16.04 LTS

##depends LAMP

  • Apache web server
  • PHP with required extensions
  • MySQL/ MariaDB database server
  • MySQL or MariaDB

config for Apache

After installing Apache, configure basic security by allowing Prod ServerTokens only on

sudo sed -i "s/^ServerTokens OS$/ServerTokens Prod/" /etc/apache2/conf-enabled/security.conf
sudo sed -i "s/^ServerSignature On$/ServerSignature Off/" /etc/apache2/conf-enabled/security.conf

note for ServerTokens

但是我們要了解所出現的站台資訊從何而來?原來就是 ServerTokens !!

引用一下有關 ServerTokens 的參數說明

ServerTokens Prod[uctOnly]
Server sends (e.g.): Server: Apache
ServerTokens Major
Server sends (e.g.): Server: Apache/2
ServerTokens Minor
Server sends (e.g.): Server: Apache/2.0
ServerTokens Min[imal]
Server sends (e.g.): Server: Apache/2.0.41
ServerTokens OS
Server sends (e.g.): Server: Apache/2.0.41 (Unix)
ServerTokens Full (or not specified)
Server sends (e.g.): Server: Apache/2.0.41 (Unix) PHP/4.2.2 MyMod/1.2

而 ServerTokens 預設的參數就是 Full,難怪我的資訊會被 Netcraft 看光光

知道原因之後就在 httpd.conf 將 ServerTokens 設定為 Prod 吧 :D Restart Apache !!!

雖然此動作只能防小人不能防君子,但多少還是有點作用 ~

继续 ...

The directive

ServerTokens 

configures what is returned as the Server HTTP response. Valid options are Full | OS | Minimal | Minor | Major | Prod.

Set ServerName:

grep ServerName /etc/apache2/apache2.conf
ServerName zabbix.example.com

Set Server Admin to receive an email in case of issues.

grep ServerAdmin /etc/apache2/apache2.conf ServerAdmin admin@example.com

Restart apache web service after making the changes

sudo systemctl restart apache2

config Firewall

If you have UFW firewall installed and enabled, allow access to port 443 and 80

sudo ufw allow proto tcp from any to any port 80,443

To enable UFW firewall on Ubuntu, use

sudo ufw enable

Don’t forget to enable ssh service

sudo ufw allow ssh

config php

Install PHP on your Ubuntu server and extensions required by Zabbix:

sudo apt-get -y install php-pear php-cgi php-common libapache2-mod-php php-mbstring php-net-socket php-gd php-xml-util php-mysql php-gettext php-bcmath

Enable PHP CGI module

$ sudo  a2enconf php7.2-cgi 

To activate the new configuration, you need to run:

sudo systemctl reload apache2

Set PHP timezone

sudo sed -i "s/^;date.timezone =$/date.timezone = \"Africa\/Nairobi\"/" /etc/php/7.2/apache2/php.ini

Restart apache2 after this change:

sudo systemctl restart apache2

config MySQL

Once Database server installation is done, you need to create a database for Zabbix user:

export db_pass="StrongPassword"
mysql -uroot -p <<MYSQL_SCRIPT
    create database zabbix;
    grant all privileges on zabbix.* to zabbix@'localhost' identified by '${db_pass}';
    FLUSH PRIVILEGES;
MYSQL_SCRIPT
Replace “StrongPassword” with your desired password for the database.

Install Zabbix 4.0

Now that we have required dependencies installed and working, we can finalize our installation by deploying Zabbix 4.0 server.

Add Zabbix 4.0 repository:

wget https://repo.zabbix.com/zabbix/4.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.0-2+bionic_all.deb
sudo dpkg -i zabbix-release_4.0*
sudo apt update

Now install Zabbix 4.0 Server and frontend with MySQL support:

sudo apt update
sudo apt -y install zabbix-server-mysql zabbix-frontend-php zabbix-agent

Import Zabbix Server database schema.For Zabbix server and Zabbix proxy daemons, a database is required. It is not needed to run Zabbix agent. If Zabbix server and proxy are installed on the same host, their databases must be created with different names!

Import initial schema and data for the server with MySQL:

zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uzabbix -p zabbix

Edit your Zabbix configuration file

/etc/zabbix/zabbix_server.conf 

and set database connection settings.

DBName=zabbix
DBUser=zabbix
DBPassword=StrongPassword

Restart Zabbix server after modifying this file:

sudo systemctl restart zabbix-server
sudo systemctl enable zabbix-server

Apache configuration file for Zabbix frontend is located in
/etc/apache2/conf-enabled/zabbix.conf.

Some PHP settings are already configured. But it’s necessary to uncomment the “date.timezone” setting and set the right timezone for you.

php_value date.timezone Africa/Nairobi

Complete settings should be like this:

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 max_input_vars 10000
php_value always_populate_raw_post_data -1
php_value date.timezone Africa/Nairobi

Configure Zabbix agent to monitor Zabbix server itself.

$ sudo vim /etc/zabbix/zabbix_agentd.conf

Hostname=zabbix.example.com

If you have ufw firewall installed and running on your system, ensure you allow port 5000 and port 5001:

sudo ufw allow proto tcp from any to any port 10050,10051

Restart apache2 and start frontend installation

sudo systemctl restart apache2

THEN access

http://(Zabbix server’s hostname or IP address)/zabbix/”  

to begin Zabbix initial setup.

Step 1 is a welcome page, click “Next step” to proceed.