Zabbix 是一个企业级的分布式开源监控方案。Zabbix 是由Alexei Vladishev创建,目前由Zabbix SIA在持续开发和支持。Zabbix是一款能够监控各种网络参数以及服务器健康性和完整性的软件。Zabbix使用灵活的通知机制,允许用户为几乎任何事件配置基于邮件的告警。这样可以快速反馈服务器的问题。基于已存储的数据,Zabbix提供了出色的报告和数据可视化功能。这些功能使得Zabbix成为容量规划的理想方案。

我是去年开始接触到这款产品,确实为我的工作带来了很大的帮助,下面介绍一下zabbix的详细部署步骤,当时的版本为zabbix3.4。

首先搭建LAMP环境(Linux+Apache+Mysql或者Mariadb+Php)。

1.查看系统环境。

# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core)

2.对系统初始默认源配置文件进行备份。

# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

3.下载阿里源。

#wget –O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

4.生成缓存。

#yum makecache

5.查看yum源。

# yum repolist Loaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.comrepo id repo name status base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 9911 extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 401 updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 1308 repolist: 11620

6.下载yum源配置文件。

# wget -p /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.rep

7.清缓存,然后再创建缓存。

# yum clean all# yum makecache

8.查看epel源加入情况。

# yum repolist Loaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.comrepo id repo name status base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 9911 epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 12660 extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 401 updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 1308 repolist: 24280

9.关闭SELINUX,可以通过vi修改配置文件来修改SELinux的状态或者用sed命令进行修改,此时需要重启才生效,使用命令setenforce 0临时生效。

# sed -i 's#SELINUX=enforcing#SELINUX=disable#g' /etc/sysconfig/selinux# setenforce 0

10.安装Apache。

# yum install httpd –y

11.启动Apache,设置开机启动Apache,设置防火墙对Apache放行,并重启防火墙。

# systemctl start httpd # systemctl enable httpdCreated symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.# firewall-cmd --permanent --add-service=httpsuccess# systemctl restart firewalld

12.打开火狐浏览器输入本服务器IP后回车,这时就应该能看到Apache的页面的,说明Apahce状态正常。




zabbix 什么语言开发的_数据库


13.安装Mariadb数据库。

yum install mariadb-server -y

14.启动数据库,设置开机启动数据库,设置防火墙端口放行,并重启防火墙生效。

# systemctl start mariadb# systemctl enable mariadb Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.# firewall-cmd --permanent --add-port=3306/tcpsuccess# firewall-cmd --reloadsuccess

15.登入数据库查看是否安装正常。

# mysql -u root -pEnter password: Welcome to the MariaDB monitor. Commands end with ; or g.Your MariaDB connection id is 2Server version: 5.5.60-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. MariaDB [(none)]> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || test |+--------------------+4 rows in set (0.00 sec) MariaDB [(none)]> exitBye

16.安装php和php对数据库的支持扩展。

yum install php php-mysql –y

17. 创建编辑一个测试文件对PHP测试。

# cat /var/www/html/testphp.php <?phpphpinfo ();?>

18.重启Apache。

# systemctl restart httpd

19. 在火狐浏览器输入IP/testphp.php回车,将看到php相关信息页面,php测试正常。


zabbix 什么语言开发的_php_02


20.至此LAMP环境搭建完成。

安装zabbix 3.4

1. 安装zabbix需要的软件包。

#yum install mysql-devel gcc net-snmp-devel curl-devel perl-DBI php-gd php-mysql php-bcmath php-mbstring php-xml

- mysql-devel: 开发用到的库以及包含文件;

- gcc:为强制安装的包。即编译器;

- net-snmp-devel:为可选安装包,按需安装。用来支持SNMP监控;

- curl-devel:为可选安装包,但建议安装。用来支持 Web 监控;

- php-gd:PHP GD扩展库必须支持 PNG 图像(--with-png-dir)、JPEG 图像 (--with-jpeg-dir)和FreeType2(--with-freetype-dir);

- php-mysql:使用MySQL作为Zabbix后端数据库所需要的组件;

- php-bcmath:包含所需的bcmath;

- php-mbstring:包含所需的mbstring扩展。

- php-xml:包含所需的libXML、xmlreader和xmlwriter扩展。

2.打开zabbix官网点击Download,选择zabbix server平台操作系统为CentOS,

Version 7 Database MySQL(默认选择)。


zabbix 什么语言开发的_mysql_03


3.安装源码库配置部署包,这个部署包包含了yum配置文件。

#rpm -ivh https://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm

4.安装Zabbix部署包,使用Mysql数据库安装Zabbix server、WEB前端以及Zabbix Agent。

# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent

5.可以安装zabbix sender、get等一些用来测试的组件。

# yum install -y zabbix-get zabbix-java-gateway zabbix-web zabbix-sender

6.关闭mariadb,更改mariadb共享表空间为独立表空间,使用vi修改my.cnf文件,添加“innodb-file-per-table=1”到配置文件,然后重新启动mariadb。

# systemctl stop mariadb# head -5 /etc/my.cnf[mysqld]innodb-file-per-table=1datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security risks # systemctl restart mariadb

7.登入数据库验证功能是否开启。

# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or g.Your MariaDB connection id is 2Server version: 5.5.60-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. MariaDB [(none)]> show variables like '%per_table%'; +-----------------------+-------+| Variable_name | Value |+-----------------------+-------+| innodb_file_per_table | ON |+-----------------------+-------+1 row in set (0.00 sec)

8.创建一个数据库‘zabbix’和数据库用户‘zabbix’,密码为‘zabbix’。

MariaDB [(none)]> create database zabbix character set utf8;Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix';Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges;Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> quit;Bye

9.解压zabbix初始化sql脚本。

# gzip -d /usr/share/doc/zabbix-server-mysql-3.4.12/create.sql.gz

10. zabbix用户登录数据库,切换到zabbix数据库,导入初始化sql脚本。

# mysql -u zabbix -pEnter password: Welcome to the MariaDB monitor. Commands end with ; or g.Your MariaDB connection id is 4Server version: 5.5.60-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. MariaDB [zabbix]> use zabbix;Database changed MariaDB [zabbix]> source /usr/share/doc/zabbix-server-mysql-3.4.12/create.sqlQuery OK, 1 row affected (0.00 sec)MariaDB [zabbix]> show tables;

11.配置zabbix server端并启动。

# vim /etc/zabbix/zabbix_server.conf修改以下内容:DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=zabbix

此处列出可能会经常修改的参数:

ListenPort=10051

#服务器端监听的端口,保持默认即可。

SourceIP=

#通过SourceIP参数可以指定服务端的源IP,当server端有多个IP地址时,我们可以指定服务端使用固定的IP与agent端进行通讯。

LogType=file

#通过LogType参数,可以指定通过哪种方式记录日志,此参数可以设置三种值,system、file、console,system表示将日志发往syslog,file表示使用指定的文件作为日志文件,console表示将日志发往控制台,默认为file。

LogFile=/var/log/zabbix/zabbix_server.log

#当LogType设置为file时,通过LogFile参数设置日志文件位置。

LogFileSize=0

#指明日志文件达到多大时自动滚动,单位为MB,如果设置为50,表示日志大小到达50MB滚动一次,设置为0表示日志文件不会滚动,所有日志保存再一个文件中。

DebugLevel=3

#通过DebugLevel参数可以定义日志的详细程度,即为日志级别。

DBHost=localhost

#通过DBHost参数设置zabbix数据库所在的服务器IP,由于此处zabbix与mysql安装在同一服务器上,所以设置为localhost。

DBName=zabbix

#通过DBName指定zabbix数据库对应的名称。

DBUser=Zabbix

#通过DBUser指定zabbix数据库用户名。

DBPassword=Zabbix

#通过DBPassword指定zabbix数据库用户的密码。

DBPort=3306

#通过DBPort指定zabbix所在数据库服务监听的端口号。

防火墙开放zabbix server端口10051,重启防火墙生效。

# firewall-cmd --permanent --add-port=10051/tcpsuccess# firewall-cmd --reloadsuccess

配置完成启动zabbix server并设置开机启动,启动后,10051端口已经被监听。

# systemctl start zabbix-server# systemctl enable zabbix-server# ss -ntlState Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 50 *:3306 *:* LISTEN 0 5 192.168.122.1:53 *:* LISTEN 0 128 *:22 *:* LISTEN 0 128 127.0.0.1:631 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 *:10051 *:* LISTEN 0 128 :::80 :::*LISTEN 0 128 :::22 :::*LISTEN 0 128 ::1:631 :::*LISTEN 0 128 ::1:25 :::*LISTEN 0 128 :::10051 :::*

12.编辑Zabbix前端的PHP配置。

# cat /etc/httpd/conf.d/zabbix.conf ## Zabbix monitoring system php web frontend# Alias /zabbix /usr/share/zabbix  Options FollowSymLinks AllowOverride None Require all granted   php_value max_execution_time 300 php_value memory_limit 128M php_value post_max_size 16M php_value upload_max_filesize 2M php_value max_input_time 300 php_value max_input_vars 10000 php_value always_populate_raw_post_data -1 # php_value date.timezone Europe/Riga php_value date.timezone Asia/Shanghai #设置时区  Require all granted #可以允许全部可以访问 Require all granted Require all granted Require all granted

13.配置完成,重启httpd服务。

# systemctl restart httpd

14. 登录Zabbix管理页面http://zabbix_webip/zabbix,显示Zabbix安装向导。


zabbix 什么语言开发的_mysql_04


15.第2步zabbix自动检查了安装环境是否满足要求,如果出现不满足要求的情况需要进一步处理,检查全部OK,点击’Nest step’。


zabbix 什么语言开发的_数据库_05


16.第三步zabbix需要配置数据库连接,此处配置数据库的类型、IP、端口、数据库名、用户密码等信息,端口填写0表示使用默认端口(3306端口)。


zabbix 什么语言开发的_php_06


17.第四步填写zabbix server的详细信息,包括IP地址,端口号以及server名称。


zabbix 什么语言开发的_php_07


18.第五步查看安装信息汇总,没有问题,继续安装。


zabbix 什么语言开发的_zabbix 什么语言开发的_08


19.第六步提示初始化配置已经完成,而且提示这些配置信息被保存到了‘/etc/zabbix/web/zabbix.conf.php’配置文件中,如果想要更改刚才的配置,可以通过修改此文件,点击’Finish’进入登陆界面。


zabbix 什么语言开发的_php_09


20.第七步点击完成后,可以看到zabbix的登录页面,默认用户名密码admin/zabbix。


zabbix 什么语言开发的_c++监控mysql是否停止_10


21.第八步登入成功。


zabbix 什么语言开发的_zabbix 什么语言开发的_11


22.设置中文显示界面。

1点击右上角的小人图标,进入个性化设置界面,可以选择各种语言,设置为Chinese(zh_CN)。


zabbix 什么语言开发的_c++监控mysql是否停止_12


2中文显示界面。


zabbix 什么语言开发的_php_13


3图形界面会产生乱码情况。


zabbix 什么语言开发的_zabbix 什么语言开发的_14


4打开windows开始运行,输入fonts(或者控制面板进入字体),回车进入Windows字体目录,找到楷体-常规字体,复制出来,名称为simkai.ttf。


zabbix 什么语言开发的_数据库_15


5将simkai.ttf上传到服务器zabbix字体目录中。

# ls /usr/share/zabbix/fonts/graphfont.ttf simkai.ttf

6vi修改配置文件/usr/share/zabbix/include/defines.inc.php,查找graphfont替换成simkai,一共需替换2处,也可以使用sed命令进行替换。

# sed -i 's#graphfont#simkai#g' /usr/share/zabbix/include/defines.inc.php

7刷新页面中文乱码问题完美解决。


zabbix 什么语言开发的_数据库_16


至此zabbix监控系统安装完成。