赞
踩
- 以前用的监控:Nagios+Cacti
- 现在使用监控: Zabbix+Grafana,OpenFalcon,Prometheus
- LTS:Long time support 长期维护版本
- Zabbix是一个CS(服务端/客户端)架构的服务
- Zabbix-agent(客户端)获取数据—>发送给Zabbix-server(服务端)
- 数据会被存放在数据库内
- Zabbix Web从数据库内取出数据并展示出来
- 系统: centos 7.x,不支持yum方式安装服务端。
- 安装方式:服务端编译安装
- zabbix官网:Download Zabbix sources
Zabbix 服务端编译安装流程
1. 安装 ngx+php环境
2. 安装mysql 5.7 或者 mariadb 10.5
3. 编译安装Zabbix服务端及配置
4. 部署前端页面
# 1. 配置Nginx yum源
cat /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=https://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
# 安装 nginx
yum -y install nginx --enablerepo=nginx-stable
yum -y install epel-release.noarch
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y install php72w-cli php72w-fpm php72w-gd php72w-mbstring php72w-bcmath php72w-xml php72w-ldap php72w-mysqlnd
root@master:/etc/nginx/conf.d # cat zbx.yzs.cn.conf server{ listen 80; server_name zbx.yzs.cn; root /app/code/zbx/; location / { index index.php; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /app/code/zbx$fastcgi_script_name; include fastcgi_params; } }
# 1.替换
root@master:/etc/nginx/conf.d # sed -ri '/^(user|group)/s#apache#nginx#g' /etc/php-fpm.d/www.conf
# 2. 检查
root@master:/etc/nginx/conf.d # egrep '^(user|group)' /etc/php-fpm.d/www.conf
user = nginx
group = nginx
# 1.创建目录和测试文件
root@master:/etc/nginx/conf.d # mkdir -p /app/code/zbx
root@master:/etc/nginx/conf.d # vim /app/code/zbx/info.php
root@master:/etc/nginx/conf.d # cat /app/code/zbx/info.php
phpinfo();
?>
# 2. 启动服务和设置开机自启动
root@master:/etc/nginx/conf.d # systemctl start nginx php-fpm.service
root@master:/etc/nginx/conf.d # systemctl enable nginx php-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
- Zabbix 6.0 不支持 mariadb 5.5 (默认源中的)
- 个人选择mysql,安装mysql
# 1. 下载mysql源 wget https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm # 2. 安装mysql的yum仓库 yum -y localinstall mysql80-community-release-el7-7.noarch.rpm # 3.修改yum仓库,默认安装8.0版本,不安装5.7 yum-config-manager --disable mysql57-community yum-config-manager --enable mysql80-community # 4.安装数据库 yum install -y mysql-community-server # 5.启动数据库和开机自启动 root@master:/etc/yum.repos.d # systemctl start mysqld && systemctl enable mysqld root@master:/etc/yum.repos.d # ss -ntulp | grep 3306 tcp LISTEN 0 80 [::]:3306 [::]:* users:(("mysqld",pid=29908,fd=21)) # 6. 查找密码 root@master:/etc/yum.repos.d # grep pass /var/log/mysqld.log 2024-04-04T06:11:26.701823Z 1 [Note] A temporary password is generated for root@localhost: L=FqNR%sz5hz # 7. 修改密码 root@master:/etc/yum.repos.d # mysqladmin -u root -p'L=FqNR%sz5hz' password 'Yangzs@123' mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety. # 8. 测试登录 root@master:/etc/yum.repos.d # mysql -u root -p'Yangzs@123' 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.44 MySQL Community Server (GPL) Copyright (c) 2000, 2023, 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)
# Zabbix 创建数据库要指定字符集
# 1. 创建库
mysql> create database zabbix charset utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
# 2.创建用户
mysql> grant all on zabbix.* to 'zabbix'@localhost' identified by 'yzeSen@1';
Query OK, 0 rows affected, 1 warning (0.00 sec)
root@master:/root # wget --no-check-certificate https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.28.tar.gz
root@master:/root # tar xf zabbix-6.0.28.tar.gz
# 1. 进入存放sql的目录
root@master:/root # cd zabbix-6.0.28/database/mysql
# 2. 按照顺序导入sql
mysql -u root -p'Yangzs@123' zabbix < schema.sql
mysql -u root -p'Yangzs@123' zabbix < images.sql
mysql -u root -p'Yangzs@123' zabbix < data.sql
mysql -u root -p'Yangzs@123' zabbix < double.sql
mysql -u root -p'Yangzs@123' zabbix < history_pk_prepare.sql
# 1. 进入源码目录 root@master:/root # cd zabbix-6.0.28/database/mysql # 2. 安装依赖 yum -y install mysql-devel pcre-devel openssl-devel zlib-devel libxml2-devel net-snmp-devel net-snmp libssh2-devel OpenIPMI-devel libevent-devel openldap-devel libcurl-devel # 3.编译安装,参考下图1:https://tiknmp6phqg.feishu.cn/docx/A8Ssd0z2Vok1i5xsFJjc93IGnyh#PnaodfweYoMBFNxufxycJKLznzd root@master:/root/zabbix-6.0.28 # ./configure \ > --sysconfdir=/etc/zabbix/ \ > --enable-server \ > --with-mysql \ > --with-net-snmp \ > --with-libxml2 \ > --with-ssh2 \ > --with-openipmi \ > --with-zlib \ > --with-libpthread \ > --with-libevent \ > --with-openssl \ > --with-ldap \ > --with-libcurl \ > --with-libpcre # 4. 编译成功后,提示我们直接 make install,如图2 root@master:/root/zabbix-6.0.28 # make install # 5.检查是否成功,待make install执行结束后,执行下面语句,为0则成功 root@master:/root/zabbix-6.0.28 # echo $? 0 # 6. 查看zabbix版本 root@master:/root/zabbix-6.0.28 # zabbix_server --version zabbix_server (Zabbix) 6.0.28 Revision 1f9d541d29a 25 March 2024, compilation time: Apr 4 2024 14:56:13 Copyright (C) 2024 Zabbix SIA License GPLv2+: GNU GPL version 2 or later . This is free software: you are free to change and redistribute it according to the license. There is NO WARRANTY, to the extent permitted by law. This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit (http://www.openssl.org/). Compiled with OpenSSL 1.0.2k-fips 26 Jan 2017 Running with OpenSSL 1.0.2k-fips 26 Jan 2017
图1:编译安装选项说明
图2:编译成功的提示
修改Zabbix配置文件
# 修改配置文件,配置数据库地址、用户、密码
cat /etc/zabbix/zabbix_agent2.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=yzeSen@1
# 1. 启动之前需创建一个zabbix用户
root@master:/root/zabbix-6.0.28 # useradd -s /sbin/nologin -m zabbix
# 2. 启动zabbix
root@master:/root/zabbix-6.0.28 # zabbix_server
# 3.验证zabbix是否启动
root@master:/root/zabbix-6.0.28 # ps -ef | grep zabbix
root@master:/root/zabbix-6.0.28 # ss -ntulp | grep 10051
root@master:/root/zabbix-6.0.28 # cat /usr/lib/systemd/system/zabbix-server.service [Unit] Description=Zabbix Server with Mysql DB After=syslog.target network.target mysqld.service [Service] Type=simple ExecStart=/usr/local/sbin/zabbix_server -f User=zabbix [Install] WantedBy=multi-user.target # 关闭手动运行的zabbix pkill zabbix # 启动zabbix root@master:/root/zabbix-6.0.28 # systemctl start zabbix-server root@master:/root/zabbix-6.0.28 # systemctl enable zabbix-server Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
root@master:/root/zabbix-6.0.28/ui # cp -R ./* /app/code/zbx
root@master:/root/zabbix-6.0.28/ui # chown -R nginx:nginx /app/code/zbx
root@master:/root/zabbix-6.0.28/ui # egrep '^(max_.*_time|post_max_size)' /etc/php.ini
max_execution_time = 300
max_input_time = 600
post_max_size = 80M
# 重启php
root@master:/root/zabbix-6.0.28/ui # systemctl restart php-fpm
# 安装yum源
root@master:/root/zabbix-6.0.28/ui # rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-2.el7.noarch.rpm
# 安装 zabbix-agent2
root@master:/root/zabbix-6.0.28/ui # yum -y install zabbix-agent2
# 配置客户端
root@master:/root/zabbix-6.0.28/ui # vim /etc/zabbix/zabbix_agent2.conf
Server=127.0.0.1 # 地址改为zabbix服务端地址即可
# 启动zabbix客户端
root@master:/root/zabbix-6.0.28/ui # systemctl start zabbix-agent2
# 上传windows的微软雅黑字体,替换
root@master:/root/zabbix-6.0.28/ui # cp /app/code/zbx/assets/fonts/DejaVuSans.ttf{,.bak}
root@master:/root/zabbix-6.0.28/ui # cd
root@master:/root # cp msyh.ttc /app/code/zbx/assets/fonts/DejaVuSans.ttf
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。