zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
zabbix由zabbix server与可选组件zabbix agent两部门组成。
zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视。
zabbix agent需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。
zabbix的主要特点:
- 安装与配置简单,学习成本低
- 支持多语言(包括中文)
- 免费开源
- 自动发现服务器与网络设备
- 分布式监视以及WEB集中管理功能
- 可以无agent监视
- 用户安全认证和柔软的授权方式
- 通过WEB界面设置或查看监视结果
- email等通知功能
等等
Zabbix主要功能:
- CPU负荷
- 内存使用
- 磁盘使用
- 网络状况
- 端口监视
- 日志监视
#yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel bzip2-devel expat-devel cmake libaio libaio-devel bzr bison libtool wget vim
运行安装脚本
#!/bin/bash
#Get the parent directory of the currently executing script file
basepath=$(cd "$(dirname "$0")"; pwd)
#get nginx 1.6 source
toolspath=/opt/tools
mkdir -p $toolspath
cd $toolspath
wget -q http://nginx.org/download/nginx-1.6.2.tar.gz
tar -xzf nginx-1.6.2.tar.gz
#create own
groupadd nginx
useradd -g nginx -s /sbin/nologin nginx
#complie nginx
echo "start complie source,may wait a minute..."
cd nginx-1.6.2
./configure --user=nginx --group=nginx --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre --with-http_image_filter_module --with-file-aio --with-http_ssl_module --with-http_spdy_module
make && make install
if [ $? -eq 0 ];
then
echo "install success"
else
echo "install error"
fi
#Startup script
cp $basepath/nginx_init /etc/init.d/nginx
chmod +x /etc/init.d/nginx
#tar -xzvf php-5.6.24.tar.gz && cd php-5.6.24
#./configure –prefix=/usr/local/php-5.6.24 –with-config-file-path=/usr/local/php-5.6.24/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
# cp php.ini-production /usr/local/php-5.6.24/etc/php.ini
# cp /usr/local/php-5.6.24/etc/php-fpm.conf.default /usr/local/php-5.6.24/etc/php-fpm.conf
# cp /usr/local/php-5.6.24/sbin/php-fpm /bin/
# chmod +x /bin/php-fpm
# php-fpm
# netstat -tunlp | grep 9000
#mkdir -p /data/nginx
#chown -R nginx:nginx /data/nginx/
# cd /data/nginx/ && vim index.php
phpinfo();
?>
添加nginx对php的支持
#vim /etc/nginx/nginx.conf
root /data/nginx;
index index.php index.html index.htm;
location ~ .*\.(php)?$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param PATH_INTO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
#chkconfig nginx on
4.Mysql
# groupadd mysql
# useradd mysql -g mysql -s /sbin/nologin
# rpm -qa | grep mysql
# rpm -e –nodeps mysql-libs-5.1.71-1.el6.x86_64
# cp -r mysql-5.6.14-linux-glibc2.5-x86_64 /usr/local/mysql
# mkdir /var/lib/mysql
# chown mysql:mysql -R /var/lib/mysql/
# vim /etc/my.cnf
[client]
default-character-set=utf8
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
character-set-server=utf8
collation-server=utf8_general_ci
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/var/lib/mysql
# chmod 755 /etc/init.d/mysqld
初始化数据库
# cd /usr/local/mysql/ && ./scripts/mysql_install_db –user=mysql –defaults-file=/etc/my.cnf
# service mysqld start
# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
更改root密码
# /usr/local/mysql/bin/mysql -u root
mysql> update mysql.user set password=password('redhat') where user='root';
mysql> drop user ''@localhost;
mysql> flush privileges;
拷贝常用二进制文件,使之可快捷打开
# cd bin && cp mysql mysqladmin mysqlbinlog mysqldump mysqld_safe /bin/
# chkconfig –add mysqld
# chkconfig mysqld on
#yum install net-snmp-devel libxml2-devel libcurl-devel -y
修改php配置文件,否则zabbix安装不
# vim /usr/local/php-5.6.24/etc/php.ini
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
#date.timezone PRC
date.timezone = "Asia/Shanghai"
# groupadd zabbix
# useradd zabbix -g zabbix
#wget “http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.2.2/zabbix-2.2.2.tar.gz?r=http%3A%2F%2Fwww.zabbix.com%2Fdownload.php&ts=1395066528&use_mirror=jaist”
# tar -xzvf zabbix-2.2.2.tar.gz && cd zabbix-2.2.2
将zabbix的初始数据导入到数据库
#mysql -uroot -p
sql> create database zabbix default charset utf8;
mysql> grant all privileges on zabbix.* to zabbix@'%' identified by 'redhat';
mysql> flush privileges;
mysql> use zabbix;
mysql> source /opt/tools/zabbix-2.2.2/database/mysql/schema.sql
mysql> source /opt/tools/zabbix-2.2.2/database/mysql/data.sql
mysql> source /opt/tools/zabbix-2.2.2/database/mysql/images.sql
编译安装
# find / -name mysql_config
# ./configure –prefix=/usr/local/zabbix-2.2.2/ –enable-server –enable-agent –with-mysql=/usr/local/mysql/bin/mysql_config –with-net-snmp –with-libcurl –with-libxml2
# make && make install
服务端
配置zabbix_server配置文件
# vim /usr/local/zabbix-2.2.2/etc/zabbix_server.conf
DBName=zabbix
DBUser=root
DBPassword=***
DBPort=3306
启动zabbix server
# /usr/local/zabbix-2.2.2/sbin/zabbix_server
若zabbix_server启动时报错
zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
# find / -name libmysqlclient.so.18
# vim /etc/ld.so.conf
/usr/local/mysql/lib
# ldconfig
客户端
# 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管理网站配置
# mkdir -p /data/nginx/zabbix/
拷贝前端文件
# cp -r frontends/php/* /data/nginx/zabbix/
# chown nginx:nginx -R /data/nginx/zabbix/
Nginx配置修改
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ ^(.+.php)(.*)$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param PATH_INTO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
打开127.0.0.1/zabbix,进行配置
配置完毕后默认户名admin 密码zabbix
zabbix2.2.2 登陆后报错
ini_set(): Use of mbstring.internal_encoding is deprecated [dashboard.php:21 → require_once() → ZBase->run() → ZBase->initLocales() → init_mbstrings() → ini_set() in /data/nginx/zabbix/include/locales.inc.php:25]
则
#vim /data/nginx/zabbix/include/locales.inc.php
把 /*ini_set('mbstring.internal_encoding', 'UTF-8');*/ 注释掉
中文乱码问题
找到本地 C:\Windows\Fonts\simkai.ttf(楷体)上传到服务器 zabbix 网站目录 fonts 目录下。
修改配置
# cd /data/nginx/zabbix/include/fonts
# mv SIMKAI.TTF SIMKAI.ttf
#vim /data/nginx/zabbix/include/defines.inc.php
:%s/DejaVuSans/SIMKAI/g
ODBC是C语言开发的、用于访问数据库的中间件接口.zabbix支持查询任何ODBC支持的数据库.zabbix通过调用ODBC来获取数据库的数据以及数据库状态等等信息.
#yum -y install unixODBC unixODBC-devel mysql-connector-odbc
配置odbcinst.ini和odbc.ini两个配置文件即可,验证配置是否正常,如下命令:
# odbcinst -j
# vim /etc/odbc.ini
[test]
Description = MySQL test database
Driver = mysql
Server = 127.0.0.1
User = zabbix
Password = ****
Port = 3306
Database = zabbix
test 数据源名称 (DSN).
Description 数据源描述.
Driver 数据库驱动名 - 在 odbcinst.ini指定
Server 数据库 IP/DNS.
User 数据库用户名.
Password 数据库密码.
Port 数据库端口
Database 数据库名称.
测试
#isql <DSN> <user> <password>
重新编译
#./configure –prefix=/usr/local/zabbix-2.2.2/ –enable-server –enable-agent –with-mysql=/usr/local/mysql/bin/mysql_config –with-net-snmp –with-libcurl –with-libxml2 –with-unixodbc
make && make install
更换zabbix_server zabbix_agentd