LNMP架构基础上zabbix监控平台部署

it2023-02-02  48

文章目录

前言一:zabbix部署1.1:开局优化1.2:LNMP安装环境(使用yum安装的方式) 二 . 具体部署设置YUM软件源安装部署nginx防火墙设置安装mysql 5.7安装php 7.2 及配置参数修改nginx 配置文件配置php请求被传送到后端的php-fpm模块,默认情况下php配置块是被注释的,此时去掉注释并修改把fastcgi_param中的/scripts改为$document_root。root是配置php程序放置的根目录。配置php测试首页测试连接数据库在数据库创建 zabbix 账户访问网页测试以下开始部署zabbix Server查看修改zabbix 相关配置可选择操作,修改字体----设置站点文件权限,进行访问测试访问测试

前言

一:zabbix部署

主机分配 主机 IP地址 部署服务 server 192.168.100.12 LNMP、zabbix zabbix-agent

1.1:开局优化

关闭防火墙、网络管理、主机名修改

// systemctl stop firewalld && systemctl disable firewalld Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. setenforce 0 && sed -i "s/SELINUX=*/SELINUX=disabled/g" /etc/selinux/config // systemctl stop NetworkManager && systemctl disable NetworkManager Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service. Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service. Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service. Removed symlink /etc/systemd/system/network-online.target.wants/NetworkManager-wait-online.service.

1.2:LNMP安装环境(使用yum安装的方式)

nagios是一款比较老的监控工具,但是因为插件太多,不是主流

cacti是一款图形化的监控分析工具

zabbix是基于web界面的提供分布式功能的监控工具,监控上线是300-500台

zabbix可以监控网络设备(例如思科、华为等)、服务器(例如IBM、联想、戴尔等)、应用监控(Apache、MQ、中间件、Tomcat等)和服务(HTTP、https、nginx、ssl等)等监控

zabbix使用的最稳定的版本是4.0,LTS是指测试,5.0版本在官网下载的时候比4.0版本多了一个nginx服务器的选择

ajax:异步刷新

zcat:不解压直接查看压缩包

二 . 具体部署

设置YUM软件源

[root@zabbix ~]# 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 yum安装源 [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1

安装部署nginx

yum install nginx -y 已安装: nginx.x86_64 1:1.18.0-1.el7.ngx [root@zabbix ~]# systemctl start nginx [root@zabbix ~]# systemctl enable nginx

防火墙设置

[root@zabbix ~]# systemctl start firewalld [root@zabbix ~]# firewall-cmd --permanent --add-service=http --zone=public success [root@zabbix ~]# firewall-cmd --reload

安装mysql 5.7

yum install -y mariadb-server mariadb systemctl enable mariadb.service systemctl start mariadb.service mysql_secure_installation [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! [root@server ~]# mysql -uroot -p '//测试登陆mysql数据库' Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 8 Server version: 5.5.65-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)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec) MariaDB [(none)]> exit Bye

安装php 7.2 及配置参数

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源 //等待时间取决于网络 yum install -y php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql php –v //查看php版本 [root@zabbix ~]# 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 vim /etc/php-fpm.d/www.conf #修改php-fpm配置文件,把apache改为nginx //8 user = nginx //10 group = nginx

修改nginx 配置文件

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

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

//30~36 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; }

把fastcgi_param中的/scripts改为$document_root。root是配置php程序放置的根目录。

配置php

vim /etc/php.ini #修改PHP配置文件 //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 //时区

测试首页

vim /usr/share/nginx/html/info.php <?php phpinfo(); ?>

测试连接数据库

在数据库创建 zabbix 账户

[root@zabbix html]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 10 Server version: 5.5.65-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; GRANT all privileges ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123'; flush privileges;

访问网页测试

以下开始部署zabbix Server

zabbix 官网 https://www.zabbix.com/download 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 //导入数据库脚本 zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix //生成数据库文件,注意密码不要输成root的 MariaDB [zabbix]> show tables; +----------------------------+ | Tables_in_zabbix | +----------------------------+ | acknowledges | | actions | | alerts | ................................. | widget | | widget_field | +----------------------------+ 144 rows in set (0.00 sec)

查看修改zabbix 相关配置

[root@zabbix html]# vim /etc/zabbix/zabbix_server.conf [root@zabbix 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

可选择操作,修改字体----

vim /usr/share/zabbix/include/defines.inc.php //修正图表中文乱码 :%s /graphfont/kaiti/g //从微软系统下复制相应的字体文件到 /usr/share/zabbix/fonts 目录中注意字体名称要对应配置文件,且注意大小写 cp STKAITI.TTF /usr/share/zabbix/fonts/ [root@zabbix html]# cd /usr/share/zabbix/fonts [root@zabbix fonts]# rz -E rz waiting to receive. [root@zabbix fonts]# ls STKAITI.TTF

设置站点文件权限,进行访问测试

setenforce 0 //一定要关闭 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/ systemctl start zabbix-server.service systemctl enable zabbix-server.service systemctl start zabbix-agent.service systemctl enable zabbix-agent.service netstat -anpl | grep 10051 systemctl restart php-fpm.service systemctl restart nginx

访问测试

[root@zabbix fonts]# cd /etc/zabbix/web [root@zabbix web]# ls maintenance.inc.php [root@zabbix web]# rz -E rz waiting to receive. [root@zabbix web]# ls maintenance.inc.php zabbix.conf.php -----------------无法创建配置文件问题--------------------------- 在页面安装过程中遇到无法创建的问题根据提示的连接地址下载配置文件zabbix.conf.php cp zabbix.conf.php /etc/zabbix/web/ chown zabbix.zabbix /etc/zabbix/web/zabbix.conf.php systemctl restart zabbix-server.service

最新回复(0)