记住Zabbix日志文件路径/var/log/zabbix/
:
- zabbix_agentd.log 代理日志文件
- zabbix_server.log 服务日志文件
启动出现问题时可用查看这两个文件。
2.1 程序安装
# 1.安装存储库
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum clean all
# 2.安装Server及Agent
yum install -y zabbix-server-pgsql zabbix-agent
# 3.启用软件集并安装Web及
yum install -y centos-release-scl
# Edit file /etc/yum.repos.d/zabbix.repo and enable zabbix-frontend repository.
vim /etc/yum.repos.d/zabbix.repo
[zabbix-frontend]
enabled=1
# Install Zabbix frontend package
yum install -y zabbix-web-pgsql-scl zabbix-nginx-conf-scl
# 安装完成后
[root@tcloud ~]# rpm -qa | grep zabbix
zabbix-agent-5.0.32-1.el7.x86_64
zabbix-web-5.0.32-1.el7.noarch
zabbix-web-deps-scl-5.0.32-1.el7.noarch
zabbix-release-5.0-1.el7.noarch
zabbix-server-pgsql-5.0.32-1.el7.x86_64
zabbix-web-pgsql-scl-5.0.32-1.el7.noarch
zabbix-nginx-conf-scl-5.0.32-1.el7.noarch
2.2 数据库初始化
官方文档会根据不同的数据库给出不同的初始化脚本:
以下过程为PostgreSQL数据库:
# 1.(官网指导)创建用户和数据库
sudo -u postgres createuser --pwprompt zabbix
sudo -u postgres createdb -O zabbix zabbix
#(真实操作)这个过程可以在 Navicat 上进行
# 2.(官网指导)初始化数据库
zcat /usr/share/doc/zabbix-server-pgsql*/create.sql.gz | sudo -u zabbix psql zabbix
#(真实操作)解压 create.sql.gz
gzip -d create.sql.gz
# 在 Navicat 里执行 create.sql
# 3.(官网指导)Edit file /etc/zabbix/zabbix\_server.conf
DBPassword=password
# (真实操作)修改配置文件(主要是数据库相关)使用的是非localhost的库
vim /etc/zabbix/zabbix_server.conf
DBHost=xxx.xx.x.x[云服务器的内网IP]
DBName=zabbix[根据初始化的数据库名称设置]
DBUser=zabbix[根据实际情况设置]
DBPassword=zabbix[根据设置的密码设置]
DBPort=5432[根据数据库的端口填写]
2.3 前端配置
由于项目使用的是 Nginx,这里展示的是使用 Nginx 的配置:
# 1.(官网指导)
Edit file /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf uncomment and set 'listen' and 'server\_name' directives.
# listen 80;
# server\_name example.com;
# (真实操作)
cat /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf
复制/etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf
的内容并进行修改,添加到Nginx的配置/usr/local/nginx/conf/nginx.conf
内:
# 修改内容为 listen 和 server\_name 和 fastcgi\_pass
server {
listen 8081;
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|vendor) {
deny all;
return 404;
}
location ~ [^/]\.php(/|$) {
fastcgi_pass localhost:9000;
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;
}
}
# 将内容复制出来修改后复制到 /usr/local/nginx/conf/nginx.conf 内
vim /usr/local/nginx/conf/nginx.conf
修改 /etc/opt/rh/rh-php72/php.ini 否则会出现,Check of pre-requisites:
- Minimum required size of PHP post is 16M (configuration option “post_max_size”).
- Minimum required limit on execution time of PHP scripts is 300 (configuration option “max_execution_time”).
- Minimum required limit on input parse time for PHP scripts is 300 (configuration option “max_input_time”).
- Time zone for PHP is not set (configuration parameter “date.timezone”).
# 修改 /etc/opt/rh/rh-php72/php.ini
vim /etc/opt/rh/rh-php72/php.ini
# 默认值8M
post\_max\_size=16M
# 默认值30
max\_execution\_time=300
# 默认值60
max\_input\_time=300
# 默认未设置 ;date.timezone =
date.timezone = Asia/Shanghai
# 2.(官网指导)
Edit file /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf add nginx to listen.acl_users directive.
listen.acl_users = apache,nginx
# Then uncomment and set the right timezone for you.
; php_value[date.timezone] = Europe/Riga
# (真实操作)
vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
# 修改user和group
user = nginx
group = nginx
# 修改listen.acl\_users
listen.acl_users = nginx
# 修改listen.allowed\_clients
listen.allowed_clients = xxx.xx.x.x[云服务器内网IP]
# 时区调整
; php_value[date.timezone] = Asia/Shanghai
2.4 服务启动
#(官网指导)启动
systemctl restart zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
#(真实操作)启动【由于使用了 Nginx 这里不再启动 rh-nginx116-nginx】
systemctl restart zabbix-server zabbix-agent rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent rh-php72-php-fpm
3.Web登录
- 检查先决条件【问题已处理】
- 配置数据库连接
- 配置服务详情
- 配置总览
- 登录【默认用户名为:Admin 密码为:zabbix】
- 登录成功