安装
[root@localhost ~]#yum install httpd –y
检查版本
[root@localhost ~]#httd –v
更新源
[root@localhost ~]#
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
[root@localhost ~]#rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
查看php版本:
[root@localhost ~]#yum list php7*
安装php
[root@localhost ~]#yum install -y php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mysql.x86_64 php70w-xml.x86_64 php70w-bcmath.x86_64 php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-pdo.x86_64 php70w-gd.x86_64
安装zabbix源
[root@localhost ~]#
wget http://repo.zabbix.com/zabbix/4.0/rhel/6/x86_64/zabbix-release-4.0-1.el6.noarch.rpm
[root@localhost ~]#rpm -ivh zabbix-release-4.0-1.el6.noarch.rpm
检查:
[root@localhost ~]#rpm -ql zabbix-release
结果:
[root@localhost ~]#yum -y install zabbi x zabbix-server zabbix-server-mysql
[root@localhost ~]#yum -y install zabbix-web zabbix-web-mysql
[root@localhost ~]#yum -y install zabbix-agent
[root@localhost ~]#yum -y install mysql-server mysql
【mysql初始化设置:
设置远程访问:
mysql> SELECT User, Password, Host FROM user;
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.116.96.38' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
其中"*.*"代表所有资源所有权限, “'root'@%”其中root代表账户名,%代表所有的访问地址,也可以使用一个唯一的地址进行替换,只有一个地址能够访问。如果是某个网段的可以使用地址与%结合的方式,如10.0.42.%。IDENTIFIED BY 'root',这个root是指访问密码。WITH GRANT OPTION允许级联授权。】
[root@localhost ~]#yum -y install zabbix-agent
【出错:
事务测试出错:
file /etc/zabbix/zabbix_agentd.conf from install of zabbix-agent-4.0.9-3.el6.x86_64 conflicts with file from package zabbix22-2.2.23-1.el6.x86_64
分析:安装zabbix-agent-4.0从package zabbix22-2.2中发生冲突,通过
[root@localhost ~]#rpm –qa | grep zabbix确认后
解决:
移除发生冲突的版本
[root@localhost ~]#yum -y remove zabbix22-2.2.23-1.el6.x86_64
】
配置zabbix服务相关:
配置mysql
[root@localhost ~]# \cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
[root@localhost ~]# vim /etc/my.cnf
在[mysqld](第26行)标签下增加如下三行后保存
[mysqld]
character-set-server = utf8
init-connect = 'SET NAMES utf8'
collation-server = utf8_general_ci
启动mysql数据库,进行初始化:
[root@localhost ~]# /etc/init.d/mysqld start
[root@localhost ~]#mysql -uroot –p [没有密码,直接敲回车]
mysql>create database zabbix character set utf8 collate utf8_bin;
mysql>grant all privileges on zabbix.* to zabbix@localhost identified by 'password';
mysql>flush privileges;
mysql>exit
mysql -uzabbix –p [使用刚才使用的password确认登录,后面会用到这个密码]
导入表结构
[root@localhost ~]#zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
配置zabbix相关
[root@localhost ~]#
sed -i 's/^.*DBPassword=.*$/DBPassword=zabbix/' /etc/zabbix/zabbix_server.conf
[root@localhost ~]#service zabbix-server start
[root@localhost ~]#service zabbix-agent start
[root@localhost ~]#
sed -i 's/^.*date.timezone =.*$/date.timezone = Asia\/Shanghai/g' /etc/php.ini
[root@localhost ~]#sed -i 's/^.*post_max_size =.*$/post_max_size = 16M/g' /etc/php.ini
[root@localhost ~]#
sed -i 's/^.*max_execution_time =.*$/max_execution_time = 300/g' /etc/php.ini
[root@localhost ~]#sed -i 's/^.*max_input_time =.*$/max_input_time = 300/g' /etc/php.ini
[root@localhost ~]#service httpd restart
[root@localhost ~]#chkconfig mysqld on
[root@localhost ~]#chkconfig zabbix-server on
[root@localhost ~]#chkconfig zabbix-agent on
[root@localhost ~]#chkconfig httpd on
[root@localhost ~]#vim /etc/sysconfig/iptables
在防火墙内,插入以下策略
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
[root@localhost ~]#/etc/init.d/iptables restart
通过这个地址访问http://Server_IP/zabbix/
安装邮件服务
[root@localhost ~]#yum install -y mailx
在/etc/mail.rc最后加入一下内容
[root@localhost ~]#vi /etc/mail.rc
set from=2932826605@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=2932826605@qq.com
set smtp-auth-password="wyrsyywqabivdggi"
#这个密码是QQ邮箱的独立密码,不是登录密码
#set smtp-auth-password="plepncdsciaceafc"
set smtp-auth=login
[root@localhost ~]#vi /usr/lib/zabbix/alertscripts/mail.sh
#!/bin/sh
FILE=/tmp/mailtmp.txt
echo "$3" > $FILE
dos2unix -k $FILE ###解决了发送的邮件内容变成附件的问题。
echo -e "$FILE" | mail -s "$2" $1 < $FILE
rm -rf /tmp/mailtmp.txt
##$1 收件人地址 $2 邮件标题 $3邮件内容
给文件赋予执行权限
[root@localhost ~]#chmod +x mail.sh
测试邮件是否正常发送
[root@localhost ~]#./mail.sh 15775977551@163.com 邮箱主题 邮件内容
Web页面配置
名称自定义
类型选择:脚本
脚本名称是刚才在usr/lib/zabbix/alertscripts/下的mail.sh
脚本参数请参考官方文档:
https://www.zabbix.com/documentation/3.0/manual/appendix/macros/supported_by_location
这里第一个参数为收件人,第二个参数为对象,即标题名称,第三个参数为内容
测试是否正常发送邮件: