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等平台上。php
Zabbix agent:负责部署在被监控主机上,把被监控主机的数据传送给zabbix server
Zabbix server:负责接收agent发送的信息,组织配置信息,统计配置信息和操做数据等
Zabbix database: 用于存储zabbix的全部配置信息,监控数据的数据库
Zabbix web: zabbix的web界面,管理能够经过zabbix的web界面管理zabbix配置以及查看zabbix的监控信息,能够独一部署在一台服务器上
Zabbix proxy:分布式环境中使用,zabbix proxy表明server端管理该区域中的信息收集,最终统一发往zabbix serverhtml
agent:经过专用的代理程序进行监控
ssh/Telnet:经过远程控制协议进行通信
SNMP:经过SNMP协议与被监控对象进行通信,路由器和交换机支持SNMP,其实也是一种agent
IPMI:经过IPMI接口进行监控,经过IPMI硬件接口监控,电压,温度,风扇,和电源状态
JMX:经过(java management extensions Java管理扩展)监控JVM虚拟机~~java
分布式的监控体系:监控数据被提交给zabbix proxy 再 提交给zabbix server
主动模式:由agent端主动收集信息发送给server端 工具是zabbix_sender 被动模式:由server端主动拉取信息 工具是zabbix_get
检测端server 192.168.13.128 被检测端agent 192.168.13.130
[root@server ~]# systemctl stop firewalld.service ##关闭防火墙 [root@server ~]# systemctl disable firewalld.service [root@server ~]# setenforce 0 ##安装lamp架构## [root@server ~]# 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@server ~]# vim /etc/httpd/conf/httpd.conf 95 ServerName www.yun.com:80 #第95行,删除注释,域名自定义 164 DirectoryIndex index.html index.php #164行,添加首页支持类类型index.php [root@server ~]# vim /etc/php.ini 878 date.timezone = PRC #878行,把前面模板的;号删除,后面添加中国时区PRC [root@server ~]# systemctl start httpd.service ##开启服务 [root@server ~]# systemctl start mariadb.service [root@server ~]# netstat -natp | egrep '(3306|80)' ##查看端口号 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 5087/mysqld tcp6 0 0 :::80 :::* LISTEN 4807/httpd [root@server ~]# mysql_secure_installation ##初始化数据库 Enter current password for root (enter for none): #此处直接回车 Set root password? [Y/n] y #设置密码 New password: #abc123 Re-enter new password: #确认输入:abc123 Password updated successfully! Remove anonymous users? [Y/n] n #是否删除匿名用户,选择不删除 Disallow root login remotely? [Y/n] y #是否远程链接 Remove test database and access to it? [Y/n] n #是否删除测试数据库 Reload privilege tables now? [Y/n] y #是否从新加载 ... Success! [root@server ~]# mysql -u root -p ##登陆数据库 MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin; Query OK, 1 row affected (0.00 sec) ##建立zabbix数据库,而且设置为utf8形式,把里面的字符串转换为二进制 MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | zabbix | +--------------------+ 5 rows in set (0.00 sec) MariaDB [(none)]> GRANT all privileges ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123'; Query OK, 0 rows affected (0.01 sec) #把全部数据库和全部表都交给zabbix用户进行管理,而且设置密码为admin123 MariaDB [(none)]> flush privileges; #刷新 Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> quit #退出数据库 Bye //测试php基本信息// [root@server ~]# cd /var/www/html/ [root@server html]# ls [root@server html]# vim index.php <?php phpinfo(); ?> //用浏览器访问网页//
//测试数据库链接状况// [root@localhost html]# vim index.php <?php $link=mysql_connect('192.168.13.128','zabbix','admin123'); if($link) echo "<h1>Success!!</h1>"; else echo "Fail!!"; mysql_close(); ?>
[root@server html]# mysql -u zabbix -p Enter password: #此时输入admin123没法登陆数据库,说明有用户占用 ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES) `先使用root用户登陆数据库` [root@server html]# mysql -u root -p MariaDB [(none)]> select user,host from mysql.user; ##查看用户表 +--------+-----------+ | user | host | +--------+-----------+ | zabbix | % | | root | 127.0.0.1 | | root | ::1 | | | server | | | localhost | | root | localhost | +--------+-----------+ MariaDB [(none)]> drop user ''@localhost; ##删除空用户 MariaDB [(none)]> drop user ''@server; ##删除空用户 MariaDB [(none)]> select user,host from mysql.user; +--------+-----------+ | user | host | +--------+-----------+ | zabbix | % | | root | 127.0.0.1 | | root | ::1 | | root | localhost | +--------+-----------+ 4 rows in set (0.00 sec) MariaDB [(none)]> quit Bye ##此时再次刷新页面就会显示Success!!成功登陆
[root@server html]# yum install php-bcmath php-mbstring -y [root@server html]# rpm -ivh http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm ##安装zabbix源 [root@server html]# cd /etc/yum.repos.d/ [root@server yum.repos.d]# cat zabbix.repo ##这是下载的zabbix的源 [zabbix] name=Zabbix Official Repository - $basearch baseurl=http://repo.zabbix.com/zabbix/3.5/rhel/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 [zabbix-non-supported] name=Zabbix Official Repository non-supported - $basearch baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/ enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX gpgcheck=1 [root@server yum.repos.d]# yum install zabbix-server-mysql zabbix-web-mysql -y ##安装zabbix [root@server yum.repos.d]# zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz | mysql -u zabbix -p zabbix ##在zabbix数据库中生成数据文件 [root@server yum.repos.d]# vim /etc/zabbix/zabbix_server.conf ##修改zabbix配置文件 125 DBPassword=admin123 ##添加zabbix数据库密码 [root@server yum.repos.d]# vim /etc/httpd/conf.d/zabbix.conf 20 php_value date.timezone Asia/Shanghai ##修改成中国时区 [root@server yum.repos.d]# vim /usr/share/zabbix/include/defines.inc.php #####修正图表中文乱码#### ##在末行模式下进行替换 :%s /graphfont/kaiti/g [root@server yum.repos.d]# cd /usr/share/zabbix/fonts/ ##在此目录下上传stkaiti.ttf字体 [root@server fonts]# rz -E [root@server fonts]# ls graphfont.ttf stkaiti.ttf [root@server fonts]# systemctl start zabbix-server.service ##开启zabbix服务 [root@server fonts]# systemctl enable zabbix-server.service [root@server fonts]# netstat -antp | grep zabbix (端口10051) tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 43984/zabbix_server tcp6 0 0 :::10051 :::* LISTEN 43984/zabbix_server [root@server fonts]# systemctl restart httpd.service ##重启httpd服务
点击右上角人物头像,在Language语言栏选择Chinese(zh_CN)简体中文,点击Update更新
[root@agent ~]# systemctl stop firewalld.service [root@agent ~]# systemctl disable firewalld.service [root@agent ~]# setenforce 0 [root@agent ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm ##安装yum源 [root@agent ~]# yum install zabbix-agent -y ##安装代理agent [root@agent ~]# vim /etc/zabbix/zabbix_agentd.conf ##修改配置文件 98 Server=192.168.13.128 ##指定监控端server地址 139 ServerActive=192.168.13.128 ##指定监控端server地址 150 Hostname=test ##名称 [root@agent ~]# systemctl start zabbix-agent.service ##开启服务 [root@agent ~]# systemctl enable zabbix-agent.service [root@agent ~]# netstat -natp | grep zabbix (agent端口号10050) tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 41189/zabbix_agentd tcp6 0 0 :::10050 :::* LISTEN 41189/zabbix_agentd
[root@server ~]# yum install mailx -y ##安装mailx软件 [root@server ~]# vim /etc/mail.rc ##修改配置文件 ##末行添加 set from=706858376@qq.com set smtp=smtp.qq.com set smtp-auth-user=706858376@qq.com set smtp-auth-password=受权码 ##此处是你邮箱的第三方登陆的受权码 set smtp-auth=login [root@server ~]# echo "hello world" | mail -s "testmail" 706858376@qq.com ##发送邮件
[root@server ~]# cd /usr/lib/zabbix/alertscripts/ ##切换到zabbix脚本目录下 [root@server alertscripts]# vim mailx.sh ##编辑发送邮件脚本 #!/bin/bash #send mail messages=`echo $3 | tr '\r\n' '\n'` subject=`echo $2 | tr '\r\n' '\n'` echo "${messages}" | mail -s "${subject}" $1 >>/tmp/mailx.log 2>&1 [root@server alertscripts]# touch /tmp/mailx.log ##建立日志 [root@server alertscripts]# chown -R zabbix.zabbix /tmp/mailx.log ##受权属主属组 [root@server alertscripts]# chmod +x /usr/lib/zabbix/alertscripts/mailx.sh ##执行权限 [root@server alertscripts]# chown -R zabbix.zabbix /usr/lib/zabbix/ ##受权属主属组 [root@server alertscripts]# ./mailx.sh 706858376@qq.com "yun" "heihei"
模板: 默认操做步骤持续时间 60 默认接收人 : {TRIGGER.STATUS}:{TRIGGER.NAME} 默认信息: 告警主机:{HOST.NAME} 告警 IP:{HOST.IP} 告警时间:{EVENT.DATE}-{EVENT.TIME} 告警等级:{TRIGGER.SEVERITY} 告警信息:{TRIGGER.NAME}:{ITEM.VALUE} 事件 ID:{EVENT.ID}
模板: 恢复操做:{TRIGGER.STATUS}:{TRIGGER.NAME} 恢复信息: 恢复主机:{HOST.NAME} 恢复 IP:{HOST.IP} 恢复时间:{EVENT.DATE}-{EVENT.TIME} 恢复等级:{TRIGGER.SEVERITY} 恢复信息:{TRIGGER.NAME}:{ITEM.VALUE} 恢复 ID:{EVENT.ID}
[root@agent yum.repos.d]# systemctl stop sshd ##关闭被监控端的ssh服务
[root@agent yum.repos.d]# systemctl start sshd ##开启被监控端的ssh服务