目录
- 一、RPM安装LAMP(server)
- 二、部署zabbix Server(server)
- 三、配置agent端
- 四、配置邮件报警(server)
- 五、zabbix平台上设置邮箱报警
- 5.1 设置媒体类型
- 5.2 设置指定用户接收报警信息的媒体类型和方式
- 5.3 设置触发器动作
- 5.4 测试邮件报警
【介绍】
Zabbix官网: https://www.zabbix.com
zabbix 主要由2部分构成 zabbix server和 zabbix agent
zabbix proxy是用来管理其他的agent,作为代理
zabbix监控范畴:
硬件监控 :Zabbix IPMI Interface
系统监控 :Zabbix Agent Interface
Java 监控:ZabbixJMX Interface
网络设备监控:Zabbix SNMP Interface
应用服务监控:Zabbix Agent UserParameter
MySQL 数据库监控:percona-monitoring-pldlgins
URL监控:Zabbix Web监控【实验环境】
20.0.0.15 server端
20.0.0.16 agent端
一、RPM安装LAMP(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-mhashvi /etc/httpd/conf/httpd.conf
ServerName www.aa.com
DirectoryIndex index.html index.php
'//搜索修改这两行'vi /etc/php.ini
date.timezone = PRC
'//修改php时区为中国'systemctl stop firewalld && systemctl disable firewalld && setenforce 0
systemctl start httpd && systemctl start mariadb
netstat -anpt | grep 80 && netstat -anpt | grep 3306mysql_secure_installation
'//初始化数据库'
mysql -u root -pabc123CREATE DATABASE zabbix character set utf8 collate utf8_bin;
GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123';
GRANT all ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED BY 'admin123';
flush privileges;
exit
'//建立数据库zabbix,并且将所有权限授给zabbix用户'vi /var/www/html/index.php
<?php
$link&#61;mysql_connect(&#39;20.0.0.15&#39;,&#39;zabbix&#39;,&#39;admin123&#39;);
if($link) echo "Success!!
";
else echo "Fail!!";
mysql_close();
?>
&#39;//http://20.0.0.15验证php连接数据库是否正常&#39;&#39;连接成功LAMP搭建完毕&#39;
二、部署zabbix Server(server)
vi /etc/yum.repos.d/CentOS-Base.repo
[Ali]
name&#61;CentOS-$releasever - Base
baseurl&#61;http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck&#61;1
gpgkey&#61;http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
yum makecache
&#39;//加载加载元数据缓存&#39;
yum install -y php-mbstring php-bcmath
&#39;//安装必备插件&#39;rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
&#39;//会自动生成yum源文件&#xff0c;需保证系统可以上网&#39;yum -y install zabbix-web-mysql.noarch zabbix-server-mysql
&#39;//安装zabbix服务端和web页面支持&#39;zcat /usr/share/doc/zabbix-server-mysql-4.0.26/create.sql.gz | mysql -uzabbix -padmin123 zabbix
&#39;//导入zabbix监控数据库&#39;grep -n &#39;^&#39;[a-Z] /etc/zabbix/zabbix_server.conf
&#39;//查看zabbix未注释的生效行&#39;vi /etc/zabbix/zabbix_server.conf
38:LogFile&#61;/var/log/zabbix/zabbix_server.log
49:LogFileSize&#61;0
72:PidFile&#61;/var/run/zabbix/zabbix_server.pid
82:SocketDir&#61;/var/run/zabbix
100:DBName&#61;zabbix
116:DBUser&#61;zabbix
124:DBPassword&#61;admin123 &#39; //修改此行即可&#39;
356:SNMPTrapperFile&#61;/var/log/snmptrap/snmptrap.log
473:Timeout&#61;4
516:AlertScriptsPath&#61;/usr/lib/zabbix/alertscripts
527:ExternalScripts&#61;/usr/lib/zabbix/externalscripts
563:LogSlowQueries&#61;3000vi /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai
&#39;//修改时区&#xff0c;将此行注释去掉修改即可&#39;vi /usr/share/zabbix/include/defines.inc.php
&#39;//下面操作是修改图表中文乱码&#39;
:%s /graphfont/kaiti/g
&#39;从微软系统C:\Windows\Fonts下复制相应的字体文件到 /usr/share/zabbix/fonts 目录中注意字体名称要对应配置文件改为kaiti.ttf&#xff0c;且注意大小写&#39;
cd /usr/share/zabbix/
mkdir fonts && cd fonts
ls
simkai.ttf
mv simkai.ttf kaiti.ttfsystemctl enable zabbix-server && systemctl start zabbix-server
netstat -anpt | grep zabbix
&#39;//监听在10051端口上&#39;systemctl restart httpd
http://20.0.0.15/zabbix/
&#39;//安装后登录 用户名Admin 密码&#xff1a;zabbix&#39;
登录之后会发现页面是全英文的&#xff0c;下面可以设置一下中文界面
三、配置agent端
rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
&#39;//生成zabbix的yum仓库&#xff0c;联网状态&#39;
yum install -y zabbix-agent.x86_64grep -n &#39;^&#39;[a-Z] /etc/zabbix/zabbix_agentd.conf
vi /etc/zabbix/zabbix_agentd.conf
13:PidFile&#61;/var/run/zabbix/zabbix_agentd.pid
32:LogFile&#61;/var/log/zabbix/zabbix_agentd.log
43:LogFileSize&#61;0
98:Server&#61;20.0.0.16
139:ServerActive&#61;20.0.0.16
150:Hostname&#61;ae.com
268:Include&#61;/etc/zabbix/zabbix_agentd.d/*.conf
&#39;//修改确认agent端配置文件如上&#39;service firewalld stop && setenforce 0
systemctl enable zabbix-agent && systemctl restart zabbix-agent && netstat -anpt | grep zabbix
&#39;//默认监听在10051端口&#39;
增加被控主机–在WEB平台上做
四、配置邮件报警&#xff08;server&#xff09;
yum install mailx –y
vi /etc/mail.rc
&#39;//注意网易邮箱需要开启客户端授权码进行第三方登录&#39;
set from&#61;1562366350&#64;qq.com
set smtp&#61;smtp.qq.com
set smtp-auth-user&#61;1562366350&#64;qq.com
set smtp-auth-password&#61;nynkwzuehbehdbdh &#39;//qq邮箱授权码&#39;
set smtp-auth&#61;loginecho "test" | mail -s "testmail" 1562366350&#64;qq.com
测试发信正常
cd /usr/lib/zabbix/alertscripts
vi mailx.sh
&#39;//编写发邮件脚本&#39;
messages&#61;&#96;echo $3 | tr &#39;\r\n&#39; &#39;\n&#39;&#96;
subject&#61;&#96;echo $2 | tr &#39;\r\n&#39; &#39;\n&#39;&#96;
echo "${messages}" | mail -s "${subject}" $1 >>/tmp/mailx.log 2>&1touch /tmp/mailx.log
chown -R zabbix.zabbix /tmp/mailx.log
chmod &#43;x /usr/lib/zabbix/alertscripts/mailx.sh
chown -R zabbix.zabbix /usr/lib/zabbix/
./mailx.sh 1562366350&#64;qq.com "test1"
&#39;//测试邮件脚本是否能够使用&#39;
五、zabbix平台上设置邮箱报警
5.1 设置媒体类型
5.2 设置指定用户接收报警信息的媒体类型和方式
5.3 设置触发器动作
5.4 测试邮件报警
被监控主机上关闭sshd服务&#xff0c;等待60s&#xff0c;查看状态
开启sshd服务后&#xff0c;再次查看&#xff0c;检测到已启动sshd服务