运维监控三剑客之Zabbix

zabbix

zabbix是由 Alexei Vladishev开发的一种网络监视、管理系统,基于 Server-Client架构。可用于监视各类网络服务、服务器和网络机器等状态。php

使用各类 Database-end 如 MySQL, PostgreSQL, SQLite, Oracle 或 IBM DB2 储存资料。Server 端基于 C语言、Web 管理端frontend则是基于PHP所制做的。Zabbix可使用多种方式监视。能够只使用 Simple Check 不须要安装 Client 端,亦可基于 SMTP 或 HTTP ... 各类协定作死活监视。html

在客户端如 UNIX, Windows 中安装 Zabbix Agent 以后,可监视 CPU Load、网络使用情况、硬盘容量等各类状态。而就算没有安装 Agent 在监视对象中,Zabbix 也能够经由 SNMP、TCP、ICMP、利用 IPMI、SSH、telnet 对目标进行监视。mysql

另外,Zabbix 包含 XMPP 等各类 Item 警示功能。linux

zabbix官网: https://www.zabbix.comweb

zabbix主要由二个部分构成 zabbix server和 zabbix agent;
zabbix proxy是用来管理其余的agent,做为代理使用。sql

系统环境:

主机名 操做系统 IP地址 服务名
zabbix centos7.4 192.168.96.70 zabbix2.2.23
www centos7.4 192.168.96.71 zabbix-agent
客户端 windows 10 192.168.96.2 网页浏览器

百度网盘 密码:x1uy数据库

1、安装LAMP环境

1.安装lamp相关软件包

yum install -y httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash php-bcmath php-mbstring

2.关闭防火墙及selinux

systemctl stop firewalld.service
setenforce 0

3.编辑httpd.conf

vim /etc/httpd/conf/httpd.confvim

#设置域名
ServerName www.yun.com:80

#修改监听地址
Listen 192.168.96.70:80
#Listen 80

#添加主页类型index.php
DirectoryIndex index.html index.php

4.设置php配置中的时区

vim /etc/php.iniwindows

#PRC:中国时区
date.timezone = PRC

运维监控三剑客之Zabbix

5.启动httpd、mariadb服务

systemctl enable httpd.service
systemctl start httpd.service
systemctl enable mariadb.service
systemctl start mariadb.service

6.检查服务信息

netstat -ntap | egrep '(80|3306)'

运维监控三剑客之Zabbix

7.添加php测试页

vim /var/www/html/index.phpcentos

<?php
    phpinfo();
?>

8.客户端访问php测试页

http://192.168.96.70/index.php

运维监控三剑客之Zabbix

9.初始化mysql数据库

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] n     //是否移除anonymous用户
 ... skipping.

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] n       //是否容许root用户远程登陆
 ... skipping.

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] n    //是否移除test数据库
 ... skipping.

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!

10.登陆mysql,建立zabbix数据库及建立zabbix用户并设置密码

mysql -u root -p

mysql> create database zabbix character set utf8 collate utf8_bin;

mysql> grant all privileges on zabbix.* to zabbix@'%' identified by '123123';

mysql>flush privileges;

11.建立mysql数据库的测试网页文件

vim /var/www/html/mysql.php

<?php
$link=mysql_connect('192.168.96.70','zabbix','123123');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
mysql_close();
?>

12.客户端访问mysql.php网页,显示success则访问mysql正常,fail则访问失败,请检查mysql.php中链接地址、用户名、密码是否正确,若仍是有问题请检查mysql.user表用户名称是否有空而致使的错误,如下为解决方法

> select user,host from mysql.user;   

#用户名称为空占用致使本地没法登陆远程可登陆
+--------+-----------+
| user   | host      |
+--------+-----------+
| zabbix | %         |
| root   | 127.0.0.1 |
| root   | ::1       |
|        | localhost |
| root   | localhost |
|        | zabbix    |
| root   | zabbix    |
+--------+-----------+

> drop user ''@localhost;

> drop user ''@zabbix;

> flush privileges;

运维监控三剑客之Zabbix

运维监控三剑客之Zabbix

2、部署zabbix Server

1.下载zabbix官方yum源文件

rpm -i https://repo.zabbix.com/zabbix/2.2/rhel/7/x86_64/zabbix-release-2.2-1.el7.noarch.rpm

2.安装zabbix服务端及被控端软件包

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

3.导入zabbix数据库(必须安装此顺序导入,否则会报错)

cd /usr/share/doc/zabbix-server-mysql-2.2.23/create/

mysql -uzabbix -p  zabbix < schema.sql
mysql -uzabbix -p  zabbix < images.sql
mysql -uzabbix -p  zabbix < data.sql

4.编辑zabbix_service.conf配置,结果以下

egrep -n '^'[a-Z] /etc/zabbix/zabbix_server.conf

39:LogFile=/var/log/zabbix/zabbix_server.log
50:LogFileSize=0
72:PidFile=/var/run/zabbix/zabbix_server.pid
91:DBName=zabbix
107:DBUser=zabbix
115:DBPassword=123123
124:DBSocket=/var/lib/mysql/mysql.sock
288:SNMPTrapperFile=/var/log/snmptt/snmptt.log
426:Timeout=3
468:AlertScriptsPath=/usr/lib/zabbix/alertscripts
478:ExternalScripts=/usr/lib/zabbix/externalscripts
512:LogSlowQueries=3000

5.编辑zabbix配置文件,指定时区

vim /etc/httpd/conf.d/zabbix.conf

php_value date.timezone Asia/Shanghai

运维监控三剑客之Zabbix

6.修正zabbix-web图表中文乱码

vim /usr/share/zabbix/include/defines.inc.php

#替换全文中全部graphfot为kaiti
:%s/graphfont/kaiti/g

运维监控三剑客之Zabbix

7.复制字体文件至zabbix/fonts/目录下

cp kaiti.ttf /usr/share/zabbix/fonts/

8.启动zabbix-server服务

systemctl enable zabbix-server
systemctl start zabbix-server

9.检查是否已监听10051端口

netstat -anpt | grep zabbix

运维监控三剑客之Zabbix

10.重启httpd服务

systemctl restart httpd.service

11.客户端访问(用户名:Admin 密码:zabbix),进入zabbix的安装界面

http://192.168.96.70/zabbix/

运维监控三剑客之Zabbix

运维监控三剑客之Zabbix

运维监控三剑客之Zabbix

运维监控三剑客之Zabbix

运维监控三剑客之Zabbix

运维监控三剑客之Zabbix

运维监控三剑客之Zabbix

运维监控三剑客之Zabbix

3、设置中文环境

1. Profile ---->User -----> Languages 中设置chinese(zh_cn)

运维监控三剑客之Zabbix

2. 网页界面已经显示为中文了

运维监控三剑客之Zabbix

4、添加被控服务器

服务器:zabbix

zabbix以前已经安装好了zabbix—agent软件包,这里就不用再安装,直接进行设置

1.编辑zabbix_agentd.conf配置,结果以下

egrep -n '^'[a-Z] /etc/zabbix/zabbix_agentd.conf

13:PidFile=/var/run/zabbix/zabbix_agentd.pid
23:LogFile=/var/log/zabbix/zabbix_agentd.log
34:LogFileSize=0
85:Server=192.168.96.70
126:ServerActive=192.168.96.70
137:Hostname=zabbix
246:Include=/etc/zabbix/zabbix_agentd.d/

2.启动zabbix-agent服务

systemctl enable zabbix-agent.service
systemctl restart zabbix-agent.service

3.检查是否已监听10050端口

netstat -anpt | grep zabbix

运维监控三剑客之Zabbix

服务器:www

1.关闭防火墙及selinux

systemctl stop firewalld
setenforce 0

2.下载安装yum源文件

rpm -i https://repo.zabbix.com/zabbix/2.2/rhel/7/x86_64/zabbix-release-2.2-1.el7.noarch.rpm

3.安装zabbix-agent软件包

yum install -y zabbix-agent httpd

4.编辑zabbix_agentd.conf配置,结果以下

egrep -n '^'[a-Z] /etc/zabbix/zabbix_agentd.conf

13:PidFile=/var/run/zabbix/zabbix_agentd.pid
23:LogFile=/var/log/zabbix/zabbix_agentd.log
34:LogFileSize=0
85:Server=192.168.96.70
126:ServerActive=192.168.96.70
137:Hostname=www
246:Include=/etc/zabbix/zabbix_agentd.d/

5.启动zabbix-agent服务

systemctl enable zabbix-agent.service
systemctl restart zabbix-agent.service
systemctl enable httpd.service
systemctl start httpd.service

6.检查是否已监听10050端口

netstat -anpt | grep zabbix_agent

运维监控三剑客之Zabbix

5、添加被控主机:

1. 配置-主机-建立主机:

运维监控三剑客之Zabbix

2.添加主机信息

运维监控三剑客之Zabbix

3.成功添加2台被控主机

运维监控三剑客之Zabbix

相关文章
相关标签/搜索