zabbix的安装部署

一、zabbix 环境部署:

1、配置IP和主机名、关闭防火墙

[root@localhost ~]# hostnamectl set-hostname zabbix-server

[root@zabbix-server ~]# systemctl stop firewalld

[root@zabbix-server ~]# systemctl disable firewalld

Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@zabbix-server ~]# sed -i 's/=enforcing/=disabled/' /etc/sysconfig/selinux
[root@zabbix-server ~]# sed -i 's/=enforcing/=disabled/' /etc/selinux/config
[root@zabbix-server ~]# setenforce 0

安装常用软件:

[root@zabbix-server ~]# yum install net-tools bash-completion wget vim ntpdate -y

时间同步:

[root@zabbix-server ~]# ntpdate cn.pool.ntp.org

18 Feb 11:15:44 ntpdate[2701]: step time server 185.209.85.222 offset -278.244560 sec
[root@zabbix-server ~]# hwclock -w

准备LAMP环境:

[root@zabbix-server ~]# yum install httpd mariadb mariadb-server php php-mysql php-gd -y

国内 zabbix 源总结 
目前发现的有以下几个站点: 
1.阿里巴巴开源镜像站(推荐使用) 
地址:https://mirrors.aliyun.com/zabbix/ 
2.华为开源镜像站(推荐使用) 
地址:https://mirrors.huaweicloud.com/zabbix/ 
3.清华大学开源软件镜像站 
地址:https://mirror.tuna.tsinghua.edu.cn/zabbix/ 
4.上海大学开源镜像站 
地址:https://mirrors.shu.edu.cn/zabbix/ 
以上几个可根据自身网络情况选择使用

配置 zabbix yum 源
以使用阿里巴巴开源镜像站为例子,介绍如何使用 zabbix 4.0 源

添加源:

[root@zabbix-server yum.repos.d]# cat zabbix.repo 
[zabbix]
name=Zabbix Official Repository - \$basearch 
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/\$basearch/ 
enabled=1 
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 
[zabbix-non-supported] 
name=Zabbix Official Repository non-supported - \$basearch 
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/\$basearch/ 
enabled=1 
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX 
gpgcheck=1 

添加gpgkey:

[root@zabbix-server yum.repos.d]# curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 -o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

[root@zabbix-server yum.repos.d]# curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX -o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX

添加后执行 yum makecache -y

2、安装zabbix server

安装相关软件包:

[root@zabbix-server ~]# yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-agent

[root@zabbix-server ~]# rpm -aq | grep zabbix

修改php时区:

[root@zabbix-server ~]# sed -i 's@# php_value date.timezone Europe/Riga@php_value date.timezone Asia/Shanghai@g' /etc/httpd/conf.d/zabbix.conf

3、数据库设置

启动数据库:

[root@zabbix-server ~]# systemctl start mariadb

[root@zabbix-server ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

创建zabbix数据库及用户:

[root@zabbix-server ~]# mysql -e "create database zabbix character set utf8;"
[root@zabbix-server ~]# mysql -e "grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';"
[root@zabbix-server ~]# mysqladmin flush-privileges

导入数据库:

[root@zabbix-server ~]# cd /usr/share/doc/zabbix-server-mysql-4.0.17/

[root@zabbix-server zabbix-server-mysql-4.0.17]# zcat create.sql.gz | mysql -uzabbix -p zabbix
Enter password:
[root@zabbix-server zabbix-server-mysql-4.0.17]# mysql -uzabbix -p -e 'use zabbix;show tables;'

4、修改zabbix配置文件,修改主要参数即可正常工作:

vim /etc/zabbix/zabbix_server.conf

[root@zabbix-server zabbix-server-mysql-4.0.17]# grep ^DB /etc/zabbix/zabbix_server.conf
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix

5、启动zabbix及apache

[root@zabbix-server ~]# systemctl start zabbix-server.service httpd.service

[root@zabbix-server ~]# systemctl enable zabbix-server.service httpd.service

[root@zabbix-server ~]# netstat -nltup|egrep '80|10051'

tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 3320/zabbix_server
tcp6 0 0 :::80 :::* LISTEN 3318/httpd
tcp6 0 0 :::10051 :::* LISTEN 3320/zabbix_server

6、web 界面安装master

http://192.168.131.139/zabbix/setup.php

前面没有错误的话,nextstep,直到以下页面;

默认登录用户admin;

密码是/etc/zabbix/zabbix_server.conf 中DBPassword=zabbix

1581997470494

成功进入页面:1581997641037

修改密码及语言:

现在用户名是:admin

密码是:123456

注意:登录上去立即修改密码

1581997733354

7、菜单说明

1581998663572

1581998705831

1581998738488

二、监控 Linux 服务器 192.168.131.137

1、Linux 服务器安装agent 代理程序

监控方式很多,比如 snmp、ssh、telent 脚本、agent 等,本例使用 agent 实现监控;

安装常用软件:

[root@localhost ~]# yum install net-tools bash-completion wget vim ntpdate -y

时间同步、配置主机名、关闭防火墙

[root@localhost ~]# ntpdate cn.pool.ntp.org 

[root@localhost ~]# hwclock -w

[root@localhost ~]# hostnamectl set-hostname zabbix-agent
[root@localhost ~]# su -l
Last login: Tue Dec 24 05:28:05 CST 2019 from 192.168.131.1 on pts/1
[root@zabbix-agent ~]# systemctl stop firewalld
[root@zabbix-agent ~]# systemctl disable firewalld 
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@zabbix-agent ~]# sed -i 's/=enforcing/=disabled/' /etc/sysconfig/selinux
[root@zabbix-agent ~]# sed -i 's/=enforcing/=disabled/' /etc/selinux/config 
[root@zabbix-agent ~]#  setenforce 0

2、安装zabbix yum 源

[zabbix] 
name=Zabbix Official Repository - \$basearch 
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/\$basearch/ 
enabled=1 
gpgcheck=1 
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 
[zabbix-non-supported] 
name=Zabbix Official Repository non-supported - \$basearch  
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/\$basearch/ 
enabled=1 
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX 
gpgcheck=1 

添加gpgkey

[root@zabbix-agent ~]# curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 -o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

[root@zabbix-agent ~]# curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX -o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX

添加后 yum makecache -y

3、安装zabbix-agent 并修改配置文件:

[root@zabbix-agent ~]# yum install zabbix-agent.x86_64 -y

Server=192.168.131.139 被动 (zabbix-server 地址)
ServerActive=192.168.131.137 主动
Hostname=zabbix-agnet

4、开启zabbix_agent

[root@zabbix-agent ~]# systemctl start zabbix-agent.service 
[root@zabbix-agent ~]# systemctl enable zabbix-agent.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.

5、查看端口

[root@zabbix-agent ~]# netstat -nltup|grep 10050
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      7715/zabbix_agentd  
tcp6       0      0 :::10050                :::*                    LISTEN      7715/zabbix_agentd  

6、测试zabbix 客户端与zabbix 服务的通信是否正常

注意:以下命令在zabbix-server 端执行:

[root@zabbix-server ~]# yum install zabbix-get.x86_64 -y

[root@zabbix-server ~]# zabbix_get -s 192.168.131.137 -k system.uptime 
4421

三、在 web 界面添加监控主机及设置

1、添加监控主机:

1581999854420

1581999941873

2、创建自定义模板:

1582000010971

3、用户自定义监控:

在客户端配置文件 /etc/zabbix/zabbix_agentd.conf, 里面配置 UserParameter;

语法: UserParameter=key,command 用户自定义参数包含一个 key 和一个命令,key 必须整个系统唯一,配置好之后,重启客户端。
然后配置 item,在 key 的位置填上我们自定义的 key 即可。

例如:监控 Linux 服务器根分区磁盘使用百分比

分析:先在客户端测试命令 
[root@agent1 ~]# df -hP |awk '/\/$/ {print +$(NF-1)}' 
40 

在客户端配置文件添加以下内容,并重启 agent 
[root@zabbix-agent zabbix_agentd.d]#/etc/zabbix/zabbix_agentd.d/disk_root.conf 
UserParameter=Per_of_root,/bin/df -hP | awk '/\/$/ {print +$(NF-1)}' 
[root@zabbix-agent zabbix_agentd.d]# systemctl restart zabbix-agent Zabbix 

服务器端测试: 
[root@Zabbix-server ~]# zabbix_get -s 192.168.131.137 -k Per_of_root 
40 

注意:和 shell 脚本不同的是,名称执行成功返回 1,失败返回 0

如下为灵活的用户自定义参数

UserParameter=key[*],command

参数          描述 
Key          唯一. [*]表示里面可以传递多个参数 
Command      需要执行的脚本, key 的[]里面的参数一一对应$1 到$9,一共 9 个参数。 $0 表 示脚本命令. 

注意事项:
1. 如果需要使用命令行里面出现$2 这种变量,那么你要使用两个$$2,例如 awk ’{ print $$2 }’,之前
   就遇到过这个问题,不停的测试自己脚本输出正常,但是 zabbix 却拿不到数据,原来是出在这里。
   为了防止和参数冲突,所以 zabbix 做了这个规定。 
2. zabbix 禁止使用一些不安全的参数,如下: \ ' ” ` * ? [ ] { } ~ $ ! & ; ( ) < > | # @ 
3. 从 zabbix 2.0 开始,zabbix 返回文本数据可以是空格。 

4、配置自定义监控项:

1582001773662

cpuUsed=top -n 1|awk -F'[, %]+' ' NR==3 {print 100-$11}'
100

top -n 1|awk -F '[, %]+' 'NR==3 {print100-$11}

1582001870809

mail.example.com", SMTP HELO: "example.com", SMTP电邮: "zabbix@example.com

df -h|awk '/^/dev/sda1/{print 1}'

1582006101422

1582008784262

全部评论

相关推荐

06-27 12:54
已编辑
门头沟学院 Java
累了,讲讲我的大学经历吧,目前在家待业。我是一个二本院校软件工程专业。最开始选专业是觉得计算机感兴趣,所以选择了他。本人学习计算机是从大二暑假结束开始的,也就是大三开始。当时每天学习,我个人认为Java以及是我生活的一部分了,就这样持续学习了一年半,来到了大四上学期末,大概是在12月中旬,我终于找的到了一家上海中厂的实习,但我发现实习生的工作很枯燥,公司分配的活也不多,大多时间也是自己在自学。就这样我秋招末才找到实习。时间来到了3月中旬,公司说我可以转正,但是转正工资只有7000,不过很稳定,不加班,双休,因为要回学校参加答辩了,同时当时也是心高气傲,认为可以找到更好的,所以放弃了转正机会,回学校准备论文。准备论文期间就也没有投递简历。然后时间来到了5月中旬,这时春招基本也结束了,然后我开始投递简历,期间只是约到了几家下场面试。工资也只有6-7k,到现在我不知道该怎么办了。已经没有当初学习的心劲了,好累呀,但是又不知道该干什么去。在家就是打游戏,boss简历投一投。每天日重一次。26秋招都说是针对26届的人,25怎么办。我好绝望。要不要参加考公、考研、央国企这些的。有没有大佬可以帮帮我。为什么感觉别人找工作都是顺其自然的事情,我感觉自己每一步都在艰难追赶。八股文背了又忘背了又忘,我每次都花很长时间去理解他,可是现在感觉八股、项目都忘完了。真的已经没有力气再去学习了。图片是我的简历,有没有大哥可以指正一下,或者说我应该走哪条路,有点不想在找工作了。
码客明:太累了就休息一下兄弟,人生不会完蛋的
如果实习可以转正,你会不...
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-04 14:23
steelhead:你回的有问题,让人感觉你就是来学习的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务