文章目录
1. zabbix介绍
zabbix(音同 za:bix)是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
zabbix由2部分构成,zabbix server与可选组件zabbix agent。
zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。
2. zabbix特点
zabbix的主要特点:
- 安装与配置简单,学习成本低
- 支持多语言(包括中文)
- 免费开源
- 自动发现服务器与网络设备
- 分布式监视以及WEB集中管理功能
- 可以无agent监视
- 用户安全认证和柔软的授权方式
- 通过WEB界面设置或查看监视结果
- email等通知功能
Zabbix主要功能:
- CPU负荷
- 内存使用
- 磁盘使用
- 网络状况
- 端口监视
- 日志监视
3. zabbix配置文件
zabbix配置文件有两种:
- 服务器端配置文件(/usr/local/etc/zabbix_server.conf)
- 客户端配置文件(/usr/local/etc/zabbix_agentd.conf)
- zabbix代理配置文件(/usr/local/etc/zabbix_proxy.conf)
服务器端配置文件zabbix_server.conf常用配置参数:
参数 | 作用 |
---|---|
LogFile | 设置服务端日志文件存放路径 |
ListenIP | 设置服务端监听IP |
ListenPort | 设置服务端监听的端口号 |
PidFile | 设置服务端进程号文件存放路径 |
DBHost | 指定zabbix的数据库服务器IP |
DBName | 指定zabbix使用的数据库库名 |
DBUser | 指定zabbix数据库登录用户 |
DBPassword | 指定zabbix数据库登录密码 |
DBPort | 指定zabbix数据库端口号 |
User | 设置zabbix以什么用户的身份运行 |
AlertScriptsPath | 设置告警脚本存放路径 |
ExternalScripts | 外部脚本存放路径 |
客户端配置文件zabbix_agentd.conf常用配置参数:
参数 | 作用 |
---|---|
Server | 指定zabbix服务器的IP或域名 |
ServerActive | 指定zabbix服务器的IP或域名 |
Hostname | 指定本机的主机名,此项必须与web界面配置项一致 |
UnsafeUserParameters | 是否启用自定义监控项,可选值为{1 |
UserParameter | 指定自定义监控脚本参数 |
LogFile | 设置客户端日志文件存放路径 |
4. 部署zabbix
环境说明:
环境 | IP | 要安装的应用 |
---|---|---|
服务器 | 192.168.100.100 | lamp架构 zabbix server zabbix agent |
客户端 | 192.168.100.96 | zabbix agent |
因为zabbix
是用php
语言开发的,所以必须先部署lamp
架构,使其能够支持运行php
网页
4.1 zabbix服务端安装
# 安装依赖包
[root@100 ~]# yum -y install net-snmp-devel libevent-devel mysql-devel
安装过程略....
# 下载zabbix
[root@100 ~]# cd /usr/src/
[root@100 ~]# wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz
下载过程略....
# 解压
[root@100 src]# tar xf zabbix-4.0.3.tar.gz
# 创建zabbix用户和组
[root@100 src]# groupadd -r zabbix
[root@100 src]# useradd -r -M -s /sbin/nologin -g zabbix zabbix
# 配置zabbix数据库
[root@100 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.22
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> alter user 'root'@'localhost' identified by 'scl666'; #重置密码
Query OK, 0 rows affected (0.00 sec)
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix123!';
Query OK, 0 rows affected, 2 warnings (0.07 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
[root@100 ~]# cd /usr/src/zabbix-4.0.3/database/mysql/
[root@100 mysql]# ls
data.sql images.sql Makefile.am Makefile.in schema.sql
[root@100 mysql]# mysql -uzabbix -pzabbix123! zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@100 mysql]# mysql -uzabbix -pzabbix123! zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@100 mysql]# mysql -uzabbix -pzabbix123! zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
# 编译安装zabbix
[root@100 mysql]# cd /usr/src/zabbix-4.0.3
[root@100 zabbix-4.0.3]# ./configure --enable-server \
> --enable-agent \
> --with-mysql \
> --with-net-snmp \
> --with-libcurl \
> --with-libxml2
[root@100 zabbix-4.0.3]# make install
4.2 zabbix服务端配置
# 修改服务端配置文件
# 设置数据库信息
[root@100 ~]# ls /usr/local/etc/
zabbix_agentd.conf zabbix_agentd.conf.d zabbix_server.conf zabbix_server.conf.d
[root@100 ~]# vim /usr/local/etc/zabbix_server.conf
....
DBPassword=zabbix123! //设置zabbix数据库连接密码
# 启动zabbix_server和zabbix_agentd
[root@100 ~]# zabbix_server
[root@100 ~]# zabbix_agentd
[root@100 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
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 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
4.3 zabbix服务端web界面安装与配置
zabbix web界面安装前配置
# 修改/etc/php.ini的配置并重启php-fpm
[root@100 ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@100 ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@100 ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@100 ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@100 ~]# service php-fpm restart
[root@100 ~]# cd /usr/src/zabbix-4.0.3
[root@100 zabbix-4.0.3]# 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
[root@100 zabbix-4.0.3]# mkdir /usr/local/apache/htdocs/zabbix
[root@100 zabbix-4.0.3]# cp -a frontends/php/* /usr/local/apache/htdocs/zabbix/
[root@100 zabbix-4.0.3]# chown -R apache.apache /usr/local/apache/htdocs
# 配置apache虚拟主机
[root@100 zabbix-4.0.3]# vim /etc/httpd24/httpd.conf
# 在末尾添加以下内容
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/zabbix"
ServerName www.scl.com
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
[root@100 conf.d]# chmod 777 /usr/local/apache/htdocs/zabbix/conf
[root@100 conf.d]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxrwxrwx 2 apache apache 81 12月 20 2018 /usr/local/apache/htdocs/zabbix/conf
# 重启apache
[root@100 conf.d]# apachectl -t
Syntax OK
[root@100 conf.d]# apachectl stop
[root@100 conf.d]# apachectl start
安装zabbix web界面
- 修改/etc/hosts文件,添加域名与IP的映射
- 在浏览器上访问域名,本文设置的域名为www.scl.com,你需要修改成你自己的域名
- 恢复zabbix/conf目录的权限为755
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
192.168.100.100 www.scl.com
在浏览器上访问域名或ip进行安装:
直接下一步后,这里要填写zabbix数据库ip地址和数据库zabbix用户密码
下一步
下一步
下一步
下一步,出现登录界面后,账号是Admin,密码是zabbix
恢复zabbix/conf目录的权限为755:
[root@localhost ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf
[root@localhost ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxr-xr-x 2 apache apache 104 8月 22 02:00 /usr/local/apache/htdocs/zabbix/conf
4.4 zabbix客户端配置
# 安装依赖包
[root@96 ~]# yum -y install net-snmp-devel libevent-devel libxml2-devel curl-devel pcre*
# 下载zabbix并解压
[root@96 ~]# cd /usr/src/
[root@96 src]# wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz
[root@96 src]# tar xf zabbix-4.0.3.tar.gz
# 创建zabbix用户和组
[root@96 src]# groupadd -r zabbix
[root@96 src]# useradd -r -M -s /sbin/nologin -g zabbix zabbix
# 编译安装zabbix
[root@96 src]# cd zabbix-4.0.3
[root@96 zabbix-4.0.3]# ./configure --enable-agent
编译过程略。。。
[root@96 zabbix-4.0.3]# make install
[root@96 zabbix-4.0.3]# ls /usr/local/etc/
zabbix_agentd.conf zabbix_agentd.conf.d
# 修改服务端配置文件
# 设置数据库信息
[root@96 zabbix-4.0.3]# vim /usr/local/etc/zabbix_agentd.conf #找到以下三行并修改为:
Server=192.168.100.100
ServerActive=192.168.100.100
Hostname=runtime # 可自定义
# 启动zabbix_agentd
[root@96 zabbix-4.0.3]# zabbix_agentd
[root@96 zabbix-4.0.3]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 80 :::3306 :::*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::22 :::*
创建新主机:
主机名必须和刚刚自定义的主机名一致: Hostname=runtime
可以看到添加了一台新主机