zabbix3.x服务端安装和配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix3.x服务端安装和配置相关的知识,希望对你有一定的参考价值。

一 简介

zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案
zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题
zabbix由2部分构成,zabbix server与可选组件zabbix agent
zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上

zabbix agent需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。zabbix agent可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD, OS X, Tru64/OSF1, Windows NT4.0, Windows (2000/2003/XP/Vista)等系统之上

zabbix server可以单独监视远程服务器的服务状态;同时也可以与zabbix agent配合,可以轮询zabbix agent主动接收监视数据(agent方式),同时还可被动接收zabbix agent发送的数据(trapping方式)

(注:以上简介参考至百度百科)

二 关闭selinux

[[email protected] ~]# setenforce 0
[[email protected] ~]# getenforce

三 LNMP环境配置

mysql5.6安装

[[email protected] ~]# cd /usr/local/src

(1)配置依赖以及卸载旧版本的mariadb-server:

[[email protected] src]# yum install java-1.8.0-openjdk
[[email protected] src]# rpm -qa | grep mariadb-server
[[email protected] src]# rpm -e --nodeps mariadb-server-5.5.47-1.el7_2.x86_64

(2)安装MySQL:

[[email protected] src]# rpm -ivh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm

[[email protected] src]# yum install mysql-server -y
[[email protected] src]# yum install mysql-devel -y
[[email protected] php-5.6.20]# vim /etc/my.cnf

修改:

[mysqld]

innodb_file_per_table

[[email protected] nginx]# chkconfig mysqld on
[[email protected] src]# service mysqld start
Starting mysqld (via systemctl):                           [  OK  ]

(3)设置root密码及其他安全选项:

[[email protected] src]# mysql_secure_installation

(4)创建zabbix数据库:

[[email protected] src]# mysql -uroot -p
mysql> CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
mysql> GRANT ALL PRIVILEGES ON zabbix.* TO [email protected] IDENTIFIED BY ‘password‘;
mysql> flush privileges;

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| zabbix             |
+--------------------+
4 rows in set (0.00 sec)

mysql> quit;

 PHP-5.6.20的源码安装

(1)下载地址:http://php.net/get/php-5.6.20.tar.gz/from/a/mirror

(2)安装依赖包:

[[email protected] libgd-2.1.1]# yum -y install freetype-devel
[[email protected] libgd-2.1.1]# yum -y install libXpm-devel
[[email protected] php-5.6.20]# yum install libxml2
[[email protected] php-5.6.20]# yum install libxml2-devel -y
[[email protected] php-5.6.20]# yum install -y curl curl-devel

安装yasm:

下载地址:http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz

[[email protected] src]# cd /usr/local/src
[[email protected] src]# tar -zxvf yasm-1.2.0.tar.gz
[[email protected] yasm-1.2.0]# cd yasm-1.2.0
[[email protected] yasm-1.2.0]# ./configure
[[email protected] yasm-1.2.0]# make && make install

安装libmcrypt:

下载地址:http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

[[email protected] src]# tar -zxvf libmcrypt-2.5.8.tar.gz
[[email protected] src]# cd libmcrypt-2.5.8
[[email protected] libmcrypt-2.5.8]# ./configure
[[email protected] libmcrypt-2.5.8]# make && make install

安装libvpx:

下载地址:https://webm.googlecode.com/files/libvpx-v1.3.0.tar.bz2

[[email protected] src]# tar -jxvf libvpx-v1.3.0.tar.bz2
[[email protected] src]# cd libvpx-v1.3.0
[[email protected] libvpx-v1.3.0]# ./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9
[[email protected] libvpx-v1.3.0]# make && make install

安装tiff:

下载地址:http://download.osgeo.org/libtiff/tiff-4.0.3.tar.gz

[[email protected] tiff-4.0.3]# tar -zxvf tiff-4.0.3.tar.gz
[[email protected] tiff-4.0.3]# cd tiff-4.0.3
[[email protected] tiff-4.0.3]# ./configure --prefix=/usr/local/tiff --enable-shared
[[email protected] tiff-4.0.3]# make && make install

安装libpng:

下载地址:http://sourceforge.net/projects/libpng/

[[email protected] src]# tar -zxvf libpng-1.6.23.tar.gz
[[email protected] libpng-1.6.23]# cd libpng-1.6.23
[[email protected] libpng-1.6.23]# ./configure --prefix=/usr/local/libpng --enable-shared
[[email protected] libpng-1.6.23]# make && make install

安装freetype:

下载地址:http://sourceforge.net/projects/freetype/

[[email protected] src]# tar zxvf freetype-2.6.4.tar.gz
[[email protected] src]# cd freetype-2.6.4/
[[email protected] freetype-2.6.4]# ./configure --prefix=/usr/local/freetype --enable-shared
[[email protected] freetype-2.6.4]# make && make install

安装Jpeg:

下载地址:http://www.ijg.org/

[[email protected] src]# tar -zxvf jpegsrc.v9b.tar.gz
[[email protected] src]# cd jpeg-9b/
[[email protected] jpeg-9b]# ./configure --prefix=/usr/local/jpeg --enable-shared
[[email protected] jpeg-9b]# make && make install

安装libgd:

下载地址:https://bitbucket.org/libgd/gd-libgd/downloads

[[email protected] libgd-2.1.1]# tar -zxvf libgd-2.1.1.tar.gz
[[email protected] libgd-2.1.1]# cd libgd-2.1.1
[[email protected] libgd-2.1.1]# ./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-xpm=/usr/ --with-tiff=/usr/local/tiff --with-vpx=/usr/local/libvpx
[[email protected] libgd-2.1.1]# make && make install

安装t1lib:

下载地址:ftp://sunsite.unc.edu/pub/Linux/libs/graphics/t1lib-5.1.2.tar.gz

[[email protected] t1lib-5.1.2]# tar -zxvf t1lib-5.1.2.tar.gz
[[email protected] t1lib-5.1.2]# cd t1lib-5.1.2
[[email protected] t1lib-5.1.2]# ./configure --prefix=/usr/local/t1lib --enable-shared
[[email protected] t1lib-5.1.2]# make without_doc
[[email protected] t1lib-5.1.2]# make install

(3)php源码安装:

[[email protected] src]# cd /usr/local/src
[[email protected] src]# tar -zxvf php-5.6.20.tar.gz
[[email protected] php-5.6.20]# cd php-5.6.20/

注:如果系统是64位,请执行以下两条命令,否则安装php会出错(32位系统不需要执行)

[[email protected] php-5.6.20]# \cp -frp /usr/lib64/libltdl.so*  /usr/lib/
[[email protected] php-5.6.20]# \cp -frp /usr/lib64/libXpm.so* /usr/lib/
[[email protected] php-5.6.20]# export LD_LIBRARY_PATH=/usr/local/libgd/lib

[[email protected] ~]# ln -s /usr/lib64/mysql/libmysqlclient.so.16 /usr/lib/libmysqlclient.so
[[email protected] ~]# cd /usr/lib
[[email protected] lib]# mkdir mysql
[[email protected] lib]# cp /usr/lib64/mysql/* /usr/lib/mysql/
[[email protected] php-5.6.20]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr --with-mysqli=/usr/bin/mysql_config --with-pdo-mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-vpx-dir=/usr/local/libvpx/ --with-zlib-dir=/usr/local/zlib --with-t1lib=/usr/local/t1lib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --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 --enable-ctype

[[email protected] php-5.6.20]# make && make install

(4)配置php:

[[email protected] php-5.6.20]# cd /usr/local
[[email protected] local]# ln -s php-5.6.20/ php

[[email protected] local]# cp /usr/local/src/php-5.6.20/php.ini-production /usr/local/php/etc/php.ini

[[email protected] local]# cp /usr/local/src/php-5.6.20/sapi/fpm/php-fpm.conf.in /usr/local/php/etc/php-fpm.conf

[[email protected] local]# ln -s /usr/local/php/sbin/* /usr/sbin/

[[email protected] php-5.6.20]# ln -s /usr/local/php/etc/php.ini /etc/php.ini
[[email protected] php-5.6.20]# ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf

(5)修改php.ini:

修改:

post_max_size = 16M

max_execution_time = 300

max_input_time = 300

date.timezone = PRC  #设置时区

mbstring.func_overload = 0

always_populate_raw_post_data = -1

expose_php = Off #禁止显示php版本的信息

short_open_tag = ON #支持php短标签

opcache.enable=1 #php支持opcode缓存

opcache.enable_cli=0 #php支持opcode缓存

在最后一行添加:zend_extension=opcache.so #开启opcode缓存功能

附:禁止部分函数的执行(也可以不添加这步配置):

修改:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

(6)配置和启动php-fpm:

[[email protected] mysql]# vim /usr/local/php-5.6.20/etc/php-fpm.conf

修改:

request_terminate_timeout = 300

user = www 

group = www 

pid = run/php-fpm.pid #取消前面的分号

添加php-fpm自启动脚本:

[[email protected] ~]# cp /usr/local/src/php-5.6.20/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[[email protected] init.d]# chmod a+x /etc/init.d/php-fpm

[[email protected] ~]# chkconfig php-fpm on

[[email protected] local]# php-fpm
或:
[[email protected] local]# service php-fpm start
[[email protected] local]# netstat -anp | grep 9000

tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN

出现上面的提示则说明php-fpm已经启动起来了

注:php-fpm重启关闭命令:

# 启动

service php-fpm start

# 关闭

service php-fpm stop

# 重启

service php-fpm restart

# 重载

service php-fpm reload

nginx的安装和配置

安装略

修改nginx配置文件,添加server,用于访问zabbix的web页面

(1)修改/usr/local/nginx/conf/nginx.conf:

server {
         listen 80;
         server_name  localhost;
         access_log /usr/local/nginx/logs/zabbix.access.log;                                                                                                                                                                      

         index index.php index.html index.html;
         root /usr/local/nginx/html/zabbix;

         location /
         {
                try_files $uri $uri/ /index.php?$args;                

         }

         location ~ .*\.(php)?$
         {
                   expires -1s;
                   try_files $uri =404;
                   fastcgi_split_path_info ^(.+\.php)(/.+)$;
                   include fastcgi_params;
                   fastcgi_param PATH_INFO $fastcgi_path_info;
                   fastcgi_index index.php;
                   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                   fastcgi_pass 127.0.0.1:9000;

         }
}

(2)测试nginx中的php访问:

[[email protected] local]# mkdir -p /usr/local/nginx/html/zabbix
[[email protected] local]# vim /usr/local/nginx/html/zabbix/info.php

内容:

<?php

    phpinfo();

?>


浏览器中访问:http://127.0.0.1/info.php

四 zabbix服务端的安装和配置

下载地址:https://sourceforge.net/projects/zabbix/

(1)安装:

[[email protected] ~]# groupadd zabbix
[[email protected] ~]# useradd zabbix -g zabbix -s /bin/false

[[email protected] ~]# cd /usr/local/src
[[email protected] src]# tar -zxvf zabbix-3.0.3.tar.gz

[[email protected] zabbix-3.0.3]# cd zabbix-3.0.3/
[[email protected] zabbix-3.0.3]# yum install -y net-snmp-devel

[[email protected] zabbix-3.0.3]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --enable-java
[[email protected] zabbix-3.0.3]# make && make install

(2)导入数据库文件:

[[email protected] zabbix-3.0.3]# mysql -uzabbix -p
mysql> use zabbix;
mysql> source /usr/local/src/zabbix-3.0.3/database/mysql/schema.sql;

mysql> source /usr/local/src/zabbix-3.0.3/database/mysql/images.sql;

mysql> source /usr/local/src/zabbix-3.0.3/database/mysql/data.sql;

mysql> quit;

(3)添加系统软连接:

[[email protected] zabbix-3.0.3]# ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
[[email protected] zabbix-3.0.3]# ln -s /usr/local/zabbix/bin/* /usr/local/bin/

(4)添加zabbix服务对应的端口:

[[email protected] mysql]# vim /etc/services

在文件末尾添加:

# Zabbix

zabbix-agent 10050/tcp # Zabbix Agent

zabbix-agent 10050/udp # Zabbix Agent

zabbix-trapper 10051/tcp # Zabbix Trapper

zabbix-trapper 10051/udp # Zabbix Trapper

(5)修改zabbix配置文件:

[[email protected] mysql]# vim /usr/local/zabbix/etc/zabbix_server.conf

修改以下几处:

DBName=zabbix

DBUser=zabbix

DBPassword=zabbix,123.

AlertScriptsPath==/usr/local/zabbix/share/zabbix/alertscripts  #zabbix运行脚本存放目录

DBPort=3306

[[email protected] mysql]# vim /usr/local/zabbix/etc/zabbix_agentd.conf

修改:

Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/

UnsafeUserParameters=1  #启用自定义key


(6)添加开机启动脚本:

服务端:

[[email protected] mysql]# cp /usr/local/src/zabbix-3.0.3/misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server

客户端:

[[email protected] mysql]# cp /usr/local/src/zabbix-3.0.3/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd
[[email protected] mysql]# chmod a+x /etc/rc.d/init.d/zabbix_*

[[email protected] mysql]# chkconfig zabbix_server on
[[email protected] mysql]# chkconfig zabbix_agentd on

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

[[email protected] mysql]# vim /etc/rc.d/init.d/zabbix_server

修改以下内容:

BASEDIR=/usr/local/zabbix/

[[email protected] mysql]# vim /etc/rc.d/init.d/zabbix_agentd

修改以下内容:

BASEDIR=/usr/local/zabbix/

(7)复制zabbix的web站点文件到nginx:

[[email protected] mysql]# cp -r /usr/local/src/zabbix-3.0.3/frontends/php/* /usr/local/nginx/html/zabbix/

(8)启动:

[[email protected] mysql]# systemctl daemon-reload
[[email protected] mysql]# service zabbix_server start
[[email protected] mysql]# service zabbix_agentd start

查看zabbix_server相关进程:

[[email protected] ~]# ps -eaf|grep zabbix_server

五 zabbix的web页面设置

在zabbix服务端访问:http://127.0.0.1

然后按提示完成zabbix的web站点安装,最后再进行登录,默认账号密码:Admin    zabbix

修改页面语言:页面右上角用户 –>  语言

注:如果出现检查PHP环境时一直缺少某些库,可以尝试删掉php的源码,然后重新编译安装

单独的zabbix客户端安装请参考我的这篇文章:http://www.zifangsky.cn/575.html

参考文章:

本文出自 “zifangsky的个人博客” 博客,请务必保留此出处http://983836259.blog.51cto.com/7311475/1854791

以上是关于zabbix3.x服务端安装和配置的主要内容,如果未能解决你的问题,请参考以下文章

zabbix3.x客户端安装和配置

zabbix3.x邮件报警简单笔记!

zabbix自定义监控实现思路以及自定义监控某个端口的连接数

zabbix3.x自动发现主机

CentOS 7.3 安装Zabbix3.X

SpringCloud系列四:Eureka 服务发现框架(定义 Eureka 服务端Eureka 服务信息Eureka 发现管理Eureka 安全配置Eureka-HA(高可用) 机制Eur(代码片段