zabbix部署(server端)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix部署(server端)相关的知识,希望对你有一定的参考价值。
Linux下常用的系统监控软件有Nagios、Cacti、Zabbix、Monit等,这些开源的软件,可以帮助我们更好的管理机器,在第一时间内发现,并警告系统维护人员。
今天开始研究下Zabbix,使用Zabbix的目的,是为了能够更好的监控mysql数据库服务器,并且能够生成图形报表,虽然Nagios也能够生成图形报表,但没有Zabbix这么强大。
首先,我们先来介绍下Zabblx:
一.Zabbix简介
zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
zabbix由zabbix server与可选组件zabbix agent两部门组成。
zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视。
zabbix agent需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。
zabbix的主要特点:
- 安装与配置简单,学习成本低
- 支持多语言(包括中文)
- 免费开源
- 自动发现服务器与网络设备
- 分布式监视以及WEB集中管理功能
- 可以无agent监视
- 用户安全认证和柔软的授权方式
- 通过WEB界面设置或查看监视结果
- email等通知功能
等等
Zabbix主要功能:
- CPU负荷
- 内存使用
- 磁盘使用
- 网络状况
- 端口监视
- 日志监视
zabbix部署
1.环境说明
环境 | IP | 需要的应用 |
---|---|---|
服务端 | 192.168.24.168 | LAMP zabbix-serverzabbix-agent |
因为zabbix是由php语言开发的,所以要先部署LAMP架构 来支持php网页
2.zabbix安装
安装依赖包
[[email protected] ~]# yum -y install net-snmp-devel libevent-devel
下载zabbix
[[email protected] ~]# cd /usr/src/
[[email protected] src]# wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.12/zabbix-3.4.12.tar.gz
解压
[[email protected] src]# tar xf zabbix-3.4.12.tar.gz
[[email protected] src]# ls
apr-1.6.3 apr-util-1.6.1.tar.bz2 mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz zabbix-3.4.12
apr-1.6.3.tar.bz2 debug php-7.2.8 zabbix-3.4.12.tar.gz
apr-util-1.6.1 kernels php-7.2.8.tar.xz
创建zabbix用户和组
[[email protected] ~]# groupadd -r zabbix
[[email protected] ~]# useradd -r -g zabbix -M -s /sbin/nologin zabbix
配置zabbix数据库
[email protected] ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.22 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;‘ or ‘h‘ for help. Type ‘c‘ to clear the current input statement.
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.01 sec)
mysql> grant all privileges on zabbix.* to [email protected] identified by ‘linfan123‘;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> grant all privileges on zabbix.* to [email protected] identified by ‘linfan123‘;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
mysql> show grants for [email protected];
+------------------------------------------------------------+
| Grants for [email protected] |
+------------------------------------------------------------+
| GRANT USAGE ON *.* TO ‘zabbix‘@‘localhost‘ |
| GRANT ALL PRIVILEGES ON `zabbix`.* TO ‘zabbix‘@‘localhost‘ |
+------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> show grants for [email protected];
+------------------------------------------------------------+
| Grants for [email protected] |
+------------------------------------------------------------+
| GRANT USAGE ON *.* TO ‘zabbix‘@‘127.0.0.1‘ |
| GRANT ALL PRIVILEGES ON `zabbix`.* TO ‘zabbix‘@‘127.0.0.1‘ |
+------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> quit
Bye
[[email protected] ~]# cd /usr/src/zabbix-3.4.12/database/mysql/
[[email protected] mysql]# ls
data.sql images.sql schema.sql
//倒着追加
[[email protected] mysql]# mysql -uzabbix -plinfan123 zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[[email protected] mysql]# mysql -uzabbix -plinfan123 zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[[email protected] mysql]# mysql -uzabbix -plinfan123 zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
编译安装zabbix
[[email protected] ~]# cd /usr/src/zabbix-3.4.12
[[email protected] zabbix-3.4.12]# ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
[[email protected] zabbix-3.4.12]# make install
修改服务端配置文件
设置数据库信息
[[email protected] ~]# ls /usr/local/etc/
zabbix_agentd.conf zabbix_agentd.conf.d zabbix_server.conf zabbix_server.conf.d
[[email protected] ~]# vim /usr/local/etc/zabbix_server.conf
...
...
DBUser=zabbix
### Option: DBPassword
# Database password. Ignored for SQLite.
# Comment this line if no password is used.
#
# Mandatory: no
# Default:
DBPassword=linfan123 搜索‘DBPassword=‘在后面添加设置的zabbix连接密码并取消#号注释
启动zabbix_server和zabbix_agentd服务
[[email protected] ~]# zabbix_server
[[email protected] ~]# ss -natl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:10051 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
[[email protected] ~]# zabbix_agentd
[[email protected] ~]# ss -natl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 *:10051 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
zabbix web界面安装前配置
修改/etc/php.ini的配置并重启php-fpm
[[email protected] ~]# sed -ri ‘s/(post_max_size =).*/1 16M/g‘ /etc/php.ini
[[email protected] ~]# sed -ri ‘s/(max_execution_time =).*/1 300/g‘ /etc/php.ini
[[email protected] ~]# sed -ri ‘s/(max_input_time =).*/1 300/g‘ /etc/php.ini
[[email protected] ~]# sed -i ‘/;date.timezone/a date.timezone = Asia/Shanghai ‘ /etc/php.ini
[[email protected] ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[[email protected] ~]# cd /usr/src/zabbix-3.4.12
[[email protected] zabbix-3.4.12]# ls
aclocal.m4 ChangeLog config.log configure.ac frontends m4 man README
AUTHORS compile config.status COPYING include Makefile misc sass
bin conf config.sub database INSTALL Makefile.am missing src
build config.guess configure depcomp install-sh Makefile.in NEWS upgrades
[[email protected] zabbix-3.4.12]# mkdir /usr/local/apache/htdocs/zabbix
[[email protected] zabbix-3.4.12]# cp -r frontends/php/* /usr/local/apache/htdocs/zabbix/
[[email protected] zabbix-3.4.12]# chown -R apache.apache /usr/local/apache/htdocs
配置apache虚拟主机
在配置文件末尾添加如下内容:
[[email protected] ~]# vim /etc/httpd24/httpd.conf
...
...
</IfModule>
<VirtualHost 192.168.24.168:80>
ServerName zabbix.doudou.com
DocumentRoot "/usr/local/apache/htdocs/zabbix"
ProxyRequests Off
ProxyPassMatch ^/(.*.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix/$1
<Directory "/usr/local/apache/htdocs/zabbix">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
设置zabbix/conf目录的权限,让zabbix有权生成配置文件zabbix.conf.php
[[email protected] ~]# chmod 777 /usr/local/apache/htdocs/zabbix/conf
[[email protected] ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxrwxrwx. 2 apache apache 81 Jul 30 19:41 /usr/local/apache/htdocs/zabbix/conf
重启apache
[[email protected] ~]# apachectl -t
Syntax OK
[[email protected] ~]# apachectl stop
[[email protected] ~]# apachectl start
[[email protected] ~]# ss -nalt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 *:10051 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
安装zabbix web界面
- 恢复zabbix/conf的755权限
[[email protected] ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf
[[email protected] ~]# ll /usr/local/apache/htdocs/zabbix/conf -d
drwxr-xr-x. 2 apache apache 104 Aug 21 15:37 /usr/local/apache/htdocs/zabbix/conf
- 修改/etc/hosts文件,添加域名与IP映射
- 在浏览器上访问域名
以上是关于zabbix部署(server端)的主要内容,如果未能解决你的问题,请参考以下文章