记录日常工作关于系统运维,虚拟化云计算,数据库,网络安全等各方面问题。
 
0

备份原有的yum


[root@ns1 ~]# find /etc/yum.repos.d/ -name '*.repo' -exec mv {} {}.back \;


#配阿里云yum源


[root@ns1 ~]# vim /etc/yum.repos.d/aliyun.repo 

[aliyun]

name=centos6

baseurl=https://mirrors.aliyun.com/centos/6/os/x86_64/

enabled=1

gpgkey=https://mirrors.aliyun.com/centos/6/os/x86_64/RPM-GPG-KEY-CentOS-6

gpgcheck=1

 

[epel]

name=Extra Packages for Enterprise Linux 6 - $basearch

baseurl=http://mirrors.aliyun.com/epel/6/$basearch

        http://mirrors.aliyuncs.com/epel/6/$basearch

failovermethod=priority

enabled=1

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6


安装前端web


[root@ns1 ~]yum -y install httpd PHP php-MySQL mysql-server 


[root@ns1 ~]service httpd start



修改数据库配置文件,把编码改为utf8


[root@ns1 ~]vim /etc/my.cnf

[mysqld]

default-character-set=utf8


[root@ns1 ~]service mysqld start


加入开机自启动


[root@ns1 ~]chkconfig httpd on

[root@ns1 ~]chkconfig mysqld on


安装zabbix服务端


[root@ns1 ~]#yum -y install zabbix22-server

初始化数据库


[root@ns1 ~]#  mysql -uroot <<END

delete from mysql.user where user='';

update mysql.user set password=password('123') where user='root';

delete from mysql.db where user='';

flush privileges;


create database zabbix default charset utf8;


grant all on zabbix.* to zabbix@localhost identified by '123';


END

找出要导入数据库的数据文件


[root@ns1 ~]# find /usr/share/zabbix-mysql/ -name '*.sql'


/usr/share/zabbix-mysql/images.sql

/usr/share/zabbix-mysql/data.sql

/usr/share/zabbix-mysql/schema.sql


导入数据,这里要注意导入的顺序


[root@ns1 ~]#  mysql -uzabbix -p123 zabbix < /usr/share/zabbix-mysql/mysql.sql

[root@ns1 ~]#  mysql -uzabbix -p123 zabbix </usr/share/zabbix-mysql/images.sql

[root@ns1 ~]#  mysql -uzabbix -p123 zabbix </usr/share/zabbix-mysql/data.sql


修改zabbix的配置文件,按照自己之前的配置修改数据库名,用户名,密码


[root@ns1 ~]# vim /etc/zabbix/zabbix_server.conf


LogFile=/var/log/zabbix/zabbix_server.log

LogFileSize=0

PidFile=/var/run/zabbix/zabbix_server.pid

DBName=zabbix

DBUser=zabbix

DBPassword=123

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

SNMPTrapperFile=/var/log/snmptt/snmptt.log

AlertScriptsPath=/usr/lib/zabbix/alertscripts

ExternalScripts=/usr/lib/zabbix/externalscripts


启动zabbix


[root@ns1 ~]#  /etc/init.d/zabbix-server start 

Starting Zabbix server:    

                                [确定]

[root@ns1 ~]# chkconfig zabbix-server on



[root@ns1 ~]# netstat -tnlp |grep zabbix


tcp        0      0 0.0.0.0:10051               0.0.0.0:*                   LISTEN      28656/zabbix_server 

tcp        0      0 :::10051                    :::*                        LISTEN      28656/zabbix_server


安装zabbix-web


[root@ns1 ~]# yum -y install zabbix22-web zabbix22-web-mysql


修改php的配置,zabbix有配置要求,具体在web界面安装时会有提示,注意时区是否一致


[root@ns1 ~]#  vim /etc/php.ini 

 440 max_execution_time = 300

 449 max_input_time = 300

 729 post_max_size = 16M

 946 date.timezone = 'Asia/Shanghai'


[root@ns1 ~]#  service httpd restart

此时可进入web界面安装了

本机登录:http://localhost/zabbix

非本机登录注意selinux,防火墙


[root@ns1 ~]# setenforce 0

[root@ns1 ~]# iptables -F




    ​    ​   客户端配置


[root@www ~]# find /etc/yum.repos.d/ -name '*.repo' -exec mv {} {}.back \;


#配置阿里云yum


[root@www ~]# vim /etc/yum.repos.d/aliyun.repo 

[aliyun]

name=centos6

baseurl=https://mirrors.aliyun.com/centos/6/os/x86_64/

enabled=1

gpgkey=https://mirrors.aliyun.com/centos/6/os/x86_64/RPM-GPG-KEY-CentOS-6

gpgcheck=1

  

[epel]

name=Extra Packages for Enterprise linux 6 - $basearch

baseurl=http://mirrors.aliyun.com/epel/6/$basearch

        http://mirrors.aliyuncs.com/epel/6/$basearch

failovermethod=priority

enabled=1

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6



[root@www ~]# yum -y install zabbix22-agent.x86_64 



[root@www ~]# service zabbix-agentd start


[root@www ~]# chkconfig zabbix-agent on


[root@www ~]# cd /etc/zabbix/


[root@www zabbix]# cp zabbix_agent.conf zabbix_agent.conf.bak 


[root@www zabbix]# vim zabbix_agent.conf


Server=192.168.1.111            #服务端ip地址



[root@www ~]# vim /etc/zabbix_agentd.conf 


Server=192.168.1.111

ServerActive=192.168.1.111


[root@www zabbix]# service zabbix-agentd restart


部署完成后在服务端测试,能获取到客户端主机名,说明服务端能对客户端进行监控


[root@ns1 ~]# zabbix_get -s 192.168.1.102 -k system.hostname

www.nginx.com








1.官方文档地址:

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

 

2.导入源:

rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm

 

3.安装zabbix包

yum install zabbix-server-mysql zabbix-web-mysql


清楚的看一下要安装那些包(httpd php基本都依赖安装了)

Package                                Arch                      Version                                   Repository                  Size

=====================================================================================================================

Installing:

 zabbix-server-mysql                    x86_64                    3.0.1-1.el7                               zabbix                     1.7 M

 zabbix-web-mysql                       noarch                    3.0.1-1.el7                               zabbix                     3.5 k

Installing for dependencies:

 OpenIPMI-libs                          x86_64                    2.0.19-11.el7                             base                       501 k

 OpenIPMI-modalias                      x86_64                    2.0.19-11.el7                             base                        15 k

 dejavu-fonts-common                    noarch                    2.33-6.el7                                base                        64 k

 dejavu-sans-fonts                      noarch                    2.33-6.el7                                base                       1.4 M

 fping                                  x86_64                    3.10-4.el7                                epel                        46 k

 httpd                                  x86_64                    2.4.6-40.el7.centos                       base                       2.7 M

 httpd-tools                            x86_64                    2.4.6-40.el7.centos                       base                        82 k

 iksemel                                x86_64                    1.4-6.el7                                 epel                        50 k

 libtool-ltdl                           x86_64                    2.4.2-21.el7_2                            updates                     49 k

 libzip                                 x86_64                    0.10.1-8.el7                              base                        48 k

 mailcap                                noarch                    2.1.41-2.el7                              base                        31 k

 net-snmp-libs                          x86_64                    1:5.7.2-24.el7                            base                       747 k

 php                                    x86_64                    5.4.16-36.el7_1                           base                       1.4 M

 php-bcmath                             x86_64                    5.4.16-36.el7_1                           base                        56 k

 php-cli                                x86_64                    5.4.16-36.el7_1                           base                       2.7 M

 php-common                             x86_64                    5.4.16-36.el7_1                           base                       563 k

 php-gd                                 x86_64                    5.4.16-36.el7_1                           base                       126 k

 php-ldap                               x86_64                    5.4.16-36.el7_1                           base                        51 k

 php-mbstring                           x86_64                    5.4.16-36.el7_1                           base                       503 k

 php-mysql                              x86_64                    5.4.16-36.el7_1                           base                        99 k

 php-pdo                                x86_64                    5.4.16-36.el7_1                           base                        97 k

 php-xml                                x86_64                    5.4.16-36.el7_1                           base                       124 k

 t1lib                                  x86_64                    5.1.2-14.el7                              base                       166 k

 unixODBC                               x86_64                    2.3.1-11.el7                              base                       413 k

 zabbix-web                             noarch                    3.0.1-1.el7                               zabbix                     3.3 M

Transaction Summary

=============================================================================================================================================

Install  2 Packages (+25 Dependent packages)

Total download size: 17 M

 

 

4.我们给本机也安装上客户端(如果服务端不需要监控略过此步)


yum install zabbix-agent

 

 

5.安装mysql数据库


CentOS 7 版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替了。用mariadb也行。我还是选择了mysql


#导入安装源


rpm -ivh mysql-community-release-el7-5.noarch.rpm


#用 yum 安装 Mysql


yum install mysql-community-server

systemctl enable mysqld  #设置开机启动

systemctl start mysqld   #启动服务


=================================================

备注:1 mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码


      2 grep 'temporary password' /var/log/mysqld.log 找到root默认密码


      3 mysql5.7默认安装了密码安全检查插件(validate_password)


默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误

===================================================

#修改root本地登录密码

mysqladmin -u root  -p oldpass password "Admin@123"

#登录mysql

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 'Admin@123';

Query OK, 0 rows affected (0.00 sec)

mysql> quit

Bye


(2)进入到这个目录


cd /usr/share/doc/zabbix-server-mysql-3.0.8


运行命令


zcat create.sql.gz | mysql -uroot -p zabbix


6.启动zabbix server服务


修改配置文件:


vi /etc/zabbix/zabbix_server.conf


DBHost=localhost

DBName=zabbix

DBUser=zabbix

DBPassword=Admin@123


备注:实际上我的配置文件修改的是DBHost和DBPassword去掉前面的#号。


启动zabbix服务,设置开机自启动


systemctl start zabbix-server

systemctl enable zabbix-server

 

 

7.编辑zabbix前端的PHP配合配置


vi /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

备注:实际上我就是修改了时区

 

启动apache服务,设置开机自启动

systemctl start httpd

systemctl enable httpd

 

8.登陆zabbix

http://IP/zabbix/

显示的界面 




Zabbix之配置文件详解


zabbix的配置文件一般有三种:


zabbixserver的配置文件zabbix_server.conf

zabbixproxy的配置文件zabbix_proxy.conf

zabbix_agentd的配置文件zabbix_agentd.conf


  1. zabbixserver的配置文件:


NodeID=0 #分布式节点id号,0代表是独立服务器,默认是被注释掉的,不强制配置 

ListenPort=10051 #zabbix server的端口,默认是10051,可以自行修改, 


范围是1024-32767 ,一般默认即可 


SourceIP=  #连接的源ip地址,默认为空,默认即可 


LogFile=/tmp/zabbix_server.log #日志文件的存放位置 


LogFileSize=1 #日志文件的大小,单位为MB,当设置为0时,表示不仅行日志轮询, 

默认设置为1,默认即可 


DebugLevel=3 #指定调试级别,默认即可 


PidFile=/tmp/zabbix_server.pid #pid文件的存放位置 


DBHost=localhost #数据库主机名,当设置为localhost时,连接mysql通过sock 

DBName=zabbix #指定存放zabbix数据数据库的名字 

DBUser=zabbix #指定连接数据库的用户名 

DBPassword=123456 #用户连接数据库需要的密码 


DBSocket=/var/lib/mysql/mysql.sock #前文主机设置为localhost,用户 

连接数据库所用的sock位置, 


DBPort=3306 #数据库的端口号,当用sock连接时,无关紧要,当通过网络连接时需设置 


StartPollers=5 #默认即可 

StartIPMIPollers=0 #使用IPMI协议时,用到的参数 

StartTrappers=5 #打开的进程数, 

StartPingers=1 同上 

StartDiscoverers=1 

StartHTTPPollers=1 

JavaGateway=127.0.0.1 #JavaGateway的ip地址或主机名 

JavaGatewayPort=10052 #JavaGateway的端口号 

StartJavaPollers=5 #开启连接javagatey的进程数 


SNMPTrapperFile=/tmp/zabbix_traps.tmp 

StartSNMPTrapper=0 #如果设置为1,snmp trapper进程就会开启 


ListenIP=0.0.0.0 #监听来自trapper的ip地址 


ListenIP=127.0.0.1 

HousekeepingFrequency=1 #zabbix执行Housekeeping的频率,单位为hours 


MaxHousekeeperDelete=500 #每次最多删除历史数据的行 


SenderFrequency=30 #zabbix试图发送未发送的警报的时间,单位为秒 


CacheSize=8M #缓存的大小 


CacheUpdateFrequency=60#执行更新缓存配置的时间,单位为秒数 


StartDBSyncers=4 

HistoryCacheSize=8M 

TrendCacheSize=4M 

HistoryTextCacheSize=16M 

NodeNoEvents=0 

NodeNoHistory=0 

Timeout=3 

TrapperTimeout=300 

UnreachablePeriod=45 

UnavailableDelay=60 

UnreachableDelay=15 


AlertScriptsPath=/usr/local/zabbix/shell #脚本的存放路径


FpingLocation=/usr/local/sbin/fping #fping指令的绝对路径 


SSHKeyLocation= 

LogSlowQueries=0 

TmpDir=/tmp

Include=/usr/local/etc/zabbix_server.general.conf 


Include=/usr/local/etc/zabbix_server.conf.d/ #子配置文件路径 


StartProxyPollers=1 #在zabbix proxy被动模式下用此参数 


ProxyConfigFrequency=3600#同上 

ProxyDataFrequency=1



zabbixagentd的配置文件


PidFile=/tmp/zabbix_agentd.pid #pid文件的存放位置 

LogFile=/tmp/zabbix_agentd.log #日志文件的位置 


LogFileSize=1 #当日志文件达到多大时进行轮询操作 


DebugLevel=3 #日志信息级别 


SourceIP= #连接的源ip地址,默认为空,即可 


EnableRemoteCommands=0 #是否允许zabbix server端的远程指令

 

0表示不允许, 

1表示允许 


LogRemoteCommands=0 #是否开启日志记录shell命令作为警告 0表示不允许,1表示允许 


Server=127.0.0.1 #zabbix server的ip地址或主机名,可同时列出多个,需要用逗号隔开 

ListenPort=10050 #zabbix agent监听的端口 

ListenIP=0.0.0.0 #zabbix agent监听的ip地址 


StartAgents=3 #zabbix agent开启进程数 

ServerActive=127.0.0.1 #开启主动检查 


Hostname=Zabbix server#在zabbix server前端配置时指定的主机名要相同,最重要的配置 


RefreshActiveChecks=120 #主动检查刷新的时间,单位为秒数 

BufferSend=5 #数据缓冲的时间 

BufferSize=100 #zabbix agent数据缓冲区的大小,当达到该值便会发送所有的数据到zabbixserver

 

MaxLinesPerSecond=100 #zabbix agent发送给zabbix server最大的数据行 


AllowRoot=0 #是否允许zabbix agent 以root用户运行 


Timeout=3 #设定处理超时的时间 


Include=/usr/local/etc/zabbix_agentd.userparams.conf 


Include=/usr/local/etc/zabbix_agentd.conf.d/ #包含子配置文件的路径 


UnsafeUserParameters=0 #是否允许所有字符参数的传递 

UserParameter= #指定用户自定义参数


zabbixproxy的配置文件


Server=192.168.70.133#指定zabbix server的ip地址或主机名 

Hostname=zabbix-proxy-1.35 #定义监控代理的主机名,需和zabbix server前端配置时指定的节点名相同 

LogFile=/tmp/zabbix_proxy.log #指定日志文件的位置 

PidFile=/tmp/zabbix_proxy.pid #pid文件的位置 

DBName=zabbix_proxy #数据库名 

DBUser=zabbix #连接数据库的用户 

DBPassword=123456#连接数据库用户的密码 


ConfigFrequency=60 #zabbix proxy从zabbix server取得配置数据的频率 


DataSenderFrequency=60 #zabbix proxy发送监控到的数据给zabbix server的频率





                zabbix清理历史数据

zabbix属于一个细度化的监控工具,其入库数据随着细度的增加相应的入库数据量也会较大,当数据量到一定时候的时候其反映速度会比较慢,尽管其监控服务在配置时可以指定数据的保存周期, 但是了解下通过直接操作数据库进行数据删除还是有必要的。


通过数据库进行删除的脚本如下:


#!/bin/bash

User="root"

Passwd="361way"

Date=`date -d $(date -d "-30 day" +%Y%m%d) +%s` #取30天之前的时间戳

$(which mysql) -u${User} -p${Passwd} -e "

use zabbix;

DELETE FROM history WHERE 'clock' < $Date;

optimize table history;

DELETE FROM history_str WHERE 'clock' < $Date;

optimize table history_str;

DELETE FROM history_uint WHERE 'clock' < $Date;

optimize table history_uint;

DELETE FROM  trends WHERE 'clock' < $Date;

optimize table  trends;

DELETE FROM trends_uint WHERE 'clock' < $Date;

optimize table trends_uint;

DELETE FROM events WHERE 'clock' < $Date;

optimize table events;

"

注:其中histroy是详细的历史数据,trends是图表趋势数据。一般情况下,根据我的自定义,会将histroy数据保留7天,trend数据保留365天。


             zabbix_get命令


在zabbix server上执行zabbix_get命令来试着获取item值


zabbix_get命令详解


    命令在zabbix安装目录bin下,如果是window命令自然是zabbix_get.exe,使用方法都是一样的

。端口和源(绑定)IP是可选的,其他参数不能漏掉



# /usr/local/zabbix-2.2.1/bin/zabbix_get -h


 Zabbix get v2.2.1 (revision 40808) (09 December 2013)

usage: zabbix_get [-hV] -s <host name or IP> [-p <port>] [-I <IP address>] -k <key>

Options:

 -s --host <host name or IP>          Specify host name or IP address of a host

 -p --port <port number>              Specify port number of agent running on the host. Default is 10050

 -I --source-address <IP address>     Specify source IP address

-k --key <key of metric>             Specify key of item to retrieve value for

-h --help                            Give this help

 -V --version                         Display version number

Example: zabbix_get -s 127.0.0.1 -p 10050 -k "system.cpu.load[all,avg1]"



参数说明:

-s --host: 指定客户端主机名或者IP


-p --port:客户端端口,默认10050


-I --source-address:指定源IP,写上zabbix server的ip地址即可,一般留空,服务器如果有多ip的时候,你指定一个。


-k --key:你想获取的key


至于使用长参数还是短的,自己选,我经常使用-s而不是-host,太长了。来个例子

 

zabbix_get获取数据


获取负载


./zabbix_get -s 127.0.0.1 -p 10050 -k "system.cpu.load[all,avg15]"

0.270000



./zabbix_get -s 127.0.0.1 -p 10050 -k "system.cpu.load[all,avg15]"

0.270000



获取主机名


# ./zabbix_get -s 127.0.0.1 -p 10050 -I 127.0.0.1 -k "system.hostname"

 10-9-4-20



./zabbix_get -s 127.0.0.1 -p 10050 -I 127.0.0.1 -k "system.hostname"

 10-9-4-20 




zabbix_get是什么?


zabbix-get 是Zabbix 中的一个程序,用于zabbix-Server 到zabbix-agent 的数据获取,通常可以用来

检测验证agent 的配置是否正确,类似nagios的./check_nt等监控工具。


zabbix_get作用?


1)Server端和Agent端测试数据


2)判断一些故障问题,或者获取指定数据。


zabbix_get格式:


[root@loganalyzer bin]# ./zabbix_get -h

usage:

  zabbix_get -s host-name-or-IP [-p port-number] [-I IP-address] -k item-key

  zabbix_get -h

  zabbix_get -V

Get data from Zabbix agent.

General options:

  -s --host host-name-or-IP  Specify host name or IP address of a host

  -p --port port-number      Specify port number of agent running on the host

                             (default: 10050)

  -I --source-address IP-address   Specify source IP address

  -k --key item-key          Specify key of the item to retrieve value for

  -h --help                  Display this help message

  -V --version               Display version number

  Example(s):

  zabbix_get -s 127.0.0.1 -p 10050 -k "system.cpu.load[all,avg1]"

zabbix_get基本参数详解:


-s --host: 指定客户端主机名或者IP

-p --port:客户端端口,默认10050


-I --source-address:指定源IP,写上zabbix server的ip地址即可,一般留空,服务器如果有多ip的


时候,你指定一个。


-k --key:  你想获取的key

-h --help  帮助

-V --version 版本

zabbix_get获取信息案例:


1)获取指定主机cpu五分钟之内的负载


[root@loganalyzer bin]# ./zabbix_get -s 192.168.1.245 -p 10050 -k 'system.cpu.load[all,avg5]'

0.350000

[root@loganalyzer bin]# 




zabbix_get是zabbix中的一个程序,用于zabbix-server到zabbix-agent获取数据。通常用来检测agent的配置是否正确。


获取CPU负载


[root@localhost ~]# zabbix_get -s 127.0.0.1 -p 10050 -k "system.cpu.load[all,avg15]"

0.000000


key可以加引号,也可以不加。


获取主机名


[root@localhost ~]# zabbix_get -s 127.0.0.1 -p 10050 -k system.hostname

localhost.localdomain



Zabbix_sender命令:

zabbix_sender是什么?有什么作用?


zabbix获取key值有超时时间,如果自定义的key脚本一般需要执行很长时间,这根本没法去做监控,那

怎么办呢?使用zabbix监控类型zabbix trapper,需要配合zabbix_sender给它传递数据。关于trapper

的用法,我们来弄个实例。


执行超长时间脚本,如:脚本去几十台服务器拉去数据,每个日志都上G,然后日志整合在一起,统计出

​返回值。这种脚本比如超时,所以我们必须改成让客户端提交数据的方式。


zabbix_sender命令用法:


[root@localhost ~]# zabbix_sender -h

Zabbix Sender v2.2.11 (revision 56693) (12 November 2015)

usage: zabbix_sender [-Vhv] {[-zpsI] -ko | [-zpI] -T -i <file> -r} [-c <file>]

Options:

  -c --config <file>                   Absolute path to the configuration file

  -z --zabbix-server <server>          Hostname or IP address of Zabbix server

  -p --port <server port>              Specify port number of server trapper running on the server. Default is 10051

  -s --host <hostname>                 Specify host name. Host IP address and DNS name will not work

  -I --source-address <IP address>     Specify source IP address

  -k --key <key> 

                       Specify item key

  -o --value <key value>               Specify value

  -i --input-file <input file>         Load values from input file. Specify - for standard input

                                       Each line of file contains whitespace delimited: <hostname> <key> <value>

                                       Specify - in <hostname> to use hostname from configuration file or --host argument

  -T --with-timestamps                 Each line of file contains whitespace delimited: <hostname> <key> <timestamp> <value>

                                       This can be used with --input-file option

                                       Timestamp should be specified in Unix timestamp format

  -r --real-time                       Send metrics one by one as soon as they are received

                                       This can be used when reading from standard input

  -v --verbose                         Verbose mode, -vv for more details

Other options:

  -h --help                            Give this help

  -V --version                         Display version number


使用参数:


  -c --config <file>                   配置文件绝对路径

  -z --zabbix-server <server>          zabbix server的IP地址

  -p --port <server port>              zabbix server端口.默认10051

  -s --host <hostname>                 主机名,zabbix里面配置的主机名(不是服务器的hostname),不能使用ip地址

  -I --source-address <IP address>     源IP

  -k --key <key>                       监控项的key

  -o --value <key value>               key值

  -i --input-file <input file>         从文件里面读取hostname、key、value 一行为一条数据,使用空格作为分隔符,如果主机名带空格,那么请使用双引号包起来

  -T --with-timestamps              一行一条数据,空格作为分隔符: <hostname> <key> <timestamp> <value>,配合 --input-file option,timestamp为unix时间戳

  -r --real-time                      将数据实时提交给服务器

  -v --verbose                         详细模式, -vv 更详细





zabbix的服务器端与客户端连接的主要工具就是zabbix里bin文件夹下的zabbix_get文件,这个命令只能在zabbix的server端使用,如果在agent端使用就会提示如下的错误:


zabbix_get [7189]: Check access restrictions in Zabbix agent configuration


在server端使用也是有说法,这里先查查看它的官方帮助


[root@chen-zk-001 bin]# ./zabbix_get -h

Zabbix get v2.2.6 (revision 48483) (27 August 2014)

usage: zabbix_get [-hV] -s <host name or IP> [-p <port>] [-I <IP address>] -k <key>

Options:

  -s --host <host name or IP>          Specify host name or IP address of a host

  -p --port <port number>              Specify port number of agent running on the host. Default is 10050

  -I --source-address <IP address>     Specify source IP address

  -k --key <key of metric>             Specify key of item to retrieve value for

  -h --help                            Give this help

  -V --version                         Display version number

   

Example: zabbix_get -s 127.0.0.1 -p 10050 -k "system.cpu.load[all,avg1]"


里面说明了,-s后面接的是目标地址,-p后面要加端口号,这个一般都是10050, -I 后面加原地址,不过这个一般用不上,-k 后面接的就是item项目里的key。


不过这里要注意一点!-s 后面是要接上web界面里能连上的ip地址,本人实验里,监控zabbix_server使用127.0.0.1会报错,会提示Received empty response from Zabbix Agent at [127.0.0.1]. Assuming that agent dropped connection because of access permission。然后在agentd.conf里把127.0.0.1更改成了机器的内网ip就可以成功监控了。








Item属性含义:(拿3.0举例)

属性 描述

名称 监控项item名称

类型 item类型(常见agent、SNMP、agent(active)等)

Key 监控项item的key,点击select可看到系统很多自带的key,也可以看到用户自定义的key。

主机接口 主机接口,例如agent、SNMP、impi等

信息类型 自己根据要监控项目定义

数据类型 一般十进制

单位 默认情况下,如果原始值超过1000,那么他会先除以1000并且显示出来。

如果单位被指定为 B (byte),那么它会除以1024然后再显示数据。因此在监控流量和文件大小的时候不要用错单位,否则会出现数据不一致的情况。

自定义倍数 启用这个选项,所有接收到的整数或者浮点数都会乘以这个文本框里面的值。使用这个选项,zabbix将会把收到的KB,MBps等数据先转为B,Bps。否则zabbix不能正确设置前缀(K,M,G等等)。

数据更新间隔 数据更新时间注意:如果设置为0,那么这个数据将永久不更新。但是如果在灵活更新间隔(flexible interval)里面设置了一个非0间隔,那么以这个为准

自定义时间间隔 eg:

1-5,11:00-19:00,表示周一到周五的早上10点到晚上19点每十秒更新一次数据。其余时间使用默认值,不会更新。在zabbix主动方式的item不适用

历史数据保留时长 默认天,历史保留天数。

趋势数据存储 默认天

存储值 涉及到计算公式

查看值 值映射,需要配置数字映射到字符的映射表。

新应用 创建一个新的应用

应用集 eg:cpu、disk、network,监控项可以属于多个应用

主机资产记录 自动模式数据自动填充到inventory资产清单的相应属性

描述 监控项的描述

启用 是否启用这个监控项.






 LNMP+zabbix-3.2.1 


一、zabbix服务端部署 


1、解压 

tar -xf nginx-1.10.1.tar.gz 

tar -xf php-5.6.22.tar.gz 

tar -xf freetype-2.4.0.tar.bz2 

tar -xf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz 

tar -xf zabbix-3.2.1.tar.gz  


2、安装Nginx yum -y install gcc openssl-devel pcre-devel  

   

useradd -s /sbin/nologin nginx 

 

cd ~/nginx-1.10.1/ 

./configure \ 

>--prefix=/usr/local/nginx \ 

>--user=nginx \ >--group=nginx \ 

>--with-http_ssl_module 


make && make install 


vim /usr/local/nginx/conf/nginx.conf   

   

location / {             

root    html;             

index    index.php        

index.html        

index.htm;     

}     

location ~ \.php$ {             

root   html;             

fastcgi_pass        

127.0.0.1:9000;             

fastcgi_index        

index.php;             

fastcgi_param        

SCRIPT_FILENAME    $document_root$fastcgi_script_name;             

include            fastcgi_params;     


/usr/local/nginx/sbin/nginx    #启动nginx


3、安装MySQL 


useradd mysql 


mv mysql-5.6.30-linux-glibc2.5-x86_64/ /usr/local/mysql 


chown -R mysql.mysql /usr/local/mysql/ 


su - mysql   

  

cd /usr/local/mysql/scripts/  

   

./mysql_install_db \     

>--user=mysql \     

>--basedir=/usr/local/mysql \     

>--datadir=/usr/local/mysql/data  

   

exit 


cd /usr/local/mysql/support-files/ 


cp my-default.cnf /etc/my.cnf 

cp mysql.server /etc/init.d/mysql 

vim /etc/init.d/mysql     

basedir=/usr/local/mysql     

datadir=/usr/local/mysql/data 


echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile 


source /etc/profile 


chkconfig --add mysql 

chkconfig mysql on 


service mysql start 


/usr/local/mysql/bin/mysqladmin -u root password '123456' mysql -uroot -p123456     

mysql> create database zabbix character set utf8;     

mysql> grant all on zabbix.* to zabbix@localhost identified by 'qwe123';  


4、安装Freetype(可以使用系统自带的) 


cd ~/freetype-2.4.0 

./configure --prefix=/opt/freetype-2.4.0 

make && make install 

yum  -y  install freetype  


5、安装PHP 


yum -y install libjpeg-devel libxml2-devel libpng-devel 


cd ~/php-5.6.22/

./configure \ 

>--prefix=/usr/local/php5/ \ 

>--enable-fpm \ 

>--enable-mbstring \ 

>--enable-bcmath \ 

>--enable-sockets \ 

>--with-config-file-path=/usr/local/php5/etc \ 

>--with-mysql=/usr/local/mysql/ \ 

>--with-mysqli=/usr/local/mysql/bin/mysql_config \ 

>--with-gd \ 

>--with-gettext \ 

>--with-jpeg-dir \ 

>--with-freetype-dir=/opt/freetype-2.4.0/  

#使用系统自带的不用指安装目录 

make && make install 


cp  php.ini-production /usr/local/php5/etc/php.ini 


vim /usr/local/php5/etc/php.ini 

    

date.timezone = Asia/Shanghai     

max_execution_time = 300     

post_max_size = 32M     

max_input_time = 300     

memory_limit = 128M     

always_populate_raw_post_data = -1 

cd /usr/local/php5/etc/ 

cp php-fpm.conf.default php-fpm.conf 

vim php-fpm.conf     

pid = run/php-fpm.pid     

error_log = log/php-fpm.log     

log_level = error     

daemonize = yes     

user = nginx     

group = nginx     

listen = 127.0.0.1:9000     

pm = dynamic     

pm.max_children = 32     

pm.start_servers = 15     

pm.min_spare_servers = 5     

pm.max_spare_servers = 32 

cd ~/php-5.6.22/sapi/fpm/ 

cp init.d.php-fpm /etc/rc.d/init.d/php-fpm 

chmod +x /etc/rc.d/init.d/php-fpm 

chkconfig --add php-fpm 


chkconfig php-fpm on 


service php-fpm start  


6、安装Zabbix 


yum -y install net-snmp-devel curl-devel 


useradd zabbix 

cd zabbix-3.2.1 

./configure \ 

>--prefix=/usr/local/zabbix \ 

>--enable-server \ 

>--enable-proxy \ 

>--enable-agent \ 

>--with-mysql=/usr/local/mysql/bin/mysql_config \ 

>--with-net-snmp \ 

>--with-libcurl 


make && make install 


cd ~/zabbix-3.2.1/database/mysql/ 

#导入数据库

mysql -uzabbix -pqwe123 zabbix < schema.sql 

mysql -uzabbix -pqwe123 zabbix < images.sql 

mysql -uzabbix -pqwe123 zabbix < data.sql 


mkdir /var/log/zabbix 


chown zabbix.zabbix /var/log/zabbix 


ln -s /usr/local/zabbix/etc/ /etc/zabbix 

ln -s /usr/local/zabbix/bin/* /usr/bin/ 

ln -s /usr/local/zabbix/sbin/* /usr/sbin/ 

ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18  

#可以使用设置搜索库文件的路径方式实现 


[root@localhost LNMP+zabbix-3.2.1]# tail -1  /etc/ld.so.conf /usr/local/mysql/lib/ 

[root@localhost LNMP+zabbix-3.2.1]# ldconfig  -v |  grep libmysqlclient.so.18  

cd ~/zabbix-3.2.1/misc/init.d/fedora/core 

cp zabbix_* /etc/init.d/ 


vim /etc/init.d/zabbix_server 

    

BASEDIR=/usr/local/zabbix 


vim /etc/init.d/zabbix_agentd     


BASEDIR=/usr/local/zabbix 


vim  /etc/services     z

abbix-agent    10050/tcp    # Zabbix Agent     

zabbix-agent    10050/udp    # Zabbix Agent     

zabbix-server    10051/tcp    # Zabbix Trapper     

zabbix-server    10051/udp    # Zabbix Trapper 


vim /etc/zabbix/zabbix_server.conf     

DBName=zabbix     

DBUser=zabbix     

DBPassword=qwe123     

LogFile=/var/log/zabbix/zabbix_server.log 


vim /etc/zabbix/zabbix_agentd.conf     

Server=127.0.0.1,192.168.100.10     

ServerActive=192.168.100.10:10051     

Hostname=zabbix server     

LogFile=/var/log/zabbix/zabbix_server.log     

UnsafeUserParemeters=1 

cd ~/zabbix-3.2.1/frontends/ 

cp -r php/ /usr/local/nginx/html/zabbix 


chown -R nginx.nginx /usr/local/nginx/html/zabbix/ 


service zabbix_server start 

chkconfig zabbix_server on 

service zabbix_agentd start 

chkcongig zabbix_agentd on  


二、zabbix客户端部署 


tar -xf zabbix-3.2.1.tar.gz 


yum -y install gcc 


useradd zabbix 


./configure --prefix=/usr/local/zabbix --enable-agent && make && make install 


mkdir /var/log/zabbix 


chown zabbix.zabbix /var/log/zabbix/ 


cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/ 


chmod +x /etc/init.d/zabbix_agentd  


ln -s /usr/local/zabbix/etc/ /etc/zabbix 

ln -s /usr/local/zabbix/bin/* /usr/bin/ 

ln -s /usr/local/zabbix/sbin/* /usr/sbin/ 


vim /etc/zabbix/zabbix_agentd.conf  

   

LogFile=/var/log/zabbix/zabbix_agentd.log     

Server=127.0.0.1,192.168.100.10     

ServerActive=192.168.100.10:10051     

Hostname=zabbix client     

UnsafeUserParameters=1 


vim /etc/init.d/zabbix_agentd   

  

BASEDIR=/usr/local/zabbix 


chkconfig zabbix_agentd on 


service zabbix_agentd start





一、           zabbix简介:

zabbix是完全开源的工具,整合了cacti和nagios等特性
附:SNMP(udp 161  udp 162)
众多网络工具都支持此协议,比如常见路由交换,常见OS
其既可以做管理端也可以做被管理端
snmp协议大致有3个版本分别是v1 v2v3

无论是v1 和 v2 的安全性是比较差的,因为传输是明文的, V3的认证密码用MD5/SHA摘要算法加密

 很多工具支持网络管理的功能,而对于非网络设备(操作系统),可以完全抛开snmp这种不安全的架构来实现监控的。所以很多工具都是控制端和agent架构,他们有专属的agent

Zabbix的主要功能:

具备常见的商业监控软件所具备的功能(主机的性能监控、网络设备性能监控、数据库、FTP 等通用协议监控、多种告警方式、详细的报表图表绘制)

支持自动发现网络设备和服务器(可以通过配置自动发现服务器规则来实现)

支持分布式,能集中展示、管理分布式的监控点,扩展性强

server 提供通用接口(api 功能),可以自己开发完善各类监控(根据相关接口编写程序实现),编写插件容易,可以自定义监控项,报警级别的设置。

数据收集,支持 snmp(包括 trapping and polling ),IPMI,JMX,SSH,TELNET;

自定义的检测;自定义收集数据的频率;

服务器/代理和客户端模式;

灵活的触发器;可以定义非常灵活的问题阈值,称为触发器;
高可定制的报警;发送通知,可定制的报警升级,收件人,媒体类型。

CPU负荷、内存使用、磁盘使用、网络状况、端口监视、日志监视等等。
硬件监控:Zabbix IPMI Interface
系统监控:ZabbixAgent Interface
Java监控:Zabbix JMXInterface
网络设备监控:Zabbix SNMP Interface
应用服务监控:Zabbix Agent UserParameter 
MySQL数据库监控:percona-monitoring-plulgins  
URL监控:Zabbix Web 监控

zabbix重要组件说明:

1)zabbix server:负责接收agent发送的报告信息的核心组件,所有配置、统计数据及操作数据都由它组织进行;
2)database storage:专用于存储所有配置信息,以及由zabbix收集的数据;
3)web interface:zabbix的GUI接口;
4)proxy:可选组件,常用于监控节点很多的分布式环境中,代理server收集部分数据转发到server,可以减轻server的压力;
5)agent:部署在被监控的主机上,负责收集主机本地数据如cpu、内存、数据库等数据发往server端或proxy端;

另外,zabbix server、proxy、agent都有自己的配置文件以及log文件,重要的参数需要在这里配置,后面会详细说明。

一个监控系统运行的大概的流程是这样的:

agentd需要安装到被监控的主机上,它负责定期收集各项数据,并发送到zabbix server端,zabbix server将数据存储到数据库中,zabbix web根据数据在前端进行展现和绘图。这里agentd收集数据分为主动和被动两种模式:

主动:agent请求server获取主动的监控项列表,并主动将监控项内需要检测的数据提交给server/proxy
被动:server向agent请求获取监控项的数据,agent返回数据。

zabbix常用的监控架构平台

1、server-agentd模式:
这个是最简单的架构了,常用于监控主机比较少的情况下。

2、server-proxy-agentd模式:

这个常用于比较多的机器,使用proxy进行分布式监控,有效的减轻server端的压力。

zabbix的系统架构:
wKiom1jZHxHxKVjRAALia40Bn5Y669.png


Zabbix是一个基于Web界面的提供分布式系统监视以及网络监视功能的企业级开源解决方案。借助Zabbix,可以很轻松地减轻运维人员们繁重的服务器管理任务,实现业务系统的持续运行。下面会逐步介绍Zabbix分布式监控系统的部署及使用

配置好IP、DNS 、网关,确保使用远程连接工具能够连接服务器


zabbix server监控服务器:192.168.0.103 #zabbix的服务端(若要监控本机,则需要配置本机的zabbix agent)


Zabbix agent被监控主机:192.168.0.104 #zabbix的客户端(被监控端,需要配置Zabbix agent)


二、Zabbix部署前的LNMP环境的搭建过程:


安装编译工具及库文件


[root@Zabbix-Server ~]# yum -y install make apr* autoconf automake curl-devel gcc gcc-c++  openssl openssl-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng*  libtool* libxml2 libxml2-devel patch libcurl-devel bzip2-devel freetype-devel




安装mysql5.7.13


安装nginx


解压zlib
[root@Zabbix-Server ~]# tar zxf zlib-1.2.8.tar.gz
说明:不需要编译,只需要解压就行。


解压pcre

[root@Zabbix-Server ~]# tar zxf pcre-8.39.tar.gz 

[root@Zabbix-Server ~]# groupadd www

[root@Zabbix-Server ~]# useradd -g www www -s /sbin/nologin


下载nginx的源码包:http://nginx.org/download
解压源码包:


[root@Zabbix-Server ~]# tar zxf nginx-1.10.2.tar.gz 


[root@Zabbix-Server nginx-1.10.2]# cd nginx-1.10.2/

[root@Zabbix-Server nginx-1.10.2]# ./configure --prefix=/usr/local/nginx1.10 --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module  --with-http_flv_module --with-http_mp4_module --with-pcre=/root/pcre-8.39 --with-zlib=/root/zlib-1.2.8 --with-http_ssl_module --with-http_gzip_static_module --user=www --group=www && make && make install


[root@Zabbix-Server nginx-1.10.2]# ln -s /usr/local/nginx1.10/sbin/nginx /usr/local/sbin/

[root@Zabbix-Server nginx-1.10.2]# nginx
[root@Zabbix-Server nginx-1.10.2]# netstat -antp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      99063/nginx: master
[root@Zabbix-Server nginx-1.10.2]# firewall-cmd --permanent --add-port=80/tcp
success
[root@Zabbix-Server nginx-1.10.2]# firewall-cmd --reload 
success


安装php
[root@Zabbix-Server ~]# tar zxf libmcrypt-2.5.7.tar.gz 

[root@Zabbix-Server ~]# cd libmcrypt-2.5.7/
[root@Zabbix-Server libmcrypt-2.5.7]# ./configure && make && make install


[root@Zabbix-Server libmcrypt-2.5.7]# cd


[root@Zabbix-Server ~]# tar zxf php-5.6.27.tar.gz

[root@Zabbix-Server ~]# cd php-5.6.27/


[root@Zabbix-Server php-5.6.27]# ./configure --prefix=/usr/local/php5.6 --with-config-file-path=/etc  --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/usr/local/mysql/mysql.sock --with-gd --with-iconv --with-libxml-dir=/usr --with-mhash --with-mcrypt --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-zlib --with-freetype-dir --with-png-dir --with-jpeg-dir --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl && make && make install


[root@Zabbix-Server php-5.6.27]# cp php.ini-production /etc/php.ini


编辑配置文件/etc/php.ini ,修改后的内容如下:编辑配置文件/etc/php.ini ,修改后的内容如下:
找到:
;date.timezone = 
修改为:
date.timezone = PRC #设置时区
找到:
expose_php = On 
修改为:
expose_php = Off #禁止显示php版本的信息
找到:
short_open_tag = Off 
修改为:
short_open_tag = On //支持php短标签
找到:
post_max_size = 8M
修改为:
post_max_size = 16M  //上传文件大小
找到:
max_execution_time = 30
修改为:
max_execution_time = 300  //php脚本最大执行时间
找到:
max_input_time = 60
修改为:
max_input_time = 300  //以秒为单位对通过POST、GET以及PUT方式接收数据时间进行限制
找到:
;always_populate_raw_post_data = -1
修改为:
always_populate_raw_post_data = -1
找到:
;mbstring.func_overload = 0
修改为:
mbstring.func_overload= 0

创建php-fpm服务启动脚本:

[root@Zabbix-Server php-5.6.27]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@Zabbix-Server php-5.6.27]# chmod +x /etc/init.d/php-fpm 

[root@Zabbix-Server php-5.6.27]# chkconfig --add php-fpm
[root@Zabbix-Server php-5.6.27]# chkconfig php-fpm on

提供php-fpm配置文件并编辑:

[root@Zabbix-Server php-5.6.27]# cp /usr/local/php5.6/etc/php-fpm.conf.default  /usr/local/php5.6/etc/php-fpm.conf

[root@Zabbix-Server php-5.6.27]# vi /usr/local/php5.6/etc/php-fpm.conf

修改内容如下:
pid = run/php-fpm.pid
user = www
group = www
listen =127.0.0.1:9000
pm.max_children = 300
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers =50

启动php-fpm服务:

[root@Zabbix-Server php-5.6.27]# service php-fpm start
Starting php-fpm  done
[root@Zabbix-Server php-5.6.27]# netstat -anpt | grep php-fpm
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      110892/php-fpm: mas 

配置nginx支持php

[root@Zabbix-Server php-5.6.27]# cat /usr/local/nginx1.10/conf/nginx.conf
user  www www;
worker_processes  4;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
use epoll;
    worker_connections  1024;
}
http {
include       mime.types;
    default_type  application/octet-stream;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
 
    #access_log  logs/access.log  main;
sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
server {
listen       80;
        server_name  localhost;
charset utf-8;
        #access_log  logs/host.access.log  main;
location / {
root   html;
index  index.php index.html index.htm;
        }
location ~ \.php$ { 
root html; 
            fastcgi_pass 127.0.0.1:9000; 
            fastcgi_index index.php; 
include fastcgi.conf; 
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
        }
location /status {
stub_status on;
        }
   }
}


[root@Zabbix-Server php-5.6.27]# nginx -t

nginx: the configuration file /usr/local/nginx1.10/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx1.10/conf/nginx.conf test is successful

[root@Zabbix-Server php-5.6.27]# killall -s HUP nginx

测试LNMP
进入nginx默认的网页根目录,创建.php的测试页


[root@Zabbix-Server php-5.6.27]# cat /usr/local/nginx1.10/html/test1.php
<?php
phpinfo()
?>
[root@Zabbix-Server php-5.6.27]# cat /usr/local/nginx1.10/html/test2.php
<?php
$link=mysql_connect('localhost','root','123.abc');
if($link) echo "ok";
mysql_close();
?>


至此,LNMP部署完毕。

三、监控系统Zabbix-3.2.1的安装


zabbix-server端的操作
zabbix服务器端要提前安装好LNMP环境(mysql,nginx,php5的安装目录均是/usr/local)

创建Zabbix运行的用户:
[root@Zabbix-Server ~]# groupadd zabbix
[root@Zabbix-Server ~]# useradd -g zabbix zabbix

安装libcurl和net-snmp:
[root@Zabbix-Server ~]# yum -y install net-snmp net-snmp-devel curl-devel java-1.8.0-openjdk java-1.8.0-openjdk-devel OpenIPMI-devel libssh2-devel

注:OpenIPMI-devel 和libssh2-devel软件包使用centos在线yum软件源安装


安装Fping:

[root@Zabbix-Server ~]# tar zxf fping-3.12.tar.gz 
[root@Zabbix-Server ~]# cd fping-3.12/
[root@Zabbix-Server fping-3.12]# ./configure && make && make install
[root@Zabbix-Server fping-3.12]# chown root:zabbix /usr/local/sbin/fping 
[root@Zabbix-Server fping-3.12]# chmod 4710 /usr/local/sbin/fping 

安装Zabbix Server:

[root@Zabbix-Server fping-3.12]# cd
[root@Zabbix-Server ~]# tar zxf zabbix-3.2.1.tar.gz 
[root@Zabbix-Server ~]# cd zabbix-3.2.1/
[root@Zabbix-Server zabbix-3.2.1]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-java --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-openipmi


注意:编译时最好带上--enable-java这个参数,方便后续监控tomcat程序所用。

--with-ssh2 是不需要在客户端服务器上面安装Zabbix agent,如果需要使用ssh检查,需要在编译的时候加上这项,最低需要libssh2 1.0.0版本,需要安装ssh开发包
--with-openipmi用户可以利用 IPMI 监视服务器的物理特征,如温度、电压、电扇工作状态、电源供应等。

如果添加了--enable-proxy, 那么会生成get和sender两条命令. 如下, 用于接收agent发生过来的信息, 同时发送给server.

[root@Zabbix-Server zabbix-3.2.1]# make && make install

添加系统软连接

[root@Zabbix-Server zabbix-3.2.1]# ln -s /usr/local/zabbix/bin/* /usr/local/bin/

[root@Zabbix-Server zabbix-3.2.1]# ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/

ZabbixServer配置与启动

创建Zabbix数据库和MySQL用户:

mysql> create database zabbix character set utf8;

Query OK, 1 row affected (0.00 sec)
 
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';

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

导入Zabbix初始数据:

切换到zabbix的解压目录下

[root@Zabbix-Server zabbix-3.2.1]# cd database/mysql/
[root@Zabbix-Server mysql]# pwd
/root/zabbix-3.2.1/database/mysql
[root@Zabbix-Server mysql]# ls
data.sql  images.sql  schema.sql

[root@Zabbix-Server mysql]# mysql -uzabbix -pzabbix -hlocalhost zabbix < schema.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.

[root@Zabbix-Server mysql]# mysql -uzabbix -pzabbix -hlocalhost zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.

[root@Zabbix-Server mysql]#  mysql -uzabbix -pzabbix -hlocalhost zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.

编辑/usr/local/zabbix/etc/zabbix_server.conf:

[root@Zabbix-Server mysql]# grep -v "^#" /usr/local/zabbix/etc/zabbix_server.conf | grep -v "^$"

LogFile=/usr/local/zabbix/logs/zabbix_server.log
PidFile=/usr/local/zabbix/logs/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBPort=3306
FpingLocation=/usr/local/sbin/fping

[root@Zabbix-Server mysql]# mkdir -p /usr/local/zabbix/logs

[root@Zabbix-Server mysql]# chown -R zabbix:zabbix /usr/local/zabbix/

启动Zabbix Server:
[root@Zabbix-Server mysql]# /usr/local/zabbix/sbin/zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf

/usr/local/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory

解决方法:

在ld.so.conf中加入/usr/local/mysql/lib

[root@Zabbix-Server mysql]# find / -name libmysqlclient.so.20

/root/mysql-5.7.13/libmysql/libmysqlclient.so.20

/usr/local/mysql/lib/libmysqlclient.so.20

[root@Zabbix-Server mysql]# vi /etc/ld.so.conf

[root@Zabbix-Server mysql]# cat /etc/ld.so.conf

include ld.so.conf.d/*.conf
/root/mysql-5.7.13/libmysql/
/usr/local/mysql/lib/

加载/etc/ld.so.conf文件生效并再次启动zabbix_server

[root@Zabbix-Server mysql]# ldconfig 

[root@Zabbix-Server mysql]# /usr/local/zabbix/sbin/zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf

[root@Zabbix-Server mysql]# netstat -anpt | grep zabbix_server

tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      15820/zabbix_server 

添加开机启动脚本
[root@Zabbix-Server ~]# cd zabbix-3.2.1/

[root@Zabbix-Server zabbix-3.2.1]# cp misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server
[root@Zabbix-Server zabbix-3.2.1]# cp misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd
[root@Zabbix-Server zabbix-3.2.1]# chmod +x /etc/rc.d/init.d/zabbix_server 
[root@Zabbix-Server zabbix-3.2.1]# chmod +x /etc/rc.d/init.d/zabbix_agentd 
[root@Zabbix-Server zabbix-3.2.1]# chkconfig --add zabbix_server
[root@Zabbix-Server zabbix-3.2.1]# chkconfig --add zabbix_agentd
[root@Zabbix-Server zabbix-3.2.1]# chkconfig zabbix_server on
[root@Zabbix-Server zabbix-3.2.1]# chkconfig zabbix_agentd on

修改zabbix开机启动脚本中的zabbix安装目录

vi /etc/rc.d/init.d/zabbix_server #编辑服务端配置文件

BASEDIR=/usr/local/zabbix/ #zabbix安装目录
PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid    #pid文件路径

:wq! #保存退出


vi /etc/rc.d/init.d/zabbix_agentd #编辑客户端配置文件

BASEDIR=/usr/local/zabbix/ #zabbix安装目录
PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid  #pid文件路径
:wq! #保存退出

[root@Zabbix-Server zabbix-3.2.1]# systemctl daemon-reload

[root@Zabbix-Server zabbix-3.2.1]# /etc/init.d/zabbix_server stop

Stopping zabbix_server (via systemctl):                    [  OK  ]
[root@Zabbix-Server zabbix-3.2.1]# netstat -antp | grep zabbix

[root@Zabbix-Server zabbix-3.2.1]# /etc/init.d/zabbix_server start
Starting zabbix_server (via systemctl):                    [  OK  ]
[root@Zabbix-Server zabbix-3.2.1]# netstat -antp | grep zabbix
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      17223/zabbix_server
设置防火墙规则
[root@Zabbix-Server zabbix-3.2.1]# firewall-cmd --permanent --add-port=10051/tcp
success
[root@Zabbix-Server zabbix-3.2.1]# firewall-cmd --reload 
success
配置zabbix web页面
在安装目录将frontends拷贝到指定的web root:
[root@Zabbix-Server zabbix-3.2.1]# pwd
/root/zabbix-3.2.1
[root@Zabbix-Server zabbix-3.2.1]# cp -r frontends/php/ /usr/local/nginx1.10/html/zabbix
[root@Zabbix-Server zabbix-3.2.1]# chown -R www:www /usr/local/nginx1.10/html/zabbix/

注:/usr/local/nginx/html为Nginx默认站点目录 www为Nginx运行账户

注:PHP需要至少开启扩展:  gd,bcmath,ctype,libXML,xmlreader,xmlwriter,session,sockets,mbstring,gettext,mysql

如下,查看是否包括了上面所提到的扩展模块

[root@Zabbix-Server zabbix-3.2.1]# /usr/local/php5.6/bin/php -m
[PHP Modules]
bcmath
bz2
Core
ctype
curl
date
dom
ereg
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
libxml
mbstring
mcrypt
mhash
mysql
mysqli
openssl
pcntl
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvsem
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
zip
zlib
 
[Zend Modules]



至此 ZABBIX的基础安装完成
注:1.      显示简体中文界面
在安装数据库时已经将zabbix库设置了utf-8字符
首先确定zabbix开启了中文支持功能:
登录到zabbix服务器的数据目录下(前面部署的zabbix数据目录是/usr/local/nginx1.10/html/zabbix/),打开 locales.inc.php文件
[root@Zabbix-Server include]# pwd
/usr/local/nginx1.10/html/zabbix/include

[root@Zabbix-Server include]# vi locales.inc.php



解决zabbix绘图中出现中文乱码问题:

a.从windows下控制面板->字体->选择一种中文字库例如“楷体”

b.把它拷贝到zabbix的web端的fonts目录下例如:/usr/local/nginx1.10/html/zabbix/fonts/,并且把TTF后缀改为ttf 

并且将之前的字体文件DejaVuSans.ttf移动到别处

c.然后,接着修改代码include/defines.inc.php文件中的字体配置,将里面关于字体设置从DejaVuSans替换成simkai  

vi替换技巧:%s/DejaVuSans/simkai

其中:simkai为字库名字,不包含ttf后缀

[root@Zabbix-Server fonts]# cd /usr/local/nginx1.10/html/zabbix/

[root@Zabbix-Server zabbix]# vi include/defines.inc.php 

在vi编辑器的末行模式下输入%s/DejaVuSans/simkai

这样,修改后,zabbix监控图形中的中文字就不会出现乱码了

四、zabbix客户端的安装
既然要监控我们就要添加要监控的主机,在添加主机之前我们首先要在被检测主机上面安装agent,安装agent比较简单,我们也是按照安装server的流程,下载软件包,在编译的时候,我们只选择agent
192.168.0.104作为zabbix的被监控端,提供web和mysql应用
安装Zabbix,配置Zabbix agent:

[root@Zabbix-agent ~]#tar zxf zabbix-3.2.1.tar.gz
[root@Zabbix-agent ~]# cd zabbix-3.2.1/
[root@Zabbix-agent zabbix-3.2.1]# ./configure --prefix=/usr/local/zabbix --enable-agent && make && make install
[root@Zabbix-agent zabbix-3.2.1]# cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
[root@Zabbix-agent zabbix-3.2.1]# mkdir -p /usr/local/zabbix/logs
[root@Zabbix-agent zabbix-3.2.1]# groupadd zabbix
[root@Zabbix-agent zabbix-3.2.1]# useradd -g zabbix zabbix
[root@Zabbix-agent zabbix-3.2.1]# chown -R zabbix:zabbix /usr/local/zabbix/

配置开机自动启动:

[root@Zabbix-agent zabbix-3.2.1]# chkconfig --add zabbix_agentd
[root@Zabbix-agent zabbix-3.2.1]# chkconfig zabbix_agentd on

修改zabbix开机启动脚本中的zabbix安装目录

vi /etc/rc.d/init.d/zabbix_agentd #编辑客户端配置文件

BASEDIR=/usr/local/zabbix/ #zabbix安装目录
PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid  #pid文件路径
:wq! #保存退出
编辑zabbix_agentd.conf

[root@Zabbix-agent zabbix-3.2.1]# vi /usr/local/zabbix/etc/zabbix_agentd.conf
内容如下:
[root@Zabbix-agent zabbix-3.2.1]#grep -v "^#" /usr/local/zabbix/etc/zabbix_agentd.conf | grep -v "^$"
PidFile=/usr/local/zabbix/logs/zabbix_agentd.pid
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
Server=192.168.0.103
ListenPort=10050
ServerActive=192.168.0.103
Hostname=192.168.0.104
Timeout=15
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
注:
其中Server和ServerActive都指定zabbixserver的IP地址,不同的是,前者是被动后者是主动。也就是说Server这个配置是用来允许192.168.0.103这个ip来我这取数据。而serverActive的192.168.0.103的意思是,客户端主动提交数据给他。

Hostname=XXX,这个定义的名字必须和web页面里面host的名字一样。

启动zabbix_agentd:


[root@Zabbix-agent zabbix-3.2.1]# /usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf

[root@Zabbix-agent zabbix-3.2.1]# netstat -anpt | grep zabbix_agentd
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      18142/zabbix_agentd

[root@Zabbix-agent zabbix-3.2.1]# firewall-cmd --permanent --add-port=10050/tcp
success
[root@Zabbix-agent zabbix-3.2.1]# firewall-cmd --reload 
success
到此,zabbix3.2.1监控系统的基本环境安装完成。
实现zabbix添加监测项
添加对Linux主机的监控
在浏览器中打开:http://192.168.0.103/zabbix
登录zabbix,先在“配置”-“主机”里添加主机监控,监控os资源:内存,cpu,io,负载,带宽等.
登录zabbix,先在“配置”-“主机”里单击”创建主机”



zabbix3.0 server已自带mysql的模板了,只需配置好agent客户端,然后在web端给主机增加模板就行了。

Zabbix_agent客户端操作

(1)首先在客户端的mysql里添加权限,即本机使用zabbix账号连接本地的mysql


mysql> grant all on *.* to zabbix@'localhost' identified by '123.abc';
Query OK, 0 rows affected, 1 warning (0.19 sec)
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
(2)在zabbix_agent服务目录下创建.my.cnf 连接文件,zabbix安装目录是/usr/local/zabbix


[root@Zabbix-agent zabbix-3.2.1]# cd /usr/local/zabbix/etc/
[root@Zabbix-agent zabbix]# vi .my.cnf
[root@Zabbix-agent zabbix]# cat .my.cnf 
[client]
user=zabbix
password=123.abc
注意:
如果在数据库grant授权时,针对的是localhost,这个.my.cnf里面就不用加host参数了【如上配置】

但如果grant授权时针对的是本机的ip(如192.168.0.104),那么在.my.cnf文件里就要加上host参数进行指定了

即在.my.cnf文件就要加上:


host=192.168.0.104
socket= /usr/local/mysql/mysql.sock
user=zabbix
password=123.abc

(3)配置MySQL的key文件

这个可以从zabbix3.2安装时的解压包里拷贝过来,从zabbix_server服务端安装时解压目录

/root/zabbix-3.2.1/conf/zabbix_agentd/userparameter_mysql.conf 拷贝到zabbix_agent客户端上的/usr/local/zabbix/etc/zabbix_agentd.conf.d/ 目录下的


[root@Zabbix-agent zabbix]# cd /usr/local/zabbix/etc/zabbix_agentd.conf.d/
[root@Zabbix-agent zabbix_agentd.conf.d]# pwd
/usr/local/zabbix/etc/zabbix_agentd.conf.d
[root@Zabbix-agent zabbix_agentd.conf.d]# cp /root/zabbix-3.2.1/conf/zabbix_agentd/userparameter_mysql.conf  ./
[root@Zabbix-agent zabbix_agentd.conf.d]# ls userparameter_mysql.conf 
userparameter_mysql.conf

然后查看 userparameter_mysql.conf 文件,看到类似 HOME=/var/lib/zabbix 的路径设置,把路径全都替换为 /usr/local/zabbix/etc/,也就是上面的.my.cnf文件所在的目录路径
另外,注意userparameter_mysql.conf 文件里的mysql命令路径(提前做好mysql的系统环境变量,以防mysql命令不被系统识别)
如下:
[root@Zabbix-agent zabbix_agentd.conf.d]# cat userparameter_mysql.conf 
[root@Zabbix-agent zabbix_agentd.conf.d]# cat userparameter_mysql.conf 
# For all the following commands HOME should be set to the directory that has .my.cnf file with password information.


# Flexible parameter to grab global variables. On the frontend side, use keys like mysql.status[Com_insert].
# Key syntax is mysql.status[variable].
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/usr/local/zabbix/etc/ mysql -N | awk '{print $$2}'


# Flexible parameter to determine database or table size. On the frontend side, use keys like mysql.size[zabbix,history,data].
# Key syntax is mysql.size[<database>,<table>,<type>].
# Database may be a database name or "all". Default is "all".
# Table may be a table name or "all". Default is "all".
# Type may be "data", "index", "free" or "both". Both is a sum of data and index. Default is "both".
# Database is mandatory if a table is specified. Type may be specified always.
# Returns value in bytes.
# 'sum' on data_length or index_length alone needed when we are getting this information for whole database instead of a single table
UserParameter=mysql.size[*],bash -c 'echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema=\"$1\"")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name=\"$2\"");" | HOME=/usr/local/zabbix/etc/ mysql -N'


UserParameter=mysql.ping,HOME=/usr/local/zabbix/etc/ mysqladmin ping | grep -c alive
UserParameter=mysql.version,mysql -V

(4)按照上面修改完之后检查一下,然后重启zabbix_agent


[root@Zabbix-agent zabbix_agentd.conf.d]# pkill -9 zabbix_agent
[root@Zabbix-agent zabbix_agentd.conf.d]# netstat -anpt | grep zabbix_agent
[root@Zabbix-agent zabbix_agentd.conf.d]# /usr/local/zabbix/sbin/zabbix_agentd 

[root@Zabbix-agent zabbix_agentd.conf.d]# netstat -anpt | grep zabbix_agent

tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      100593/zabbix_agent

接着在zabbix_server服务端进行命令行测试[下面的192.168.0.103是客户端的ip]
若下面报错
[root@localhostzabbix]# /usr/local/zabbix/bin/zabbix_get -s 192.168.0.104 -p 10050 -k"mysql.status[Uptime]"
sh: mysql: command notfound

解决方法:
在userparameter_mysql.conf中关于mysql命令前面添加绝对路径


[root@Zabbix-Server zabbix]# /usr/local/zabbix/bin/zabbix_get -s 192.168.0.104 -p 10050 -k "mysql.status[Uptime]"
6893897
如果出现类似这一串key的数字,就说明配置ok,服务端能监控到客户端的mysql数据了!

成功啦,之后在监控界面增加主机对应的MySQL模板就ok了。

注:zabbix_get命令介绍

参数说明:
-s --host:指定客户端主机名或者IP
-p --port:客户端端口,默认10050
-I --source-address:指定源IP,写上zabbixserver的ip地址即可,一般留空,服务器如果有多ip的时候,你指定一个。
-k --key:你想获取的key
zabbix_get获取数据
获取负载


[root@Zabbix-Server zabbix]# zabbix_get -s 192.168.0.104 -p 10050 -k "system.cpu.load[all,avg15]"
0.050000
获取主机名


[root@Zabbix-Server zabbix]# zabbix_get -s 192.168.0.104 -p 10050 -k "system.hostname"
Zabbix-agent
(5)登录zabbix监控界面,在“配置”-“模板”里可以看到自带的mysql监控模板




zabbix3.2.1邮件报警设置:
Zabbix监控服务端、客户端都已经部署完成,被监控主机已经添加,Zabiix监控运行正常。
在Zabbix服务端设置邮件报警,当被监控主机宕机或者达到触发器预设值时,会自动发送报警邮件到指定邮箱。
具体操作:


以下操作在Zabbix监控服务端进行
下载sendemail软件
然后安装那两个依赖包,命令是:


[root@Zabbix-Server zabbix]# yum -y install perl-Net-SSLeay perl-IO-Socket-SSL

解压软件,然后将sendemail复制到/usr/local/bin/目录下,并加上可执行权限,然后修改用户和群组。

[root@Zabbix-Server ~]# tar zxf sendEmail-v1.56.tar.gz 
[root@Zabbix-Server ~]# cd sendEmail-v1.56/
[root@Zabbix-Server sendEmail-v1.56]# cp sendEmail /usr/local/bin/sendEmail
[root@Zabbix-Server sendEmail-v1.56]# chown zabbix:zabbix /usr/local/bin/sendEmail

[root@Zabbix-Server sendEmail-v1.56]# ll /usr/local/bin/sendEmail 

-rwxr-xr-x. 1 zabbix zabbix 80213 Mar 28 21:42 /usr/local/bin/sendEmail

执行# /usr/local/bin/sendEmail -h查看sendEmail的帮助

[root@Zabbix-Server sendEmail-v1.56]# /usr/local/bin/sendEmail -h
 
sendEmail-1.56 by Brandon Zehm <caspian@dotconf.net>
 
Synopsis:  sendEmail -f ADDRESS [options]
 
  Required:
    -f ADDRESS                from (sender) email address
    * At least one recipient required via -t, -cc, or -bcc
    * Message body required via -m, STDIN, or -o message-file=FILE
 
  Common:
    -t ADDRESS [ADDR ...]     to email address(es)
    -u SUBJECT                message subject
    -m MESSAGE                message body
    -s SERVER[:PORT]          smtp mail relay, default is localhost:25
 
  Optional:
    -a   FILE [FILE ...]      file attachment(s)
    -cc  ADDRESS [ADDR ...]   cc  email address(es)
    -bcc ADDRESS [ADDR ...]   bcc email address(es)
    -xu  USERNAME             username for SMTP authentication
    -xp  PASSWORD             password for SMTP authentication
 
  Paranormal:
    -b BINDADDR[:PORT]        local host bind address
    -l LOGFILE                log to the specified file
    -v                        verbosity, use multiple times for greater effect
    -q                        be quiet (i.e. no STDOUT output)
    -o NAME=VALUE             advanced options, for details try: --help misc
        -o message-content-type=<auto|text|html>
        -o message-file=FILE         -o message-format=raw
        -o message-header=HEADER     -o message-charset=CHARSET
        -o reply-to=ADDRESS          -o timeout=SECONDS
        -o username=USERNAME         -o password=PASSWORD
        -o tls=<auto|yes|no>         -o fqdn=FQDN
 
 
  Help:
    --help                    the helpful overview you're reading now
    --help addressing         explain addressing and related options
    --help message            explain message body input and related options
    --help networking         explain -s, -b, etc
    --help output             explain logging and other output options
    --help misc               explain -o options, TLS, SMTP auth, and more


[root@Zabbix-Server sendEmail-v1.56]# /usr/local/bin/sendEmail -f 17600339557@163.com -t 17600339557@163.com -s smtp.163.com -u "hello" -o message-content-type=html -o message-charset=utf8 -xu 17600339557@163.com -xp 123abc -m "hello"

命令主要选项说明:
/usr/local/bin/sendEmail                    #命令主程序
-f  from@163.com                         #发件人邮箱
-t to@163.com                             #收件人邮箱
-s smtp.163.com                          #发件人邮箱的smtp服务器
-u "我是邮件主题"                              #邮件的标题
-o message-content-type=html          #邮件内容的格式,html表示它是html格式
-o message-charset=utf8                  #邮件内容编码
-xu from@163.com                      #发件人邮箱的用户名
-xp WEE78@12l$                            #发件人邮箱密码
-m "我是邮件内容"                            #邮件的具体内容

进入/usr/local/zabbix/share/zabbix/alertscripts/目录

然后在这个目录下创建报警脚本sendmail.sh


[root@Zabbix-Server alertscripts]# vi mail.sh
#!/bin/bash
to=$1
subject=$2
body=$3
/usr/local/bin/sendEmail -o tls=auto -f 17600339557@163.com -t "$to" -s smtp.163.com -u "$sbuject" -o message-content-type=html -o messag
e-charset=utf8 -xu 17600339557@163.com -xp 123abc -m "$body"


[root@Zabbix-Server alertscripts]# chmod +x mail.sh 
[root@Zabbix-Server alertscripts]# ./mail.sh 17600339557@163.com test 123
*******************************************************************
 Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client
 is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER
 together with SSL_ca_file|SSL_ca_path for verification.
 If you really don't want to verify the certificate and keep the
 connection open to Man-In-The-Middle attacks please set
 SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application.
*******************************************************************
  at /usr/local/bin/sendEmail line 1906.
invalid SSL_version specified at /usr/share/perl5/vendor_perl/IO/Socket/SSL.pm line 415.
注:进行发送邮件测试时,出现了第一个报错
原因是sendemail软件和perl5里面的ssl版本不兼容导致的,通过修改sendemail里面的内容可以解决这个问题。
解决方法:
在sendemail文件中把1906行的内容


if (!IO::Socket::SSL->start_SSL($SERVER, SSL_version => 'SSLv3 TLSv1')) {
修改为
if(! IO::Socket::SSL->start_SSL($SERVER)) {
即不指定SSL的版本,让程序来自己选择
不管你使用的是163/126邮箱还是qq邮箱,你都必须开通pop3服务,而且126/qq邮箱还要求使用第三方客户端发送邮件是必须使用授权码登录,使用账号密码验证时,会出现下面图片中的错误。


sendEmail[50684]: ERROR => ERROR => SMTP-AUTH: Authentication to smtp.163.com:25 failed.
至于邮箱的授权码,自己登录163邮箱去设置就好。
经过上面两个问题的处理后就可以正常发送邮件如下所示显示成功提示


[root@Zabbix-Server alertscripts]# ./mail.sh 17600339557@163.com test 123
*******************************************************************
 Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client
 is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER
 together with SSL_ca_file|SSL_ca_path for verification.
 If you really don't want to verify the certificate and keep the
 connection open to Man-In-The-Middle attacks please set
 SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application.
*******************************************************************
  at /usr/local/bin/sendEmail line 1906.
Mar 28 22:34:28 zabbix-server sendEmail[50764]: Email was sent successfully!


转载请标明出处【LNMP编译环境配置Zabbix】。

《www.micoder.cc》 虚拟化云计算,系统运维,安全技术服务.

网站已经关闭评论