当前位置:   article > 正文

LAMP环境下zabbix 4.0安装配置_zabbix源码安装lamp4.0

zabbix源码安装lamp4.0


Zabbix简介

mark

Zabbix是一个企业级的开源分布式监控解决方案,由一个国外的团队持续维护更新,软件可以自由下载使用,运作团队靠提供收费的技术支持赢利。

官方网站:http://www.zabbix.com

Zabbix 1.8官方文档:http://www.zabbix.com/documentation/1.8/start

Zabbix通过C/S模式采集数据,通过B/S模式在web端展示和配置。

被监控端:主机通过安装agent方式采集数据,网络设备通过SNMP方式采集数据

Server端:通过收集SNMP和agent发送的数据,写入MySQL数据库,再通过php+apache在web前端展示。

Zabbix运行条件:

Server:

Zabbix Server需运行在LAMP(Linux+Apache+Mysql+PHP)环境下,对硬件要求低

Agent:

目前已有的agent基本支持市面常见的OS,包含Linux、HPUX、Solaris、Sun、windows

SNMP:

支持各类常见的网络设备

一:zabbix概述

1.1:Zabbix功能

具备常见的商业监控软件所具备的功能(主机的性能监控、网络设备性能监控、数据库性能监控、FTP等通用协议监控、多种告警方式、详细的报表图表绘制)

支持自动发现网络设备和服务器

支持分布式,能集中展示、管理分布式的监控点

扩展性强,server提供通用接口,可以自己开发完善各类监控

1.2:Zabbix 优劣势

优点:

开源,无软件成本投入

Server对设备性能要求低(实际测试环境:虚拟机Redhat EL AS5,2GCPU
1G内存,监控5台设备,CPU使用率基本保持在10%以下,内存剩余400M以上)

支持设备多

支持分布式集中管理

开放式接口,扩展性强

缺点:

全英文,界面不友好

无厂家支持,出现问题解决比较麻烦

需在被监控主机上安装agent

二:zabbix部署安装

操作系统:CentOS7.6

IP地址:20.0.0.45

Web环境:Nginx+MySQL+PHP

zabbix版本:Zabbix 4.0 LTS

备注:Linux下安装zabbix需要有LAMP或者LNMP运行环境

2.1:安装LNMP

环境准备

[root@zabbix ~]#  systemctl stop firewalld && systemctl disable firewalld

'临时关闭跟永久关闭防护功能'
[root@zabbix ~]# setenforce 0 && sed -i "s/SELINUX=*/SELINUX=disabled/g" /etc/selinux/config
  • 1
  • 2
  • 3
  • 4

安装nginx1.14

'安装yum源码'
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

'创建yum仓库'
[root@zabbix ~]# vim /etc/yum.repos.d/ngin.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

[root@zabbix ~]# yum clean all   '清理cache缓存'
[root@zabbix ~]# yum list

'其中baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/,把”OS”替换成”rhel”或”centos”,把”OSRELEASE”替换成”6”或”7”,用于6.x或7.x版本。
'
'开启nginx服务并设置开机启动'
[root@zabbix ~]# yum install nginx -y
[root@zabbix ~]# systemctl start nginx
[root@zabbix ~]# systemctl enable nginx

'查看nginx端口'
netstat -ntap | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      19485/nginx: master 

'设置防火墙规则'
firewall-cmd --permanent --add-service=http --zone=public
firewall-cmd --reload
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

进行访问查看

mark

2.2:安装mysql 5.7

[root@zabbix ~]# yum install -y mariadb-server mariadb

'开启服务'
systemctl enable mariadb.service
systemctl start  mariadb.service
mysql_secure_installation                 '初始化'

'//接下来执行mysql安全配置向导'
[root@server ~]# 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	'//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	'//是否删除匿名用户,建议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	       '//是否禁止root远程登录,建议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] 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	         '//是否重新加载权限表,建议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!
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66

2.3:安装php7.2

'安装epel'
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 

yum install epel-release

'建立yum仓库'
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm  'yum源'

'下载php依赖'
yum install -y php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql

'查看版本'
 php -v
PHP 7.2.34 (cli) (built: Oct  1 2020 13:37:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

2.4:配置nginx支持php

#修改php-fpm配置文件,把apache改为nginx
vim /etc/php-fpm.d/www.conf 
//8 user = nginx
//10 group = nginx

'配置location,在index中添加index.php。以支持index.php的首页'
vim /etc/nginx/conf.d/default.conf
//10         index index.php index.html index.htm; 

//30~36取消注释 //把fastcgi_param中的/scripts改为$document_root。root是配置php程序放置的根目录。
location ~ \.php$ {
          root        /usr/share/nginx/html;   '配置站点'
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          include        fastcgi_params;
      }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

2.5:优化php配置文件

vim /etc/php.ini

max_execution_time = 300	'//执行时间,在一个程序执行的过程中能够等待的执行时间,执行时间过程中如果没有执行完会结束该程序,以防出现卡死,默认30秒'
max_input_time = 300	    '//378行,接受数据的等待时间'
memory_limit = 128M		    '//389行,每个脚本的占用内存限制'
post_max_size = 16M		    '//656行,post数据的最大限制'
upload_max_filesize = 2M	'//799,下载文件的大小限制'
always_populate_raw_post_data = -1	'//800行添加此句,可以用$HTTP_RAW_POST_DATA接受post raw data(原始未处理数据)'
date.timezone = Asia/Shanghai	    '//878行,修改时区为上海'

'重启服务'
[root@zabbix ~]# systemctl start php-fpm
[root@zabbix ~]# systemctl enable php-fpm

'刚刚配置,现在重启nginx服务'
[root@zabbix ~]# systemctl restart nginx

[root@zabbix ~]# netstat -ntap | grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      22155/php-fpm: mast 
[root@zabbix ~]# netstat -ntap | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      22201/nginx: master 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

编写PHP测试首页并测试并测试网页

vim /usr/share/nginx/html/info.php

<?php
 phpinfo();
?>
  • 1
  • 2
  • 3
  • 4
  • 5

浏览器登录http://20.0.0.45/info.php进行访问

mark

2.6:测试连接数据库

vim /usr/share/nginx/html/info.php	'//重新修改首页文件'

<?php
 $link=mysqli_connect('127.0.0.1','root','abc123');
 if ($link) echo "连接成功 !!!";
 else echo "连接失败 !!!";
?>

注:mysql_connect扩展自 PHP 5.5.0 起已废弃,改用mysqli或pdo_mysql
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

mark:

2.61:mysql数据库创建zabbix用户
mysql -u root -p       '登录数据库'

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 *.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

'查看数据库'
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| zabbix             |
+--------------------+

'//collate的作用:对于mysql中的那些字符类型的列,如varchar,char,text类型的列,都需要有一个collate类型来告知mysql如何对该列进行排序和比较'

'修改首页文件进行测试'
vim /usr/share/nginx/html/info.php
<?php
 $link=mysqli_connect('127.0.0.1','zabbix','admin123');
 if ($link) echo "zabbix数据库连接成功";
 else echo "连接失败";
?>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

mark

2.7:部署zabbix的server

安装数据库、Zabbix server,Web前端,agent

rpm -i https://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
  • 1
  • 2
  • 3
  • 4

导入数据库脚本

'生成数据库文件,注意密码不要输成root的'
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
Enter password:     '输入密码admin123'

'登录数据库查看导入数据'
[root@zabbix ~]# mysql -uroot -p
Enter password: 

MariaDB [(none)]> use zabbix;
MariaDB [zabbix]> show tables;    '查看导入的数据'
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| application_discovery      |
| application_prototype      |
| application_template       |
| applications               |
| auditlog                   |
......省略...............
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

优化zabbix配置文件修改图表中中文乱码

[root@zabbix ~]# vim /etc/zabbix/zabbix_server.conf 
DBHost=localhost	'//91行取消注释,订格写'
DBPassword=admin123	'//124行添加设置密码'
  • 1
  • 2
  • 3

可选择操作修正图表中乱码

'修正图表中文乱码'
[root@zabbix ~]# vim /usr/share/zabbix/include/defines.inc.php 
:%s /graphfont/kaiti/g   '末行模式修改'

'从微软系统下复制相应的字体文件到 /usr/share/zabbix/fonts 目录中注意字体名称要对应配置文件,且注意大小写'
[root@zabbix ~]# cd /usr/share/zabbix/
[root@zabbix zabbix]# mkdir fonts
[root@zabbix zabbix]# cd fonts/
[root@zabbix fonts]# rz -E
rz waiting to receive.
[root@zabbix fonts]# ls
STKAITI.TTF      '已经复制过来了'

setenforce 0 //一定要关闭

'复制到/usr/share/ngin/html中'
[root@zabbix fonts]# cp -r /usr/share/zabbix/ /usr/share/nginx/html/
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

开启相应的zabbix服务

[root@zabbix fonts]# systemctl start zabbix-server.service
[root@zabbix fonts]# systemctl enable zabbix-server.service
[root@zabbix fonts]# systemctl start zabbix-agent.service
[root@zabbix fonts]# systemctl enable zabbix-agent.service
[root@zabbix fonts]# netstat -anpl | grep 10051
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      24227/zabbix_server 
tcp        0      0 127.0.0.1:10051         127.0.0.1:54530         TIME_WAIT   -                   
tcp6       0      0 :::10051                :::*                    LISTEN      24227/zabbix_server 
[root@zabbix fonts]# 
[root@zabbix fonts]# systemctl restart php-fpm.service 
[root@zabbix fonts]# systemctl restart nginx
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

登录网页:20.0.0.45/zabbix

mark

增加权限

[root@zabbix fonts]# chown -R zabbix:zabbix /etc/zabbix/
[root@zabbix fonts]# chown -R zabbix:zabbix /usr/share/nginx/
[root@zabbix fonts]# chown -R zabbix:zabbix /usr/lib/zabbix/
[root@zabbix fonts]# chmod -R 755 /etc/zabbix/web/
[root@zabbix fonts]# chmod -R 777 /var/lib/php/session/
  • 1
  • 2
  • 3
  • 4
  • 5

再次访问

mark

mark

mark

无法创建配置文件问题

mark

2.8:在页面安装过程中遇到无法创建的问题

根据提示的连接地址下载配置文件zabbix.conf.php

'提示要点击Download the configuration file下载这边我们本地下载好了'
'给予相应的数主属组 在增加执行权限重启服务'
[root@zabbix web]# chmod +x zabbix.conf.php 
[root@zabbix web]# chown zabbix.zabbix /etc/zabbix/web/zabbix.conf.php
[root@zabbix web]# systemctl restart zabbix-server.service
  • 1
  • 2
  • 3
  • 4
  • 5

mark

mark

mark

三:配置代理端

3.1:安装yum源与zabbix代理

[root@client ~]# rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
警告:/var/tmp/rpm-tmp.pkqh2D: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY

[root@client ~]# yum install -y zabbix-agent
  • 1
  • 2
  • 3
  • 4

3.2:修改zabbix代理配置文件并开启服务

vim /etc/zabbix/zabbix_agentd.conf 

13//   PidFile=/var/run/zabbix/zabbix_agentd.pid
32//   LogFile=/var/log/zabbix/zabbix_agentd.log
43//   LogFileSize=0
98//   Server=20.0.0.45          '//指向监听地址'
139//  ServerActive=20.0.0.45   '//指向监听地址'
150//  Hostname=zabbix-test             '//名称'
268//  Include=/etc/zabbix/zabbix_agentd.d/*.conf

'关闭防火墙并开启服务'
service firewalld stop
setenforce 0
systemctl enable zabbix-agent.service
systemctl restart zabbix-agent.service

'检查端口'
netstat -anpt | grep zabbix
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      10739/zabbix_agentd 
tcp6       0      0 :::10050                :::*                    LISTEN      10739/zabbix_agentd
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

3.3:进行添加新主机

mark

配置名称、组等监控IP

mark

mark

mark

本节部署完毕,欢迎留言

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/645677
推荐阅读
相关标签
  

闽ICP备14008679号