Zabbix安装配置(一)

第1章 系统环境

  • CentOS 6
[root@centos6 ~]# cat /etc/redhat-release
CentOS release 6.9 (Final)
[root@centos6 ~]# uname -r
2.6.32-696.el6.x86_64
[root@centos6 ~]# hostname -I
10.0.0.61 172.16.1.61
[root@centos6 ~]# getenforce
Disabled
[root@centos6 ~]# /etc/init.d/iptables status
iptables: Firewall is not running.
[root@centos6 ~]# ll -d /tmp
drwxrwxrwt. 3 root root 4096 Oct 10 09:17 /tmp
  • CentOS 7
[root@centos7 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@centos7 ~]# uname -r
3.10.0-327.el7.x86_64
[root@centos7 ~]# hostname -I
10.0.0.210 172.16.1.210
[root@centos7 ~]# getenforce
Disabled
[root@centos7 ~]# systemctl status
● firewalldfirewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
[root@centos7 ~]# ll -d /tmp
drwxrwxrwt 5 root root 120 Oct 28 01:29 /tmp

第2章 YUM安装zabbix3.0

Zabbix 3.0 LTS (stable):Long Term Support(长时间支持版本)

提示:zabbix软件下载地址:https://pan.baidu.com/s/1qYw4V2s

2.1 服务端安装

2.1.1 在线yum安装

2.1.1.1 安装zabbix源:

  • CentOS 6
[root@centos6 ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
  • CentOS 7
[root@centos7 ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm

2.1.1.2 安装apache、mysql和zabbix

  • CentOS 6
[root@centos6 ~]# yum install -y httpd mysql-server zabbix-get zabbix-web zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-java-gateway net-snmp net-snmp-utils
  • CentOS 7
[root@centos7 ~]# yum install -y httpd mariadb-server zabbix-get zabbix-web zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-java-gateway net-snmp net-snmp-utils

2.1.1.3 安装PHP源(PHP版本需要5.4版本以上)

  • CentOS 6
[root@centos6 ~]# rpm -ivh http://repo.webtatic.com/yum/el6/x86_64/webtatic-release-6-9.noarch.rpm
  • CentOS 7
[root@centos7 ~]# rpm -Uvh http://mirror.webtatic.com/yum/el7/epel-release.rpm
[root@centos7 ~]# rpm -Uvh http://mirror.webtatic.com/yum/el7/webtatic-release.rpm
提示:repo文件的网址是https,如果https网站访问不了,使用sed将https替换为http即可。

2.1.1.4 卸载已经安装的低版本的PHP

[root@centos ~]# yum remove -y php*

2.1.1.5 安装高版本的PHP

[root@centos ~]# yum install -y php55w php55w-mysql php55w-common php55w-gd php55w-mbstring php55w-mcrypt php55w-devel php55w-xml php55w-bcmath php55w-ldap

2.1.2 离线yum安装

2.1.2.1 设置保留yum缓存

[root@centos ~]# vim /etc/yum.conf
keepcache=1 # 更改此项为1,开启保存缓存项

2.1.2.2 解压离线yum缓存包

[root@centos ~]# cd /server/tools/
# 解压时必须使用P参数保证解压文件按照压缩包内的绝对路径解压
[root@centos tools]# tar xfP zabbix-3.0.12-e7_yum.tar.gz

2.1.2.3 安装LAMP环境

  • CentOS 6
[root@centos6 ~]# yum --nogpgcheck -C install -y httpd mysql-server php55w php55w-mysql php55w-common php55w-gd php55w-mbstring php55w-mcrypt php55w-devel php55w-xml php55w-bcmath
  • CentOS 7
[root@centos7 ~]# yum --nogpgcheck -C install -y httpd mariadb-server php55w php55w-mysql php55w-common php55w-gd php55w-mbstring php55w-mcrypt php55w-devel php55w-xml php55w-bcmath
  • 命令说明:
  1. –nogpgcheck:取消对rpm的完整性进行校验
  2. -C:离线安装rpm包,不从网络下载

2.1.2.4 安装zabbix

[root@centos ~]# yum --nogpgcheck -C install -y zabbix-web zabbix-server-mysql zabbix-web-mysql zabbix-get zabbix-java-gateway net-snmp net-snmp-utils wqy-microhei-fonts
  • 必装软件包:
  1. zabbix-web
  2. zabbix-server-mysql
  3. zabbix-web-mysql
  4. zabbix-get
  • 提前安装的rpm包:
  1. zabbix-java-gateway:监控tomcat需要的包
  2. wqy-microhei-fonts: 解决中文乱码的包
  3. net-snmp net-snmp-utils:snmp服务安装包

2.1.3 配置MySQL

2.1.3.1 复制配置文件

[root@centos ~]# \cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

2.1.3.2 启动MySQL

  • CentOS 6
[root@centos6 ~]# /etc/init.d/mysqld start
  • CentOS 7
[root@centos7 ~]# systemctl start mariadb.service

2.1.3.3 创建用户并授权

[root@centos ~]# mysql
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@'172.16.1.%' identified by 'zabbix';
mysql> flush privileges;
mysql> quit

2.1.4 导入数据文件

[root@centos ~]# cd /usr/share/doc/zabbix-server-mysql-3.0.12/
# 需根据数据库内zabbix用户授权主机网段通过-h参数连接数据库,若zabbix@'localhost'则不需要-h参数
[root@centos zabbix-server-mysql-3.0.12]# zcat create.sql.gz | mysql -uzabbix -pzabbix -h 172.16.1.61 zabbix

2.1.5 相关数据修改

2.1.5.1 修改PHP配置文件:

[root@centos ~]# sed -i 's#max_execution_time = 30#max_execution_time = 300#;s#max_input_time = 60#max_input_time = 300#;s#post_max_size = 8M#post_max_size = 16M#;910a date.timezone = Asia/Shanghai' /etc/php.ini

2.1.5.2 修改zabbix_server配置文件:

[root@centos ~]# sed -i '115a DBPassword=zabbix' /etc/zabbix/zabbix_server.conf
# 需根据数据库内zabbix用户授权主机网段设置此处主机IP地址,若zabbix@'localhost'则保持默认即可
[root@centos ~]# sed -i '81a DBHost=172.16.1.61' /etc/zabbix/zabbix_server.conf

2.1.6 复制网页文件

[root@centos ~]# cp -R /usr/share/zabbix/ /var/www/html/

2.1.7 网页文件授权

[root@centos ~]# chmod -R 755 /etc/zabbix/web
[root@centos ~]# chown -R apache.apache /etc/zabbix/web

2.1.8 启动zabbix和apache

# 配置服务主机地址,防止启动服务的时候出现警告信息
[root@centos ~]# echo "ServerName 127.0.0.1:80">>/etc/httpd/conf/httpd.conf
  • CentOS 6
[root@centos6 ~]# /etc/init.d/httpd start
[root@centos6 ~]# /etc/init.d/zabbix-server start
  • CentOS 7
[root@centos7 ~]# systemctl start httpd
[root@centos7 ~]# systemctl start zabbix-server.service
提示:此处不需要单独启动PHP,因为在LAMP架构中的php是apache的一个模块,不需要单独启动php服务,只需要启动http即可;而在LNMP架构中的php是单独的一个服务用来开启9000端口,所以需要单独启动服务。

2.1.9 添加开机自启动

  • CentOS 6
[root@centos6 ~]# chkconfig mysqld on
[root@centos6 ~]# chkconfig httpd on
[root@centos6 ~]# chkconfig zabbix-server on
[root@centos6 ~]# chkconfig zabbix-agent on
  • CentOS 7
[root@centos7 ~]# systemctl enable mariadb.service
[root@centos7 ~]# systemctl enable httpd
[root@centos7 ~]# systemctl enable zabbix-server.service
[root@centos7 ~]# systemctl enable zabbix-agent.service
注意:必须先启动mysql再启动apache和zabbix server。

2.2 网页配置

2.2.1 通过网页设置配置文件

图片[1]|Zabbix安装配置(一)|leon的博客

图片[2]|Zabbix安装配置(一)|leon的博客 图片[3]|Zabbix安装配置(一)|leon的博客 图片[4]|Zabbix安装配置(一)|leon的博客 图片[5]|Zabbix安装配置(一)|leon的博客 图片[6]|Zabbix安装配置(一)|leon的博客

2.2.2 手动编辑配置文件

[root@centos ~]# vim /etc/zabbix/web/zabbix.conf.php
< php
// Zabbix GUI configuration file.
global $DB;

$DB['TYPE'] = 'MYSQL';
$DB['SERVER'] = '172.16.1.61';
$DB['PORT'] = '0';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'zabbix';
$DB['PASSWORD'] = 'zabbix';

// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';

$ZBX_SERVER = '172.16.1.61';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = '监控服务器';

$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;

2.3 登陆zabbix

图片[7]|Zabbix安装配置(一)|leon的博客

2.4 中文配置

图片[8]|Zabbix安装配置(一)|leon的博客 图片[9]|Zabbix安装配置(一)|leon的博客

2.5 zabbix agent 客户端安装使用

2.5.1 在线yum安装

2.5.1.1 安装zabbix源

  • CentOS 6
[root@centos6 ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
  • CentOS 7
[root@centos7 ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm

2.5.1.2 安装zabbix-agent

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

2.5.2 在线阿里云yum安装

  • CentOS 6
[root@centos6 ~]# yum localinstall -y http://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/6/x86_64/zabbix-agent-3.0.12-1.el6.x86_64.rpm
  • CentOS 7
[root@centos7 ~]# yum localinstall -y http://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/7/x86_64/zabbix-agent-3.0.12-1.el7.x86_64.rpm

2.5.3 离线rpm安装

2.5.3.1 下载安装包

  • CentOS 6
[root@centos6 ~]# wget -O /server/tools/zabbix-agent-3.0.12-1.el6.x86_64.rpm http://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/6/x86_64/zabbix-agent-3.0.12-1.el6.x86_64.rpm
  • CentOS 7
[root@centos7 ~]# wget -O /server/tools/zabbix-agent-3.0.12-1.el7.x86_64.rpm http://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/7/x86_64/zabbix-agent-3.0.12-1.el7.x86_64.rpm

2.5.3.2 rpm离线安装

  • CentOS 6
[root@centos6 ~]# rpm -ivh /server/tools/zabbix-agent-3.0.12-1.el6.x86_64.rpm
  • CentOS 7
[root@centos7 ~]# rpm -ivh /server/tools/zabbix-agent-3.0.12-1.el7.x86_64.rpm
  • 命令说明:
  1. -i:(install)安装
  2. -v:显示安装过程
  3. -h:显示进度条

2.5.4 配置客户端文件

  • yum安装:
[root@centos ~]# sed -i.bak "95s#^Server=.*#Server=172.16.1.61#;136s#^ServerActive=.*#ServerActive=172.16.1.61#;147s#^Hostname=.*#Hostname=`hostname`#" /etc/zabbix/zabbix_agentd.conf
  • 编译安装:
[root@centos zabbix-3.4.1]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
261 Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/ #指定客户端的配置文件目录
提示:agent的配置支持Server=127.0.0.1,172.16.1.61,10.0.0.61这种写法,用于配置多个服务端。

2.5.5 启动客户端服务

  • CentOS 6
[root@centos6 ~]# /etc/init.d/zabbix-agent start
  • CentOS 7
[root@centos7 ~]# systemctl start zabbix-agent

2.5.6 添加开机自启动

  • CentOS 6
[root@centos6 ~]# chkconfig zabbix-agent on
  • CentOS 7
[root@centos7 ~]# systemctl enable zabbix-agent

2.5.7 测试连通性

[root@centos ~]# zabbix_get -s 172.16.1.8 -p 10050 -k "system.cpu.load[all,avg1]"
0.000000 # 有数据表示连接正常
[root@centos ~]# zabbix_get -s 172.16.1.61 -p 10050 -k "system.cpu.load[all,avg1]"
0.020000 # 有数据表示连接正常

2.6 Windows安装客户端

2.6.1  编辑配置文件

参看2.5.4配置参数

2.6.2  安装agent

C:\Users\Administrator>"C:\Program Files\zabbix_agents_3.0.10.win\bin\win64\zabbix_agentd.exe" -c "C:\Program Files\zabbix_agents_3.0.10.win\conf\zabbix_agentd.win.conf" -i

2.6.3  启动agent服务

C:\Users\Administrator>"C:\Program Files\zabbix_agents_3.0.10.win\bin\win64\zabbix_agentd.exe" -c "C:\Program Files\zabbix_agents_3.0.10.win\conf\zabbix_agentd.win.conf" -s
  • 参数详解:
  1. -c –config config-file:指定配置文件位置
  2. -i –install:安装zabbix agent
  3. -d –uninstall:卸载zabbix agent
  4. -s –start:启动zabbix agent服务
  5. -x –stop:停止zabbix agent服务
温馨提示:本文最后更新于2022-12-20 20:57:49,已超过493天没有更新。某些文章具有时效性,若文章内容或图片资源有错误或已失效,请联系站长。谢谢!
转载请注明本文链接:https://blog.leonshadow.cn/763482/926.html
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享