一 简介
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
1
2
|
[root@app01 ~]
# setenforce 0
[root@app01 ~]
# getenforce
|
三 LNMP环境配置
MySQL5.6安装
1
|
[root@prx02 ~]
# cd /usr/local/src
|
(1)配置依赖以及卸载旧版本的mariadb-server:
1
2
3
|
[root@prx02 src]
# yum install java-1.8.0-openjdk
[root@prx02 src]
# rpm -qa | grep mariadb-server
[root@prx02 src]
# rpm -e --nodeps mariadb-server-5.5.47-1.el7_2.x86_64
|
(2)安装MySQL:
1
2
3
4
|
[root@prx02 src]
# rpm -ivh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
[root@prx02 src]
# yum install mysql-server -y
[root@prx02 src]
# yum install mysql-devel -y
|
1
|
[root@prx02 php-5.6.20]
# vim /etc/my.cnf
|
修改:
[mysqld]
innodb_file_per_table
1
|
[root@nmp01 nginx]
# chkconfig mysqld on
|
1
2
|
[root@prx02 src]
# service mysqld start
Starting mysqld (via systemctl): [ OK ]
|
(3)设置root密码及其他安全选项:
1
|
[root@prx02 src]
# mysql_secure_installation
|
(4)创建zabbix数据库:
1
|
[root@prx02 src]
# mysql -uroot -p
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
mysql>
CREATE
DATABASE
zabbix
CHARACTER
SET
utf8
COLLATE
utf8_bin;
mysql>
GRANT
ALL
PRIVILEGES
ON
zabbix.*
TO
zabbix@localhost 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)安装依赖包:
1
2
3
4
5
|
[root@nmp01 libgd-2.1.1]
# yum -y install freetype-devel
[root@nmp01 libgd-2.1.1]
# yum -y install libXpm-devel
[root@nmp01 php-5.6.20]
# yum install libxml2
[root@nmp01 php-5.6.20]
# yum install libxml2-devel -y
[root@nmp01 php-5.6.20]
# yum install -y curl curl-devel
|
安装yasm:
下载地址:http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
1
2
3
4
5
|
[root@nmp01 src]
# cd /usr/local/src
[root@nmp01 src]
# tar -zxvf yasm-1.2.0.tar.gz
[root@nmp01 yasm-1.2.0]
# cd yasm-1.2.0
[root@nmp01 yasm-1.2.0]
# ./configure
[root@nmp01 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
1
2
3
4
|
[root@nmp01 src]
# tar -zxvf libmcrypt-2.5.8.tar.gz
[root@nmp01 src]
# cd libmcrypt-2.5.8
[root@nmp01 libmcrypt-2.5.8]
# ./configure
[root@nmp01 libmcrypt-2.5.8]
# make && make install
|
安装libvpx:
下载地址:https://webm.googlecode.com/files/libvpx-v1.3.0.tar.bz2
1
2
3
4
|
[root@nmp01 src]
# tar -jxvf libvpx-v1.3.0.tar.bz2
[root@nmp01 src]
# cd libvpx-v1.3.0
[root@nmp01 libvpx-v1.3.0]
# ./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9
[root@nmp01 libvpx-v1.3.0]
# make && make install
|
安装tiff:
下载地址:http://download.osgeo.org/libtiff/tiff-4.0.3.tar.gz
1
2
3
4
|
[root@nmp01 tiff-4.0.3]
# tar -zxvf tiff-4.0.3.tar.gz
[root@nmp01 tiff-4.0.3]
# cd tiff-4.0.3
[root@nmp01 tiff-4.0.3]
# ./configure --prefix=/usr/local/tiff --enable-shared
[root@nmp01 tiff-4.0.3]
# make && make install
|
安装libpng:
下载地址:http://sourceforge.net/projects/libpng/
1
2
3
4
|
[root@nmp01 src]
# tar -zxvf libpng-1.6.23.tar.gz
[root@nmp01 libpng-1.6.23]
# cd libpng-1.6.23
[root@nmp01 libpng-1.6.23]
# ./configure --prefix=/usr/local/libpng --enable-shared
[root@nmp01 libpng-1.6.23]
# make && make install
|
安装freetype:
下载地址:http://sourceforge.net/projects/freetype/
1
2
3
4
|
[root@nmp01 src]
# tar zxvf freetype-2.6.4.tar.gz
[root@nmp01 src]
# cd freetype-2.6.4/
[root@nmp01 freetype-2.6.4]
# ./configure --prefix=/usr/local/freetype --enable-shared
[root@nmp01 freetype-2.6.4]
# make && make install
|
安装Jpeg:
下载地址:http://www.ijg.org/
1
2
3
4
|
[root@nmp01 src]
# tar -zxvf jpegsrc.v9b.tar.gz
[root@nmp01 src]
# cd jpeg-9b/
[root@nmp01 jpeg-9b]
# ./configure --prefix=/usr/local/jpeg --enable-shared
[root@nmp01 jpeg-9b]
# make && make install
|
安装libgd:
下载地址:https://bitbucket.org/libgd/gd-libgd/downloads
1
2
3
4
|
[root@nmp01 libgd-2.1.1]
# tar -zxvf libgd-2.1.1.tar.gz
[root@nmp01 libgd-2.1.1]
# cd libgd-2.1.1
[root@nmp01 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
[root@nmp01 libgd-2.1.1]
# make && make install
|
安装t1lib:
下载地址:ftp://sunsite.unc.edu/pub/Linux/libs/graphics/t1lib-5.1.2.tar.gz
1
2
3
4
5
|
[root@nmp01 t1lib-5.1.2]
# tar -zxvf t1lib-5.1.2.tar.gz
[root@nmp01 t1lib-5.1.2]
# cd t1lib-5.1.2
[root@nmp01 t1lib-5.1.2]
# ./configure --prefix=/usr/local/t1lib --enable-shared
[root@nmp01 t1lib-5.1.2]
# make without_doc
[root@nmp01 t1lib-5.1.2]
# make install
|
(3)php源码安装:
1
2
3
|
[root@prx02 src]
# cd /usr/local/src
[root@prx02 src]
# tar -zxvf php-5.6.20.tar.gz
[root@prx02 php-5.6.20]
# cd php-5.6.20/
|
注:如果系统是64位,请执行以下两条命令,否则安装php会出错(32位系统不需要执行)
1
2
|
[root@prx02 php-5.6.20]
# \cp -frp /usr/lib64/libltdl.so* /usr/lib/
[root@prx02 php-5.6.20]
# \cp -frp /usr/lib64/libXpm.so* /usr/lib/
|
1
2
3
4
5
6
|
[root@prx02 php-5.6.20]
# export LD_LIBRARY_PATH=/usr/local/libgd/lib
[root@nmp01 ~]
# ln -s /usr/lib64/mysql/libmysqlclient.so.16 /usr/lib/libmysqlclient.so
[root@nmp01 ~]
# cd /usr/lib
[root@nmp01 lib]
# mkdir mysql
[root@nmp01 lib]
# cp /usr/lib64/mysql/* /usr/lib/mysql/
|
1
2
3
|
[root@prx02 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
[root@prx02 php-5.6.20]
# make && make install
|
(4)配置php:
1
2
3
4
5
6
7
8
9
10
11
|
[root@prx02 php-5.6.20]
# cd /usr/local
[root@prx02
local
]
# ln -s php-5.6.20/ php
[root@prx02
local
]
# cp /usr/local/src/php-5.6.20/php.ini-production /usr/local/php/etc/php.ini
[root@prx02
local
]
# cp /usr/local/src/php-5.6.20/sapi/fpm/php-fpm.conf.in /usr/local/php/etc/php-fpm.conf
[root@prx02
local
]
# ln -s /usr/local/php/sbin/* /usr/sbin/
[root@nmp01 php-5.6.20]
# ln -s /usr/local/php/etc/php.ini /etc/php.ini
[root@nmp01 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:
1
|
[root@prx02 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自启动脚本:
1
2
3
4
5
6
7
8
|
[root@prx02 ~]
# cp /usr/local/src/php-5.6.20/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@prx02 init.d]
# chmod a+x /etc/init.d/php-fpm
[root@prx02 ~]
# chkconfig php-fpm on
[root@prx02
local
]
# php-fpm
或:
[root@prx02
local
]
# service php-fpm start
|
1
|
[root@prx02
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:
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
|
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访问:
1
|
[root@prx02
local
]
# mkdir -p /usr/local/nginx/html/zabbix
|
1
|
[root@prx02
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)安装:
1
2
3
4
5
6
7
8
9
10
11
|
[root@prx02 ~]
# groupadd zabbix
[root@prx02 ~]
# useradd zabbix -g zabbix -s /bin/false
[root@prx02 ~]
# cd /usr/local/src
[root@prx02 src]
# tar -zxvf zabbix-3.0.3.tar.gz
[root@prx02 zabbix-3.0.3]
# cd zabbix-3.0.3/
[root@prx02 zabbix-3.0.3]
# yum install -y net-snmp-devel
[root@prx02 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
[root@prx02 zabbix-3.0.3]
# make && make install
|
(2)导入数据库文件:
1
|
[root@nmp01 zabbix-3.0.3]
# mysql -uzabbix -p
|
1
2
3
4
5
6
7
8
|
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)添加系统软连接:
1
2
|
[root@prx02 zabbix-3.0.3]
# ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
[root@prx02 zabbix-3.0.3]
# ln -s /usr/local/zabbix/bin/* /usr/local/bin/
|
(4)添加zabbix服务对应的端口:
1
|
[root@prx02 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配置文件:
1
|
[root@prx02 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
1
|
[root@prx02 mysql]
# vim /usr/local/zabbix/etc/zabbix_agentd.conf
|
修改:
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
UnsafeUserParameters=1 #启用自定义key
(6)添加开机启动脚本:
服务端:
1
|
[root@prx02 mysql]
# cp /usr/local/src/zabbix-3.0.3/misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server
|
客户端:
1
|
[root@prx02 mysql]
# cp /usr/local/src/zabbix-3.0.3/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd
|
1
2
3
4
|
[root@prx02 mysql]
# chmod a+x /etc/rc.d/init.d/zabbix_*
[root@prx02 mysql]
# chkconfig zabbix_server on
[root@prx02 mysql]
# chkconfig zabbix_agentd on
|
修改zabbix开机启动脚本中的zabbix安装目录:
1
|
[root@prx02 mysql]
# vim /etc/rc.d/init.d/zabbix_server
|
修改以下内容:
BASEDIR=/usr/local/zabbix/
1
|
[root@prx02 mysql]
# vim /etc/rc.d/init.d/zabbix_agentd
|
修改以下内容:
BASEDIR=/usr/local/zabbix/
(7)复制zabbix的web站点文件到nginx:
1
|
[root@prx02 mysql]
# cp -r /usr/local/src/zabbix-3.0.3/frontends/php/* /usr/local/nginx/html/zabbix/
|
(8)启动:
1
2
3
|
[root@prx02 mysql]
# systemctl daemon-reload
[root@prx02 mysql]
# service zabbix_server start
[root@prx02 mysql]
# service zabbix_agentd start
|
查看zabbix_server相关进程:
1
|
[root@prx02 ~]
# ps -eaf|grep zabbix_server
|
五 zabbix的web页面设置
在zabbix服务端访问:http://127.0.0.1
然后按提示完成zabbix的web站点安装,最后再进行登录,默认账号密码:Admin zabbix
修改页面语言:页面右上角用户 –> 语言
注:如果出现检查PHP环境时一直缺少某些库,可以尝试删掉php的源码,然后重新编译安装
本文转自 pangfc 51CTO博客,原文链接:http://blog.51cto.com/983836259/1854791,如需转载请自行联系原作者