Zabbix学习笔记第1篇.Zabbix安装

前言

因为一个运维项目关注了一下开源监控软件,比较了Nagios、Zabbix、Zenoss、Cacti、Ganglia等,最终选择了Zabbix,主要是因为Zabbix流行(研究讨论的人多,文档多)、功能齐全(涵盖了监控数据收集和可视化、异常报警、与其他系统协同工作等功能)。

计划采用的学习方法

1、读书
2、看****
3、实践,边学边干
4、产生问题,寻求帮助,解决问题

学习笔记

实践笔记

1、安装Zabbix

这个实验是2018年2月1日开始的,官方网站的版本是3.4,如下图所示:

Zabbix学习笔记第1篇.Zabbix安装

2018年2月1日Zabbix网站截图

CentOS 7 最小化安装,禁用Firewall和SeLinux,安装Apache、MySQL、PHP。
CentOS官方网站下载的“CentOS-7-x86_64-Everything-1708.iso”安装镜像文件。

更新系统到最新版本

[email protected]# yum update

查看系统版本(2018年2月1日)

[email protected]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)

查看内核版本(2018年2月1日)

[email protected]# cat /proc/version
Linux version 3.10.0-693.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP Tue Aug 22 21:09:27 UTC 2017

总是记不住vi编辑器的那些命令,所以先安装一个nano编辑器备用

[email protected]# yum install nano

安装Apache服务器,开启Web访问服务,设置Apache开机启动。

[email protected]# yum install httpd
[email protected]# systemctl start httpd
[email protected]# systemctl enable httpd.service

添加防火墙规则,允许HTTP和HTTPS协议,重新载入防火墙规则。

[email protected]# firewall-cmd --permanent --zone=public --add-service=http
success
[email protected]# firewall-cmd --permanent --zone=public --add-service=https
success
[email protected]# firewall-cmd --reload
success

关闭SeLinux(修改完/etc/selinux/config文件,记得重新启动一次CentOS)

[email protected]# nano /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
# SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
# SELINUXTYPE=targeted

[email protected]# reboot -h now

Zabbix学习笔记第1篇.Zabbix安装

Apache正常工作

首先检查 MySQL 是否已安装

[email protected]# yum list installed | grep mysql

安装 MySQL 并开放防火墙端口。

[email protected]# rpm -Uvh 'https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm'
[email protected]# yum repolist all | grep mysql
[email protected]# yum install mysql-community-server
[email protected]# systemctl start mysqld
[email protected]# systemctl status mysqld
[email protected]# firewall-cmd --permanent --zone=public --add-port=3306/tcp
[email protected]# firewall-cmd --permanent --zone=public --add-port=3306/udp
[email protected]# firewall-cmd --reload

为了加强安全性,MySQL 5.7为root用户随机生成了一个密码,在”error_log“文件中,默认是在 /var/log/mysqld.log。使用随机生成密码登录,然后更改密码。
MySQL 5.7版本默认的密码策略是:密码要包含数字、小写字母、大写字母、特殊字符且长度至少8位

[email protected]# cat /var/log/mysqld.log | grep password
2018-02-02T01:22:10.814000Z 1 [Note] A temporary password is generated for [email protected]: cnofwNLxj8.m
[email protected]# mysql -u root -p'cnofwNLxj8.m'
mysql> SET PASSWORD = PASSWORD('XXXXXXXX');
Query OK, 0 rows affected, 1 warning (0.00 sec)

安装PHP的5.6版本,因为Zabbix集成的是5.X版本(安装过7.2版的PHP,结果在Zabbix frontend的检查时,很多模块都是off,搞了好久也没解决,绕路躲过)

[email protected]# rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
[email protected]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
[email protected]# yum install php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64

Zabbix学习笔记第1篇.Zabbix安装

PHP当下最新版

安装php-fpm

[email protected]# yum install php56w-fpm

确认一下PHP的版本,重启Apache

[email protected]# php -v
PHP 5.6.33 (cli) (built: Jan 14 2018 08:07:11)
[email protected]# systemctl restart httpd.service

编辑“/var/www/html/index.php”,写入内容,浏览器打开PHP信息页面,验证安装是否正确

[email protected]# nano /var/www/html/index.php
<?php
phpinfo();
?>

Zabbix学习笔记第1篇.Zabbix安装

Web页面显示PHP信息

下载安装Zabbix的包信息文件,安装Zabbix server,Zabbix frontend,Zabbix agent。

[email protected]# rpm -Uvh 'http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm'
[email protected]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent

以root角色登录MySQL,创建zabbix数据库,用户名是”zabbix“,密码还是要包含数字、小写字母、大写字母、特殊字符且长度至少8位。

[email protected]# mysql -uroot -p
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to [email protected] identified by 'XXXXXXXX';
mysql> quit

根据提示输入root用户的密码,将Zabbix服务器的初始化数据导入到zabbix数据库中

[email protected]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uroot -p zabbix

修改Zabbix server的配置文件”zabbix_server.conf“

[email protected]# nano /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=password

启动”zabbix-server“和”zabbix-agent“服务并且将服务设为开机自动启动

[email protected]# systemctl start zabbix-server zabbix-agent
[email protected]# systemctl enable zabbix-server zabbix-agent

修改“/etc/httpd/conf.d/zabbix.conf”文件,配置Zabbix frontend的PHP设置
注意:去掉“php_value date.timezone”字段前面的“#”,将值改为“Asia/Shanghai”

[email protected]# nano /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 always_populate_raw_post_data -1
php_value date.timezone Asia/Shanghai

给Zabbix Server和Zabbix Agent开放防火墙端口

[email protected]# firewall-cmd --permanent --zone=public --add-port=10050/tcp
[email protected]# firewall-cmd --permanent --zone=public --add-port=10050/udp
[email protected]# firewall-cmd --permanent --zone=public --add-port=10051/tcp
[email protected]# firewall-cmd --permanent --zone=public --add-port=10051/udp
[email protected]# firewall-cmd --reload

好了,Zabbix Server就绪了。下面开始配置Zabbix frontend:在浏览器地址栏输入“http://ip_address/zabbix

Zabbix学习笔记第1篇.Zabbix安装

Zabbix欢迎界面

Zabbix学习笔记第1篇.Zabbix安装

Zabbix配置页面发现错误

编辑“/etc/php.ini”文件,修改“date.timezone = Asia/Shanghai”后,重启Apache,问题解决。

[email protected]# nano /etc/php.ini

[Date]
; Defines the default timezone used by the date functions
http://php.net/date.timezone
date.timezone = Asia/Shanghai

[email protected]# systemctl restart httpd

Zabbix学习笔记第1篇.Zabbix安装

Zabbix配置OK

按照页面中的配置向导,一步一步执行,将要完成。

Zabbix学习笔记第1篇.Zabbix安装

Zabbix配置将要完成

Zabbix学习笔记第1篇.Zabbix安装

Zabbix配置完成

Zabbix学习笔记第1篇.Zabbix安装

Zabbix初次登录

Zabbix frontend安装完成后,系统自动生成“/etc/zabbix/web/zabbix.conf.php”文件。用浏览器打开:http://X.X.X.X/zabbix,默认用户名和密码:Admin/zabbix。第一次成功登录后记得修改密码。