简介:
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 的主要特点:
安装与配置简单, 学习成本低
支持多语言 (包括中文)
免费开源
自动发现服务器与网络设备
分布式监视以及 Web 集中管理功能
可以无 agent 监视
用户安全认证和柔软的授权方式
通过 Web 界面设置或查看监视结果
email 等通知功能
功能:
CPU 负荷
内存使用
- 磁盘使用
网络状况
端口监视
日志监视
实验环境: CentOS7(两台: 监控服务器, 被监控端)
编译包: 链接: https://pan.baidu.com/s/19DvMqz0s01ByYBQl79ptqw
提取码: ha42
具体实验步骤:
搭建监控服务器:
- # 关闭防火墙 ##
- [root@cacti ~]# systemctl stop firewalld.service
- [root@cacti ~]# systemctl disable firewalld.service
- Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
- Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
- [root@cacti ~]# setenforce 0
-------- 安装 LAMP-------------------------------------------------------
- [root@cacti ~]# yum install -y \
- httpd \
- mariadb-server mariadb \
- PHP \
- PHP-MySQL \
- PHP-gd \
- libjpeg* \
- PHP-ldap \
- PHP-odbc \
- PHP-Pear \
- PHP-xml \
- PHP-xmlrpc \
- PHP-mhash
- [root@cacti ~]# VIM /etc/httpd/conf/httpd.conf
- ServerName www.yun.com:80 ##95 行
- DirectoryIndex index.html index.PHP ##164 行
- [root@cacti ~]# VIM /etc/PHP.INI
- date.timezone = PRC ##878 行 设置中国时区 (去掉分号, 添加 PRC)
- [root@cacti ~]# systemctl start httpd.service
- [root@cacti ~]# systemctl start mariadb.service
- [root@cacti ~]# netstat -ntap | egrep '(3306|80)'
- tcp 0 0 0.0.0.0:3306 0.0.0.0:LISTEN 45660/mysqld
- tcp6 0 0 :::80 ::: LISTEN 45388/httpd
- [root@cacti ~]# mysql_secure_installation
- y
- abc123 (自己设置密码)
- abc123
- n
- n
- n
- y
- ## 进入数据库
- [root@cacti ~]# MySQL -uroot -p
- Enter password: ## 输入密码
- MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin;
- Query OK, 1 row affected (0.00 sec)
- MariaDB [(none)]> GRANT all privileges ON . TO 'zabbix'@'%' IDENTIFIED BY 'admin123';
- Query OK, 0 rows affected (0.00 sec)
- MariaDB [(none)]> flush privileges;
- Query OK, 0 rows affected (0.00 sec)
- ## 测试
- [root@cacti ~]# cd /var/www/HTML/
- [root@cacti HTML]# VIM index.PHP
- <?PHP
- phpinfo();
- ?>
- ## 浏览器访问服务器: 192.168.120.181
- ## 测试完成后删除原来的测试语句
- [root@cacti HTML]# VIM index.PHP
- <?PHP
- $link=mysql_connect('192.168.120.181','zabbix','admin123');
- if($link) echo "<h1>Success!!</h1>";
- else echo "Fail!!";
- mysql_close();
- ?>
- ## 修改完成后, 刷新网页
## 网页是 Success 的可以跳过一下问题 (如果是 Faill, 请按以下步骤操作)##
------------- 解决本地无法登录问题 (可忽略)---------------------------
- [root@cacti HTML]# MySQL -uzabbix -p
- Enter password:
- ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES)
- ## 出错 ##
- ## 解决方案:
- ## 进入 root 用户数据库
- [root@cacti HTML]# MySQL -uroot -p
- MariaDB [(none)]> select user,host from MySQL.user;
- +--------+-----------+
- | user | host |
- +--------+-----------+
- | zabbix | % |
- | root | 127.0.0.1 |
- | root | ::1 |
- | | cacti |
- | root | cacti |
- | | localhost |
- | root | localhost |
- +--------+-----------+
- ## 出现空用户, 删除空用户
- MariaDB [(none)]> drop user ''@localhost;
- Query OK, 0 rows affected (0.02 sec)
- MariaDB [(none)]> drop user ''@cacti;
- Query OK, 0 rows affected (0.00 sec)
- MariaDB [(none)]> select user,host from MySQL.user;
- +--------+-----------+
- | user | host |
- +--------+-----------+
- | zabbix | % |
- | root | 127.0.0.1 |
- | root | ::1 |
- | root | cacti |
- | root | localhost |
- +--------+-----------+
- ## 空用户已删除
- [root@cacti HTML]# MySQL -uzabbix -p
- Enter password:
- MariaDB [(none)]>
- ## 登录成功
---------------- 以下开始部署 zabbix Server-------
- [root@cacti HTML]# yum install PHP-bcmath PHP-mbstring -y
- ## 会自动生成 yum 源文件, 保证系统可以上网
- [root@cacti HTML]# rpm -ivh
- ## 安装
- [root@cacti yum.repos.d]# yum install zabbix-server-MySQL zabbix-Web-MySQL -y
- ## 生成数据库文件, 注意密码不要输成 root 的 (是之前设置的 admin123)
- [root@cacti yum.repos.d]# zcat /usr/share/doc/zabbix-server-MySQL-4.0.0/create.sql.gz | MySQL -uzabbix -p zabbixEnter password:
- [root@cacti yum.repos.d]# grep -n '^'[a-Z] /etc/zabbix/zabbix_server.conf
- 38:LogFile=/var/log/zabbix/zabbix_server.log
- 49:LogFileSize=0
- 72:PidFile=/var/run/zabbix/zabbix_server.pid
- 82:SocketDir=/var/run/zabbix
- 101:DBName=zabbix
- 117:DBUser=zabbix
- 357:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
- 475:Timeout=4
- 518:AlertScriptsPath=/usr/lib/zabbix/alertscripts
- 529:ExternalScripts=/usr/lib/zabbix/externalscripts
- 565:LogSlowQueries=3000
- [root@cacti yum.repos.d]# VIM /etc/zabbix/zabbix_server.conf
- DBPassword=admin123 ##125 行
- [root@cacti yum.repos.d]# VIM /etc/httpd/conf.d/zabbix.conf
- php_value date.timezone Asia/Shanghai ##20 行 (修改时区)
------------------ 修正图表中文乱码 ---------------------
- [root@cacti yum.repos.d]# VIM /usr/share/zabbix/include/defines.inc.PHP
- ##shift: 输入
- :%s /graphfont/kaiti/g
- ## 挂载软件包
- [root@cacti yum.repos.d]# mkdir /abc
- [root@cacti yum.repos.d]# mount.cifs //192.168.100.10/rhel7 /abc
- Password for root@//192.168.100.10/rhel7:
- [root@cacti yum.repos.d]# cd /abc/zabbix/
- [root@cacti zabbix]# ls
- PHP-bcmath-5.4.16-42.el7.x86_64.rpm PHP-mbstring-5.4.16-42.el7.x86_64.rpm STKAITI.TTF
- [root@cacti zabbix]# cp STKAITI.TTF /usr/share/zabbix/fonts/
- ## 启动服务
- [root@cacti zabbix]# systemctl start zabbix-server.service
- [root@cacti zabbix]# systemctl enable zabbix-server.service
- Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
- [root@cacti zabbix]# netstat -anpt | grep zabbix
- tcp 0 0 0.0.0.0:10051 0.0.0.0: LISTEN 46594/zabbix_server
- tcp6 0 0 :::10051 ::: LISTEN 46594/zabbix_server
- [root@cacti zabbix]# systemctl restart httpd.service
- http://192.168.120.181/zabbix/ // 安装后登录 用户名 Admin 密码: zabbix
设置中文环境
Administrator-Users - 点击用户 - 语言中设置
====== 配置代理端 - 就是被控服务器 ---- 如果服务器也需要被自己监控也需要安装 --zabbix-agent=====
- [root@localhost ~]# systemctl stop firewalld.service
- [root@localhost ~]# systemctl disable firewalld.service
- Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
- Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
- [root@localhost ~]# setenforce 0
- ## 安装 yum 源
- [root@localhost ~]# rpm -ivh
- [root@localhost ~]# yum install -y zabbix-agent
- [root@localhost ~]# VIM /etc/zabbix/zabbix_agentd.conf
- Server=192.168.120.181 ##98 行 (IP 为之前的监控服务器)
- ServerActive=192.168.120.181 ##139 行
- Hostname=abc ##150 行 (名字自定义)
- ## 启动服务
- [root@localhost ~]# systemctl start zabbix-agent.service
- [root@localhost ~]# systemctl enable zabbix-agent.service
- Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
- [root@localhost ~]# netstat -ntap | grep 10050
- tcp 0 0 0.0.0.0:10050 0.0.0.0:LISTEN 45402/zabbix_agentd
- tcp6 0 0 :::10050 ::: LISTEN 45402/zabbix_agentd
到网页设置 http://192.168.120.181/zabbix/
选择监控 http,SSH(具体监控什么, 自己定义)
搭建 Zabbix 及如何设置监控就详解到这了.
来源: http://blog.51cto.com/13756916/2308906