RHEL6 Zabbix3.4.7 部署及配置percona-zabbix、orazabbix插件
一、环境说明
系统:Red Hat Enterprise Linux Server release 6.3
安装包:zabbix-3.4.7.tar,
二、安装mysql
rpm –qa | grep mysql
删除列表中已安装的mysql
rpm –e –nodeps mysql包
wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
rpm -ivh mysql-community-release-el6-5.noarch.rpm
yum repolist all | grep mysql
yum install mysql-community-server -y
配置mysql
vi my.cnf
[mysqld]
innodb_file_per_table=1
启动mysql
service mysqld start
mysql_secure_installation
二、安装php5.6和apache
2.1 安装依赖包
rpm -ivh http://repo.webtatic.com/yum/el6/latest.rpm
yum -y install httpd php56w php56w-gd php56w-mysqlnd php56w-bcmath php56w-mbstring php56w-xml php56w-ldap
2.2 配置php修改
vi /etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
always_populate_raw_post_data = -1
2.3 配置apache
vi /etc/httpd/conf/httpd.conf
DocumentRoot "/var/www/html/zabbix"
<Directory "/var/www/html/zabbix">
ServerName 127.0.0.1
DirectoryIndex index.html index.html.var index.php
2.4 设置web前端
mkdir /var/www/html/zabbix
cp -a zabbix-3.4.7/frontends/php /var/www/html/zabbix
2.5 设置apache的执行和所有者
chown -R apache:apache /var/www/html/zabbix
2.6 赋予可执行权限
chmod +x /var/www/html/zabbix/conf/
2.7 创建zabbix用户和组
groupadd zabbix
useradd -g zabbix zabbix
三、编译安装zabbix
yum install gcc* mysql-devel libxml2-devel net-snmp* java* curl-devel unixODBC-devel libssh2-devel OpenIPMI-devel libevent-devel pcre* -y
cd zabbix-3.4.7
./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --enable-java --with-net-snmp --with-libcurl --with-libxml2 --with-unixodbc --with-ssh2 --with-openipmi --with-openssl --prefix=/usr/local/zabbix
make install
四、修改zabbix_server参数
vi /usr/local/zabbix/etc/zabbix_server.conf
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
cp misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix_server
cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix_agentd
修改 /etc/init.d/zabbix_server /etc/init.d/zabbix_agentd的BASEDIR=/usr/local/为BASEDIR=/usr/local/zabbix
五、mysql导入zabbix数据库
CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@'%' IDENTIFIED BY 'zabbix';
use zabbix;
source database/mysql/schema.sql;
source database/mysql/images.sql;
source database/mysql/data.sql;
六、启动所有服务,并设置开机启动
service httpd start
service mysqld start
/etc/init.d/zabbix_server start
/etc/init.d/zabbix_agentd start
chkconfig httpd on
chkconfig mysqld on
chkconfig --add /etc/init.d/zabbix_server
chkconfig --add /etc/init.d/zabbix_agentd
chkconfig zabbix_server on
chkconfig zabbix_agentd on
查看80,3306,10050,10051是否监听
ss -tunlp | grep -E '80|3306|10050|10051'
七、登陆zabbix界面设置
浏览器传统(兼容)模式图片无法显示,需要设置为极速模式
http://IP地址登陆zabbix
7.1 欢迎界面
7.2 检测系统环境
7.3 输入数据库信息
7.4 输入主机信息
7.5 确认信息
7.6 完成
usr:Admin
psw:zabbix
八、zabbix 客户端安装
8.1 安装依赖包
yum install -y openssh-clients gcc gcc-c++ net-snmp* net-snmp-devel curl curl-devel pcre*
8.2 添加zabbix用户
groupadd zabbix
useradd -g zabbix zabbix
8.3 安装zabbix
cd /zabbix
./configure --prefix=/usr/local/zabbix --enable-agent
make install
8.4 配置zabbix
cp misc/init.d/fedora/core5/zabbix_agentd /etc/rc.d/init.d/
vi /etc/rc.d/init.d/zabbix_agentd 修改
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd"
chkconfig zabbix_agentd on
vi /usr/local/zabbix/etc/zabbix_agentd.conf
Server=zabbix服务器IP
ServerActive=agentIP(本机)
Hostname=本机IP
UnsafeUserParameters=1
重启zabbix服务
/etc/init.d/zabbix_agentd restart
检查10050端口
ss - tunl | grep 10050
8.5 文件说明
zabbix_agentd.conf agent配置文件
zabbix_agent.conf 依赖超级服务
zabbix_server.conf 服务器配置文件
zabbix_get 检测配置是否有问题
zabbix_get -s ip地址 -k
九、配置邮件报警
9.1 安装sendEmail
yum install perl-Net-SSLeay perl-IO-Socket-SSL -y
cd /tmp
wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
tar -xvf sendEmail-v1.56.tar.gz
cd sendEmail-v1.56/
cp -ra sendEmail /usr/local/bin/
chmod +x /usr/local/bin/sendEmail
ls -d /usr/local/bin/sendEmail
9.2 sendEmail命令说明
/usr/local/bin/sendEmail
-f from@163.com 发件人邮箱
-t to@163.com 收件人邮箱
-s smtp.163.com 发件人邮箱的smtp服务器
-u "我是邮件主题" 邮件的标题
-o message-content-type=html 邮件内容的格式,html表示它是html格式
-o message-charset=utf8 邮件内容编码
-xu user 发件人邮箱的用户名
-xp password 发件人邮箱密码
-m "我是邮件内容" 邮件的具体内容
9.3 测试邮件
/usr/local/bin/sendEmail -f 发件人邮箱地址 -t 收件人邮箱地址 -s 发件人邮箱的smtp服务器地址 -u "title" -o message-content-type=html -o message-charset=utf8 -xu 发件人邮箱用户名 -xp 发件人邮箱密码 -m "content"
9.4 编写脚本
mkdir /usr/local/zabbix/alertscripts
cd /usr/local/zabbix/alertscripts
vi /usr/local/zabbix/etc/zabbix_server.conf
AlertScriptsPath=/usr/local/zabbix/alertscripts
9.5 编写脚本
vi sendEmail.sh
#!/bin/bash
to=$1
subject=$2
body=$3
from=发件人邮箱地址
smtp=发件人smtp地址
passwd=发件人邮箱密码
/usr/local/bin/sendEmail -f "$from" -t "$to" -s "$smtp" -u "$subject" -o message-content-type=html -o message-charset=utf8 -xu "$from" -xp "$passwd" -m "$body"
9.6 测试发送脚本
sh sendEmail.sh 收件人邮箱地址 title content
chmod +x sendEmail.sh
chown zabbix.zabbix sendEmail.sh
9.7 页面设置
Administration--->Media types
Create media type
name:email
Type:Scipt
script name:sendEmail.sh
Script parameters:
{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}
Administration--->Users
Admin-->users->Media
增加邮箱信息,type选择media type中的name:email
Send to中输入收件邮箱信息
Administration--->user groups
Zabbix administrators Debug mode enable
user groups-->Permissions
select add all update
Configuration--->Actions status:Enabled
Actions--->Operations Edit
Send to User groups:Zabbix administrators
Send to Users:Admin (Zabbix Administrator)
Recovery operation
Send to User groups:Zabbix administrators
Send to Users:Admin (Zabbix Administrator)
检查点:
Administration->User groups->Zabbix administrators Debug mode必须为enable
Administration->Users:Admin Debug mode必须为enable
十、安装percona-zabbix插件
10.1 客户端安装依赖包
yum install php-cli php-mysql -y
10.2 客户端安装percona-zabbix插件
rpm -ivh percona-zabbix-templates-1.1.7-2.noarch.rpm
安装成功会在/var/lib/zabbix/percona/下有两个目录
10.3 客户端mysql数据库添加用户
mysql创建zabbix用户
GRANT USAGE ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'zabbix';
flush privileges;
10.4 客户端配置脚本
vi /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
$mysql_user = 'zabbix';
$mysql_pass = 'zabbix';
cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /usr/local/zabbix/etc/zabbix_agentd.conf.d/
echo "Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf" >> /usr/local/zabbix/etc/zabbix_agentd.conf
10.5 服务器端导入xml
服务器端网页导入zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.7.xml
导入Percona MySQL Server模板
测试获取数据是否成功
php -q /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host localhost --items gg
成功会在/tmp下生成localhost-mysql_cacti_stats.txt文件
chown zabbix.zabbix /tmp/localhost-mysql_cacti_stats.txt
/etc/init.d/zabbix_agentd restart
10.6 客户端测试:
/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh iu
10.7 服务端测试:
/usr/local/zabbix/bin/zabbix_get -s 客户端IP地址 -p 10050 -k "MySQL.Threads-connected"
zabbix_agentd服务需要重启
十一、安装orazabbix插件
客户端oracle服务器不用装zabbix-agent
11.1 准备软件环境
yum install -y java java-devel
unzip Orabbix-1.2.3.zip
mv orabbix-1.2.3 /usr/local/orabbix
11.2 调整配置文件
cd /usr/local/orabbix
cp init.d/orabbix /etc/init.d/
chmod +x /etc/init.d/orabbix
chmod +x /usr/local/orabbix/run.sh
11.3 创建数据库账号
首先我们需要在被监控的Oracle上面创建一个账号,用于zabbix的数据获取,在oracle的sqlplus里面执行。
CREATE USER ZABBIX
IDENTIFIED BY "zabbix"
DEFAULT TABLESPACE SYSTEM
TEMPORARY TABLESPACE TEMP
PROFILE DEFAULT
ACCOUNT UNLOCK;
#Roles for ZABBIX
GRANT CONNECT TO ZABBIX;
GRANT RESOURCE TO ZABBIX;
ALTER USER ZABBIX DEFAULT ROLE ALL;
#System Privileges for ZABBIX
GRANT SELECT ANY TABLE TO ZABBIX;
GRANT CREATE SESSION TO ZABBIX;
GRANT SELECT ANY DICTIONARY TO ZABBIX;
GRANT UNLIMITED TABLESPACE TO ZABBIX;
GRANT SELECT ANY DICTIONARY TO ZABBIX;
如果我们的数据库是Oracle 11g,我们还需要执行下面的语句。
exec dbms_network_acl_admin.create_acl(acl => 'resolve.xml',description => 'resolve acl', principal =>'ZABBIX', is_grant => true, privilege => 'resolve');
exec dbms_network_acl_admin.assign_acl(acl => 'resolve.xml', host =>'*');
commit;
11.4 配置config.props
cp /usr/local/orabbix/conf/config.props.sample /usr/local/orabbix/conf/config.props
vim /usr/local/orabbix/conf/config.props
#comma separed list of Zabbix servers
ZabbixServerList=ZabbixServer1
ZabbixServer1.Address=zabbix服务器IP地址
ZabbixServer1.Port=10051
#pidFile
OrabbixDaemon.PidFile=./logs/orabbix.pid
#frequency of item's refresh
OrabbixDaemon.Sleep=300
#MaxThreadNumber should be >= than the number of your databases
OrabbixDaemon.MaxThreadNumber=100
#put here your databases in a comma separated list
DatabaseList=Oracle数据库IP地址
#Configuration of Connection pool
#if not specified Orabbis is going to use default values (hardcoded)
#Maximum number of active connection inside pool
DatabaseList.MaxActive=10
#The maximum number of milliseconds that the pool will wait
#(when there are no available connections) for a connection to be returned
#before throwing an exception, or <= 0 to wait indefinitely.
DatabaseList.MaxWait=100
DatabaseList.MaxIdle=1
#define here your connection string for each database
数据库IP地址.Url=jdbc:oracle:thin:@数据库IP地址:1521:SID名
数据库IP地址.User=zabbix
数据库IP地址.Password=zabbix
#Those values are optionals if not specified Orabbix is going to use the general values
数据库IP地址.MaxActive=10
数据库IP地址.MaxWait=100
数据库IP地址.MaxIdle=1
数据库IP地址.QueryListFile=./conf/query.props
五、启动Orabbix服务
service orabbix start
ps -ef | grep orabbix
日志文件/usr/local/orabbix/logs/orabbix.log
六、服务端添加监控
6.1 导入模板
Configuration-->Templates-->Import
6.2 Oracle主机添加监控模板