zabbix监控部署在LNMP

一、nginx

iptables -F
setenforce 0
#从官网上下载
[root@localhost ~]#wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
--2021-04-01 15:57:23--  http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
正在解析主机 nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:edb:5704::6, ...
正在连接 nginx.org (nginx.org)|3.125.197.172|: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 15:57:23 (325 MB/s) - 已保存 “nginx-release-centos-7-0.el7.ngx.noarch.rpm” [4680/4680])

#手动创建nginx yum安装源
vim /etc/yum.repos.d/nginx.repo

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
#重新加载
yum list

#安装nginx
yum install nginx -y

systemctl start nginx
netstat  -natp | grep nginx

systemctl enable nginx

到这验证nginx,访问192.168.109.66

在这里插入图片描述

二、db数据库

yum install mariadb-server mariadb -y

systemctl start mariadb.service 
systemctl enable mariadb.service
[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] 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 -u root -p
Enter password: (前面设置的密码)
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 5.5.68-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)]> 

三、php

#安装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.Az83Pd: 头V4 RSA/SHA256 Signature, 密钥 ID 352c64e5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:epel-release-7-13                ################################# [100%]
#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.gB2yzu: 头V4 RSA/SHA1 Signature, 密钥 ID 62e74ca5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:webtatic-release-7-3             ################################# [100%]
#安装软件包
 [root@localhost ~]#yum install -y php72w php72w-devel php72w-fpm php72wpgd php72w-mbstring php72w-mysql
#查看版本
[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
#配置nginx支持php
vim /etc/php-fpm.d/www.conf  #修改php-fpm配置文件

//8 user = nginx
//10 group = nginx


vim /etc/nginx/conf.d/default.conf

//10     index index.php  index.html index.htm;
//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_root$fastcgi_script_name;
//35         include        fastcgi_params;
//36     }
#配置php文件
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/Shanghi  //时区
#开启服务
[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 -natp | grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      42208/php-fpm: mast 

[root@localhost ~]#systemctl restart nginx
[root@localhost ~]#cd /usr/share/nginx/html
[root@localhost html]#ls
50x.html  index.html
[root@localhost html]#vim  info.php

<?php
  phpinfo();
?>

在这里插入图片描述

#测试连接数据库
[root@localhost html]#vim  info.php

<?php
  $link=mysqli_connect('127.0.0.1','root','abc123');
  if ($link) echo "true !!!";
  else echo "false !!!";
?>

在这里插入图片描述

四、zabbix

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

#创建zabbix数据库
[root@localhost html]#mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 5.5.68-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 *.* 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)]> 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)]> quit
Bye

测试连通性

#测试能否连接zabbix数据库
[root@localhost html]#mysql -uzabbix -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 5.5.68-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)]> 
[root@localhost html]#vim  info.php

<?php
  $link=mysqli_connect('127.0.0.1','zabbix','admin123');
  if ($link) echo "zabbix true !!!";
  else echo "zabbix false !!!";
?>

在这里插入图片描述

部署zabbix server

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

[root@localhost html]#yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
[root@localhost html]#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 html]#grep -n '^'[a-Z] /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 ~]# vim /usr/share/zabbix/include/defines.inc.php
:%s /graphfont/kaiti/g    #同时按住shift与:键

在这里插入图片描述

#赋予权限
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/
'//递归修改文件权限'
#导入数据库
[root@localhost zabbix]#zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
Enter password: 
[root@localhost zabbix]#mysql -uzabbix -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 5.5.68-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)]> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [zabbix]> show tables;
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| application_discovery      |
| application_prototype      |
| application_template       |
| applications               |
| auditlog                   |
| auditlog_details           |
| autoreg_host               |
| conditions                 |
| config                     |
| corr_condition             |
| corr_condition_group       |
| corr_condition_tag         |
| corr_condition_tagpair     |
| corr_condition_tagvalue    |
| corr_operation             |
| correlation                |
| dashboard                  |
| dashboard_user             |
| dashboard_usrgrp           |
| dbversion                  |
| dchecks                    |
| dhosts                     |
| drules                     |
| dservices                  |
| escalations                |
| event_recovery             |
| event_suppress             |
| event_tag                  |
| events                     |
| expressions                |
| functions                  |
| globalmacro                |
| globalvars                 |
| graph_discovery            |
| graph_theme                |
| graphs                     |
| graphs_items               |
| group_discovery            |
| group_prototype            |
| history                    |
| history_log                |
| history_str                |
| history_text               |
| history_uint               |
| host_discovery             |
| host_inventory             |
| hostmacro                  |
| hosts                      |
| hosts_groups               |
| hosts_templates            |
| housekeeper                |
| hstgrp                     |
| httpstep                   |
| httpstep_field             |
| httpstepitem               |
| httptest                   |
| httptest_field             |
| httptestitem               |
| icon_map                   |
| icon_mapping               |
| ids                        |
| images                     |
| interface                  |
| interface_discovery        |
| item_application_prototype |
| item_condition             |
| item_discovery             |
| item_preproc               |
| items                      |
| items_applications         |
| maintenance_tag            |
| maintenances               |
| maintenances_groups        |
| maintenances_hosts         |
| maintenances_windows       |
| mappings                   |
| media                      |
| media_type                 |
| opcommand                  |
| opcommand_grp              |
| opcommand_hst              |
| opconditions               |
| operations                 |
| opgroup                    |
| opinventory                |
| opmessage                  |
| opmessage_grp              |
| opmessage_usr              |
| optemplate                 |
| problem                    |
| problem_tag                |
| profiles                   |
| proxy_autoreg_host         |
| proxy_dhistory             |
| proxy_history              |
| regexps                    |
| rights                     |
| screen_user                |
| screen_usrgrp              |
| screens                    |
| screens_items              |
| scripts                    |
| service_alarms             |
| services                   |
| services_links             |
| services_times             |
| sessions                   |
| slides                     |
| slideshow_user             |
| slideshow_usrgrp           |
| slideshows                 |
| sysmap_element_trigger     |
| sysmap_element_url         |
| sysmap_shape               |
| sysmap_url                 |
| sysmap_user                |
| sysmap_usrgrp              |
| sysmaps                    |
| sysmaps_elements           |
| sysmaps_link_triggers      |
| sysmaps_links              |
| tag_filter                 |
| task                       |
| task_acknowledge           |
| task_check_now             |
| task_close_problem         |
| task_remote_command        |
| task_remote_command_result |
| timeperiods                |
| trends                     |
| trends_uint                |
| trigger_depends            |
| trigger_discovery          |
| trigger_tag                |
| triggers                   |
| users                      |
| users_groups               |
| usrgrp                     |
| valuemaps                  |
| widget                     |
| widget_field               |
+----------------------------+
144 rows in set (0.00 sec)

MariaDB [zabbix]> quit
Bye
#修改时区
[root@localhost zabbix]#vim /etc/httpd/conf.d/zabbix.conf

//20         php_value date.timezone Asia/Shanghai
#启动查看状态设置开机自启
[root@localhost zabbix]#systemctl start zabbix-server.service 
[root@localhost zabbix]#systemctl status zabbix-server.service 
[root@localhost zabbix]#systemctl enable zabbix-server.service 
#设置自身也在监控范围
[root@localhost zabbix]#systemctl start zabbix-agent.service 
[root@localhost zabbix]#systemctl enable zabbix-agent.service

systemctl restart php-fpm.service && systemctl restart nginx
netstat -anpl | grep 10051

登录http://192.168.109.66/zabbix/
在这里插入图片描述

都OK再进行下一步
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
步骤一下载文件后传到步骤二的目录下,再进行下一步。
在这里插入图片描述
赋权:chmod -R +x /etc/zabbix/
重启服务
在这里插入图片描述
默认:用户名Admin 密码:zabbix
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

五、配置 Client 客户端测试

部署zabbix-agent

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代理配置文件'

//98  Server=192.168.109.66			//指向监控服务器地址
//139 ServerActive=192.168.109.66		//指向监控服务器地址
//150 Hostname=Zabbix-test			//98G修改名称
systemctl start zabbix-agent.service && systemctl enable zabbix-agent.service

netstat -ntap |grep 'zabbix'

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值