在 Ubuntu 16.04 Server 上安装 Zabbix
监控 Zabbix
![](/data/attachment/album/201708/08/184554jpycmmmppx1jzjx4.jpg)


### 监控服务器 - 什么是 Zabbix


[Zabbix](http://www.zabbix.com/) 是企业级开源分布式监控服务器解决方案。该软件能监控网络的不同参数以及服务器的完整性，还允许为任何事件配置基于电子邮件的警报。Zabbix 根据存储在数据库（例如 MySQL）中的数据提供报告和数据可视化功能。软件收集的每个测量指标都可以通过基于 Web 的界面访问。


Zabbix 根据 GNU 通用公共许可证版本 2（GPLv2）的条款发布，完全免费。


在本教程中，我们将在运行 MySQL、Apache 和 PHP 的 Ubuntu 16.04 server 上安装 Zabbix。


### 安装 Zabbix 服务器


首先，我们需要安装 Zabbix 所需的几个 PHP 模块：



```
# apt-get install php7.0-bcmath php7.0-xml php7.0-mbstring

```

Ubuntu 仓库中提供的 Zabbix 软件包已经过时了。使用官方 Zabbix 仓库安装最新的稳定版本。


通过执行以下命令来安装仓库软件包：



```
$ wget http://repo.zabbix.com/zabbix/3.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.2-1+xenial_all.deb
# dpkg -i zabbix-release_3.2-1+xenial_all.deb

```

然后更新 `apt` 包源：



```
# apt-get update

```

现在可以安装带有 MySQL 支持和 PHP 前端的 Zabbix 服务器。执行命令：



```
# apt-get install zabbix-server-mysql zabbix-frontend-php

```

安装 Zabbix 代理：



```
# apt-get install zabbix-agent

```

Zabbix 现已安装。下一步是配置数据库来存储数据。


### 为 Zabbix 配置 MySQL


我们需要创建一个新的 MySQL 数据库，Zabbix 将用来存储收集的数据。


启动 MySQL shell：



```
$ mysql -uroot -p

```

接下来：



```
mysql> CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
Query OK, 1 row affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost IDENTIFIED BY 'usr_strong_pwd';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> EXIT;
Bye

```

接下来，导入初始表和数据。



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

```

输入在 MySQL shell 中创建的 **zabbix** 用户的密码。


接下来，我们需要编辑 Zabbix 服务器配置文件，它是 `/etc/zabbix/zabbis_server.conf`：



```
# $EDITOR /etc/zabbix/zabbix_server.conf

```

搜索文件的 `DBPassword` 部分：



```
### Option: DBPassword                           
#       Database password. Ignored for SQLite.   
#       Comment this line if no password is used.
#                                                
# Mandatory: no                                  
# Default:                                       
# DBPassword=


```

取消注释 `DBPassword=` 这行，并添加在 MySQL 中创建的密码：



```
DBPassword=usr_strong_pwd


```

接下来，查找 `DBHost=` 这行并取消注释。


保存并退出。


### 配置 PHP


我们需要配置 PHP 来使用 Zabbix。在安装过程中，安装程序在 `/etc/zabbix` 中创建了一个名为 `apache.conf` 的配置文件。打开此文件：



```
# $EDITOR /etc/zabbix/apache.conf

```

此时，只需要取消注释 `date.timezone` 并设置正确的时区：



```

<IfModule mod_php7.c>
    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 always_populate_raw_post_data -1
    php_value date.timezone Europe/Rome
</IfModule>


```

保存并退出。


此时，重启 Apache 并启动 Zabbix Server 服务，使其能够在开机时启动：



```
# systemctl restart apache2
# systemctl start zabbix-server
# systemctl enable zabbix-server

```

用 `systemctl` 检查 Zabbix 状态：



```
# systemctl status zabbix-server

```

这个命令应该输出：



```
â zabbix-server.service - Zabbix Server
 Loaded: loaded (/lib/systemd/system/zabbix-server.service; enabled; vendor pr
 Active: active (running) ...

```

此时，Zabbix 的服务器端已经正确安装和配置了。


### 配置 Zabbix Web 前端


如介绍中所述，Zabbix 有一个基于 Web 的前端，我们将用于可视化收集的数据。但是，必须配置此接口。


使用 Web 浏览器，进入 URL `http://localhost/zabbix`。


![Zabbix monitoring server Frontend Setup](/data/attachment/album/201708/08/184556emrdrj34z3jedlek.png)


点击 **Next step**


![snapshot2](/data/attachment/album/201708/08/184559zczwq9gbisv98ggi.png)


确保所有的值都是 **Ok**，然后再次单击 **Next step** 。


![Zabbix MySQL configuration](/data/attachment/album/201708/08/184601b79ty59b5dbnxtzn.png)


输入 MySQL **zabbix** 的用户密码，然后点击 **Next step**。


![Zabbix server details](/data/attachment/album/201708/08/184604fx3y3ox8swnl3la9.png)


单击 **Next step** ，安装程序将显示具有所有配置参数的页面。再次检查以确保一切正确。


![Zabbix pre-installation details](/data/attachment/album/201708/08/184608t3202m229sg9p1qd.png)


![Zabbix installation finished](/data/attachment/album/201708/08/184610abfapfbpbwwbh3ws.png)


点击 **Next step** 进入最后一页。


点击完成以完成前端安装。默认用户名为 **Admin**，密码是 **zabbix**。


### Zabbix 服务器入门


![Zabbix login interface](/data/attachment/album/201708/08/184612rauzzcaa27mmmcsy.png)


使用上述凭证登录后，我们将看到 Zabbix 面板：


![zabbix dashboard](/data/attachment/album/201708/08/184615mww7i8l7lw6ziw4z.png)


前往 **Administration -> Users**，了解已启用帐户的概况：


![Zabbix users](/data/attachment/album/201708/08/184617gsn6ixxcm55yx65x.png)


通过点击 **Create user** 创建一个新帐户。


![Zabbix User Creation](/data/attachment/album/201708/08/184620o7788tmmmx30ta8r.png)


点击 **Groups** 中的 **Add**，然后选择一个组：


![snapshot11](/data/attachment/album/201708/08/184622xdnh4vwndfavyjtd.png)


保存新用户凭证，它将显示在 **Administration -> Users** 面板中。


**请注意，在 Zabbix 中，主机的访问权限分配给用户组，而不是单个用户。**


### 总结


我们结束了 Zabbix Server 安装的教程。现在，监控基础设施已准备好完成其工作并收集有关需要在 Zabbix 配置中添加的服务器的数据。




---


via: <https://www.unixmen.com/monitoring-server-install-zabbix-ubuntu-16-04/>


作者：[Giuseppe Molica](https://www.unixmen.com/author/tutan/) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
### Monitoring Server – What is Zabbix

[Zabbix](http://www.zabbix.com/) is an enterprise-class open source distributed monitoring server solution. The software monitors different parameters of a network and the integrity of a server, and also allows the configuration of email based alerts for any event. Zabbix offers reporting and data visualization features based on the data stored in a database (MySQL, for example). Every metric collected by the software is accessible through a web-based interface.

Zabbix is released under the terms of the GNU General Public License version 2 (GPLv2), totally free of cost.

In this tutorial we will install Zabbix on an Ubuntu 16.04 server running MySQL, Apache and PHP.

### Install the Zabbix Server

First, we’ll need to install a few PHP modules required by Zabbix:

# apt-get install php7.0-bcmath php7.0-xml php7.0-mbstring

Install the repository package by executing the following commands:

$ wget http://repo.zabbix.com/zabbix/3.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.2-1+xenial_all.deb # dpkg -i zabbix-release_3.2-1+xenial_all.deb

Then update the

packages source:

# apt-get update

# apt-get install zabbix-server-mysql zabbix-frontend-php

Install the Zabbix agent:

# apt-get install zabbix-agent

Zabbix is now installed. The next step is to configure a database for storing its data.

### Configure MySQL for Zabbix

We need to create a new MySQL database, in which Zabbix will store the collected data.

Start the MySQL shell:

$ mysql -uroot -p

Next:

mysql> CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin; Query OK, 1 row affected (0.00 sec) mysql> GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost IDENTIFIED BY 'usr_strong_pwd'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> EXIT; Bye

Next, import the initial schema and data.

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

Enter the password for the **zabbix** user created in the MySQL shell.

Next, we need to edit the Zabbix Server configuration file, which is

:

# $EDITOR /etc/zabbix/zabbix_server.conf

Search the

section of the file:

### Option: DBPassword

# Database password. Ignored for SQLite.

# Comment this line if no password is used.

#

# Mandatory: no

# Default:

# DBPassword=

Uncomment the

line and edit by adding the password created in MySQL:

DBPassword=<span class="highlight">usr_strong_pwd</span>

Next, look for the

line and uncomment it.

Save and exit.

### Configure PHP

We need to configure PHP for working with Zabbix. During the installation process, the installer created a configuration file in

, named

. Open this file:

# $EDITOR /etc/zabbix/apache.conf

Here, right now, it’s necessary only to uncomment the

setting and set the correct timezone:

<IfModule <strong>mod_php7</strong>.c>

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 always_populate_raw_post_data -1

<strong><span class="highlight">php_value date.timezone Europe/Rome</span></strong>

</IfModule>

Save and exit.

At this point, restart Apache and start the Zabbix Server service, enabling it for starting at boot time:

# systemctl restart apache2 # systemctl start zabbix-server # systemctl enable zabbix-server

:

# systemctl status zabbix-server

This command should output:

â zabbix-server.service - Zabbix Server Loaded: loaded (/lib/systemd/system/zabbix-server.service; enabled; vendor prActive: active (running)...

At this point, the server-side part of Zabbix has been correctly installed and configured.

### Configure Zabbix Web Fronted

As mentioned in the introduction, Zabbix has a web-based front-end which we’ll use for visualizing collected data. However, this interface has to be configured.

With a web browser, go to URL

.

Click on **Next step**

Be sure that all the values are **Ok**, and then click on * Next step *again.

Insert the MySQL

**zabbix** user password, and then click on * Next step*.


Click on * Next step*, and the installer will show the following page with all the configuration parameters. Check again to ensure that everything is correct..

Click

**Next step**to proceed to the final screen.

Click finish to complete the front-end installation. The default user name is **Admin** with **zabbix **as the password.

### Getting Started with the Zabbix Server

*Administration -> Users*for an overview about enabled accounts


**Create user****Add**in the

**Groups**section and select one group

*Administration -> Users*panel.

**Note that in Zabbix access rights to hosts are assigned to user groups, not individual users.**

### Conclusion

This concludes the tutorial for the Zabbix Server installation. Now, the monitoring infrastructure is ready to do its job and collect data about servers that need to be added in the Zabbix configuration.