01 监控服务zabbix部署

1. zabbix介绍

zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。

zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。

zabbix由2部分构成,zabbix server与可选组件zabbix agent

zabbix server可以通过SNMPzabbix agentping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Ubuntu,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。

zabbix agent需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。

zabbix server可以单独监视远程服务器的服务状态;同时也可以与zabbix agent配合,可以轮询zabbix agent主动接收监视数据(agent方式),同时还可被动接收zabbix agent发送的数据(trapping方式)。
另外zabbix server还支持SNMP (v1,v2),可以与SNMP软件(例如:net-snmp)等配合使用。

1.1 常用的监控软件

  • cacti 擅长画图、流量图、架构图
  • nagios 擅长警告、配置非常麻烦
  • zabbix 结合了cacti和nagios的特点、配置简单、有web界面、配合grafna画图
  • 普罗米修斯(prometheus)
  • 自研

2. zabbix特点

zabbix的主要特点:

  • 安装与配置简单,学习成本低

  • 支持多语言(包括中文)

  • 免费开源

  • 自动发现服务器与网络设备

  • 分布式监视以及WEB集中管理功能

  • 可以无agent监视

  • 用户安全认证和柔软的授权方式

  • 通过WEB界面设置或查看监视结果

  • email等通知功能
    Zabbix主要功能:

  • CPU负荷

  • 内存使用

  • 磁盘使用

  • 网络状况

  • 端口监视

  • 日志监视

zabbix配置:
zabbix配置文件有两种:

  • 服务器端配置文件(/usr/local/etc/zabbix_server.conf)
  • 客户端配置文件(/usr/local/etc/zabbix_agentd.conf)
  • zabbix代理配置文件(/usr/local/etc/zabbix_proxy.conf)

3. 部署zabbix

因为zabbix是用php语言开发的,所以必须先部署lamp架构,使其能够支持运行php网页

3.1安装httpd

//安装epel-release源
[root@localhost ~]# yum -y install epel-release

//安装开发工具包
[root@localhost ~]# yum groups mark install 'Development Tools' -y

//创建apache服务的用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache

//安装依赖包
[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make

//下载和安装apr以及apr-util
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://dlcdn.apache.org/httpd/httpd-2.4.49.tar.gz
[root@localhost src]# wget https://dlcdn.apache.org/apr/apr-1.7.0.tar.gz
[root@localhost src]# wget https://dlcdn.apache.org/apr/apr-util-1.6.1.tar.gz
[root@localhost src]# ls
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  debug  httpd-2.4.49.tar.gz  kernels
[root@localhost src]#

//解压
[root@localhost src]# tar xf apr-1.7.0.tar.gz 
[root@localhost src]# tar xf apr-util-1.6.1.tar.gz 
[root@localhost src]# tar xf httpd-2.4.49.tar.gz 
[root@localhost src]# ls
apr-1.7.0         apr-util-1.6.1         debug         httpd-2.4.49.tar.gz
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.49  kernels
[root@localhost src]# 
[root@localhost src]# cd apr-1.7.0/
[root@localhost apr-1.7.0]# vim configure
31878     cfgfile=${ofile}T
31879     trap "$RM \"$cfgfile\"; exit 1" 1 2 15
31880 #    $RM "$cfgfile"   //将此行加上注释

[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.0]# make
[root@localhost apr-1.7.0]# make install

[root@localhost apr-1.7.0]# cd ../apr-util-1.6.1/
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# make
[root@localhost apr-util-1.6.1]# make install

[root@localhost apr-util-1.6.1]# cd ../httpd-2.4.49/
[root@localhost httpd-2.4.49]# ./configure --prefix=/usr/local/apache \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util/ \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
[root@localhost httpd-2.4.49]# make
[root@localhost httpd-2.4.49]# make install

//安装后配置
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh[root@localhost ~]# source /etc/profile.d/httpd.sh
[root@localhost ~]# which httpd 
/usr/local/apache/bin/httpd
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/apache
[root@localhost ~]# vim /etc/man_db.conf 
 20 MANDATORY_MANPATH                       /usr/man
 21 MANDATORY_MANPATH                       /usr/share/man
 22 MANDATORY_MANPATH                       /usr/local/share/man
 23 MANDATORY_MANPATH                       /usr/local/apache/man   //添加这一行
 24 #---------------------------------------------------------

[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf 
201 # If your host doesn't have a registered DNS name, enter its IP address here.
202 #
203 ServerName www.example.com:80   //将这一行注释取消掉
204 
205 #

//使用service控制apache
[root@localhost ~]# vim /usr/lib/systemd/system/httpd.service
[root@localhost ~]# cat /usr/lib/systemd/system/httpd.service
[Unit]
Description=Httpd server daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecStop=/usr/local/apache/bin/apachectl stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@localhost ~]# 
[root@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# ss -antl
State       Recv-Q      Send-Q           Local Address:Port           Peer Address:Port      
LISTEN      0           128                    0.0.0.0:111                 0.0.0.0:*         
LISTEN      0           32               192.168.122.1:53                  0.0.0.0:*         
LISTEN      0           128                    0.0.0.0:22                  0.0.0.0:*         
LISTEN      0           5                    127.0.0.1:631                 0.0.0.0:*         
LISTEN      0           128                  127.0.0.1:6010                0.0.0.0:*         
LISTEN      0           128                       [::]:111                    [::]:*         
LISTEN      0           128                          *:80                        *:*         
LISTEN      0           128                       [::]:22                     [::]:*         
LISTEN      0           5                        [::1]:631                    [::]:*         
LISTEN      0           128                      [::1]:6010                   [::]:*         
[root@localhost ~]# 

3.2 安装mysql

部署zabbix需要使用mysql-5.7.28版本以上

//安装依赖包
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

//创建用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql

//下载二进制格式的mysql软件包,上传到/usr/src
[root@localhost src]# ls
apr-1.7.0         apr-util-1.6.1.tar.gz  httpd-2.4.49.tar.gz
apr-1.7.0.tar.gz  debug                  kernels
apr-util-1.6.1    httpd-2.4.49           mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz

//解压软件至/usr/local/
[root@localhost src]# tar xf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# 
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
apache  apr-util  etc    include  lib64    mysql-5.7.34-linux-glibc2.12-x86_64  share
apr     bin       games  lib      libexec  sbin                                 src
[root@localhost local]# mv mysql-5.7.34-linux-glibc2.12-x86_64 mysql
[root@localhost local]# chown -R mysql.mysql mysql
[root@localhost local]# 

//添加环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost ~]# source /etc/profile.d/mysql.sh 
[root@localhost ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/apache/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost ~]# 
[root@localhost ~]# ln -s /usr/local/mysql/include/ /usr/include/mysql
[root@localhost ~]# vim /etc/man_db.conf 
 20 MANDATORY_MANPATH                       /usr/man
 21 MANDATORY_MANPATH                       /usr/share/man
 22 MANDATORY_MANPATH                       /usr/local/share/man
 23 MANDATORY_MANPATH                       /usr/local/apache/man
 24 MANDATORY_MANPATH                       /usr/local/mysql/man   //添加这一行

[root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf
[root@localhost ~]# cat /etc/ld.so.conf.d/mysql.conf 
/usr/local/mysql/lib
[root@localhost ~]# ldconfig 
[root@localhost ~]# 

//建立数据存放目录
[root@localhost ~]# mkdir -p /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data/

//初始化数据库
[root@localhost ~]# mysqld --initialize-insecure --user mysql --datadir /opt/data/
2021-09-23T10:49:13.943769Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-09-23T10:49:15.135201Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-09-23T10:49:15.300616Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-09-23T10:49:15.319952Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: e51e1956-1c5b-11ec-82b9-000c29fb6a38.
2021-09-23T10:49:15.321052Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-09-23T10:49:15.708527Z 0 [Warning] CA certificate ca.pem is self signed.
2021-09-23T10:49:15.884677Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@localhost ~]# 

//生成配置文件
[root@localhost ~]# cat > /etc/my.cnf <<EOF
> [mysqld]
> basedir = /usr/local/mysql
> datadir = /opt/data
> socket = /tmp/mysql.sock
> port = 3306
> pid-file = /opt/data/mysql.pid
> user = mysql
> skip-name-resolve
> EOF
[root@localhost ~]# 

//使用service控制mysql
[root@localhost ~]# cp /usr/lib/systemd/system/httpd.service /usr/lib/systemd/system/mysqld.service
[root@localhost ~]# vim /usr/lib/systemd/system/mysqld.service
[root@localhost ~]# cat /usr/lib/systemd/system/mysqld.service 
[Unit]
Description=Mysql server daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@localhost ~]# 

[root@localhost ~]# vim /usr/local/mysql/support-files/mysql.server 
46 basedir=/usr/local   //修改这两行
47 datadir=/opt/data

[root@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# systemctl enable --now mysqld.service 
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@localhost ~]# ss -antl
State       Recv-Q      Send-Q           Local Address:Port           Peer Address:Port      
LISTEN      0           128                    0.0.0.0:111                 0.0.0.0:*         
LISTEN      0           32               192.168.122.1:53                  0.0.0.0:*         
LISTEN      0           128                    0.0.0.0:22                  0.0.0.0:*         
LISTEN      0           5                    127.0.0.1:631                 0.0.0.0:*         
LISTEN      0           128                  127.0.0.1:6010                0.0.0.0:*         
LISTEN      0           128                       [::]:111                    [::]:*         
LISTEN      0           128                          *:80                        *:*         
LISTEN      0           128                       [::]:22                     [::]:*         
LISTEN      0           5                        [::1]:631                    [::]:*         
LISTEN      0           128                      [::1]:6010                   [::]:*         
LISTEN      0           80                           *:3306                      *:*         
[root@localhost ~]# 

//设置密码
[root@localhost ~]# yum -y install ncurses-compat-libs
[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.34 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> set password = password("1");
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit
Bye
[root@localhost ~]# mysql -uroot -p1
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 3
Server version: 5.7.34 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> exit
Bye
[root@localhost ~]# 

3.3 安装php

//安装zabbix需要使用php7.4版本
//安装依赖包

[root@localhost ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel  pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel libsqlite3x-devel php-mysqlnd libzip-devel

[root@localhost ~]# yum -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm

//下载php
[root@localhost local]# wget https://www.php.net/distributions/php-7.2.24.tar.gz
[root@localhost local]# tar xf php-7.2.24.tar.gz 
[root@localhost local]# cd php-7.2.24/
[root@localhost php-7.2.24]# 

//编译安装php
[root@localhost php-7.2.24]# ./configure --prefix=/usr/local/php7  \
--with-config-file-path=/etc \
--enable-fpm \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-openssl \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif  \
--enable-ftp \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--with-gettext \
--enable-json \
--enable-mbstring \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-pcntl \
--enable-posix

[root@localhost php-7.2.24]# make && make install

//安装后配置
[root@localhost php-7.2.24]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php.sh
[root@localhost php-7.2.24]# source /etc/profile.d/php.sh
[root@localhost php-7.2.24]# which php
[root@localhost php-7.2.24]# php -v
PHP 7.2.24 (cli) (built: Sep 26 2021 16:40:58) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

//配置php-fpm
[root@localhost php-7.2.24]# cp php.ini-production /etc/php.ini
[root@localhost php-7.2.24]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.2.24]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost php-7.2.24]# cd /usr/local/php7
[root@localhost php7]# ls
bin  etc  include  lib  php  sbin  var
[root@localhost php7]# cd etc/
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# ls
www.conf.default
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# service php-fpm start 
Starting php-fpm  done
[root@localhost php-fpm.d]# ss -antl
State          Recv-Q         Send-Q                 Local Address:Port                 Peer Address:Port        
LISTEN         0              32                     192.168.122.1:53                        0.0.0.0:*           
LISTEN         0              128                          0.0.0.0:22                        0.0.0.0:*           
LISTEN         0              5                          127.0.0.1:631                       0.0.0.0:*           
LISTEN         0              128                        127.0.0.1:6010                      0.0.0.0:*           
LISTEN         0              128                        127.0.0.1:9000                      0.0.0.0:*           
LISTEN         0              128                          0.0.0.0:111                       0.0.0.0:*           
LISTEN         0              128                             [::]:22                           [::]:*           
LISTEN         0              5                              [::1]:631                          [::]:*           
LISTEN         0              128                            [::1]:6010                         [::]:*           
LISTEN         0              80                                 *:3306                            *:*           
LISTEN         0              128                             [::]:111                          [::]:*           
LISTEN         0              128                                *:80                              *:*           
[root@localhost php-fpm.d]# 

//使用service控制php
[root@localhost ~]# vim /usr/lib/systemd/system/php-fpm.service
[root@localhost ~]# cat /usr/lib/systemd/system/php-fpm.service 
[Unit]
Description=php server daemon
After=network.target

[Service]
Type=forking
ExecStart=/etc/init.d/php-fpm start
ExecStop=/etc/init.d/php-fpm stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# systemctl enable --now php-fpm.service 
Synchronizing state of php-fpm.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[root@localhost ~]# ss -antl
State          Recv-Q         Send-Q                 Local Address:Port                 Peer Address:Port        
LISTEN         0              32                     192.168.122.1:53                        0.0.0.0:*           
LISTEN         0              128                          0.0.0.0:22                        0.0.0.0:*           
LISTEN         0              5                          127.0.0.1:631                       0.0.0.0:*           
LISTEN         0              128                        127.0.0.1:6010                      0.0.0.0:*           
LISTEN         0              128                        127.0.0.1:9000                      0.0.0.0:*           
LISTEN         0              128                          0.0.0.0:111                       0.0.0.0:*           
LISTEN         0              128                             [::]:22                           [::]:*           
LISTEN         0              5                              [::1]:631                          [::]:*           
LISTEN         0              128                            [::1]:6010                         [::]:*           
LISTEN         0              80                                 *:3306                            *:*           
LISTEN         0              128                             [::]:111                          [::]:*           
LISTEN         0              128                                *:80                              *:*          

配置apache

启用代理模块

[root@localhost php-8.0.10]# vim /usr/local/apache/conf/httpd.conf 
119 #LoadModule remoteip_module modules/mod_remoteip.so
120 LoadModule proxy_module modules/mod_proxy.so   //取消注释
121 #LoadModule proxy_connect_module modules/mod_proxy_connect.so
122 #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
123 #LoadModule proxy_http_module modules/mod_proxy_http.so
124 LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so   //取消注释

配置虚拟主机

//创建虚拟主机目录并生成php测试页面
[root@localhost ~]# cd /usr/local/apache/
[root@localhost apache]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules

[root@localhost apache]# ls htdocs/
index.html  
[root@localhost apache]# mkdir htdocs/test/
[root@localhost apache]# vim htdocs/test/index.php 
[root@localhost apache]# cat htdocs/test/index.php 
<?php
        phpinfo();
?>
[root@localhost apache]# 
[root@localhost apache]# chown -R apache.apache /usr/local/apache/htdocs/

[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf 
//在配置文件的最后加入以下内容
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/test"
    ServerName www.wangqing.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/test/$1
    <Directory "/usr/local/apache/htdocs/test">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf 
//搜索AddType,添加以下内容
397     AddType application/x-compress .Z
398     AddType application/x-gzip .gz .tgz
399     AddType application/x-httpd-php .php   //添加这一行
400     AddType application/x-httpd-php-source .phps   //添加这一行

[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf 
//搜索index.html,添加以下内容
260 <IfModule dir_module>
261     DirectoryIndex index.php index.html   //修改这一行
262 </IfModule>

//重启apache服务
[root@localhost ~]# systemctl restart httpd.service 
[root@localhost ~]# 
[root@localhost ~]# ss -antl
State       Recv-Q      Send-Q           Local Address:Port           Peer Address:Port     
LISTEN      0           128                    0.0.0.0:111                 0.0.0.0:*        
LISTEN      0           32               192.168.122.1:53                  0.0.0.0:*        
LISTEN      0           128                    0.0.0.0:22                  0.0.0.0:*        
LISTEN      0           5                    127.0.0.1:631                 0.0.0.0:*        
LISTEN      0           128                  127.0.0.1:6010                0.0.0.0:*        
LISTEN      0           128                  127.0.0.1:6011                0.0.0.0:*        
LISTEN      0           128                  127.0.0.1:9000                0.0.0.0:*        
LISTEN      0           128                       [::]:111                    [::]:*        
LISTEN      0           128                          *:80                        *:*        
LISTEN      0           128                       [::]:22                     [::]:*        
LISTEN      0           5                        [::1]:631                    [::]:*        
LISTEN      0           128                      [::1]:6010                   [::]:*        
LISTEN      0           128                      [::1]:6011                   [::]:*        
LISTEN      0           80                           *:3306                      *:*        
[root@localhost ~]# 

验证
1.修改/etc/hosts文件,添加域名与IP的映射
2.在浏览器上使用域名访问,若看到以下界面则表示lamp架构搭建成功,否则请检查你的操作和防火墙是否关闭
在这里插入图片描述

3.4 zabbix服务端安装

//安装依赖软件
[root@server ~]# yum -y install net-snmp-devel libevent-devel

zabbix官网下载链接:
https://www.zabbix.com/download_sources

在这里插入图片描述

//下载完成后将它上传到/usr/src目录里
[root@server src]# ls
apr-1.7.0         apr-util-1.6.1.tar.gz  httpd-2.4.49.tar.gz                         zabbix-5.4.4.tar.gz
apr-1.7.0.tar.gz  debug                  kernels
apr-util-1.6.1    httpd-2.4.49           mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
[root@server src]# tar xf zabbix-5.4.4.tar.gz

//创建zabbix用户
[root@server src]# useradd -r -M -s /sbin/nologin zabbix

//配置abbix数据库
[root@server src]# mysql -uroot -p1
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.34 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.00 sec) 

mysql> grant all privileges on zabbix.* to zabbix@localhost identified by '1';   //授权用户
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> flush privileges;   //刷新权限
Query OK, 0 rows affected (0.00 sec)

mysql> 

[root@server src]# cd zabbix-5.4.4/database/mysql/
[root@server mysql]# ls
data.sql  double.sql  images.sql  Makefile.am  Makefile.in  schema.sql
[root@server mysql]# mysql -uroot -p1 zabbix < schema.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@server mysql]# mysql -uroot -p1 zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@server mysql]# mysql -uroot -p1 zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@server mysql]# 

//编译安装zabbix
[root@server zabbix-5.4.4]# ./configure --enable-server \
--enable-agent \
--with-mysql \
--with-net-snmp \
--with-libcurl \
--with-libxml2

[root@server zabbix-5.4.4]# make install

3.5 zabbix服务端配置

[root@server zabbix-5.4.4]# ls /usr/local/etc/
zabbix_agentd.conf  zabbix_agentd.conf.d  zabbix_server.conf  zabbix_server.conf.d
[root@server zabbix-5.4.4]# vim /usr/local/etc/zabbix_server.conf
121 # Mandatory: no
122 # Default:
123 DBPassword= 1   //取消注释,设置zabbix数据库密码
124 

//启动服务
[root@server ~]# mkdir /var/lib/mysql
[root@server ~]# ln -s /tmp/mysql.sock /var/lib/mysql/ 
[root@server ~]# zabbix_server 
[root@server ~]# zabbix_agentd 
[root@server ~]# ss -antl
State         Recv-Q        Send-Q                 Local Address:Port                  Peer Address:Port        
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                        127.0.0.1:9000                       0.0.0.0:*           
LISTEN        0             128                          0.0.0.0:111                        0.0.0.0:*           
LISTEN        0             32                     192.168.122.1:53                         0.0.0.0:*           
LISTEN        0             128                          0.0.0.0:22                         0.0.0.0:*           
LISTEN        0             5                          127.0.0.1:631                        0.0.0.0:*           
LISTEN        0             128                        127.0.0.1:6010                       0.0.0.0:*           
LISTEN        0             80                                 *:3306                             *:*           
LISTEN        0             128                             [::]:111                           [::]:*           
LISTEN        0             128                                *:80                               *:*           
LISTEN        0             128                             [::]:22                            [::]:*           
LISTEN        0             5                              [::1]:631                           [::]:*           
LISTEN        0             128                            [::1]:6010                          [::]:*           
[root@server ~]# 

3.6 zabbix服务端web界面安装

[root@server ~]# cd /usr/local/apache/htdocs/
[root@server htdocs]# mkdir zabbix
[root@server htdocs]# chown -R apache.apache /usr/local/apache/htdocs/
[root@server src]# cd zabbix-5.4.4/
[root@server zabbix-5.4.4]# cp -r ui/* /usr/local/apache/htdocs/zabbix/

//httpd文件
[root@server ~]# vim /usr/local/apache/conf/httpd.conf   //修改配置文件
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/zabbix"
    ServerName www.test.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix/$1
    <Directory "/usr/local/apache/htdocs/zabbix">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

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

3.7 安装zabbix web界面

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

//修改权限
[root@server php-7.2.24]# chown -R apache.apache /usr/local/apache/htdocs/zabbix
[root@server php-7.2.24]# chmod 777 /usr/local/apache/htdocs/zabbix/conf/
[root@server php-7.2.24]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxrwxrwx 3 apache apache 94 926 20:47 /usr/local/apache/htdocs/zabbix/conf
[root@server php-7.2.24]# 

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
zabbix默认登陆用户名:Admin,密码:zabbix
恢复zabbix/conf目录的权限为755:

[root@server ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf
[root@server ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxr-xr-x 3 apache apache 117 926 21:35 /usr/local/apache/htdocs/zabbix/conf
[root@server ~]# 

4. 故障案例

如果重启zabbix_server报了以下的错,可以使用下面的方法解决

[root@localhost zabbix-5.4.4]# zabbix_server 
zabbix_server: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
[root@localhost zabbix-5.4.4]# ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64 &>/dev/null
[root@localhost zabbix-5.4.4]# zabbix_server 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是在Linux上搭建部署Zabbix监控服务的步骤: 1.安装LAMP(Linux、Apache、MySQL、PHP)环境 2.安装Zabbix server和Zabbix agent 3.创建Zabbix数据库 4.导入Zabbix数据库 5.配置Zabbix server 6.启动Zabbix server和Zabbix agent 7.访问Zabbix web界面 具体步骤如下: 1.安装LAMP环境 在Linux上安装Apache、MySQL和PHP,可以使用以下命令: ```shell sudo apt-get update sudo apt-get install apache2 mysql-server php php-mysql libapache2-mod-php ``` 2.安装Zabbix server和Zabbix agent 可以使用以下命令安装Zabbix server和Zabbix agent: ```shell sudo apt-get install zabbix-server-mysql zabbix-frontend-php zabbix-agent ``` 3.创建Zabbix数据库 使用以下命令登录到MySQL: ```shell sudo mysql -u root -p ``` 创建一个名为“zabbix”的数据库: ```mysql create database zabbix character set utf8 collate utf8_bin; ``` 创建一个名为“zabbix”的用户,并授予该用户对“zabbix”数据库的所有权限: ```mysql grant all privileges on zabbix.* to zabbix@localhost identified by 'password'; ``` 退出MySQL: ```mysql exit; ``` 4.导入Zabbix数据库 使用以下命令导入Zabbix数据库: ```shell zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix ``` 5.配置Zabbix server 编辑Zabbix server配置文件“/etc/zabbix/zabbix_server.conf”,并将以下行取消注释并修改: ```conf DBName=zabbix DBUser=zabbix DBPassword=password ``` 6.启动Zabbix server和Zabbix agent 使用以下命令启动Zabbix server和Zabbix agent: ```shell sudo systemctl start zabbix-server zabbix-agent sudo systemctl enable zabbix-server zabbix-agent ``` 7.访问Zabbix web界面 在Web浏览器中输入服务器的IP地址或域名,然后输入用户名“Admin”和密码“zabbix”登录到Zabbix web界面。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

彭宇栋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值