掃二維碼與項目經(jīng)理溝通
我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運(yùn)營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流
開源在于折騰,源碼的好與壞各有各的看法,鑒于 CentOS 8 已經(jīng) EOL 了,而 CentOS 7 還有至少兩年多的時間,所以才有了本篇文章,不過還是希望大家能盡快切換到 Stream 版本或者其他替代發(fā)行版本,這樣方便安裝,今天的文章篇幅相對比較長,而且不太適合新手,另外編譯會遇到很多問題,需要有一定的耐心。

創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供黃陂網(wǎng)站建設(shè)、黃陂做網(wǎng)站、黃陂網(wǎng)站設(shè)計、黃陂網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、黃陂企業(yè)網(wǎng)站模板建站服務(wù),十年黃陂做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
新手建議關(guān)閉防火墻與 SElinux,不然容易出現(xiàn)意外之外的問題,老手可以忽略。
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
systemctl stop firewalld && systemctl disable firewalld
建議更新下軟件 yum update -y
yum -y install wget vim
由于 Zabbix 6.0 LTS 的官方要求為 postgresql 13,所以需要導(dǎo)入 postgresql 13 的源
yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sed -i "s@https://download.postgresql.org/pub@https://mirrors.huaweicloud.com/postgresql@g" /etc/yum.repos.d/pgdg-redhat-all.repo
yum -y install postgresql13-server
/usr/pgsql-13/bin/postgresql-13-setup initdb
systemctl enable postgresql-13
systemctl start postgresql-13
cd /tmp
wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.0.tar.gz
tar -zxvf zabbix-6.0.0.tar.gz
groupadd --system zabbix
useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
mkdir -p /app/zabbix
tar -zxvf zabbix-6.0.0.tar.gz
mv zabbix-6.0.0 /app
其實有很多參數(shù),大家可以參考 ./configure --help 自行研究
./configure --prefix=/app/zabbix --enable-server --enable-agent2 --with-postgresql=/usr/pgsql-13/bin/pg_config --with-net-snmp
gcc 環(huán)境問題
yum -y install gcc-c++
Postgresql 庫問題
yum -y install postgresql13-devel
CentOS 7 安裝此包會出現(xiàn)報錯,分別需要安裝 centos-release-scl-rh、epel-release,報錯如下兩圖。
需要 centos-release-scl-rh 源
需要 epel-release 源
yum -y install centos-release-scl-rh epel-release
缺少 net-snmp 源問題
yum -y install net-snmp-devel
缺少libevent 源
yum -y install libevent-devel
缺少 go 環(huán)境(如果是第一代 agent,無此問題)
yum -y install golang
經(jīng)過上面的步驟編譯就完成了,如下圖
需要注意的是,本文環(huán)境編譯了 agent2,agent2 是采用了 go 環(huán)境,需要通過 go 來下載一些庫,國內(nèi)是無法通過 go 下載庫,因此需要設(shè)置代理,否則會卡在下圖
設(shè)置 go 代理 并安裝
go env -w GOPROXY=https://goproxy.cn,direct
make install
安裝完成
整體安裝目錄
[root@centos7-01 zabbix]# tree /app/zabbix/
/app/zabbix/
├── bin
│ └── zabbix_js
├── etc
│ ├── zabbix_agent2.conf
│ ├── zabbix_agent2.d
│ │ └── plugins.d
│ │ ├── ceph.conf
│ │ ├── docker.conf
│ │ ├── memcached.conf
│ │ ├── modbus.conf
│ │ ├── mongodb.conf
│ │ ├── mqtt.conf
│ │ ├── mysql.conf
│ │ ├── oracle.conf
│ │ ├── postgres.conf
│ │ ├── redis.conf
│ │ └── smart.conf
│ ├── zabbix_agentd.conf
│ ├── zabbix_agentd.conf.d
│ ├── zabbix_server.conf
│ └── zabbix_server.conf.d
├── lib
│ └── modules
├── sbin
│ ├── zabbix_agent2
│ ├── zabbix_agentd
│ └── zabbix_server
└── share
├── man
│ └── man8
│ ├── zabbix_agent2.8
│ └── zabbix_server.8
└── zabbix
├── alertscripts
└── externalscripts
Zabbix 6.0 LTS 需要 php 7.2.5 版本以上,需要安裝 remi 源支持 php 7.x
yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils
yum-config-manager --disable 'remi-php*'
yum-config-manager --enable remi-php74
yum -y install php php-fpm
yum -y install nginx
首先將 Zabbix 前端文件移動到 /app/zabbix 下
mv /app/ui /app/zabbix
vim /etc/nginx/conf.d/zabbix.conf
配置文件如下
server {
listen 80;
# server_name example.com;
root /app/zabbix/ui;
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 unix:/run/php-fpm/zabbix.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param DOCUMENT_ROOT /app/zabbix/ui;
fastcgi_param SCRIPT_FILENAME /app/zabbix/ui$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED /app/zabbix/ui$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;
}
}vim /etc/nginx/nginx.conf
## listen 80 default_server;
## listen [::]:80 default_server;
nginx.conf 加注釋
zabbix.conf 取消注釋
systemctl enable nginx
systemctl start nginx
發(fā)現(xiàn)前端顯示為 502,猜測是由于 php-fpm 沒開
systemctl enable php-fpm
systemctl start php-fpm
發(fā)現(xiàn)依然是 502
通過日志可以發(fā)現(xiàn) socket 文件不存在,所以需要創(chuàng)建一個 php-fpm 的配置
tail -f /var/log/nginx/error.log
vim /etc/php-fpm.d/zabbix.conf
[zabbix]
user = apache
group = apache
listen = /run/php-fpm/zabbix.sock
listen.acl_users = apache,nginx
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 200
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
php_value[max_execution_time] = 300
php_value[memory_limit] = 128M
php_value[post_max_size] = 16M
php_value[upload_max_filesize] = 2M
php_value[max_input_time] = 300
php_value[max_input_vars] = 10000
systemctl restart php-fpm
訪問正常
通過前端的診斷,根據(jù)報錯內(nèi)容去安裝相應(yīng)的 php 擴(kuò)展插件
yum -y install php-mbstring php-bcmath php-pgsql php-gd php-xml
如不需要LDAP,這個地方可以忽略
systemctl restart php-fpm nginx
此時可以進(jìn)入數(shù)據(jù)庫配置部分了
創(chuàng)建用戶及數(shù)據(jù)庫
sudo -u postgres createuser --pwprompt zabbix
sudo -u postgres createdb -O zabbix zabbix
導(dǎo)入數(shù)據(jù)庫相關(guān)文件
cat /app/database/postgresql/schema.sql | sudo -u zabbix psql zabbix
cat /app/database/postgresql/images.sql | sudo -u zabbix psql zabbix
cat /app/database/postgresql/data.sql | sudo -u zabbix psql zabbix
導(dǎo)入完成
修改 postgresql 權(quán)限文件,將本地權(quán)限改為 md5 的驗證方式
重啟數(shù)據(jù)庫
systemctl restart postgresql-13
這里需要注意的是架構(gòu)部分填 public 即可,如下圖
填寫對應(yīng)時區(qū)和實例名稱
如果出現(xiàn)下圖問題,基本是目錄權(quán)限問題,碰到此問題修改目錄權(quán)限或者下載配置文件拷貝至提示目錄即可
默認(rèn)用戶名密碼是Admin/zabbix
由于 Zabbix Server 沒起來,導(dǎo)致前端顯示 Zabbix server 未啟動的警告提示
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target
After=postgresql.service
After=pgbouncer.service
After=postgresql-13.service
[Service]
Environment="CONFFILE=/app/zabbix/etc/zabbix_server.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-server
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/app/zabbix/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=0
[Install]
WantedBy=multi-user.target
vim /app/zabbix/etc/zabbix_server.conf
[Unit]
Description=Zabbix Agent 2
After=syslog.target
After=network.target
[Service]
Environment="CONFFILE=/app/zabbix/etc/zabbix_agent2.conf"
EnvironmentFile=-/etc/sysconfig/zabbix_agent2
Type=simple
Restart=on-failure
PIDFile=/run/zabbix/zabbix_agent2.pid
KillMode=control-group
ExecStart=/app/zabbix/sbin/zabbix_agent2 -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=zabbix
Group=zabbix
[Install]
WantedBy=multi-user.target
systemctl restart zabbix-server zabbix-agent2
首頁服務(wù)正常
圖形正常
dashboard
辛苦各位朋友能看到這里了,篇幅是比較長的,如果是完全編譯的話更費(fèi)勁,當(dāng)然針對一些完全沒有外網(wǎng)的朋友相對來說更加的麻煩,有空我會出一個完全離線編譯的版本。

我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運(yùn)營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流