欢迎光临
专业Linux运维二十年

详解Centos7.2编译安装zabbix3.2(详细步骤)

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编译器如下

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

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

?
1
2
3
[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目录下

?
1
2
[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权限。

?
1
2
3
4
[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

?
1
2
3
4
5
6
7
8
[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/目录下

?
1
2
[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 相关支持包

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

2)创建www组以及www用户

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

3)下载nginx源码包

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

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

?
1
2
[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

?
1
2
3
4
5
[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源码包

?
1
2
3
4
[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服务启动脚本

?
1
2
3
4
5
6
[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

修改内容如下:

?
1
2
3
4
5
6
7
8
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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#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

?
1
2
3
4
5
<?php
$link
=mysql_connect(
'localhost'
,
'root'
,
'123456'
);
if
(
$link
)
echo
"ok"
;
mysql_close();
?>

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

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

此环境需要提前安装好lnmp环境(mysql,nginx,php的安装目录均是/usr/local/下)

创建zabbix运行用户

?
1
2
[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

?
1
2
3
4
5
[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

?
1
2
[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

添加系统软连接

?
1
2
[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用户:

?
1
2
3
4
5
6
7
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目录)

?
1
2
3
4
5
6
7
/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(修改如下)

?
1
2
3
4
5
6
7
8
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

?
1
2
[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

?
1
2
3
4
[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主配置文件修改如下:

添加启动脚本

?
1
2
3
4
5
6
7
8
[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安装目录

?
1
2
3
4
5
6
7
8
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界面

?
1
2
3
[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正式搭建成功!

脚本之家
赞(0) 打赏
未经允许不得转载:Linux老运维 » 详解Centos7.2编译安装zabbix3.2(详细步骤)

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫