Build zabbix monitoring (c) under CentOS7 - Zabbix monitoring service configuration Mysql binary packages installed

Zabbix monitoring structures (a) under CentOS7 - Zabbix monitoring terminal configuration

CentOS7 zabbix monitoring structures (ii) the - Zabbix monitoring terminal is configured

(1) Configure Apache Zabbix Monitoring Service

  Host Name: youxi2 IP address: 192.168.5.102

  Note: You need to find a suitable template Apache monitoring

 1) installed httpd, yum directly here in order to simplify the installation steps

[root@youxi2 ~]# yum -y install httpd
[root@youxi2 ~]# systemctl enable httpd  //设置开机自启
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

 2) Open the Apache server-status, and restart httpd

[youxi2 the root @ ~] # Vim /etc/httpd/conf/httpd.conf 
EnableSendfile ON // this is the first line 348, add the following tag line below 
<LOCATION / Server-Status> 
  SetHandler-Server Status 
  the Order the allow, the deny 
  localhost 192.168.5.0/24 from the Allow 
</ LOCATION> 
[youxi2 the root @ ~] # systemctl the restart the httpd

  You can also create a .conf file format in /etc/httpd/conf.d/ directory, which will write the configuration. The final restart httpd.

  Note: Sometimes 127.0.0.1 does not take effect will lead to zapache does not support, IP address can be changed all attempts.

 3) If the firewall is turned on, remember to add the port number

[root@youxi2 ~]# firewall-cmd --permanent --zone=public --add-port=80/tcp
success
[root@youxi2 ~]# firewall-cmd --reload 
success
[root@youxi2 ~]# firewall-cmd --permanent --zone=public --list-ports
10050/tcp 80/tcp

 4) Web open Apache server-status verification

 5) Download the template file

  Each template files need to leave a copy on Windows and CentOS, address: https://github.com/lorf/zapache/archive/master.zip . Then extract

  Since the downloaded zip file format, you need to unzip program

[root@youxi2 ~]# yum -y install unzip

  After the installation is complete, unzip the file

[root@youxi2 ~]# unzip zapache-master.zip 
Archive:  zapache-master.zip
24a764b2e224f9b8d0a6bc94dcadd7568b2fe650
   creating: zapache-master/
  inflating: zapache-master/README.md  
  inflating: zapache-master/httpd-server-status.conf.sample  
  inflating: zapache-master/userparameter_zapache.conf.sample  
  inflating: zapache-master/zapache  
  inflating: zapache-master/zapache-template-active.xml  
  inflating: zapache-master/zapache-template.xml
[root@youxi2 ~]# ls zapache-master/
httpd-server-status.conf.sample    zapache
README.md                          zapache-template-active.xml
userparameter_zapache.conf.sample  zapache-template.xml

  File Description:

   httpd-server-status.conf.sample opening for configuring httpd server-status

   zapache, userparameter_zapache.conf.sample critical scripts and configuration files

   zapache-template-active.xml, zapache-template.xml template file (active is an action, a trigger template)

 6) modify the configuration files and scripts

[root @ youxi2 ~] # cp zapache-master / zapache / usr / local / bin / // copy script 
[root @ youxi2 ~] # chmod + x / usr / local / bin / zapache // execute permission to the script 
[ root @ youxi2 ~] # cp zapache -master / userparameter_zapache.conf.sample /usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_zapache.conf // copy the configuration file, rename 
[root @ youxi2 ~] # vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_zapache.conf 
UserParameter = zapache [*], / usr / local / bin / zapache \ $ 1 // points to a script file 
[root @ youxi2 ~] # vim / usr /local/zabbix/etc/zabbix_agentd.conf 
# the Include = / usr / local / etc / zabbix_agentd.userparams.conf // 263 to 265 lines 
Include = / usr / local / zabbix / etc / zabbix_agentd.conf.d / / / remove comments, modify and enable the catalog 
# Include = / usr / local / etc / zabbix_agentd.conf.d / *. conf

 7) Web end Import Template

   A. Select the template configuration, click Import

   B. Select Import File, click Import, successfully import the template of.

 8)Web端关联模板(给现有的主机添加新的模板)

   A.选择配置中的主机,点击任意主机名称

   B.选择模板,选中Template App Apache Web Server zapache模板,添加并更新

   C.之后可以在监测的图形中选择Apache相关检测项

    也可以在监测中的最新数据选择Apache相关监控项构成图形

(2).配置Zabbix监控Mysql服务

  主机:youxi2  IP地址:192.168.5.102

  和Apache一样需要先找一个监控模板,不过Zabbix默认提供了Mysql的监控模板。

 1)安装Mysql

  具体查看:二进制包安装Mysql

  mysql安装目录/usr/local/mysql/,数据目录/usr/local/mysql/data/,mysql的root用户密码为123456。启动并设置开机自启。

 2)数据库用户授权

   创建用户和授予usage权限是一样的效果。

[root@youxi2 ~]# mysql -uroot -p123456
mysql> create user 'zabbix'@'192.168.5.%' identified by '123456';  //创建用户zabbix
Query OK, 0 rows affected (0.00 sec)

mysql> show grants for 'zabbix'@'192.168.5.%';  //查看用户zabbix的权限
+----------------------------------------------+
| Grants for [email protected].%                |
+----------------------------------------------+
| GRANT USAGE ON *.* TO 'zabbix'@'192.168.5.%' |  //usage表示只有登录和查询information_schema的权限
+----------------------------------------------+
1 row in set (0.00 sec)

mysql> grant usage on *.* to 'zabbix2'@'192.168.5.%' identified by '123456';  //授权zabbix2
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show grants for 'zabbix2'@'192.168.5.%';  //查看用户zabbix2的权限
+-----------------------------------------------+
| Grants for [email protected].%                |
+-----------------------------------------------+
| GRANT USAGE ON *.* TO 'zabbix2'@'192.168.5.%' |
+-----------------------------------------------+
1 row in set (0.00 sec)

mysql> flush privileges;  //刷新
Query OK, 0 rows affected (0.00 sec)

 3)修改配置文件,并重启Zabbix Agent

[root@youxi2 ~]# cp /usr/local/src/zabbix-3.4.3/conf/zabbix_agentd/userparameter_mysql.conf /usr/local/zabbix/etc/zabbix_agentd.conf.d/
[root@youxi2 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_mysql.conf  //HOME参数的路径必须与下方编辑的.my.cnf路径必须一致
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/usr/local/zabbix/etc mysql -N | awk '{print $$2}'  //第5行
UserParameter=mysql.size[*],bash -c 'echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";;
 esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema=\"$1\"")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name=\"$2\"");"
 | HOME=/usr/local/zabbix/etc/ mysql -N'  //第15行
UserParameter=mysql.ping,HOME=/usr/local/zabbix/etc mysqladmin ping | grep -c alive  //第17行
[root@youxi2 ~]# vim /usr/local/zabbix/etc/.my.cnf  //配置数据库与zabbix连接文件。与上方userparameter_mysql.conf修改路径保持一致
#Zabbix Agent
[mysql]
host=localhost
user=zabbix
password=123456
socket=/usr/local/mysql/mysql.sock

[mysqladmin]
host=localhost
user=zabbix
password=123456
socket=/usr/local/mysql/mysql.sock
[root@youxi2 ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
# Include=/usr/local/etc/zabbix_agentd.userparams.conf  //第263~265行,三个里面有且仅有一个开启
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/  //去除注释,修改并启用该目录
# Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf
[root@youxi2 ~]# /etc/init.d/zabbix_agentd restart  //重启 Restarting zabbix_agentd (via systemctl): [ 确定 ]

 4)在监控端测试

  如果提示如下错误,需要到被监控端(youxi2)将mysql和mysqladmin做一个软链接到/usr/bin下(明明有环境变量,也可以在youxi2上直接调用,但它就不认)

[root@youxi1 ~]# /usr/local/zabbix/bin/zabbix_get -s192.168.5.102 -p10050 -k mysql.status[Uptime]
sh: mysql: 未找到命令
[root@youxi1 ~]# /usr/local/zabbix/bin/zabbix_get -s192.168.5.102 -p10050 -k mysql.ping
sh: mysqladmin: 未找到命令

  做一个软链接

[root@youxi2 ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/
[root@youxi2 ~]# ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/ 

  再次测试成功

[root@youxi1 ~]# /usr/local/zabbix/bin/zabbix_get -s192.168.5.102 -p10050 -k mysql.status[Uptime]
414
[root@youxi1 ~]# /usr/local/zabbix/bin/zabbix_get -s192.168.5.102 -p10050 -k mysql.ping
1

 5)Web端关联模板

  A.选择配置中的主机,点击任意主机名称

  B.选择模板,选中Template DB MySQL模板,添加并更新

  C.之后就可以在监测中查看了。

Guess you like

Origin www.cnblogs.com/diantong/p/11139790.html