zabbix

zabbix服务端安装

环境:

主机 ip 应用
服务端 192.168.23.140 基于lamp架构下部署zabbix server, zabbix agent

准备工作

//安装依赖包
[root@localhost ~]# yum -y install net-snmp-devel libevent-devel

//下载zabbix(官方网站下载)
https://www.zabbix.com/cn/download_sources 
[root@localhost ~]# ls
anaconda-ks.cfg  lamp  zabbix-5.2.6.tar.gz

//解压
[root@localhost ~]# tar xf zabbix-5.2.6.tar.gz 
[root@localhost ~]# ls
anaconda-ks.cfg  lamp  zabbix-5.2.6  zabbix-5.2.6.tar.gz

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

//配置zabbix数据库
[root@localhost ~]# mysql -uroot -p
Enter password: 123456
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.31 MySQL Community Server (GPL)
 
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
 
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>  grant all privileges on zabbix.* to zabbix@localhost identified by '123456';
Query OK, 0 rows affected, 1 warning (0.01 sec)
 
mysql>  grant all privileges on zabbix.* to zabbix@192.168.248.134 identified by '123456';
Query OK, 0 rows affected, 1 warning (0.01 sec)
 
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
 
mysql> quit


//导入表
[root@localhost database]# cd /usr/local/zabbix-5.2.6/database/mysql/
 
[root@localhost mysql]# ls
data.sql  double.sql  images.sql  Makefile.am  Makefile.in  schema.sql
 
[root@localhost mysql]# mysql -uroot -p123456 zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
 
[root@localhost mysql]# mysql -uroot -p123456 zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
 
[root@localhost mysql]# mysql -uroot -p123456 zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.

编译安装zabbix

[root@localhost ~]# cd /usr/local/zabbix-5.2.6/
[root@localhost zabbix-5.2.6]# ./configure --enable-server 
> --enable-agent 
> --with-mysql 
> --with-net-snmp 
> --with-libcurl 
> --with-libxml2

***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <http://www.zabbix.com>                    *
***********************************************************

[root@localhost zabbix-5.2.6]# make install

配置zabbix服务端

[root@localhost zabbix-5.2.6]# vim /usr/local/etc/zabbix_server.conf
.............................
.......................
BName=zabbix  
DBUser=zabbix
DBPassword=123456  //设置zabbix数据库的密码

//启动zabbix服务
[root@localhost zabbix-5.2.6]# zabbix_server
[root@localhost zabbix-5.2.6]# zabbix_agentd
[root@localhost zabbix-5.2.6]# ss -antl
State        Recv-Q       Send-Q              Local Address:Port                Peer Address:Port      
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            80                              *:3306                           *:*         
LISTEN       0            128                             *:80                             *:*         
LISTEN       0            128                          [::]:22                          [::]:*

zabbix服务端web界面安装与配置

zabbix web界面安装前配置

//修改/etc/php.ini的配置并重启php-fpm
[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 ~]# systemctl restart php-fpm

[root@localhost ~]# mkdir /usr/local/apache/htdocs/zabbix
[root@localhost ~]#  cp -a  /usr/local/zabbix-5.2.6/ui/*  /usr/local/apache/htdocs/zabbix/
[root@localhost ~]# chown -R apache.apache /usr/local/apache/htdocs

修改当前虚拟主机的配置文件

//修改虚拟主机配置的文件位置
[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf

//在配置文件的末尾加如下内容

<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/zabbix"
    ServerName www.yc.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>
 
//设置zabbix/conf目录的权限,让zabbix有权限生成配置文件zabbix.conf.php
[root@localhost ~]# chmod  777 /usr/local/apache/htdocs/zabbix/conf
 
//重启apache
[root@localhost ~]# apachectl -t
Syntax OK
[root@localhost ~]# apachectl restart

在web界面安装

接下来一直下一步即可

  • zabbix默认登录用户名和密码:
用户名 密码
Admin zabbix

注:恢复zabbix/conf目录的权限为755

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

设置zabbix的开机自动启动

[root@localhost ~]# cd /usr/local/zabbix-5.2.6/misc/init.d/fedora/core5
[root@localhost core5]# ls
zabbix_agentd  zabbix_server
[root@localhost ~]# chkconfig --add zabbix_server
[root@localhost ~]# chkconfig zabbix_server on
[root@localhost ~]# chkconfig --list|grep zabbix_server

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

zabbix_server  	0:off	1:off	2:on	3:on	4:on	5:on	6:off

[root@localhost ~]# chkconfig --add zabbix_agentd
[root@localhost ~]# chkconfig zabbix_agentd on
[root@localhost ~]# chkconfig --list|grep zabbix_agentd

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

zabbix_agentd  	0:off	1:off	2:on	3:on	4:on	5:on	6:off

//重启测试
[root@localhost ~]# reboot

[root@localhost ~]# ss -antl
State     Recv-Q     Send-Q         Local Address:Port          Peer Address:Port    
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                     [::]:22                    [::]:*       
LISTEN    0          80                         *:3306                     *:*  
原文地址:https://www.cnblogs.com/Ycqifei/p/14630342.html