Alexei Vladishev创建了Zabbix项目,当前处于活跃开发状态,Zabbix SIA提供支持.
Zabbix是一个企业级的、开源的、分布式的监控套件
Zabbix可以监控网络和服务的监控状况. Zabbix利用灵活的告警机制,允许用户对事件发送基于Email的告警. 这样可以保证快速的对问题作出相应. Zabbix可以利用存储数据提供杰出的报告及图形化方式. 这一特性将帮助用户完成容量规划.
Zabbix支持polling和trapping两种方式. 所有的Zabbix报告都可以通过配置参数在WEB前端进行访问. Web前端将帮助你在任何区域都能够迅速获得你的网络及服务状况. Zabbix可以通过尽可能的配置来扮演监控你的IT基础框架的角色,而不管你是来自于小型组织还是大规模的公司.
Zabbix是零成本的. 因为Zabbix编写和发布基于GPL V2协议. 意味着源代码是免费发布的.
Zabbix公司也提供商业化的技术支持.
请确保你所有的服务器时间都是正确的,为了确保时间ok,请在crontab里面加上定时时间同步。
# crontab -l 00 00 * * * /usr/sbin/ntpdate -u 192.168.124.132
Zabbix需要LNMP或者LAMP环境
LNMP环境配置
Linux
NGINX
PHP安装+NGINX配置
MYSQL安装
PHP安装参数
如下模块要特别留意加上
bcmath –enable-bcmath
mbstring –enable-mbstring
sockets –enable-sockets
gd –with-gd
libxml –with-libxml-dir=/usr/local
xmlwriter 同上
xmlreader 同上
ctype 默认支持
session 默认支持
gettext 默认支持
./configure --prefix=/usr/local/php-5.5.7 --with-config-file-path=/usr/local/php-5.5.7/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
PHP配置参数
max_execution_time = 300 memory_limit = 128M post_max_size = 16M upload_max_filesize = 2M max_input_time = 300 date.timezone = Asia/Shanghai
安装 Perl
http://www.perl.org/get.html
wget http://www.cpan.org/src/5.0/perl-5.20.0.tar.gz
tar -zxvf perl-5.20.0.tar.gz
cd perl-5.20.0
./Configure -des -Dprefix=/usr/local/perl -Dusethreads -Uversiononly
make & install
或:
apt-get install libperl-dev
安装 net-snmp
http://www.net-snmp.com/download.html
wget http://ncu.dl.sourceforge.net/project/net-snmp/net-snmp/5.7.2.1/net-snmp-5.7.2.1.tar.gz
tar -zxvf net-snmp-5.7.2.1.tar.gz
./configure --with-default-snmp-version="3" --prefix="/usr/local/net-snmp" --with-sys-contact="@@no.where" --with-sys-location="Unknown" --with-logfile="/var/log/snmpd.log" --with-persistent-directory="/var/net-snmp"
关于配置参数说明:
prefix:安装路径
with-default-snmp-version(3): 3(在这里版本通常有三种形式:1,2c,3)
with-sys-contact(配置该设备的联系信息): heaven(也可以是邮箱地址)
with-sys-location(该系统设备的地理位置):BEIJING P.R China
Location to write logfile (日志文件位置): /var/log/snmpd.log
Location to Write persistent(数据存储目录): /var/net-snmp
设置任何目录下可以运行snmp的命令,需做一下设置:
echo export LD_LIBRARY_PATH=/usr/local/lib >> .bashrc
验证安装是否成功
snmpget --version
zabbix服务端安装
http://www.zabbix.com/
wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.2.6/zabbix-2.2.6.tar.gz
./configure --prefix=/usr/local/zabbix-2.2.6 --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
或者指定
./configure --prefix=/usr/local/zabbix-2.2.6 --enable-server --enable-agent --enable-java --with-mysql --with-net-snmp=/usr/local/net-snmp/bin/net-snmp-config --with-libcurl=/usr/local/curl/bin/curl-config --with-libxml2=/usr/local/libxml2/bin/xml2-config
错误:
configure: error: MySQL library not found
没有装mysql库
apt-get install libmysql++-dev
error: Invalid Net-SNMP directory - unable to find net-snmp-config
没有装net-snmp的库
ln -s /usr/local/curl/include/curl /usr/lib
ldconfig
error:sysinc.h:383:24: error: curl/curl.h: No such file or directory
vim ~/.bash_profile export LD_LIBRARY_PATH=/usr/local/curl/lib:/usr/local/mysql/lib export PATH=$PATH:/usr/local/curl/bin:/usr/local/curl/include/curl:/usr/local/curl/lib export C_INCLUDE_PATH=/usr/local/curl/include export CPLUS_INCLUDE_PATH=/usr/local/curl/include # 保存退出 #生效 source /root/.bashrc
在zabbix server一般充当两个角色:server、angent,所以上面的配置参数也同时加上了–enable-agent。
备注:请安装好MySQL,snmp,curl开发库。
创建用户
如果你在root环境下运行zabbix,那么zabbix将会主动使用zabbix用户来运行。但是如果你的系统没有名叫zabbix的用户,你需要创建一个用户
groupadd zabbix
useradd -g zabbix zabbix
设置Mysql环境变量
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/support-files
启动Mysql
mysql.server start
mysql.server restart
mysql.server stop
设置root密码
mysqladmin -u root -p password 123456
root 用户登录
mysql -u root -p123456
建立数据库
create database zabbix default charset utf8;
初始化zabbix数据
mysql -uroot -p55570378 zabbix < /opt/zabbix-2.2.6/database/mysql/schema.sql
命令集:
#显示schema
show databases;
#打开库
use zabbix;
#列出所有表
show tables;
如果你仅仅是初始化proxy的数据库,那么够了。如果初始化server,那么接着导入下面两个sql
mysql -uroot -p55570378 zabbix < /opt/zabbix-2.2.6/database/mysql/images.sql
mysql -uroot -p55570378 zabbix < /opt/zabbix-2.2.6/database/mysql/data.sql
配置zabbix
配置zabbix_server配置文件,zabbix源码目录下
cp /usr/local/zabbix-2.2.6/etc/zabbix_server.conf /usr/local/zabbix-2.2.6/etc/server.conf vim /usr/local/zabbix-2.2.6/etc/server.conf DBName=zabbix DBUser=root DBPassword=123456 DBPort=3306
启动Zabbix Server
/usr/local/zabbix-2.2.6/sbin/zabbix_server -c /usr/local/zabbix-2.2.6/etc/zabbix_server.conf
默认端口10051
zabbix客户端安装
tar -zxvf zabbix-2.2.6.tar.gz
cd zabbix-2.2.6/
./configure --prefix=/usr/local/zabbix-2.2.2/ --enable-agent
make & make install
zabbix客户端配置
vim /usr/local/zabbix-2.2.2/etc/zabbix_agentd.conf
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server
其中Server和ServerActive都指定zabbixserver的IP地址,不同的是,前者是被动后者是主动。也就是说Server这个配置是用来允许127.0.0.1这个ip来我这取数据。而serverActive的127.0.0.1的意思是,客户端主动提交数据给他。
zabbix客户端启动
/usr/local/zabbix-2.2.2/sbin/zabbix_agentd
默认端口10050
zabbix管理网站配置
拷贝前端文件
mkdir /usr/local/zabbix-2.2.6/web
cp -rp /opt/zabbix-2.2.6/frontends/php/* /usr/local/zabbix-2.2.6/web/
配置Nginx
server { listen 8080; server_name localhost; access_log /usr/local/nginx/logs/zabbix.log; index index.html index.php index.html; root /usr/local/zabbix-2.2.6/web; location / { try_files $uri $uri/ /index.php?$args; } location ~ ^(.+.php)(.*)$ { fastcgi_split_path_info ^(.+.php)(.*)$; include fastcgi.conf; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param PATH_INFO $fastcgi_path_info; } }
启动 PHP
/usr/local/php-5.6.0/sbin/php-fpm
启动Nginx
/usr/local/nginx/sbin/nginx
访问
http://192.168.124.132:8080/
依次向导配置
登陆zabbix,默认用户名:Admin,密码:zabbix
zabbix部署文档
吴佳
2017-02-23
关于zabbix及相关服务软件版本:
Linux:centos 6.6
nginx:1.9.15
MySQL:5.5.49
PHP:5.5.35
一、安装nginx:
安装依赖包:
yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel net-snmp-devel
创建用户:
useradd nginx -s /sbin/nologin
下载nginx软件包并进入到目录中:
wget http://nginx.org/download/nginx-1.9.15.tar.gz && tar xvf nginx-1.9.15.tar.gz && cd nginx-1.9.15
编译:
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre
make && make install
tar -zxvf pcre-8.38.tar.gz
cd pcre-8.38
./configure
make &&make install
ln -s /usr/local /nginx /usr/local/nginx ==>创建软链接
参数解释:
--with-http_stub_status_module:支持nginx状态查询
--with-http_ssl_module:支持https
--with-http_spdy_module:支持google的spdy,想了解请百度spdy,这个必须有ssl的支持
--with-pcre:为了支持rewrite重写功能,必须制定pcre
二、安装PHP
下载PHP安装包:
wget http://cn2.php.net/get/php-5.5.35.tar.gz/from/this/mirror
解压并编译:
mv mirror php-5.5.35.tar.gz && tar xvf php-5.5.35.tar.gz && cd php-5.5.35
./configure --prefix=/usr/local/product/php-5.5.35 --with-config-file-path=/usr/local/product/php-5.5.35/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
make && make install
ln -s /usr/local/product/php-5.5.35 /usr/local/php
cp php.ini-production /usr/local/php/etc/php.ini
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
修改php.ini参数:(zabbix环境需要修改的参数)
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
date.timezone = PRC
三、安装MySQL --- 可以源码安装也可以yum安装
源码安装MySQL
添加mysql用户,创建mysql的数据目录:
groupadd mysql
mkdir -pv /data/mysql
useradd -r -g mysql -d /data/mysql -s /sbin/nologin mysql
chown -R mysql.mysql /data/mysql
安装cmake及依赖:
yum install cmake gcc* ncurses-devel -y
下载MySQL安装包:
wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49.tar.gz
编译安装MySQL:
tar -xvf mysql-5.5.49.tar.gz && cd mysql-5.5.49
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/product/mysql5.5.49 -DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DDEFAULT_COLLATION=utf8_general_ci
make && make install
ln -s /usr/local/product/mysql5.5.49 /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql
拷贝mysql的配置文件:
cd /usr/local/mysql/support-files/
cp my-medium.cnf /data/mysql/my.cnf
cp mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
初始化MySQL:
cd /usr/local/mysql/scripts
./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/
修改MySQL配置文件my.cnf中数据目录:
datadir=/data/mysql/
启动MySQL:
[root@zabbix ~]# /etc/init.d/mysqld start
Starting MySQL... SUCCESS!
登录数据库,创建zabbix数据库及用户名和密码:
mysql> create database zabbix default charset 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 (0.03 sec)
mysql> grant all privileges on zabbix.* to zabbix@'%' identified by 'zabbix';
Query OK, 0 rows affected (0.03 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MySQL> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| zabbix |
+--------------------+
5 rows in set (0.00 sec)
如果登录数据库出现问题:
[root@zabbix ~]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
解决办法:
[root@zabbix ~]# ln -s /tmp/mysql.sock /var/lib/mysql/
为数据库的root创建密码:
[root@zabbix zabbix-3.0.3]# mysqladmin -uroot password "zabbix"
yum安装MySQL
添加mysql用户,创建mysql的数据目录:
yum install mysql mysql-server -y
groupadd mysql
mkdir -pv /data/mysql
useradd -r -g mysql -d /data/mysql -s /sbin/nologin mysql
chown -R mysql.mysql /data/mysql
yum install gcc gcc-c++ ncurses-devel -y
yum install mysql mysql-server -y
/etc/init.d/mysqld restart
mysqladmin -uroot password "zabbix"
登录数据库,创建zabbix数据库及用户名和密码:
mysql> create database zabbix default charset 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 (0.03 sec)
mysql> grant all privileges on zabbix.* to zabbix@'%' identified by 'zabbix';
Query OK, 0 rows affected (0.03 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MySQL> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| zabbix |
+--------------------+
5 rows in set (0.00 sec)
如果登录数据库出现问题:
[root@zabbix ~]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
解决办法:
[root@zabbix ~]# ln -s /tmp/mysql.sock /var/lib/mysql/
四、安装zabbix server:
安装zabbix:
-rw-r--r-- 1 root root 15407273 5月 212016 zabbix-3.0.1.tar.gz
[root@zabbix ~]# tar zxf zabbix-3.0.1.tar.gz && cd zabbix-3.0.1
编译zabbix:
./configure --prefix=/usr/local/zabbix-3.0.1/ --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
make && make install
编译过程中如果有报错:
故障:
checking for mysql_config... no
configure: error: MySQL library not found
解决:
yum install mysql-devel -y
故障:
checking for net-snmp-config... no
configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config
解决:
yum install net-snmp-devel -y
创建zabbix用户:
[root@zabbix zabbix-3.0.1]# groupadd zabbix
[root@zabbix zabbix-3.0.1]# useradd zabbix -s /sbin/nologin -g zabbix
zabbix server需要导入3个sql文件:
[root@zabbix zabbix-3.0.1]# mysql -uroot -pzabbix zabbix < database/mysql/schema.sql
[root@zabbix zabbix-3.0.1]# mysql -uroot -pzabbix zabbix < database/mysql/images.sql
[root@zabbix zabbix-3.0.1]# mysql -uroot -pzabbix zabbix < database/mysql/data.sql
[root@zabbix zabbix-3.0.3]# pwd
/root/zabbix-3.0.3
五、zabbix管理网站配置(nginx):
创建项目目录:
[root@zabbix zabbix-3.0.3]# mkdir /data/web/zabbix.lifec.com -p
[root@zabbix zabbix-3.0.3]# mkdir /data/logs/zabbix -p
将前端文件拷贝到项目目录下:
[root@zabbix zabbix-3.0.3]# cp -rp frontends/php/* /data/web/zabbix.lifec.com/
编辑nginx虚拟主机:
[root@zabbix conf]# mkdir extra
[root@zabbix conf]# cd extra/
[root@zabbix conf]# vim /usr/local/nginx/conf/extra/zabbix.conf
server {
listen 8027;
server_name zabbix.lifec.com;
access_log /data/logs/zabbix/zabbix.lifec.com.access.log main;
index index.html index.php index.html;
root /data/web/zabbix.lifec.com;
location /{
try_files $uri $uri/ /index.php?$args;
}
location ~ ^(.+.php)(.*)$ {
fastcgi_split_path_info ^(.+.php)(.*)$;
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
编辑nginx.conf配置文件:
[root@zabbix conf]# cat nginx.conf
user nginx;
worker_processes 1;
#error_log logs/error.log warning;
#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;
include extra/*.conf;
}
编辑zabbix_server.conf文件:
[root@zabbix etc]# pwd
/usr/local/zabbix-3.0.2/etc
LogFile=/tmp/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
}
/usr/sbin/groupadd -f www
/usr/sbin/useradd -g www www
六、启动服务
启动nginx:
[root@zabbix conf]# /usr/local/nginx/sbin/nginx
启动PHP:
[root@zabbix conf]# /usr/local/php/sbin/php-fpm
启动zabbix server:
[root@zabbix conf]# /usr/local/zabbix-3.0.1/sbin/zabbix_server
如果启动的时候报错:
[root@zabbix ~]# /usr/local/zabbix-3.0.1/sbin/zabbix_server
/usr/local/zabbix-3.0.1/sbin/zabbix_server: error while loading shared
libraries: libmysqlclient.so.18: cannot open shared object file: No such file
or directory
[root@zabbix ~]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
添加/etc/hosts文件:
192.168.119.140 zabbix.lifec.com
查看服务端口:
[root@zabbix conf]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 00.0.0.0:22 0.0.0.0:* LISTEN 1029/sshd
tcp 0 00.0.0.0:8027 0.0.0.0:* LISTEN 3730/nginx
tcp 0 00.0.0.0:10051 0.0.0.0:* LISTEN 3743/zabbix_server
tcp 0 0127.0.0.1:9000 0.0.0.0:* LISTEN 3736/php-fpm
tcp 0 00.0.0.0:3306 0.0.0.0:* LISTEN 24922/mysqld
tcp 0 0 :::22 :::* LISTEN 1029/sshd
udp 0 00.0.0.0:68 0.0.0.0:* 880/dhclient
将服务加入开机自启动:
[root@zabbix ~]# echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local
[root@zabbix ~]# echo "/usr/local/php/sbin/php-fpm" >>/etc/rc.local
[root@zabbix ~]# echo "/etc/init.d/mysqld start" >>/etc/rc.local
[root@zabbix ~]# echo "/usr/local/zabbix-3.0.3/sbin/zabbix_server" >>/etc/rc.local
七、web端配置zabbix
192.168.55.12:8027
下图中的配置为:
Database host 192.168.55.12 数据库所在服务器ip地址
Database port 3306
Password zabbix
需要下载文件,并上传到指定的服务器目录中。
修改界面为中文界面
默认登录界面为英文:
修改以下配置,并重启服务即可;
vim /data/web/zabbix.lifec.com/include/locales.inc.php
vim /data/web/zabbix.lifec.com/include/locales.inc.PHP
#'zh_CN' => ['name' => _('Chinese (zh_CN)'), 'display' => false],
'zh_CN' => ['name' => _('Chinese (zh_CN)'), 'display' => true],
为了防止图形中的字符出现乱码:
需要自己上传字体:
将选择的字体上传到Linux服务器的zabbix的fonts目录:
/data/web/zabbix.lifec.com/fonts
并修改以下配置:
vim /data/web/zabbix.lifec.com/include/defines.inc.php
define('ZBX_GRAPH_FONT_NAME',
'DejaVuSans'); // font file name
define('ZBX_GRAPH_FONT_NAME', 'simsun'); // font file name ==>此行为新增行;
define('ZBX_FONT_NAME',
'DejaVuSans');
define('ZBX_FONT_NAME', 'simsun'); ==>此行为新增行;
重启服务即可