请启用 Javascript 以查看内容

LNMP安装zabbix4.4

 ·   ·  ☕ 3 分钟  ·  ✍ CNSRE

文章链接

硬件配置需求

环境 平台 CPU/内存 数据库 硬盘 监控主机数
小型 centOS 2CPU/1GB MySQL、InnoDB 普通 100
中型 centOS 2CPU/2GB MySQL、InnoDB 普通 500
大型 Red HatEnterpirse Linux 4CPU/8GB MySQL、InnoDB 或PostgreSQL RAID 10 或 SSD 大于1000
超大型 Red HatEnterpirse Linux 8CPU/16GB MySQL、InnoDB 或PostgreSQL RAID 10 或 SSD 大于10000

zabbix版本

4.4 Latest 
https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
3.0 LTS  稳定版
http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
4.0 LTS  正式版
https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
pre-4.0版
http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm

环境准备

Linux 7.7.1908
nginx 1.16.1
zabbix-server 4.4
zabbix-agent  4.4
mysql 5.7.29
php 5.4.16

关闭防火墙及selinux

1
2
systemctl stop firewalld && systemctl disable firewalld
sed -i 's/SELINUX=enforcing/SELINUX=disabled/'/etc/selinux/config

zabbix安装配置

安装MySQL数据库与知识库

1
rpm -i https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm

安装Zabbix服务器、前端、代理

1
yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y

配置Zabbix-server

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
mv /etc/zabbix/zabbix_server.conf  /etc/zabbix/zabbix_server.conf.bak
vim /etc/zabbix/zabbix_server.conf

LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBPort=3306
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
CacheSize=1024M
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000

数据库安装配置

安装数据库

1
2
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
yum localinstall mysql57-community-release-el7-8.noarch.rpm -y

检查mysql源是否安装成功

1
2
3
4
5
yum repolist enabled | grep "mysql.*-community.*"
yum install mysql-community-server -y

### 启动MySQL服务
systemctl start mysqld

登录数据库

1
2
3
4
5
6
grep 'temporary password' /var/log/mysqld.log
#登陆数据库 
mysql -uroot -p
修改默认密码
mysql> SET PASSWORD = PASSWORD('Lenovo@123');
#Lenvoo@123是你的新密码
1
2
3
4
5
6
7
8
修改validate_password_policy参数的值
set global validate_password_policy=0; 
再修改密码的长度
set global validate_password_length=1;
再次执行修改密码就可以了
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Lenovo@123';
允许root远程登陆*
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Lenovo@123' WITH GRANT OPTION;

创建zabbix数据库和用户

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
mysql –uroot –p

mysql>  create database zabbix character set utf8;

Query OK, 1 row affected (0.00 sec)

mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix';

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

导入模板数据

方法1

1
2
mysql> use zabbix;
mysql> source /usr/share/doc/zabbix-server-mysql-4.4.9/create.sql

方法2

1
[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix 

nginx安装配置

安装nginx

1
2
wget  http://nginx.org/packages/rhel/7/x86_64/RPMS/nginx-1.18.0-1.el7.ngx.x86_64.rpm
yum install nginx -y

配置nginx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
  vim /etc/nginx/conf.d/default.conf
 ...
    location / {
        root   /usr/share/zabbix;
        index  index.php;
    }
...
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/share/zabbix$fastcgi_script_name;
        include        fastcgi_params;
    }
...

修改zabbix前端文件权限

1
2
chown  nginx:nginx /usr/share/zabbix/*
chmod -R 755 /usr/share/zabbix/*

启动nginx

1
systemctl restart nginx

PHP安装配置

安装php

1
yum install php-fpm  php-gd php-mbstring php-bcmath php-gd  php-xmlwriter  php-xmlreader -y

修改配置文件

1
2
3
4
5
6
sed -i "s#max_execution_time = 30#max_execution_time = 600#g" /etc/php.ini
sed -i "s#max_input_time = 60#max_input_time = 600#g" /etc/php.ini
sed -i "s#memory_limit = 128M#memory_limit = 256M#g" /etc/php.ini
sed -i "s#post_max_size = 8M#post_max_size = 32M#g" /etc/php.ini
sed -i "s#upload_max_filesize = 2M#upload_max_filesize = 16M#g" /etc/php.ini
sed -i "s/;date.timezone =/date.timezone = Asia\/Shanghai/g" /etc/php.ini

启动php-fpm

1
systemctl start  php-fpm

启动所有服务

1
2
3
4
5
systemctl start zabbix-server
systemctl start zabbix-agent
systemctl start nginx 
systemctl start mysqld
systemctl start  php-fpm

设置开机启动项

1
systemctl enable  zabbix-server  zabbix-agent  mysqld  nginx  php-fpm

检查端口

1
2
3
4
5
6
[root@zabbix-server]# netstat -pntl 
tcp   0   0 127.0.0.1:9000   0.0.0.0:*   LISTEN    5118/php-fpm: maste 
tcp   0   0 0.0.0.0:80       0.0.0.0:*   LISTEN    5046/nginx: master  
tcp6  0   0 :::10050         :::*        LISTEN    5577/zabbix_agentd  
tcp6  0   0 :::10051         :::*        LISTEN    4821/zabbix_server  
tcp6  0   0 :::3306          :::*        LISTEN    1703/mysqld 

连接到新安装的Zabbix前端: http://server_ip
[文章链接](https://www.cnsre.cn/posts/210510512134/

分享

CNSRE
作者
CNSRE
一个📚学习中的👨‍💻SRE运维工程师🚀🚀🚀


目录