abbix是一个高度集成的企业级开源网络监控解决方案,与Cacti、nagios类似,提供分布式监控以及集中的web管理界面。zabbix具备常见商业监控软件所具备的功能,例如主机性能监控,网络设备性能监控,数据库性能监控,ftp等通用协议的监控,能够灵活利用可定制警告机制,允许用户对事件发送基于E-mail的警告,保证相关人员可以快速解决。还能够利用存储数据提供杰出的报表及实时的图形化数据处理,实现对监控主机7x24小时集中监控。
Zabbix通过C/S模式采集数据通过B/S模式在web端展示和配置,通过SNMP协议传输,而被监控对象只需要支持SNMP协议或者运行Zabbix——agents代理程序即可。服务端监听端口为10051,而被监控端即Zabbix——agents代理程序监控10050端口
LNMP环境的编译过程可以查看这里https://sulao.cn/post/111.html
安装依赖包
yum install net-snmp-devel libcurl-devel libevent-devel unixODBC-devel -y
编译安装zabbix
cd /usr/local/src tar -zxvf zabbix-3.4.11.tar.gz cd zabbix-3.4.11 mkdir -p /usr/local/zabbix ./configure --prefix=/usr/local/zabbix --enable-server --enable-proxy --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-unixodbc make && make install
创建zabbix用户和用户组
groupadd zabbix useradd -r -g zabbix zabbix chown -R zabbix:zabbix /usr/local/zabbix
创建zabbix数据库,并导入表结构
mysql -uroot -p mysql> create database if not exists zabbix default character set utf8 collate utf8_general_ci; mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix'; mysql> use zabbix; mysql> source /usr/local/src/zabbix-3.4.11/database/mysql/schema.sql; mysql> source /usr/local/src/zabbix-3.4.11/database/mysql/images.sql; mysql> source /usr/local/src/zabbix-3.4.11/database/mysql/data.sql;
创建日志目录
cd /usr/local/zabbix mkdir logs chown zabbix:zabbix logs
修改zabbix_server.conf
vi /usr/local/zabbix/etc/zabbix_server.conf LogFile=/usr/local/zabbix/logs/zabbix_server.log PidFile=/tmp/zabbix_server.pid DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=zabbix DBSocket=/tmp/mysql.sock Include=/usr/local/zabbix/etc/zabbix_server.conf.d/*.conf
修改zabbix_agent.conf
vi /usr/local/zabbix/etc/zabbix_agentd.conf PidFile=/tmp/zabbix_agentd.pid LogFile=/usr/local/zabbix/logs/zabbix_agentd.log Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
启动zabbix_server 和 zabiix_agent服务
chmod +x /usr/local/zabbix/sbin/zabbix_server /usr/local/zabbix/sbin/zabbix_server chmod +x /usr/local/zabbix/sbin/zabbix_agentd /usr/local/zabbix/sbin/zabbix_agentd #开机启动 vi /etc/rc.local #最下面添加 /usr/local/zabbix/sbin/zabbix_server /usr/local/zabbix/sbin/zabbix_agentd
如果再启动的时候报错:/usr/local/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
解决方法:
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/ ldconfig
拷贝前端到web目录
mv /usr/local/src/zabbix-3.4.11/frontends/php/* /data/www/zabbix/ chown -R www:www /data/www/zabbix/
这样我们打开zabbix界面,还需要进一步的配置
打开/etc/php.ini修改以下基础符合zabbix的最低要求
post_max_size # 16M max_execution_time #300 max_input_time #300 always_populate_raw_post_data #-1 date.timezone #Asia/Shanghai ldap模块告警,我们需要追加编译此模块 cd /usr/local/src/php-5.6.35/ext/ldap /usr/local/php5/bin/phpize ./configure --with-php-config=/usr/local/php5/bin/php-config --with-ldap make && make install
编译时候可能会有这个错误
configure: error: Cannot find ldap libraries in /usr/lib.
解决方案如下:
cp -frp /usr/lib64/libldap* /usr/lib/
再次编译通过
我们在php.ini文件添加生成.so文件,重启php-fpm
extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20131226/ldap.so
然后我们就顺利安装完成
初始化安装的默认账号:Admin,密码:zabbix
今日以后我们还可以切换到中文,操作是选择Administrator,点击Admin,然后修改Language为Chinese,点击“Update”即可
nginx下zabbix虚拟机例子
nginx.conf配置文件
user www www; worker_processes 2; #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; multi_accept on; use epoll; } 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; client_header_timeout 30; client_body_timeout 30; client_max_body_size 128m; reset_timedout_connection on; sendfile on; #tcp_nopush on; keepalive_timeout 30; send_timeout 30; limit_conn_zone $binary_remote_addr zone=addr:5m; limit_conn addr 100; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 128k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k; gzip on; gzip_min_length 1k; gzip_buffers 16 64k; gzip_http_version 1.1; gzip_comp_level 9; gzip_types text/plain application/x-javascript text/css application/xml application/x-httpd-php; gzip_vary on; proxy_buffer_size 128k; proxy_buffers 32 32k; proxy_busy_buffers_size 128k; open_file_cache max=100000 inactive=30s; open_file_cache_valid 60s; open_file_cache_min_uses 2; open_file_cache_errors on; include vhost/*.conf; }
然后再nginx配置同级目录下建立vhost目录,下面新增虚拟机
zabbix.conf内容如下
server { listen 80; server_name localhost; root /data/www/zabbix; index index.php index.html; access_log /dev/null; error_log /dev/null; location ~ .*\.(jpg|jpeg|png|gif|js|css)$ { expires 1d; } location ~ \.php(/|$) { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }