centos7 安装zabbix 服务端 和 客户端

一、zabbix 服务器端安装
1. 安装源码库配置部署包。这个部署包包含了yum配置文件。
 #rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.centos.noarch.rpm
2.安装mysql服务
      # yum install zabbix-server-mysql zabbix-web-mysql
 
3.安装MySQL
      # wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
 
      # rpm -ivh mysql-community-release-el7-5.noarch.rpm
 
      #  yum install mysql-server
 
       重置密码
      mysql -u root
      use mysql
      update user set password=password('hqgf2017') where user='root';
 
      创建zabbix数据库
      create database zabbix character set utf8 collate utf8_bin;
      grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
      
      导入zabbix数据表
      zcat /usr/share/doc/zabbix-server-mysql-3.4.1/create.sql.gz | mysql -uzabbix -p zabbix
 
4. 编辑zabbix_server.conf使用创建的数据库 
       # vi /etc/zabbix/zabbix_server.conf
DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=
 
5. 设置 启动Zabbix服务器进程并在系统启动时启动
# systemctl start zabbix-server # systemctl enable zabbix-server # systemctl start httpd.service
 
6. 浏览器访问:http://localhost/zabbix/  初始用户:Admin 密码:zabbix
 
二、本机 zabbix 客户端安装配置
1.#    yum install zabbix-agent
 
2.  配置文件: vi/etc/zabbix/zabbix_agentd.conf
#主动模式
    ServerActive=172.88.10.250
#主动模式
Server=172.88.10.250
3. 启动客户端 
# service zabbix-agent start
 
三、zabbix 运程客户端安装配置
1. #rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.centos.noarch.rpm
 
2.#    yum install zabbix-agent
 
3.  配置文件: vi/etc/zabbix/zabbix_agentd.conf
#主动模式
    ServerActive=172.88.10.250
#主动模式
Server=172.88.10.250
4. 启动客户端 
# service zabbix-agent start
 
 
四、zabbix 监控mysql
1.添加mysql 模板
 
2.添加zabbix mysql监控脚本 ch_mysql.sh 如下:
#!/bin/bash
case $1 in
Uptime)
result=`/usr/local/mysql/bin/mysqladmin -hlocalhost status|cut -f2 -d":"|cut -f1 -d"T"`
echo $result
;;
Com_update)
result=`/usr/local/mysql/bin/mysqladmin -hlocalhost extended-status |grep -w "Com_update"|cut -d"|" -f3`
echo $result
;;
Slow_queries)
result=`/usr/local/mysql/bin/mysqladmin -hlocalhost status |cut -f5 -d":"|cut -f1 -d"O"`
echo $result
;;
Com_select)
result=`/usr/local/mysql/bin/mysqladmin -hlocalhost extended-status |grep -w "Com_select"|cut -d"|" -f3`
echo $result
;;
Com_rollback)
result=`/usr/local/mysql/bin/mysqladmin -hlocalhost extended-status |grep -w "Com_rollback"|cut -d"|" -f3`
echo $result
;;
Questions)
result=`/usr/local/mysql/bin/mysqladmin -hlocalhost status|cut -f4 -d":"|cut -f1 -d"S"`
echo $result
;;
Com_insert)
result=`/usr/local/mysql/bin/mysqladmin -hlocalhost extended-status |grep -w "Com_insert"|cut -d"|" -f3`
echo $result
;;
Com_delete)
result=`/usr/local/mysql/bin/mysqladmin -hlocalhost extended-status |grep -w "Com_delete"|cut -d"|" -f3`
echo $result
;;
Com_commit)
result=`/usr/local/mysql/bin/mysqladmin -hlocalhost extended-status |grep -w "Com_commit"|cut -d"|" -f3`
echo $result
;;
Bytes_sent)
result=`/usr/local/mysql/bin/mysqladmin -hlocalhost extended-status |grep -w "Bytes_sent" |cut -d"|" -f3`
echo $result
;;
Bytes_received)
result=`/usr/local/mysql/bin/mysqladmin -hlocalhost extended-status |grep -w "Bytes_received" |cut -d"|" -f3`
echo $result
;;
Com_begin)
result=`/usr/local/mysql/bin/mysqladmin -hlocalhost extended-status |grep -w "Com_begin"|cut -d"|" -f3`
echo $result
;;
 
*)
echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)"
;;
esac
 
3.修改zabbix_agentd.conf 配置文件添加如下行:
UnsafeUserParameters=1
UserParameter=mysql.status[*],HOME=/etc/zabbix /etc/zabbix/chk_mysql.sh $1
UserParameter=mysql.ping,HOME=/etc/zabbix /usr/local/mysql/bin/mysqladmin -P3306 - h172.69.1.238 ping | grep -c alive
UserParameter=mysql.version,mysql -V
 
4. mysql添加zabbix 用户访问权限
# grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
#grant all privileges on zabbix.* to [email protected] identified by 'zabbix';
# flush privileges;
 
5.重启客户端
service zabbix-agent restart
 
五、zabbix 监控Nginx
1.添加 nginx 模板 zbx_export_templates .xml 如下:
3.4
2017-10-18T05:56:50Z
Custom Templates
Templates
{Service Nginx:proc.num[nginx].last(#2)}=0
0
Nginx not running
0
0
3
The nginx process seems to be stopped
0
0
Nginx status
900
200
0.0000
100.0000
0
0
0
1
0
0.0000
0.0000
0
0
0
0
0
0
009900
0
2
0
Service Nginx
custom.nginx.accepts
1
0
0000BB
0
2
0
Service Nginx
custom.nginx.requests
2
0
BB0000
0
2
0
Service Nginx
custom.nginx.handled
3
4
009900
0
2
0
Service Nginx
custom.nginx.connections.active
4
4
BBBB00
0
2
0
Service Nginx
custom.nginx.connections.writing
5
4
0000BB
0
2
0
Service Nginx
custom.nginx.connections.waiting
6
4
BB0000
0
2
0
Service Nginx
custom.nginx.connections.reading
 
2.添加nginx模板
 
3.添加ngx_status.sh 如下
 
#!/bin/bash
# Script to fetch nginx statuses for tribily monitoring systems
# Author: [email protected]
# License: GPLv2
 
# Set Variables
HOST="172.69.1.238"
PORT="88"
 
# Functions to return nginx stats
 
function active {
curl -s "http://$HOST:$PORT/nginx-status" | grep 'Active' | awk '{print $NF}'
}
 
function reading {
curl -s "http://$HOST:$PORT/nginx-status" | grep 'Reading' | awk '{print $2}'
}
 
function writing {
curl -s "http://$HOST:$PORT/nginx-status" | grep 'Writing' | awk '{print $4}'
}
 
function waiting {
curl -s "http://$HOST:$PORT/nginx-status" | grep 'Waiting' | awk '{print $6}'
}
 
function accepts {
curl -s "http://$HOST:$PORT/nginx-status" | awk NR==3 | awk '{print $1}'
}
 
function handled {
curl -s "http://$HOST:$PORT/nginx-status" | awk NR==3 | awk '{print $2}'
}
 
function requests {
curl -s "http://$HOST:$PORT/nginx-status" | awk NR==3 | awk '{print $3}'
}
 
# Run the requested function
$1
 
4.修改zabbix_agentd.conf文件,添加如下行:
UserParameter=custom.nginx.status[*],HOME=/etc/zabbix/ngx_status.sh $1
UserParameter=custom.nginx.accepts,/etc/zabbix/ngx_status.sh accepts
UserParameter=custom.nginx.handled,/etc/zabbix/ngx_status.sh handled
UserParameter=custom.nginx.requests,/etc/zabbix/ngx_status.sh requests
UserParameter=custom.nginx.connections.active,/etc/zabbix/ngx_status.sh active
UserParameter=custom.nginx.connections.reading,/etc/zabbix/ngx_status.sh reading
UserParameter=custom.nginx.connections.writing,/etc/zabbix/ngx_status.sh writing
UserParameter=custom.nginx.connections.waiting,/etc/zabbix/ngx_status.sh waiting
 
5.重启客户端
service zabbix-agent restart
6.添加/usr/local/nginx/conf.d/stubstatus.conf 如下:
server {
listen *:88 default_server;
server_name _;
location /nginx-status
{
stub_status on;
access_log off;
#allow 127.0.0.1;
#deny all;
}
}
 
 
六、zabbix 启用jmx 监控tomcat
1. 安装  zabbix-java-gateway
yum install -y java java-devel zabbix-java-gateway
 
2. 修改zabbix server 主机 /etc/zabbix/etc/zabbix_server.conf文件 添加以下两行
 
       JavaGateway=172.16.2.150 #gateway地址
       StartJavaPollers=5  #预启动进程轮训个数
 
3.添加jmx jar包到tomcat lib目录下
tomcat-redis-session-manager-T9.jar
 
4.vim /application/tomcat/bin/catalina.sh #tomcat的远程调用脚本添加以下行
 export CATALINA_OPTS="$CATALINA_OPTS
      -Dcom.sun.management.jmxremote
      -Dcom.sun.management.jmxremote.port=12345
      -Dcom.sun.management.jmxremote.ssl=false
      -Dcom.sun.management.jmxremote.authenticate=false
      -Djava.rmi.server.hostname=172.69.1.238"
 
5. 启动zabbix java 网关
systemctl start zabbix-java-gateway.service
 
 
6.重启客户端
service zabbix-agent restart
 

 

你可能感兴趣的:(运维技术要点)