zabbix是一个基于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等平台上。
其他开源监控软件:zabbix、cacti、nagios被称为三大监控软件,俗称监控三剑客但它们都是英文界面,而owl是国产监控软件,有时间的话这些监控软件都应该去了解一下。
另外,想从事系统运维方面工作的,可以多在开源中国社区学一下zabbix的使用,以及如何处理各种问题等,下面就先了解一下zabbix最基础的部分吧!
安装lanmp或者lnmp框架
为运行zabbix提供环境,此处以安装lamp为例
[root@localhost ~]# yum install mariadb mariadb-server httpd php php-mysql -y
初始化mariadb数据库服务
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@localhost ~]# firewall-cmd --add-port=3306/tcp --permanent
success
[root@localhost ~]# firewall-cmd --add-port=80/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
初始化数据库
[root@localhost ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@localhost ~]#
[root@localhost ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
[root@localhost ~]# yum -y install zabbix-server-mysql zabbix-web-mysql
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server 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)]> create database zabbix character set utf8 collate utf8_bin;
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)]> quit
Bye
[root@localhost ~]#
[root@localhost ~]# cd /usr/share/doc/zabbix-server-mysql-3.2.11/
[root@localhost zabbix-server-mysql-3.2.11]# zcat create.sql.gz | mysql -uroot -p zabbix
Enter password:
[root@localhost zabbix-server-mysql-3.2.11]# cd
[root@localhost ~]#
[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf
81 DBHost=localhost
91 DBName=zabbix
107 DBUser=zabbix
115 DBPassword=zabbix
[root@localhost ~]# vim /etc/httpd/conf.d/zabbix.conf
19 php_value date.timezone Asia/Shanghai
安装 ntpdate,使用ntpdate同步时间
[root@localhost ~]# yum install ntpdate -y
[root@localhost ~]# ntpdate cn.pool.ntp.org
[root@localhost ~]# systemctl restart zabbix-server
[root@localhost ~]# systemctl enable zabbix-server
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl enable httpd
先查到自己zabbix服务器也就是你的虚拟机的ip
浏览器打开:
http://IP/zabbix/
http://IP/zabbix/setup.php
默认用户名/密码:Admin/zabbix
这里连接数据库要填密码,填咱们之前设好的“zabbix”即可。
然后随便想一个主机名
默认用户名/密码:Admin/zabbix
登录上去后是这个样子的
将语言设置为中文
监控zabbix服务器自己本身默认是停用的,我们可以点击“停用的”那里对它进行启用
启用之后,可以看到“可用性”那里全是灰色的,可用性指的是使用什么插件或者协议去监控,这里说明这些协议都未生效
为了让其中的ZBX生效,我们需要安装并且重启zabbix-agent
[root@localhost ~]# yum install zabbix-agent -y
[root@localhost ~]# systemctl restart zabbix-agent
安装好之后,查看主机状态是否已启用,可用性是否亮绿灯,网上说红灯绿灯都是正常的,我的是红灯说明状态已经正常,但是连接是失败的。
我们把鼠标悬停在红色的ZBX标志那里,可以发现是端口111未被防火墙放行
我们回到zabbix服务器,放行相关端口。另外,zabbix和zabbix-agent的端口分别是10050和10051,顺带也放行了
[root@localhost ~]# firewall-cmd --add-port=111/tcp --permanent
success
[root@localhost ~]# firewall-cmd --add-port=10050/tcp --permanent
success
[root@localhost ~]# firewall-cmd --add-port=10051/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# systemctl restart zabbix-agent
放行这些端口之后,回到浏览器,要稍等一会儿,才能看到ZBX标志变成绿色了。这表示已经正常监控了zabbix服务器了
可以切换到图形监控界面,如下图,可以很直观看到zabbix服务器的cpu相关运行参数变化情况
随便开启一台赶紧的centos虚拟机作为客户端,这里我开启的虚拟机ip是192.168.141.53
[root@localhost ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
下面两个ip填你的zabbix服务器ip即可。
[root@localhost ~]# yum -y install zabbix-agent
[root@server zabbix-server-mysql-3.2.11]# vim /etc/zabbix/zabbix_agentd.conf
95 Server=192.168.141.12
136 ServerActive=192.168.141.12
[root@server zabbix-server-mysql-3.2.11]# systemctl restart zabbix-agent.service
回到浏览器,添加对客户机的监控
先选择模板,记住要选择后要添加到“链接的模板”的那个框里面,最后在点击更新
添加主机,填上客户机的ip
添加完成后可以看到
客户端放行相关端口,重启zabbix代理服务
[root@localhost ~]# firewall-cmd --add-port=111/tcp --permanent
success
[root@localhost ~]# firewall-cmd --add-port=10050/tcp --permanent
success
[root@localhost ~]# firewall-cmd --add-port=10051/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# systemctl restart zabbix-agent
然后可以看到该客户端的ZBX标志变绿了,说明可用了
可以看到其运行数据,不过本来也没有监控几分钟,所以只能看到这么点儿
我们的物理机电脑也可以被zabbix服务器所监控,但是需要下载代理组件
可以到zabbix官网:https://www.zabbix.com/自己找
也可以按照下面这个链接下载windows agent
https://www.zabbix.com/downloads/3.2.0/zabbix_agents_3.2.0.win.zip
关闭windows防火墙(本次实验完再打开)
解压zabbix_agents_3.2.0.win.zip压缩包
在windows系统中c盘根目录下新建一个目录,将解压后的zabbix_agents_3.2.0.win中bin\win64(看系统具体32位或者64位来选)下的文件和conf下的配置文件,放到新建的zabbix目录下
修改C:\zabbix\zabbix_agentd.win.conf文件(建议用notepad++)
62 EnableRemoteCommands=1
71 LogRemoteCommands=1
84 Server=192.168.141.12
136 Hostname=wintest01
windows下按win+x,点击Windows PowerShell(管理员)(A),然后进行以下操作运行zabbix agent服务
PS C:\WINDOWS\system32> cmd
C:\WINDOWS\system32>cd C:\zabbix
C:\zabbix>zabbix_agentd.exe -i -c zabbix_agentd.win.conf
zabbix_agentd.exe [4964]: service [Zabbix Agent] installed successfully
zabbix_agentd.exe [4964]: event source [Zabbix Agent] installed successfully
C:\zabbix>zabbix_agentd.exe -s -c zabbix_agentd.win.conf
zabbix_agentd.exe [6328]: service [Zabbix Agent] started successfully
回到浏览器,创建windows主机群组
创建windows主机,名称叫做wintest01
先用cmd查看你电脑ip,记住要看哪个和zabbix服务器在同一个网段的那个ip
ipconfig
可以看到我的ip是192.168.141.1
创建完成,单击wintest01主机
给它配置模板
回到主机那里,点击将它停用,然后再点击一次将它启用,可以看到ZBX从灰色变为红色
等40秒就好了,就变绿色了
和之前一样,可以看看监控图形
实验做完了,别忘了以管理员模式打开powershell再卸载掉zabbix
PS C:\WINDOWS\system32> cmd
Microsoft Windows [版本 10.0.17763.195]
(c) 2018 Microsoft Corporation。保留所有权利。
C:\WINDOWS\system32>cd C:\zabbix
C:\zabbix>zabbix_agentd.exe -d -c zabbix_agentd.win.conf
zabbix_agentd.exe [17148]: service [Zabbix Agent] uninstalled successfully
zabbix_agentd.exe [17148]: event source [Zabbix Agent] uninstalled successfully
C:\zabbix>
实验做完了,别忘了你自己电脑的防火墙可以开回去了。
本篇到此结束。