zabbix介绍php
zabbix是一个基于WEB界面的分布式监控系统,zabbix能监控各类网络参数,保证服务器系统的安全运营,并提供灵活的通知机制,让系统管理员快手定位解决存在的各类问题,主要有监控CPU负载,内存使用、磁盘使用、网络状态、端口监视,日志监视、插件开发自定义等功能。 html
zabbix Server 经过SNMP、zabbix agent,ping、端口监视等方法提供对远程服务器/网络状态的监视,数据收集功能。能够在运行Linux 、Solaris、HP-UX、AIX、FreeBSD、OpenBSD、Windows等多平台运行。 mysql
常见商业功能: nginx
其中组件: web
zabbix_agent 安装在须要被监控的目标服务器上,主要完成对硬件信息与操做系统有关的内存,CPU、硬盘等信息的收集,功能十分强大。 sql
zabbix_server 能够单独监视远程服务器的服务状态,同时也能够与zabbix_agent 结合,能够轮询zabbix Agent 主动接收监控数据,还能够被动接收zabbix_agent 发送的数据。 数据库
如图: vim
环境介绍: centos
经过C/S模式采集数据 安全
经过B/S模式在WEB端展现和配置
Agent 监控端口10050
服务端端口10051
以LNMP为监测环境 LNMP=Linux+Nginx+Mysql+PHP
环境表:
主机 | 操做系统 | IP地址 | 主要软件 |
Zabbix服务器 | Centos 7 | 192.168.10.11 | Zabbix |
客户机 | Centos 7 | 192.168.10.12 | Zabbix |
操做步骤:
#Zabbix服务器 和客户机 关闭防火墙
systemctl stop firewalld.service
setenforce 0 #不关,Zabbix没法启动
安装nginx
获取安装源
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enable=1yum list
yum install nginx –y
http防火墙设置,关闭防火墙则无需此步骤。
firewall-cmd --permanent --add-service=http --zone=public
firewall-cmd –reload
开启nginx
systemctl start nginx
netstat -ntap | grep nginx #查看端口
安装mariadb
yum install mariadb-server mariadb -y
systemctl start mariadb.service
systemctl enable mariadb.service
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 #不删除匿名用户
... 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 #删除测试数据库
... 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!
安装PHP
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install -y php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql
编辑PHP配置文件
vim /etc/php-fpm.d/www.conf
8 user = nginx
10 group = nginxvim /etc/php.ini
359 expose_php = Off //隐藏php版本
202 short_open_tag = On //支持php短标签
//如下为zabbix配置要求
368 max_execution_time = 300 //执行时间
378 max_input_time = 300 //接受数据等待时间
389 memory_limit = 128M //每一个脚本占用的内存设置
656 post_max_size = 16M //post数据大小
799 upload_max_filesize = 2M //下载文件大小
800 always_populate_raw_post_data = -1 //可用 $HTTP_RAW_POST_DATA 接受post raw data
878 date.timezone = Asia/shanghai //时区设置上海vim /etc/nginx/conf.d/default.conf
10 index index.php index.html index.htm; //添加PHP支持
30 location ~ \.php$ {
31 root /usr/share/nginx/html;
32 fastcgi_pass 127.0.0.1:9000;
33 fastcgi_index index.php;
34 fastcgi_param SCRIPT_FILENAME $document_r oot$fastcgi_script_name;
35 include fastcgi_params;
36 }
开启php服务
systemctl start php-fpm.service
systemctl enable php-fpm.service
netstat -ntap | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 76012/php-fpm: mast
systemctl restart nginx
进入数据库给Zabbix建立提供数据库
mysql -uroot -p1
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on *.* to 'zabbix'@'%' identified by 'admin123';
flush privileges;
写入一个页面测试PHP是否能链接数据库
vim info.php
<?php
$link=mysqli_connect('127.0.0.1','root','1');
if($link) echo "true!";
else echo "Fail!!";
?>
成功:
-----------若是出现没法登录问题------------
select user,host from mysql.user;
看见有空用户,删除即解决
drop user ''@localhost;
drop user ''@cent;
再次检测
安装zabbix
rpm -i http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent –y
编辑配置文件
vim /etc/zabbix/zabbix_server.conf
91 DBHost=localhost
125 DBPassword=admin123
-----------防止出现zabbix页面乱码问题------------
vim /usr/share/zabbix/include/defines.inc.php
%s /graphfont/kaiti/g //全局替换https://pan.baidu.com/s/1f5XCKPMusD1weN6AfB2UYQ
把上面这个文件放到/usr/share/zabbix/fonts/下
给zabbix相关加权,否则后面开启zabbix会出现不少问题。
cp -r /usr/share/zabbix/ /usr/share/nginx/html/
chown -R zabbix:zabbix /etc/zabbix/
chown -R zabbix:zabbix /usr/share/nginx/
chown -R zabbix:zabbix /usr/lib/zabbix/
chmod -R 755 /etc/zabbix/web/
chmod -R 777 /var/lib/php/session/
zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz | mysql -uzabbix -p zabbix
重启改动服务以及启动zabbix
systemctl stop php-fpm.service
systemctl stop nginx.service
systemctl start php-fpm.service
systemctl start nginx.service
systemctl start zabbix-server.service
systemctl start zabbix-agent.service
netstat -ntap | grep 10051
http://192.168.10.11/zabbix/
--------------------安装过程当中若是出现---------------------
解决方法以下
cp /bao/zabbix.conf.php /etc/zabbix/web/
chown zabbix.zabbix /etc/zabbix/web/zabbix.conf.php
中文能够在网站设置里面调。
进去以后测试一下,咱们添加一个SSH监控模块
干掉这个SSH
systemctl stop sshd
等个十几秒,刷新一下这个页面
至此就完成了zabbix的监控流程。