安装Zabbix-Server

安装Zabbix官方源

1
2
rpm -ivh 
http: //repo .zabbix.com /zabbix/2 .4 /rhel/6/x86_64/zabbix-release-2 .4-1.el6.noarch.rpm

安装zabbix服务端(这里安装的是2.4版本)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
yum -y  install  zabbix-server  zabbix-server-mysql  zabbix-agent zabbix-get
 
#修改配置文件:
vi  /etc/zabbix/zabbix_server .conf
DBHost=localhost               
DBName=zabbix                 
DBUser=zabbix                 
DBPassword=zabbix
  
#启动zabbix
/etc/init .d /zabbix-server  start
/etc/init .d /zabbix-agent  start
 
#设置开机启动:
chkconfig zabbix-server on
chkconfig zabbix-agent on

安装php:(默认安装的是5.3版本)

1
2
3
4
5
6
7
8
9
10
yum  install  php php-fpm
 
vim  /etc/php .ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date .timezone = Asia /Shanghai
  
/etc/init .d /php-fpm  start
chkconfig php-fpm on

安装mysql:(默认安装的是5.1版本)

1
2
3
4
5
yum  install  -y mysql mysql-server
 
chkconfig mysqld on     #加入开机启动
 
/etc/init .d /mysqld  start   #启动mysql数据库

 

创建zabbix的数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
mysqladmin -u rootpassword  'mysql'
 
mysql -uroot –pmysql
 
create database zabbixcharacter  set  utf8; 
grant all on zabbix.*to zabbix@localhost identified by  'zabbix' ;
flush privileges;
  
#导入Zabbix-Server数据库:
cd  /usr/share/doc/zabbix-server-mysql-2 .4.8 /create/ 
mysql -uzabbix-pzabbix zabbix <schema.sql     #导入数据结构
mysql -uzabbix -pzabbix zabbix<images.sql     #导入图片
mysql -uzabbix -pzabbix zabbix<data.sql     #导入数据

 

 安装zabbix Client

1
2
rpm-Uvh 
http: //repo .zabbix.com /zabbix/2 .4 /rhel/6/x86_64/zabbix-release-2 .4-1.el6.noarch.rpm

 

安装zabbix agent:

1
yum -y  install  zabbix-agent zabbix-get

编辑配置文件:

1
2
3
4
5
6
sed  -i  's#Server=127.0.0.1#Server=server_ip#g' /etc/zabbix/zabbix_agentd .conf
grepServer=  /etc/zabbix/zabbix_agentd .conf
 
启动zabbix agent:
/etc/init .d /zabbix-agent  start
chkconfig zabbix-agent on

##########################################

1
2
3
4
5
6
7
8
mysql安装遇到的错误:
/usr/bin/mysqladmin : errorwhile loading shared libraries: libmysqlclient.so.16: cannot  open  shared objectfile: No such  file  or directory
解决办法:yum reinstallmysql-libs –y
Zabbix安装以后一直在一地步和第二步之间循环,无法进入第三步。
解决:
mkdir  /var/lib/php/session –p
chown  –Rnginx.nginx  /var/lib/php/session
这样就解决了。

 


使用zabbix监控mysql数据库:

Zabbix官方也自带了MySQL监控模板,但是生产环境推荐使用percona的监控插件。

1
https: //www .percona.com /doc/percona-monitoring-plugins/1 .1 /zabbix/index .html

 

手工添加一台mysql数据库的监控(agent端):

1
2
安装percona仓库:
rpm-ivh http: //www .percona.com /downloads/percona-release/redhat/0 .1-3 /percona-release-0 .1-3.noarch.rpm


部署监控环境:

1
2
3
4
5
yum  install  zabbix22-agent php php-mysql -y
yum  install  percona-zabbix-templates -y          #安装监控模板
vi  /etc/zabbix_agentd .conf
include= /etc/zabbix_agentd .conf.d/
#mkdir /etc/ zabbix_agentd.conf.d/

 

复制模板到该目录下:

1
cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql .conf /etc/zabbix_agentd .conf.d/

 

让php可以连接到mysql上:

1
2
3
4
vim  /var/lib/zabbix/percona/scripts/ss_get_mysql_stats .php.cnf
<?php
$mysql_user= 'root' ;
$mysql_pass= 'password' ;

 

测试并修改监控脚本:

1
2
/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper .sh gg
/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper .shrunning-slave

 

导入zabbix模板:

1
2
3
/var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2 .0.9-sver1.1.6.xml
下载到本地,然后在zabbix上导入
Configuration -> Templates-> Import