zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
zabbix由2部分构成,zabbix server与可选组件zabbix agent。
zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Ubuntu,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。
zabbix agent需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。
zabbix server可以单独监视远程服务器的服务状态;同时也可以与zabbix agent配合,可以轮询zabbix agent主动接收监视数据(agent方式),同时还可被动接收zabbix agent发送的数据(trapping方式)。
另外zabbix server还支持SNMP (v1,v2),可以与SNMP软件(例如:net-snmp)等配合使用。
zabbix的主要特点:
Zabbix主要功能:
zabbix配置文件有两种:
服务器端配置文件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 | 设置客户端日志文件存放路径 |
环境说明:
环境 | IP | 要安装的应用 |
---|---|---|
服务器 | 192.168.19.138 | lamp架构 zabbix server zabbix agent |
客户端 | 192.168.19.128 | zabbix agent |
//安装依赖包
[root@yh src]# yum -y install net-snmp-devel libevent-devel libxml2-devel curl-devel pcre*
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
base | 3.6 kB 00:00:00
//下载zabbix
[root@yh src]# wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz
//解压
[root@yh src]# tar xf zabbix-4.0.3.tar.gz
[root@yh src]# ls
debug kernels nginx-1.12.2 nginx-1.12.2.tar.gz zabbix-4.0.3 zabbix-4.0.3.tar.gz
//创建zabbix用户和组
[root@yh ~]# groupadd -r zabbix
[root@yh ~]# useradd -r -g zabbix -M -s /sbin/nologin zabbix
//配置zabbix数据库
[root@yh ~]# mysql -uroot -pyh123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
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> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.07 sec)
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix123!';
Query OK, 0 rows affected, 2 warnings (0.06 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.07 sec)
mysql> exit
[root@yh ~]# cd /usr/src/zabbix-4.0.3/database/mysql/
[root@yh mysql]# ls
data.sql images.sql Makefile.am Makefile.in schema.sql
[root@yh mysql]# mysql -uzabbix -pzabbix123! zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@yh mysql]# mysql -uzabbix -pzabbix123! zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@yh mysql]# mysql -uzabbix -pzabbix123! zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
//编译安装zabbix
[root@yh ~]# cd /usr/src/zabbix-4.0.3
[root@yh zabbix-4.0.3]# ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
...
[root@localhost zabbix-4.0.3]# make install
...
make[2]: 对“install-data-am”无需做任何事。
make[2]: 离开目录“/usr/src/zabbix-4.0.3”
make[1]: 离开目录“/usr/src/zabbix-4.0.3”
[root@yh zabbix-4.0.3]#
[root@yh ~]# ls /usr/local/etc/
zabbix_agentd.conf zabbix_agentd.conf.d zabbix_server.conf zabbix_server.conf.d
//修改服务端配置文件
//设置数据库信息
[root@yh ~]# vim /usr/local/etc/zabbix_server.conf
....
DBPassword=zabbix123! //设置zabbix数据库连接密码
### Option: DBSocket
# Path to MySQL socket.
#
# Mandatory: no
# Default:
DBSocket=/tmp/mysql.sock 修改
第一次重启没有10051端口
做下列操作
[root@yh mysql]# mkdir /var/lib/mysql
[root@yh mysql]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
[root@yh mysql]# /etc/rc.d/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL.. SUCCESS!
//启动zabbix_server和zabbix_agentd
[root@yh ~]# zabbix_server
[root@yh ~]# zabbix_agentd
[root@yh ~]# 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 :::*
[root@yh ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@yh ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@yh ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@yh ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@yh ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@yh ~]# cd /usr/src/zabbix-4.0.3
[root@yh 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@yh zabbix-4.0.3]# mkdir /usr/local/apache/htdocs/zabbix
[root@yh zabbix-4.0.3]# cp -a frontends/php/* /usr/local/apache/htdocs/zabbix/
[root@yh zabbix-4.0.3]# groupadd -r apache
[root@yh zabbix-4.0.3]# useradd -r -g apache -M -s /sbin/nologin apache
[root@yh zabbix-4.0.3]# chown -R apache.apache /usr/local/apache/htdocs
配置apache虚拟主机
[root@localhost ~]# vim /etc/httpd/httpd.conf
在配置文件的末尾加如下内容
ServerName zabbix.yh.com:80
DocumentRoot "/usr/local/apache/htdocs/zabbix"
ServerName zabbix.yh.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix/$1
Options none
AllowOverride none
Require all granted
设置zabbix/conf目录的权限,让zabbix有权限生成配置文件zabbix.conf.php
[root@yh ~]# chmod 777 /usr/local/apache/htdocs/zabbix/conf
[root@yh ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxrwsrwx. 2 apache apache 81 12月 20 19:24 /usr/local/apache/htdocs/zabbix/conf
重启apache
[root@yh ~]# ln -s /usr/local/apache/bin/apachectl /bin/
[root@yh ~]# apachectl -t
Syntax OK
[root@yh ~]# apachectl stop
[root@yh ~]# apachectl start
[root@yh ~]# 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 :::*
修改/etc/hosts文件,添加域名与IP的映射
[root@yh ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.19.128 zabbix.yh.com
~
在浏览器上访问域名,本文设置的域名为zabbix.wenhs.com,你需要修改成你自己的域名
恢复zabbix/conf目录的权限为755
[root@yh ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf
[root@yh ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxr-sr-x. 2 apache apache 104 5月 16 18:58 /usr/local/apache/htdocs/zabbix/conf
zabbix默认登录用户名和密码:
用户名 | 密码 |
---|---|
Admin | zabbix |
zabbix 自带多种语言包,也包括中文。登陆zabbix web控制台默认是英文,可切换中文版本
1.默认登陆界面(英文版)
点击右上角小人图标,切换语言
汉化
解决中文乱码
上传本地字体
找到本地C:\Windows\Fonts\SIMKAI.TTF (楷体)上传到/usr/local/apache/htdocs/zabbix/fonts
将zabbix服务器正在使用字体备份
[root@yh fonts]# mv /usr/local/apache/htdocs/zabbix/fonts/DejaVuSans.ttf{,.bak}
[root@yh fonts]# ll
总用量 12252
-rw-r--r--. 1 apache apache 756072 12月 20 19:24 DejaVuSans.ttf.bak
-rw-r--r--. 1 root apache 11785184 5月 17 14:59 SIMKAI.TTF
[root@yh fonts]# scp SIMKAI.TTF [email protected]:/usr/local/apache/htdocs/zabbix/fonts/DejaVuSans.ttf
The authenticity of host '192.168.19.128 (192.168.19.128)' can't be established.
ECDSA key fingerprint is SHA256:+earxJh51iQYRB6Kge5ZuhFJGN5NSGsxjS3KJpjyzO8.
ECDSA key fingerprint is MD5:2e:7b:1b:ee:ee:91:9c:ef:37:68:e7:60:7b:59:30:88.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.19.128' (ECDSA) to the list of known hosts.
[email protected]'s password:
SIMKAI.TTF 100% 11MB 62.0MB/s 00:00
安装依赖包
[root@yh1~]# yum -y install net-snmp-devel libevent-devel libxml2-devel curl-devel pcre*
下载zabbix
[root@yh ~]# cd /usr/src/
[root@yh src]# scp 192.168.19.140:/usr/srczabbix-4..0.3.tar.gz .
[email protected]'s password:
zabbix-4.2.1.tar.gz 100% 17MB 61.7MB/s 00:00
[root@yh1 src]# tar xf zabbix-4..0.3.tar.gz
创建zabbix用户和组
[root@wenhs5479 ~]# groupadd -r zabbix
[root@wenhs5479 ~]# useradd -r -g zabbix -M -s /sbin/nologin zabbix
编译安装zabbix
[root@yh1 ~]# cd /usr/src/zabbix-4..0.3
[root@yh1 zabbix-4..0.3]# ./configure --enable-agent
[root@yh1 zabbix-4..0.3]# make install
[root@yh1 zabbix-4..0.3]# ls /usr/local/etc/
zabbix_agentd.conf zabbix_agentd.conf.d
修改配置文件
设置数据库信息
[root@yh1 zabbix-4..0.3]# vim /usr/local/etc/zabbix_agentd.conf
Server=192.168.19.138
ServerActive=192.168.19.138
Hostname=138
启动zabbix_agentd
[root@yh1 zabbix-4..0.3]# groupadd -r zabbix
[root@yh1 zabbix-4..0.3]# useradd -r -M -s /sbin/nologin -g zabbix zabbix
[root@yh1 zabbix-4..0.3]# zabbix_agentd
[root@yh1 zabbix-4..0.3]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
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 127.0.0.1:6010 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 ::1:6010 :::*
测试
[root@yh ~]# echo "hello" >> /etc/passwd
[root@zabbix ~]# systemctl restart postfix
添加报警媒介内容(可以选择默认的E-mail方式或者手动创建媒介类型);
[root@yh ~]# echo "w" >> /etc/passwd
[root@zabbix ~]# mkdir /usr/local/etc/scripts
[root@zabbix scripts]# vim sendmail.sh
#!/bin/bash
subject=$(echo $2 |tr "\r\n" "\n")
message=$(echo $3 |tr "\r\n" "\n")
echo "$message" | /usr/bin/mail -s "$subject" $1 &>/tmp/sm.log
[root@zabbix etc]# chown -R zabbix.zabbix scripts
[root@zabbix etc]# chmod +x scripts/138.sh
[root@zabbix etc]#
[root@zabbix scripts]# tail -5 /etc/mail.rc
#set [email protected]
#set smtp=smtp.163.com
#set [email protected]
#set smtp-auth-password=W授权码
#set smtp-auth=login
取消注释使用163邮箱发邮件,不取消使用本机虚拟邮箱
修改/usr/local/etc/zabbix_server.conf,修改如下
AlertScriptsPath=/usr/local/etc/scripts
重启服务
[root@server ~]# pkill zabbix
[root@server ~]# zabbix_server
[root@server ~]# zabbix_agentd
[root@server ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 *:10051
测试
[root@yh ~]# echo "w" >> /etc/passwd
[root@yh ~]# hostnamectl set-hostname zabbix.server.com
127.0.0.1 zabbix.com
[root@zabbix etc]# systemctl restart postfix
[root@yh ~]# echo "w" >> /etc/passwd