Linux安装Zabbix详细步骤

Linux安装Zabbix详细步骤

以新安装的centos7配置为例
0、首先配置好yum仓库:
[root@zabbix ~]# yum install epel-release -y
[root@zabbix ~]# yum clean all
[root@zabbix ~]# yum makecache

1、安装基本工具和编译工具:
[root@zabbix ~]# yum install net-tools lrzsz wget vim gcc gcc-c++ -y

2、提前安装php和mysql数据库:
[root@zabbix ~]# yum install php mariadb mariadb-server mariadb-devel -y
启动数据库并初始化数据库:
[root@zabbix ~]# systemctl enable mariadb
[root@zabbix ~]# systemctl start mariadb
[root@zabbix ~]# mysql_secure_installation (初始化过程略)

3、创建zabbix服务账号:
[root@zabbix ~]# groupadd --system zabbix
[root@zabbix ~]# useradd --system -g zabbix -s /sbin/nologin -c “Zabbix_Server” zabbix

4、官方下载并解压zabbix最新版本并安装:
[root@zabbix ~]# wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.4.7/zabbix-4.4.7.tar.gz
[root@zabbix ~]# yum install net-snmp net-snmp-devel libcurl libevent-devel libxml2 libxml2-devel libcurl-devel -y       #安装依赖包
[root@zabbix ~]# tar -xvf zabbix-4.4.7.tar.gz
[root@zabbix zabbix-4.4.7]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-ipv6 --with-mysql --with-net-snmp --with-libcurl --with-libxml2         #进入目录并编译
[root@zabbix zabbix-4.4.7]# make
[root@zabbix zabbix-4.4.7]# make install       #安装

5、创建zabbix数据库并导入数据库:
[root@zabbix ~]# mysql -uroot -p
Enter password:
MariaDB [(none)]> create database zabbix character set utf8;
MariaDB [(none)]> grant all on zabbix.* to zabbix@localhost identified by ‘zabbixpass’;
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> quit
将zabbix模板数据库导入刚创建的数据库中(依次导入):
[root@zabbix ~]# mysql -uzabbix -pzabbixpass -h localhost zabbix < zabbix-4.4.7/database/mysql/schema.sql
[root@zabbix ~]# mysql -uzabbix -pzabbixpass -h localhost zabbix < zabbix-4.4.7/database/mysql/images.sql
[root@zabbix ~]# mysql -uzabbix -pzabbixpass -h localhost zabbix < zabbix-4.4.7/database/mysql/data.sql

6、配置zabbix的配置文件:
[root@zabbix ~]# vim /usr/local/zabbix/etc/zabbix_server.conf       #修改配置文件大致如下参数:
[root@zabbix ~]# cat /usr/local/zabbix/etc/zabbix_server.conf | grep -v ^# | grep -v ^$
LogFile=/tmp/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbixpass
DBPort=3306
Timeout=4
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1

7、启动zabbix和agent服务:
[root@zabbix ~]# /usr/local/zabbix/sbin/zabbix_server
[root@zabbix ~]# /usr/local/zabbix/sbin/zabbix_agentd

8、安装安装nginx和php-fpm
[root@zabbix ~]# yum install nginx php-fpm -y
配置nginx:
[root@zabbix ~]# vim /etc/nginx/nginx.conf

        location / {
        }
#此字段下插入如下代码:
        location ~ \.php$ {
         fastcgi_buffer_size 128k;
         fastcgi_buffers 32 32k;
           try_files $uri /index.php =404;
           fastcgi_pass 127.0.0.1:9000;
           fastcgi_index index.php;
           fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
           include fastcgi_params;
        }

[root@zabbix ~]# systemctl enable nginx php-fpm
[root@zabbix ~]# systemctl start nginx php-fpm

9、复制源码php页面文件到nginx的root目录下,并重启nginx、php-fpm:
[root@zabbix ~]# cp -rp zabbix-4.4.7/frontends/php/* /usr/share/nginx/html
[root@zabbix ~]# systemctl restart nginx php-fpm

10、打开浏览器安装并自检所需的依赖包如下:
Linux安装Zabbix详细步骤_第1张图片
解决以下问题:
安装依赖包并修改php.ini配置:
[root@zabbix ~]# yum install php-gd php-mysql php-bcmath php-mbstring php-xml php-ldap -y
修改php.ini参数:
[root@zabbix ~]# vim /etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai

再次重启nginx、php-fpm服务并开始安装:
[root@zabbix ~]# systemctl restart nginx php-fpm

然后你可能发现连接不上数据库(需要修改如下文件中数据库):
[root@zabbix ~]# cd /usr/share/nginx/html/conf
[root@zabbix conf]# mv zabbix.conf.php.example zabbix.conf.php       #重命名文件
[root@zabbix conf]# vim zabbix.conf.php       #修改正确的端口、账号及密码
修改完重新刷新登录即可:账号admin/zabbix

Linux安装Zabbix详细步骤_第2张图片

你可能感兴趣的:(zabbix)