文章目录
- 序 自言自语
离开老东家后有一个月没操作zabbix了,由于历史原因以前一直玩的是3.X的zabbix,心血来潮打算在自己的服务器上装最新的zabbix玩玩用来监控一下自己玩的服务器。 安装3.X花费20分钟,现在居然花费了4个小时。5.0版本的前端php要自己安装,然后千万不能缺少了什么扩展,网上的教程有有点旧,php那部分缺失了一些东西。 尝试用一下zabbix的dashboard,画画图,体会到垃圾了,看板还是Grafana最优秀,最近也尝试了一下Kibana的画图,比zabbix强。总而言之,zabbix还是很适合个人玩玩的。工作1年多来,也赖得花时间写博客了,今日奉献zabbix5.0部署教程(参考官网和博客和个人知识),吐糟zabbix5.2居然需要centos8以上才能安装。。还有我用的是阿里云得虚拟服务器安装的,在大陆阿里云虚拟服务器连接互联网的能力是最好的。Tecent华为什么的,直接使用官方镜像或者源则需要多尝试几次,或者去找一下中国源。
Centos安装Zabbix5.0- -mysql/nginx
-
参考文档
https://www.zabbix.com/documentation/5.0/manual/installation/install_from_packages/rhel_centos
https://www.zabbix.com/download?zabbix=5.0&os_distribution=centos&os_version=7&db=mysql&ws=nginx -
zabbix服务由3个组件组成
- 数据库
- zabbix后端
- zabbix前端
-
其它
In Zabbix 4.4 support for Nginx was added
一 安装数据库Mysql
- 需要安装mysql5.7+
- 安装5.6导入zabbix数据库数据时报错
ERROR 1071 (42000) at line 348: Specified key was too long; max key length is 767 bytes
- 安装mysql5.7
rpm -qa|grep -i mariadb | xargs rpm -e --nodeps
wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
rpm -Uvh mysql57-community-release-el7-10.noarch.rpm
yum install -y mysql-community-server
systemctl start mysqld.service
systemctl status mysqld.service
systemctl enable mysqld
# 获取MySQL临时用户名密码
grep 'temporary password' /var/log/mysqld.log
# 2020-10-30T16:33:29.896472Z 1 [Note] A temporary password is generated for root@localhost: 1Z>qq%pFim:!
- 创建zabbix数据库
mysql -uroot -p
password
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@localhost identified by ‘password’;
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> quit;
二 安装Zabbix后端程序
- 安装
# 配置源
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum clean all
# 安装zabbix-server
yum install zabbix-server-mysql
# 导入数据库
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
- 更改配置
# 添加数据库密码,如果未能成功连接数据库,启动时端口将不会被监听
vim /etc/zabbix/zabbix_server.conf
DBPassword=zabbix
- 启动
systemctl start zabbix-server
systemctl status zabbix-server
systemctl enable zabbix-server
四 安装Zabbix前端程序
-
安装php7.2+
# 安装 EPEL 源 yum install epel-release # 安装 REMI 源 yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm # 安装php yum install -y php73-php-fpm php73-php-cli php73-php-bcmath php73-php-gd php73-php-json php73-php-mbstring php73-php-mcrypt php73-php-mysqlnd php73-php-opcache php73-php-pdo php73-php-pecl-crypto php73-php-pecl-mcrypt php73-php-pecl-geoip php73-php-recode php73-php-snmp php73-php-soap php73-php-xml php73-php-ldap # 设置开机自启 systemctl enable php73-php-fpm # 启动PHP服务 systemctl start php73-php-fpm
-
更改php-fpm配置,满足Zabbix前端对php的配置要求
find / -name php.ini
vim php.ini
max_execution_time = 300
max_input_time = 300
post_max_size = 16M
date.timezone = Asia/Shanghai
# 重启php-fpm服务 systemctl restart php73-php-fpm && systemctl status php73-php-fpm
- 安装Zabbix前端
yum install centos-release-scl
vim /etc/yum.repos.d/zabbix.repo and enable zabbix-frontend repository.
yum install zabbix-web-mysql-scl zabbix-nginx-conf-scl
- 安装nginx
yum install nginx
yum status nginx
- 配置nginx连接php
server {
listen 80;
server_name localhost;
root /usr/share/zabbix;
index index.php;
location = /favicon.ico {
log_not_found off;
}
location / {
try_files $uri $uri/ =404;
}
location /assets {
access_log off;
expires 10d;
}
location ~ /\.ht {
deny all;
}
location ~ /(api\/|conf[^\.]|include|locale) {
deny all;
return 404;
}
location ~ [^/]\.php(/|$) {
fastcgi_pass unix:/var/opt/rh/rh-php72/run/php-fpm/zabbix.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param DOCUMENT_ROOT /usr/share/zabbix;
fastcgi_param SCRIPT_FILENAME /usr/share/zabbix$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED /usr/share/zabbix$fastcgi_script_name;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
}
- 打开网页
- http://IP:PORT
- 配置数据库地址
- 配置Zabbix server地址
- 配置完成后将显示 Configuration file “/etc/zabbix/web/zabbix.conf.php” created.
- 默认管理员账号密码 Admin/zabbix
五 密码重置
select userid,alias,passwd from users;
echo -n admin | openssl md5
update users set passwd='21232f297a57a5a743894a0e4a801fc3' where userid = '1';
容器方式安装
- https://www.zabbix.com/documentation/5.0/manual/installation/containers docker方式
- https://github.com/zabbix/zabbix-docker docker-compose方式
安装Zabbix-agent
- 安装
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum install zabbix-agent - 更改配置
vim /etc/zabbix/zabbix_agentd.conf
Server=127.0.0.1 # 与web端host配置的的接口地址对应
ServerActive=127.0.0.1 # 与web端host配置的的接口地址对应
Hostname=XXX # 与web端host配置的的Name对应
!](https://img-blog.csdnimg.cn/20201102235121305.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0lNUGxvdmU=,size_16,color_FFFFFF,t_70#pic_center)
彩蛋
笔者的微信公众号,技术是人生的一部分,技术之外也光彩绚丽, 扫描二维码关注微信公众号,闲暇之余我们畅谈未来