【监控系统】Zabbix平台部署

Zabbix 4.0部署环境

Zabbix官网上有教程
http://www.zabbix.com/download
Zabbix源码下载路径
http://jaist.dl.sourceforge.net/project/zabbix

Zabbix监控系统环境部署
host1 192.168.233.201 zabbix-sever
host2 192.168.233.202 zabbix-agent

时间保持一致,并关闭防火墙
[root@host1 ~]# yum install ntp -y ; systemctl start ntpdate ; ntpdate 172.31.100.3
[root@host1 ~]# systemctl stop firewalld ; systemctl disable firewalld
[root@host1 ~]# sed -i ‘s/enforcing/disabled/g’ /etc/selinux/config
[root@host1 ~]# setenforce 0

zabbix-server端
1. 环境部署Zabbix4.0 
[root@host1 ~]# yum -y install httpd php php-gd php-bcmath php-ctype php-xml php-xmlreader php-xmlwriter php-session php-sockets php-mbstring php-gettext php-mysqli

[root@host1 ~]# rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
注意点:会出现您可以尝试添加 --skip-broken 选项来解决该问题,为什么会出现这个问题是因为需要依赖包,包是国外的,下载不了
   
2. 安装zabbix服务器,前端,代理
[root@host1 ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
注意:由于zabbix官网的yum源配置好后,yum安装zabbix一直下载报错:No more mirrors to try.

解决:配置清华大学的yum源,使用清华开源镜像站的rpm包安装zabbix
a. 下载zabbix-server-mysql:
wget https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-server-mysql-4.0.14-1.el7.x86_64.rpm

b. 下载zabbix-web:
wget https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-web-4.0.14-1.el7.noarch.rpm

c. 下载zabbix-web-mysql:
wget https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-web-mysql-4.0.14-1.el7.noarch.rpm

d. 下载zabbix-agent:
wget https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.14-1.el7.x86_64.rpm


安装
注意顺序,使用yum localinstall会自动安装本地rpm包所需的依赖包
安装zabbix-server-mysql:
yum -y localinstall zabbix-server-mysql-4.0.14-1.el7.x86_64.rpm
#如果报错iksemel xxxx 安装iksemel:yum -y install iksemel

安装zabbix-web:
yum -y localinstall zabbix-web-4.0.14-1.el7.noarch.rpm

安装zabbix-web-mysql:
yum -y localinstall zabbix-web-mysql-4.0.14-1.el7.noarch.rpm
表示已将安装了:zabbix-web-mysql-4.0.14-1.el7.noarch.rpm: does not update installed package.

安装zabbix-agent:
yum -y localinstall zabbix-agent-4.0.14-1.el7.x86_64.rpm


3. 配置MySQL数据库(可在server服务器上部署,也可以部署在其他服务器上,给权限就行了)
> create database zabbix character set utf8 collate utf8_bin;
> grant all privileges on zabbix.* to zabbix@'192.168.233.201' identified by 'zabbix';
> flush privileges;

4. 导入zibbix数据库需要的表结构
[root@host1 ~]# cd /usr/share/doc/zabbix-server-mysql-4.0.0/
[root@host1 zabbix-server-mysql-4.0.0]# scp create.sql.gz 192.168.233.202:/tmp/
[root@host2 ~]# gunzip create.sql.gz

5. 将数据导入数据库
[root@host2 tmp]# mysql -uroot -p'root密码' zabbix < create.sql 


6. 将配置文件改成跟下方一样
[root@host1 ~]#  grep ^DB /etc/zabbix/zabbix_server.conf 
DBHost=192.168.251.102          #数据库位置
DBName=zabbix                   #数据库名
DBUser=zabbix                   #数据库授权的用户
DBPassword=zabbix               #数据库授权用户的密码

[root@host1 ~]#  systemctl start zabbix-server ; systemctl enable zabbix-server  


7. 更改时区为中华共和国(PRC)
[root@host1 ~]# vim /etc/httpd/conf.d/zabbix.conf
 php_value date.timezone PRC




8. 设置中文界面(Administration > Users > Admin > Language)
可以看到有乱码(因为前边设置中文导致图形没有适合的字体)
解决乱码问题:
在windos系统的c盘搜索simkai.tff中文楷体,拷贝到zabbix的字体目录
[root@host1 ~]# cp /smb/simkai.ttf /usr/share/zabbix/fonts/
[root@host1 ~]# vim /usr/share/zabbix/include/defines.inc.php 
define('ZBX_GRAPH_FONT_NAME',           'simkai');
define('ZBX_FONT_NAME', 'simkai');



 
9. 设置开机自启动
[root@host1 ~]# systemctl restart zabbix-server zabbix-agent httpd ; systemctl enable zabbix-server zabbix-agent httpd 


10.登录网页输入服务器IP地址/zabbix
Database host:填写实际MySQL服务器地址
port 3306

填写zabbix服务器在什么位置(本机填localhost或者IP地址)
端口10051
随便起个名字 server


默认密码官网上查也有
zabbix4.0: Admin/zabbix


可以修改或不修改 Admin 密码
> select * from zabbix.users where alias='Admin' \G;
> update zabbix.users set passwd=md5('02(glw+zoYQq') where alias='Admin';
> flush privileges;



Zabbix-agent端
[root@host2 ~]# rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
[root@host2 ~]# yum install zabbix-agent -y 
注意:由于zabbix官网的yum源配置好后,yum安装zabbix一直下载报错:No more mirrors to try.

则使用下面命令安装
[root@host2 ~]# wget https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.14-1.el7.x86_64.rpm
安装zabbix-agent:
[root@host2 ~]# yum -y localinstall zabbix-agent-4.0.14-1.el7.x86_64.rpm

[root@host2 ~]# vim /etc/zabbix/zabbix_agentd.conf
Server= 被动模式               #Server端IP地址(自动发现用到)
ServerActive= 主动模式         #Server端IP地址(自动注册用到)
Hostname=host2          #Agent 端的主机名或IP地址(要在服务器上解析,或者用域名系统配置)
UnsafeUserParameters=1        #是否限制用户自定义keys使用特殊字符(0表示限制,1表示不限制)

到这里就已经部署完成
[root@host2 ~]#  systemctl start zabbix-agent ; systemctl enable zabbix-agent




实例测试
安装zabbix-get:在zabbix服务器上测试是否可以获取zabbix-agent上的数据
[root@host1 ~]# yum install zabbix-get -y
注意:由于zabbix官网的yum源配置好后,yum安装zabbix一直下载报错:No more mirrors to try.

下载zabbix-get:
[root@host1 ~]# wget https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-get-4.0.14-1.el7.x86_64.rpm
[root@host1 ~]# yum -y localinstall zabbix-get-4.0.14-1.el7.x86_64.rpm

通信有没有问题,显示的是agent内核操作系统信息
[root@host1 ~]# zabbix_get -s 192.168.233.202 -k system.uname



用户自定义监控项
Zabbix User Parameters
有时候我们想让被监控端执行一个zabbix没有预定义的检测,zabbix的用户自定义参数功能提供了这个方法。我们可以在客户端配置文件zabbix_angentd.conf里面配置UserParameter=起个名,下面命令。

[root@host1 ~]# vim /etc/zabbix/zabbix_agentd.conf
UserParameter=起个名,命令 
例如:UserParameter=ip.addr,ip addr show dev eth0 | egrep "\<inet\>" | awk '{print $2}' |awk -F/ '{print $1}'
[root@host1 ~]# systemctl restart zabbix-agent

服务器端
[root@host1 ~]# zabbix_get -s 192.168.233.202 -k ip.addr
-s 指定监控端IP地址
-k 监控项


监控Nginx状态报告
[root@vm2 ~]# vim /usr/local/nginx/conf/nginx.conf
server {
       listen       8000;
       server_name  localhost;

       location /nginx_status {
                stub_status  on;
                access_log   off;
                allow 127.0.0.1;
                allow 172.29.0.0/16;
                deny  all;
                }
        }


关于nginx的状态页面报告
https://nginx.org/en/docs/http/ngx_http_status_module.html

监控脚本
[root@vm2 ~]# mkdir /etc/zabbix/scripts
[root@vm2 ~]# vim /etc/zabbix/scripts/nginx_status 
#!/bin/bash
function active {
 curl -s "http://127.0.0.1~8000/nginxstatus" | awk '/Active/{print $3}'
}
function reading {
 curl -s "http://127.0.0.1~8000/nginxstatus" | awk '/Reading/{print $2}'
}

case "$1" in
active)
 active
 ;;
reading)
 reading
 ;;
*)
esac

[root@vm2 ~]# chmod +x /etc/zabbix/scripts/nginx_status


将脚本提取的变量加入到zabbix的一个读取文件下*.conf
Include=/etc/zabbix/zabbix_agentd.d/*.conf

[root@vm2 ~]# vim /etc/zabbix/zabbix_agentd.d/userparameter_nginx_status.conf

UserParameter=nginx.accepts,/etc/zabbix/scripts/nginx_status accepts
UserParameter=nginx.handled,/etc/zabbix/scripts/nginx_status handled



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值