基于单个主机lamp架构的zabbix服务

Posted rmㅤ-rf *

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于单个主机lamp架构的zabbix服务相关的知识,希望对你有一定的参考价值。

zabbix监控

下载依赖包

dnf -y install net-snmp-devel libevent-devel libxml2 libxml2-devel curl-devel

解压

[root@localhost ~]# tar xf zabbix-5.2.6.tar.gz 

创建用户和组

[root@localhost zabbix-5.2.6]# useradd -r -M -s /sbin/nologin zabbix

配置zabbix数据库

[root@localhost zabbix-5.2.6]# mysql -uroot -phanao.
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \\g.
Your MySQL connection id is 2
Server version: 5.7.33 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.

mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.01 sec)
mysql> create user 'zabbix'@'localhost' identified by 'hanao.';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> grant all on *.* to zabbix@'192.168.247.215' identified by 'hanao.';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

将数据导入数据库

[root@localhost mysql]# mysql -uzabbix -phanao. zabbix < schema.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -phanao. zabbix < images.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -phanao. zabbix < data.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.

编译安装zabbix

./configure --enable-server \\
--enable-agent \\
--with-mysql \\
--with-net-snmp \\
--with-libcurl \\
--with-libxml2
[root@localhost zabbix-5.2.6]# make install

配置zabbix_server.conf文件,取消注释填写自己的zabbix的mysql用户的密码

[root@localhost etc]# cd /usr/local/etc/
[root@localhost etc]# vim zabbix_server.conf
118  DBPassword=hanao.

启动zabbix_server和zabbix_agentd

[root@localhost etc]# zabbix_server 
[root@localhost etc]# zabbix_agentd 
[root@localhost etc]# ss -anlt
State  Recv-Q Send-Q Local Address:Port    Peer Address:Port Process 
LISTEN 0      128          0.0.0.0:22           0.0.0.0:*            
LISTEN 0      128          0.0.0.0:10050        0.0.0.0:*            
LISTEN 0      128          0.0.0.0:10051        0.0.0.0:*            
LISTEN 0      128          0.0.0.0:9000         0.0.0.0:*            
LISTEN 0      128                *:80                 *:*            
LISTEN 0      128                *:81                 *:*            
LISTEN 0      128             [::]:22              [::]:*            
LISTEN 0      80                 *:3306               *:*           

创建zabbix根目录并将二进制包中的ui目录下的程序复制到zabbix的根目录中设置属主和属组

[root@localhost /]# mv /usr/local/apache/htdocs/hanao /usr/local/apache/htdocs/zabbix
[root@localhost /]# cp -r /root/zabbix-5.2.6/ui/* /usr/local/apache/htdocs/zabbix/
[root@localhost /]# chown -R apache.apache /usr/local/apache/htdocs

配置虚拟主机并重启apache服务

[root@localhost /]# vim /etc/httpd24/extra/httpd-vhosts.conf 
listen 81
<VirtualHost *:81>
    DocumentRoot "/usr/local/apache/htdocs/zabbix"
    ServerName www.hanao.com
    DirectoryIndex index.php
    ProxyRequests Off
    ProxyPassMatch ^/(.*\\.php)$ fcgi://127.0.0.1:9000/usr/local/apach
e/htdocs/zabbix/$1
    <Directory "/usr/local/apache/htdocs/zabbix">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
    ErrorLog "logs/dummy-host.example.com-error_log"
    CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>
[root@localhost /]# systemctl restart httpd

修改etc/php.ini的配置并重启php服务

[root@localhost ~]# sed -ri 's/(post_max_size =).*/\\1 16M/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_execution_time =).*/\\1 300/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_input_time =).*/\\1 300/g' /etc/php.ini
[root@localhost ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@localhost ~]# service php-fpm restart

修改/usr/local/apache/htdocs/zabbix/conf的权限,这样才能自动生成数据库连接文件

[root@localhost conf]# chmod 777 /usr/local/apache/htdocs/zabbix/conf

关闭防火墙和selinux

[root@localhost zabbix]# setenforce 0
[root@localhost zabbix]# systemctl stop firewalld

在192.168.247.215:81端口上初始化zabbix
在这里插入图片描述
最后把/usr/local/apache/htdocs/zabbix/conf目录的权限修改回755

[root@localhost ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf

以上是关于基于单个主机lamp架构的zabbix服务的主要内容,如果未能解决你的问题,请参考以下文章

LAMP架构中部署Zabbix监控服务

LAMP架构之构建虚拟主机

Zabbix&LAMP安装配置

实战案例:编译安装基于 FastCGI 模式LAMP架构多虚拟主机WEB应用(WordPress 和Discuz)

编译安装基于fastcgi模式的多虚拟主机的wordpress和discuz的LAMP架构

LAMP架构