详解Centos7.2编译安装zabbix3.2(详细步骤)
author:一佰互联 2019-04-23   click:183

Zabbix简介

zabbix简介zabbix是完全开源的工具,整合了cacti和nagios等特性,SNMP(udp 161  udp 162)众多网络工具都支持此协议,比如常见路由交换,常见OS可以做管理端,也可以做被管理端,snmp大致的三个版本分为v1 v2 v3,无论是v1和v2他们的安全性还是比较差的,因为传输的是明文的,v3的认证密码用 MD5/SHA摘要算法加密。

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

Zabbix的主要功能:

具备常见的商业监控软件具备的功能比如:(主机性能的监控,网络设备性能的监控,数据库,ftp等通用协议的监控)还具备有告警方式,详细的报表图表的绘制。

支持自动发现网络设备和服务器,可以通过配置自动发现服务器规则来实现,支持分布式,能集中展示,管理分布式的监控点,扩展性强server提供通过接口(api功能)可以自己开发完善各类的监控,根据相关接口编写程序实现编写插件容易,可以自定义监控项,报警级别的设置。数据收集,支持snmp(包括trapping and polling) IPMI JMX SSH TELNEL;

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

服务器/代理和客户端模式;灵活的触发器;可以定义非常灵活的问题阀值,称为触发器,高可定制的报警,发送通过,可定制报警的升级,收件人媒体类型,cpu负荷,内存使用,磁盘使用,网络状况,端口监视,日志监视等等;

硬件监控:

  1. Zabbix IPMI Interface 系统监控:
  2. ZabbixAgent Interface Java监控:
  3. Zabbix JMX Interface 网络设备监控:
  4. Zabbix SNMP Interface 应用服务监控:
  5. 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是一个基于Web界面的提供分布式系统监视以及网络监视功能的企业级开源解决方案。借助Zabbix,可以很轻松地减轻运维人员们繁重的服务器管理任务,实现业务系统的持续运行。

下面会逐步介绍Zabbix分布式监控系统的部署及使用配置好IP、DNS 、网关,确保使用远程连接工具能够连接服务器zabbix监控服务器:192.168.146.100  #zabbix的服务端(若要监控本机,则需要配置本机的zabbix agent)Zabbix agent被监控主机:192.168.146.110 #zabbix的客户端(被监控端,需要配置Zabbix agent)

一、编译安装Zabbix3.21

安装编译工具及库文件

复制代码 代码如下:
yum-y install make apr* autoconf automake curl-devel gcc gcc-c++  openssl openssl-devel gd kernel keyutilspatch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-develkeyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-develzlib-devel libXpm* freetype libjpeg* libpng* libtool* libxml2 libxml2-devel patch libcurl-devel bzip2-devel freetype-devel2)

 

2)安装MySQL5.7并安装gcc编译器如下

[root@yankerp-zabbix ~]# yum install gcc gcc-c++ -y 

因为在Centos7中默认安装了mysql的分支mariadb 所以需要卸载mariadb

[root@yankerp-zabbix src]# rpm -qa | grep mariadb 
mariadb-libs-5.5.44-2.el7.centos.x86_64 
[root@yankerp-zabbix src]# rpm -e mariadb-libs-5.5.44-2.el7.centos.x86_64 --nodeps 

安装Mysql

下载MySQL二进制包

复制代码 代码如下:
[root@yankerp-zabbix src]# wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz 

解压Mysql二进制包,并拷贝到/usr/local/mysql目录下

[root@yankerp-zabbix src]# tar zxf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz 
[root@yankerp-zabbix src]# mv mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql 

进入/usr/local/mysql/目录创建data目录以及log目录,并给予data755权限。

[root@yankerp-zabbix src]# cd /usr/local/mysql/ 
[root@yankerp-zabbix mysql]# mkdir data 
[root@yankerp-zabbix mysql]# mkdir log 
[root@yankerp-zabbix mysql]# chmod +755 data/ 

设置变量

复制代码 代码如下:
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile && source /etc/profile 

创建mysql组,以及mysql用户

复制代码 代码如下:
[root@yankerp-zabbix mysql]# groupadd mysql && useradd -r -g mysql -s /bin/false mysql 

打开/etc/my.cnf添加MySQL的主配置文件如下:

vim /etc/my.cnf

[client] 
socket=/usr/local/mysql/mysql.sock 
[mysqld] 
basedir=/usr/local/mysql 
datadir=/usr/local/mysql/data 
pid-file=/usr/local/mysql/data/mysqld.pid 
socket=/usr/local/mysql/mysql.sock 
log_error=/usr/local/mysql/log/mysql.err 

初始化MySQL数据库

复制代码 代码如下:
[root@yankerp-zabbix mysql]# chmod 750 data/ && chown -R mysql . && chgrp -R mysql . && bin/mysqld --initialize --user=mysql 

复制Mysql启动脚本,并启动mysql数据库

复制代码 代码如下:
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld && service mysqld start 

启动完成后mysql的密码存放到了/usr/local/mysql/log/目录下

[root@yankerp-zabbix mysql]# cat /usr/local/mysql/log/mysql.err | grep password 
2018-01-06T06:31:34.837627Z 1 [Note] A temporary password is generated for root@localhost: s>2%8=/q>sKP 

进入Mysql数据库并修改mysql数据库密码

 

到这里MySQL的安装正式完成

二、安装Nginx

1)安装pcre-devel zlib-devel 相关支持包

[root@yankerp-zabbix ~]# yum install zlib-devel pcre-devel -y 

2)创建www组以及www用户

[root@yankerp-zabbix ~]# groupadd www 
[root@yankerp-zabbix ~]# useradd -g www www -s /sbin/nologin 

3)下载Nginx源码包

[root@yankerp-zabbix ~]# wget http://nginx.org/download/nginx-1.10.2.tar.gz 

4)解压Nginx源码包并进入Nginx解压目录

[root@yankerp-zabbix ~]# tar zxf nginx-1.10.2.tar.gz 
[root@yankerp-zabbix ~]# cd nginx-1.10.2 

复制代码 代码如下:
[root@yankerp-zabbix 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-http_ssl_module --with-http_gzip_static_module --user=www --group=www

make && make install

5)创建软连接,优化执行路径,并启动Nginx服务

访问测试:

三、安装PHP

[root@yankerp-zabbix ~]# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz 
[root@yankerp-zabbix ~]# tar zxf libmcrypt-2.5.7.tar.gz 
[root@yankerp-zabbix ~]# cd libmcrypt-2.5.7/
[root@yankerp-zabbix libmcrypt-2.5.7]# ./configure && make && make install
ln -s /usr/local/mysql/lib/libmysqlclient.so.20.3.0 /usr/local/mysql/lib/libmysqlclient_r.so

下载PHP源码包

[root@yankerp-zabbix ~]# tar zxf php-5.6.27.tar.gz 
[root@yankerp-zabbix ~]# cd php-5.6.27/ 
[root@yankerp-zabbix 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@yankerp-zabbix php-5.6.27]# cp php.ini-production /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
mbstring.func_overload = 0

创建php服务启动脚本

[root@yankerp-zabbix php-5.6.27]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm 
[root@yankerp-zabbix php-5.6.27]# chmod +x /etc/init.d/php-fpm 
[root@yankerp-zabbix php-5.6.27]# chkconfig --add php-fpm 
[root@yankerp-zabbix php-5.6.27]# chkconfig php-fpm on 
[root@yankerp-zabbix php-5.6.27]#cp /usr/local/php5.6/etc/php-fpm.conf.default /usr/local/php5.6/etc/php-fpm.conf
[root@yankerp-zabbix php-5.6.27]#vim /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服务

配置Nginx并解析php

#user nobody; 
worker_processes 1; 
 
#error_log logs/error.log; 
#error_log logs/error.log notice; 
#error_log logs/error.log info; 
 
#pid  logs/nginx.pid; 
 
 
events { 
 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 koi8-r; 
 
  #access_log logs/host.access.log main; 
 
  location / { 
   root html; 
   index index.php index.html index.htm; 
  } 
 
  #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; 
  } 
 
  # proxy the PHP scripts to Apache listening on 127.0.0.1:80 
  # 
  #location ~ .php$ { 
  # proxy_pass http://127.0.0.1; 
  #} 
 
  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
  # 
  location ~ .php$ { 
   root   html; 
   fastcgi_pass 127.0.0.1:9000; 
   fastcgi_index index.php; 
   fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 
   include  fastcgi.conf; 
  } 
 
  # deny access to .htaccess files, if Apache"s document root 
  # concurs with nginx"s one 
  # 
  #location ~ /.ht { 
  # deny all; 
  #} 
 } 
 
 
 # another virtual host using mix of IP-, name-, and port-based configuration 
 # 
 #server { 
 # listen  8000; 
 # listen  somename:8080; 
 # server_name somename alias another.alias; 
 
 # location / { 
 #  root html; 
 #  index index.html index.htm; 
 # } 
 #} 
 
 
 # HTTPS server 
 # 
 #server { 
 # listen  443 ssl; 
 # server_name localhost; 
 
 # ssl_certificate  cert.pem; 
 # ssl_certificate_key cert.key; 
 
 # ssl_session_cache shared:SSL:1m; 
 # ssl_session_timeout 5m; 
 
 # ssl_ciphers HIGH:!aNULL:!MD5; 
 # ssl_prefer_server_ciphers on; 
 
 # location / { 
 #  root html; 
 #  index index.html index.htm; 
 # } 
 #} 
 
} 

在html目录下创建test.php写入测试页访问测试:

写入MySQL测试页

vim /usr/local/nginx/html/test2.php

<?php 
$link=mysql_connect("localhost","root","123456"); 
if($link) echo "ok"; 
mysql_close(); 
?> 

出现以上图片证明LNMP环境已经可以正常工作!

四、正式安装Zabbix,以上只是搭建环境下面正式安装zabbix

此环境需要提前安装好LNMP环境(MySQL,Nginx,PHP的安装目录均是/usr/local/下)

创建zabbix运行用户

[root@yankerp-zabbix ~]# groupadd zabbix 
[root@yankerp-zabbix ~]# useradd -g zabbix zabbix 

安装所需的包

复制代码 代码如下:
[root@yankerp-zabbix ~]#yum install -y net-snmp net-snmp-devel curl-devel java-1.8.0-openjdk java-1.8.0-openjdk-devel  OpenIPMI-devel  libssh2-devel

安装fping

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

安装zabbix-server

[root@yankerp-zabbix ~]# tar zxf zabbix-3.2.1.tar.gz  
[root@yankerp-zabbix ~]# cd zabbix-3.2.1/ 

复制代码 代码如下:
[root@yankerp-zabbix 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等程序。

make && make install

添加系统软连接

[root@yankerp-zabbix zabbix-3.2.1]# ln -s /usr/local/zabbix/bin/* /usr/local/bin/ 
[root@yankerp-zabbix zabbix-3.2.1]# ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/ 

创建zabbix数据库和Mysql用户:

mysql> create database zabbix character set utf8; 
Query OK, 1 row affected (0.18 sec) 
 
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by "zabbix"; 
Query OK, 0 rows affected, 1 warning (0.37 sec) 
 
mysql>  

导入zabbix初始数据;(切换到zabbix目录)

/root/zabbix-3.2.1/database/mysql 
[root@yankerp-zabbix mysql]# mysql -uzabbix -pzabbix -hlocalhost zabbix < schema.sql  
mysql: [Warning] Using a password on the command line interface can be insecure. 
[root@yankerp-zabbix mysql]# mysql -uzabbix -pzabbix -hlocalhost zabbix < images.sql  
mysql: [Warning] Using a password on the command line interface can be insecure. 
[root@yankerp-zabbix 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(修改如下)

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@yankerp-zabbix mysql]# mkdir -p /usr/local/zabbix/logs 
[root@yankerp-zabbix mysql]# chown -R zabbix:zabbix /usr/local/zabbix/ 

启动zabbix server

解决方法:

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

[root@yankerp-zabbix ~]# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/mysql/lib
/usr/local/lib

插入完后执行

我们发现还是没有启动那么接下来查看zabbix_server的日志如下:

上面的提示mysql.sock问题,接下来打开zabbix主配置文件修改如下:

添加启动脚本

[root@yankerp-zabbix zabbix-3.2.1]# cp misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server 
[root@yankerp-zabbix zabbix-3.2.1]# cp misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd 
[root@yankerp-zabbix zabbix-3.2.1]# chmod +x /etc/rc.d/init.d/zabbix_server  
[root@yankerp-zabbix zabbix-3.2.1]# chmod +x /etc/rc.d/init.d/zabbix_agentd  
[root@yankerp-zabbix zabbix-3.2.1]# chkconfig --add zabbix_server 
[root@yankerp-zabbix zabbix-3.2.1]# chkconfig --add zabbix_agentd 
[root@yankerp-zabbix zabbix-3.2.1]# chkconfig zabbix_server on 
[root@yankerp-zabbix 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! #保存退出

正式启动zabbix_server

启动成功后配置zabbix的web界面

[root@zabbix-yankerp ~]# cd /root/zabbix-3.2.1/ 
[root@zabbix-yankerp zabbix-3.2.1]# cp -r frontends/php/ /usr/local/nginx/html/zabbix 
[root@zabbix-yankerp zabbix-3.2.1]# chown -R www:www /usr/local/nginx/html/zabbix/ 

出现以下界面证明 









出现以上图片那么证明zabbix正式搭建成功!

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持网页设计。