将Zabbix监控部署在LNMP平台详细步骤

文章目录

    • 项目环境:
  • 服务端安装配置
    • 关闭防火墙
  • 一、LNMP安装环境
    • 1、安装nginx1.16
      • (1)从官网上下载
      • (2)手动创建nginx yum安装源
      • (3)重新加载
      • (4)安装nginx
      • (5)开启服务
      • (6)打开网页访问 http://192.168.200.40
    • 2、安装mysql 5.7
      • (1)安装服务
      • (2)开启服务
      • (3)进行设置
    • 3、安装PHP
      • (1)安装PHP源
      • (2)yum仓库的生成
      • (3)安装软件包
      • (4)查看PHP版本
    • 4、配置nginx支持php
      • (1)修改php-fpm配置文件,把apache改为nginx
      • (2)配置location,在index中添加index.php。以支持index.php的首页
    • 5、配置php
      • (1)修改PHP配置文件
      • (2)开启PHP服务并重启nginx服务
    • 6、测试首页
      • (1)写一个简单的测试首页
      • (2)打开浏览器访问:http://192.168.200.40/info.php
    • 7、测试连接数据库
      • (1)测试页
      • (2)在浏览器刷新:
    • 8、安装zabbix前提
      • (1)准备zabbix数据库
      • (2)检查用户能否登录数据库
      • (3)、浏览器刷新,发现Zabbix连接失败
      • (4)解决以上连接失败的办法
      • (5)、重新刷新网页,显示连接成功
  • 二、部署zabbix Server
    • 1、安装yum源
    • 2、安装相关环境包
    • 3、修改配置文件
    • 4、修正图表中文乱码(可选择操作)
    • 5、从微软系统下复制相应的字体文件到 /usr/share/zabbix/fonts 目录中注意字体名称要对应配置文件,且注意大小写(可选择操作)
    • 6、赋予权限
    • 7、生成数据库文件,注意密码不要输成root的
    • 8、修改时区
    • 9、启动服务
    • 10、安装后登录 用户名Admin 密码:zabbix
  • 三、配置 Client 客户端
    • 1、Zabbix 监控服务器

项目环境:

服务端:192.168.200.40
客户端:192.168.200.60

服务端安装配置

关闭防火墙

[root@localhost ~]# systemctl stop firewalld.service 
[root@localhost ~]# systemctl disable firewalld.service 
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0

一、LNMP安装环境

1、安装nginx1.16

(1)从官网上下载

root@localhost ~]# wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
--2021-04-01 11:13:37--  http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
正在解析主机 nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5702::6, ...
正在连接 nginx.org (nginx.org)|52.58.199.22|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:4680 (4.6K) [application/x-redhat-package-manager]
正在保存至: “nginx-release-centos-7-0.el7.ngx.noarch.rpm”

100%[======================>] 4,680       --.-K/s 用时 0s      

2021-04-01 11:13:38 (400 MB/s) - 已保存 “nginx-release-centos-7-0.el7.ngx.noarch.rpm” [4680/4680])

(2)手动创建nginx yum安装源

[root@localhost ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

(3)重新加载

[root@localhost ~]# yum list

如果出现以下问题:
[root@localhost ~]# yum list
已加载插件:fastestmirror, langpacks
/var/run/yum.pid 已被锁定,PID  17043 的另一个程序正在运行。
Another app is currently holding the yum lock; waiting for it to exit...
  另一个应用程序是:PackageKit
    内存:162 M RSS 649 MB VSZ)
    已启动: Thu Apr  1 11:10:49 2021 - 03:31之前
    状态  :睡眠中,进程ID:17043


将进程杀掉即可:
[root@localhost ~]# kill -5  17043

(4)安装nginx

[root@localhost ~]# yum install nginx -y

(5)开启服务

[root@localhost ~]# systemctl start nginx                   
[root@localhost ~]# netstat -ntap | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      108485/nginx: maste 
[root@localhost ~]# systemctl enable nginx                   #设为开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

(6)打开网页访问 http://192.168.200.40

将Zabbix监控部署在LNMP平台详细步骤_第1张图片

2、安装mysql 5.7

(1)安装服务

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

(2)开启服务

[root@localhost ~]# systemctl start mariadb.service 
[root@localhost ~]# systemctl enable mariadb.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

(3)进行设置

[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:                       #abc123
Re-enter new password:                    #abc123
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              #允许远程登录
 ... 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!

//验证密码已经设置好无误

[root@localhost ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.64-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)]> \q
Bye

3、安装PHP

(1)安装PHP源

[root@localhost ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 
获取https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
警告:/var/tmp/rpm-tmp.uNc4OO: 头V3 RSA/SHA256 Signature, 密钥 ID 352c64e5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:epel-release-7-12                ################################# [100%]

(2)yum仓库的生成

[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
获取https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
警告:/var/tmp/rpm-tmp.O9dfAV: 头V4 RSA/SHA1 Signature, 密钥 ID 62e74ca5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:webtatic-release-7-3             ################################# [100%]

(3)安装软件包

[root@localhost ~]# yum install -y php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql

(4)查看PHP版本

[root@localhost ~]# 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

4、配置nginx支持php

(1)修改php-fpm配置文件,把apache改为nginx

[root@localhost ~]# vim /etc/php-fpm.d/www.conf

#8 user = nginx

#10 group = nginx

(2)配置location,在index中添加index.php。以支持index.php的首页

[root@localhost ~]# vim /etc/nginx/conf.d/default.conf

#10  index  index.php index.html index.htm;

#30~36     

#配置php请求被传送到后端的php-fpm模块,默认情况下php配置块是被注释的,此时去掉注释并修改

#把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;
      }

5、配置php

(1)修改PHP配置文件

[root@localhost ~]# vim /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
#877  date.timezone = Asia/Shanghai  //时区

(2)开启PHP服务并重启nginx服务

[root@localhost ~]# systemctl start php-fpm.service 
[root@localhost ~]# systemctl enable php-fpm.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
[root@localhost ~]# netstat -ntap | grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      86082/php-fpm: mast 

[root@localhost html]# systemctl restart nginx

6、测试首页

(1)写一个简单的测试首页

[root@localhost ~]# vim /usr/share/nginx/html/info.php

<?php
 phpinfo();
?>

(2)打开浏览器访问:http://192.168.200.40/info.php

将Zabbix监控部署在LNMP平台详细步骤_第2张图片

7、测试连接数据库

(1)测试页

[root@localhost ~]# 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

(2)在浏览器刷新:

将Zabbix监控部署在LNMP平台详细步骤_第3张图片

8、安装zabbix前提

(1)准备zabbix数据库

[root@localhost html]# mysql -uroot -p
ariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin;

MariaDB [(none)]> GRANT all privileges ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123';

MariaDB [(none)]> flush privileges;

#collate的作用
对于mysql中那些字符类型的列,如VARCHAR,CHAR,TEXT类型的列,都需要有一个COLLATE类型来告知mysql如何对该列进行排序和比较。

(2)检查用户能否登录数据库

[root@localhost ~]# vim /usr/share/nginx/html/info.php
<?php
$link=mysqli_connect('127.0.0.1','zabbix','admin123');
if ($link) echo "Zabbix数据库连接成功!";
else echo "Zabbix数据库连接失败!";
?>

(3)、浏览器刷新,发现Zabbix连接失败

将Zabbix监控部署在LNMP平台详细步骤_第4张图片

(4)解决以上连接失败的办法

[root@localhost html]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 5.5.64-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)]> select user,host from mysql.user;                      #有空用户名称占用导致本地无法登录远程可登录
+--------+-----------------------+
| user   | host                  |
+--------+-----------------------+
| zabbix | %                     |
| root   | 127.0.0.1             |
| root   | ::1                   |
|        | localhost             |
| root   | localhost             |
|        | localhost.localdomain |
| root   | localhost.localdomain |
+--------+-----------------------+
7 rows in set (0.00 sec)

MariaDB [(none)]> drop user ''@localhost;                         #删除空用户
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> drop user ''@localhost.localdomain;                     #删除空用户
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------------------+
| user   | host                  |
+--------+-----------------------+
| zabbix | %                     |
| root   | 127.0.0.1             |
| root   | ::1                   |
| root   | localhost             |
| root   | localhost.localdomain |
+--------+-----------------------+
5 rows in set (0.00 sec)

MariaDB [(none)]> \q
Bye

(5)、重新刷新网页,显示连接成功

将Zabbix监控部署在LNMP平台详细步骤_第5张图片

二、部署zabbix Server

zabbix 官网 https://www.zabbix.com/download

1、安装yum源

[root@localhost ~]# 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.ReqDjI: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY

2、安装相关环境包

[root@localhost ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y

3、修改配置文件

[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf 
38:LogFile=/var/log/zabbix/zabbix_server.log
49:LogFileSize=0
72:PidFile=/var/run/zabbix/zabbix_server.pid
82:SocketDir=/var/run/zabbix
91:DBHost=localhost                //注释去掉
100:DBName=zabbix
116:DBUser=zabbix
124:DBPassword=admin123           //修改本行
356:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
473:Timeout=4
516:AlertScriptsPath=/usr/lib/zabbix/alertscripts
527:ExternalScripts=/usr/lib/zabbix/externalscripts
563:LogSlowQueries=3000

[root@localhost ~]# grep -n '^'[a-Z] /etc/zabbix/zabbix_server.conf 
#检查修改的配置文件是否正确

4、修正图表中文乱码(可选择操作)

[root@localhost ~]# vim /usr/share/zabbix/include/defines.inc.php
:%s /graphfont/kaiti/g    #同时按住shift与:键

5、从微软系统下复制相应的字体文件到 /usr/share/zabbix/fonts 目录中注意字体名称要对应配置文件,且注意大小写(可选择操作)

cp STKAITI.TTF /usr/share/zabbix/fonts/

6、赋予权限

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/
'//递归修改文件权限'

7、生成数据库文件,注意密码不要输成root的

[root@localhost zabbix]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
Enter password:             #密码admin23

//查看文件是否存在

[root@localhost zabbix]# mysql -uzabbix -p

MariaDB [(none)]> use zabbix;

MariaDB [zabbix]> show tables;

8、修改时区

[root@localhost zabbix]# vim /etc/httpd/conf.d/zabbix.conf

#20     php_value date.timezone Asia/Shanghai

9、启动服务

systemctl start zabbix-server.service && systemctl enable zabbix-server.service 

systemctl start zabbix-agent.service && systemctl enable zabbix-agent.service

systemctl restart php-fpm.service && systemctl restart nginx

[root@localhost zabbix]# netstat -anpl | grep 10051
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      121393/zabbix_serve 
tcp        0      0 127.0.0.1:10051         127.0.0.1:58008         TIME_WAIT   -                   
tcp6       0      0 :::10051                :::*                    LISTEN      121393/zabbix_serve 

10、安装后登录 用户名Admin 密码:zabbix

浏览器输入:输入:http://192.168.200.40/zabbix/
将Zabbix监控部署在LNMP平台详细步骤_第6张图片
将Zabbix监控部署在LNMP平台详细步骤_第7张图片
将Zabbix监控部署在LNMP平台详细步骤_第8张图片
将Zabbix监控部署在LNMP平台详细步骤_第9张图片
将Zabbix监控部署在LNMP平台详细步骤_第10张图片

将Zabbix监控部署在LNMP平台详细步骤_第11张图片

将Zabbix监控部署在LNMP平台详细步骤_第12张图片

[root@localhost web]# chmod -R +x /etc/zabbix/   #赋权
[root@localhost web]# ls
maintenance.inc.php  zabbix.conf.php

将Zabbix监控部署在LNMP平台详细步骤_第13张图片
将Zabbix监控部署在LNMP平台详细步骤_第14张图片
将Zabbix监控部署在LNMP平台详细步骤_第15张图片
将Zabbix监控部署在LNMP平台详细步骤_第16张图片
将Zabbix监控部署在LNMP平台详细步骤_第17张图片
将Zabbix监控部署在LNMP平台详细步骤_第18张图片

三、配置 Client 客户端

rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm

yum -y install zabbix-agent
'//安装zabbix存储库与agent代理服务'

--
vim /etc/zabbix/zabbix_agentd.conf		'//修改zabbix代理配置文件'

Server=192.168.200.40			'//98行,指向监控服务器地址'
ServerActive=192.168.200.40		'//139行,指向监控服务器地址'
Hostname=Zabbix-test			'//150行,修改名称'

--
systemctl start zabbix-agent.service && systemctl enable zabbix-agent.service

netstat -ntap |grep 'zabbix'

1、Zabbix 监控服务器

可以将界面转换成中文界面

将Zabbix监控部署在LNMP平台详细步骤_第19张图片

将Zabbix监控部署在LNMP平台详细步骤_第20张图片
将Zabbix监控部署在LNMP平台详细步骤_第21张图片
将Zabbix监控部署在LNMP平台详细步骤_第22张图片
将Zabbix监控部署在LNMP平台详细步骤_第23张图片
查看监控数据:
将Zabbix监控部署在LNMP平台详细步骤_第24张图片
将Zabbix监控部署在LNMP平台详细步骤_第25张图片
将Zabbix监控部署在LNMP平台详细步骤_第26张图片

你可能感兴趣的:(云计算,zabbix,运维,zabbix,监控类,云计算,运维)