Zabbix 是由 Alexei Vladishev 开发的一种网络监视、管理系统,基于 Server-Client 架构。可用于监视各种网络服务、服务器和网络机器等状态。

Zabbix 使用 MySQL、PostgreSQL 储存资料。Server 端基于 C语言、Web 前端则是基于 PHP 所编写的。Zabbix 可以使用多种方式监视。在被监视对象中如 Linux、Windows 中安装 Zabbix Agent 之后,可以监视 CPU 负荷、网络使用状况、硬盘容量等各种状态。而就算在监视对象中没有安装客户端,Zabbix 也可以经由 SNMP、TCP、ICMP检查,以及利用 IPMI、SSH、telnet 等方式对目标进行监视。另外,Zabbix 包含 XMPP 等各种 Item 警示功能。

CentOS 安装 Zabbix 服务端

1、安装软件源

yum -y install epel-release
rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
# 如果国内服务器,可用阿里云的镜像服务进行加速
sed -i 's|repo.zabbix.com|mirrors.aliyun.com/zabbix|' /etc/yum.repos.d/zabbix.repo

2、安装 zabbix 服务端

yum clean all
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-nginx-conf zabbix-agent

3、数据库初始化(mysql数据库自行安装,这里不再体现)

mysql -uroot -p
password
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'password';
mysql> quit;
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

4、修改Zabbix相关配置文件

#配置数据库服务器IP
sed -i 's|^# DBHost=.*|DBHost=|g' /etc/zabbix/zabbix_server.conf
sed -i 's|^DBHost=.*|DBHost=127.0.0.1|g' /etc/zabbix/zabbix_server.conf
cat /etc/zabbix/zabbix_server.conf | grep ^DBHost

# 数据库名称
sed -i 's|^DBName=.*|DBName=zabbix|g' /etc/zabbix/zabbix_server.conf
cat /etc/zabbix/zabbix_server.conf | grep ^DBName

# 数据库账号
sed -i 's|^DBUser=.*|DBUser=zabbix|g' /etc/zabbix/zabbix_server.conf
cat /etc/zabbix/zabbix_server.conf | grep ^DBUser

# 数据库密码
sed -i 's|^# DBPassword=.*|DBPassword=|g' /etc/zabbix/zabbix_server.conf
sed -i 's|^DBPassword=.*|DBPassword=xxxxxxxxx|g' /etc/zabbix/zabbix_server.conf
cat /etc/zabbix/zabbix_server.conf | grep ^DBPassword

# 修改监听端口
sed -i 's|^# ListenPort=.*|ListenPort=|g' /etc/zabbix/zabbix_server.conf
sed -i 's|^ListenPort=.*|ListenPort=10051|g' /etc/zabbix/zabbix_server.conf
cat /etc/zabbix/zabbix_server.conf | grep ^ListenPort

# pinger 进程数,默认1
sed -i 's|^# StartPingers=.*|StartPingers=|g' /etc/zabbix/zabbix_server.conf
sed -i 's|^StartPingers=.*|StartPingers=10|g' /etc/zabbix/zabbix_server.conf
cat /etc/zabbix/zabbix_server.conf | grep ^StartPingers

# 代理配置更新间隔,默认1小时
sed -i 's|^# ProxyConfigFrequency=.*|ProxyConfigFrequency=|g' /etc/zabbix/zabbix_server.conf
sed -i 's|^ProxyConfigFrequency=.*|ProxyConfigFrequency=600|g' /etc/zabbix/zabbix_server.conf
cat /etc/zabbix/zabbix_server.conf | grep ^ProxyConfigFrequency

# 代理数据发送频率,默认1秒
sed -i 's|^# ProxyDataFrequency=.*|ProxyDataFrequency=|g' /etc/zabbix/zabbix_server.conf
sed -i 's|^ProxyDataFrequency=.*|ProxyDataFrequency=15|g' /etc/zabbix/zabbix_server.conf
cat /etc/zabbix/zabbix_server.conf | grep ^ProxyDataFrequency

# 代理服务器进程
sed -i 's|^# StartProxyPollers=.*|StartProxyPollers=|g' /etc/zabbix/zabbix_server.conf
sed -i 's|^StartProxyPollers=.*|StartProxyPollers=2|g' /etc/zabbix/zabbix_server.conf
cat /etc/zabbix/zabbix_server.conf | grep ^StartProxyPollers

# vmware 数据收集进程,默认未启用
sed -i 's|^# StartVMwareCollectors=.*|StartVMwareCollectors=|g' /etc/zabbix/zabbix_server.conf
sed -i 's|^StartVMwareCollectors=.*|StartVMwareCollectors=2|g' /etc/zabbix/zabbix_server.conf
cat /etc/zabbix/zabbix_server.conf | grep ^StartVMwareCollectors

# 修改值缓存大小 默认8M
sed -i 's|^# ValueCacheSize=.*|ValueCacheSize=|g' /etc/zabbix/zabbix_server.conf
sed -i 's|^ValueCacheSize=.*|ValueCacheSize=16M|g' /etc/zabbix/zabbix_server.conf
cat /etc/zabbix/zabbix_server.conf | grep ^ValueCacheSize

5、修改 php 环境

cp -n /etc/php.ini /etc/php.ini.mybak
sed -i 's/^;date.timezone =.*/date.timezone = PRC/g' /etc/php.ini
sed -i 's/^date.timezone =.*/date.timezone = PRC/g' /etc/php.ini
cat /etc/php.ini | grep ^date.timezone

# 关闭 X-Powered-By: PHP 头部信息 (可选)
sed -i 's/^expose_php = On/expose_php = Off/g' /etc/php.ini
cat /etc/php.ini | grep ^expose_php

6、修改 nginx 配置

修改 /etc/nginx/conf.d/zabbix.conf 中的 listen 和 server_name ,将需要的端口和域名填进去即可。

如果这台服务器为 zabbix 服务端专用的,也可以将 /etc/nginx/nginx.conf 中默认的 server 配置注释掉,然后将 /etc/nginx/conf.d/zabbix.conf 中的 listen 和 server_name 修改为如下:

server {
       listen          80 default_server;
       server_name     _;

        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:/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;
        }
}

7、启动服务并设置开机启动运行

# 启动服务
systemctl restart zabbix-server zabbix-agent nginx php-fpm

# 设置开机自动运行
systemctl enable zabbix-server zabbix-agent nginx php-fpm

8、设置防火墙规则

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --permanent --add-port=10051/tcp
firewall-cmd --reload

Zabbix 图形中汉字显示为乱码框框的处理办法

yum install google-noto-sans-simplified-chinese-fonts.noarch -y
mv -n /etc/alternatives/zabbix-web-font /etc/alternatives/zabbix-web-font.mybak
rm /etc/alternatives/zabbix-web-font -f
ln -s /usr/share/fonts/google-noto/NotoSansSC-Regular.otf /etc/alternatives/zabbix-web-font

降低服务器内存占用

修改 /etc/php-fpm.d/zabbix.conf

pm.max_children = 8
pm.start_servers = 3
pm.min_spare_servers = 3
pm.max_spare_servers = 8


原文链接地址:http://blog.exsvc.cn/article/zabbix-server-install.html
转载请注明:转载自 易科博客 ,谢谢!

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注