一、zabbix特性简介

  Zabbix可以监控网络和服务的监控状况. Zabbix利用灵活的告警机制,允许用户对事件发送基于Email的告警. 这样可以保证快速的对问题作出相应. Zabbix可以利用存储数据提供杰出的报告及图形化方式. 这一特性将帮助用户完成容量规划

二、本次实战环境

名称 主机名 ip
zabbix server server134 192.168.159.134
zabbix agent server135 192.168.159.135 

三、服务器安装步骤

3.1、安装开发软件包及zabbix安装所依赖的软件包
[[email protected] ~]yum groupinstall "Development Tools"

[[email protected] ~]# yum install php-common php-odbc php-pear curl curl-devel perl-DBI php-xml ntpdate  php-bcmath mysql httpd php-mysql mysql-server php php-gd  ntpdate


3.2、同步服务端的时间,避免时间不同导致不可用的监控数据

[[email protected] ~]# ntpdate pool.ntp.org

 8 Feb 18:41:20 ntpdate[2871]: step time server 85.199.214.100 offset 4.665038 sec


3.3、创建zabbix服务运行的用户和组

[[email protected] ~]# groupadd -g 201 zabbix

[[email protected] ~]# useradd -g zabbix -u 201 -m zabbix


3.4、启动mysql、创建zabbix数据库、设置用户密码访问

[[email protected] ~]# /etc/init.d/mysqld start

[[email protected] ~]# mysql -u root -p

mysql> create database zabbix character set utf8;

Query OK, 1 row affected (0.08 sec)

mysql> grant all privileges on *.* to 'zabbix'@'%' identified by 'zishang77';

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

因本文使用的是mysql5.7,MySQL默认开启了validate_password插件,进行密码验证,需要很强的密码强度才能通过认证此版本对密码的要求比较严格,本文做了如下调整

查阅官方文档后发现有以下三种密码策略:

Policy Tests Performed
0 or LOW Length
1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters
2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file


mysql> select @@validate_password_policy;

+----------------------------+

| @@validate_password_policy |

+----------------------------+

| MEDIUM                     |

+----------------------------+

1 row in set (0.00 sec)

mysql> SHOW VARIABLES LIKE 'validate_password%'; 

+--------------------------------------+--------+

| Variable_name                        | Value  |

+--------------------------------------+--------+

| validate_password_check_user_name    | OFF    |

| validate_password_dictionary_file    |        |

| validate_password_length             | 8      |

| validate_password_mixed_case_count   | 1      |

| validate_password_number_count       | 1      |

| validate_password_policy             | MEDIUM |

| validate_password_special_char_count | 1      |

+--------------------------------------+--------+

7 rows in set (0.08 sec)

mysql> set global validate_password_policy=0;#设置密码的策略为low

Query OK, 0 rows affected (0.00 sec)


mysql> set global validate_password_mixed_case_count=0#设置指定了密码中大小字母的长度

    -> ;

Query OK, 0 rows affected (0.00 sec)


mysql> set global validate_password_number_count=2;#设置指定了密码中数据的长度

Query OK, 0 rows affected (0.00 sec)


mysql> set global validate_password_special_char_count=0;#设置密码中的特殊字符为0

Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=6;#设置密码长度为6

Query OK, 0 rows affected (0.00 sec)


mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to 'zabbix'@'%' identified by 'zabbix';

Query OK, 0 rows affected, 1 warning (0.06 sec)


3.5、安装zabbix,并导入zabbix包中的数据到mysql的zabbix数据库中

[[email protected] mnt]# tar zxvf zabbix-2.4.8.tar.gz 

[[email protected] mnt]# cd zabbix-2.4.8

[[email protected] mnt]# cd zabbix-2.4.8

[[email protected] zabbix-2.4.8]# mysql -uzabbix -pzabbix zabbix<database/mysql/schema.sql 

mysql: [Warning] Using a password on the commnd line interface can be insecure.

[[email protected] zabbix-2.4.8]# mysql -uzabbix -pzabbix zabbix<database/mysql/p_w_picpaths.sql 

mysql: [Warning] Using a password on the command line interface can be insecure.

[[email protected] zabbix-2.4.8]# mysql -uzabbix -pzabbix zabbix<database/mysql/data.sql 

mysql: [Warning] Using a password on the command line interface can be insecure.

[[email protected] zabbix-2.4.8]# ./configure --sysconfdir=/etc/zabbix --enable-server --enable-agent --with-net-snmp --with-libcurl --with-mysql --with-ssh2 --enable-java

configure: error: MySQL library not found

[[email protected] zabbix-2.4.8]# yum install mysql-devel 

[[email protected] zabbix-2.4.8]# make &&make install


3.6、Copy zabbixserver端跟agent端的启动脚本,并设置执行权限

[[email protected] zabbix-2.4.8]# cp misc/init.d/tru64/zabbix_agentd /etc/init.d/

[[email protected] zabbix-2.4.8]# cp misc/init.d/tru64/zabbix_server /etc/init.d/

[[email protected] zabbix-2.4.8]# chmod +x /etc/init.d/zabbix_*

[[email protected] zabbix-2.4.8]# cp misc/init.d/tru64/zabbix_agentd /etc/init.d/

[[email protected] zabbix-2.4.8]# cp misc/init.d/tru64/zabbix_server /etc/init.d/

[[email protected] zabbix-2.4.8]# chmod +x /etc/init.d/zabbix_*

[[email protected] zabbix-2.4.8]# mkdir /var/www/html/zabbix

[[email protected] zabbix-2.4.8]# cp -a frontends/php/* /var/www/html/zabbix/

[[email protected] zabbix-2.4.8]# chown -R apache.apache /var/www/html/zabbix/


3.7、调整使用zabbix服务所需的php参数

[[email protected] zabbix-2.4.8]# vi /etc/php.ini 

date.timezone = Asia/Shanghai

max_execution_time = 300

max_input_time = 300

post_max_size = 32M

memory_limit = 128M

mbstring.func_overload = 0

[[email protected] zabbix-2.4.8]# service httpd restart


3.8、调整zabbix服务所需的参数

[[email protected] ~]# vi /etc/zabbix/zabbix_server.conf

DBHost=192.168.159.134

DBName= zabbix

DBUser=zabbix

DBPassword=zabbix

DBSocket=/var/lib/mysql/mysql.sock

StartPollers=30         开启多线程数,一般不要超过30个

StartTrappers=20        trapper线程数

StartPingers=10         fping线程数

StartDiscoverers=120    

ListenIP=0.0.0.0

MaxHousekeeperDelete=5000      

CacheSize=128M        用来保存监控数据的缓存数,根据监控主机的数量适当调整

StartDBSyncers=8       数据库同步时间

HistoryCacheSize=128M  

TrendCacheSize=128M     总趋势缓存大小

HistoryTextCacheSize=128M

AlertScriptsPath=/etc/zabbix/alertscripts

LogSlowQueries=1000

[[email protected] ~]# service httpd restart

[[email protected] ~]# /etc/init.d/zabbix_server start


3.8、图形化安装zabbix

http://192.168.159.134/zabbix/setup.php

wKiom1ibxyPxsavcAAWGu3H6e14810.png-wh_50

wKioL1ibxyXjLEKvAAPp8wUepyc901.png-wh_50

wKiom1ibxyfi_58eAAN04REUyHU663.png-wh_50

wKiom1ibxyiR_TnxAANGsHQxtIY575.png-wh_50

wKioL1ibxyrBFIuPAALzC3w4dJc491.png-wh_50


四、server135客户端配置zabbix agent


4.1、agent端安装开发包、创建zabbix服务所需的用户和组:

[[email protected] ~]# yum groupinstall "Development Tools"

[[email protected] ~]# groupadd -g 201 zabbix

[[email protected] ~]# useradd -g zabbix -u 201 -m zabbix

[

4.2、安装zabbix客户端、copy服务至/etc/init.d 

[email protected] mnt]# tar zxvf zabbix-2.4.8.tar.gz 

[[email protected] mnt]# cd zabbix-2.4.8

[[email protected] zabbix-2.4.8]# ./configure --sysconfdir=/etc/zabbix --enable-agent

[[email protected] zabbix-2.4.8]# make &&make install

[[email protected] zabbix-2.4.8]# cp misc/init.d/tru64/zabbix_agentd /etc/init.d/

[[email protected] zabbix-2.4.8]# chmod +x /etc/init.d/zabbix_agentd 


4.3、修改zabbix_agentd.conf的参数,并启动。

[[email protected] zabbix-2.4.8]# vi /etc/zabbix/zabbix_agentd.conf

Server=192.168.159.134                    填写Server的IP地址

ServerActive=192.168.159.134:10051            修改为Server的IP地址+端口号

Hostname=192.168.159.134                   填写本机的HostName,注意Server端要能解析

UnsafeUserParameters=1                    是否允许自定义的key,1为允许,0为不允许

Include= /etc/zabbix/zabbix_agentd.conf.d/       自定义的agentd配置文件(key)可以在这里面写;

[[email protected] zabbix-2.4.8]# /etc/init.d/zabbix_agentd start