新聞中心
開(kāi)源在于折騰,源碼的好與壞各有各的看法,鑒于 CentOS 8 已經(jīng) EOL 了,而 CentOS 7 還有至少兩年多的時(shí)間,所以才有了本篇文章,不過(guò)還是希望大家能盡快切換到 Stream 版本或者其他替代發(fā)行版本,這樣方便安裝,今天的文章篇幅相對(duì)比較長(zhǎng),而且不太適合新手,另外編譯會(huì)遇到很多問(wèn)題,需要有一定的耐心。

創(chuàng)新互聯(lián)建站專(zhuān)業(yè)為企業(yè)提供黃陂網(wǎng)站建設(shè)、黃陂做網(wǎng)站、黃陂網(wǎng)站設(shè)計(jì)、黃陂網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、黃陂企業(yè)網(wǎng)站模板建站服務(wù),十年黃陂做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
正文
本文環(huán)境
- CentOS 7.9.2009
- PHP 7.4
- Postgresql 13
- Nginx 1.20
新手建議
新手建議關(guān)閉防火墻與 SElinux,不然容易出現(xiàn)意外之外的問(wè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
數(shù)據(jù)庫(kù)部分
由于 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
安裝 postgresql
yum -y install postgresql13-server
啟動(dòng)并初始化數(shù)據(jù)庫(kù)
/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
創(chuàng)建 Zabbix 用戶(hù)以及 Zabbix 用戶(hù)組
groupadd --system zabbix
useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
創(chuàng)建 Zabbix 安裝目錄
mkdir -p /app/zabbix
解壓源碼包
tar -zxvf zabbix-6.0.0.tar.gz
mv zabbix-6.0.0 /app
開(kāi)始編譯
- prefix 指定安裝目錄
- enable-server 啟用 Zabbix Server
- enable-agent2 啟用 Zabbix agent2
- with-postgresql 后端指定數(shù)據(jù)庫(kù)為 PG,并指定路徑
- net-snmp 支持 snmp 協(xié)議
其實(shí)有很多參數(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)境問(wèn)題
yum -y install gcc-c++
Postgresql 庫(kù)問(wèn)題
yum -y install postgresql13-devel
CentOS 7 安裝此包會(huì)出現(xiàn)報(bào)錯(cuò),分別需要安裝 centos-release-scl-rh、epel-release,報(bào)錯(cuò)如下兩圖。
需要 centos-release-scl-rh 源
需要 epel-release 源
yum -y install centos-release-scl-rh epel-release
缺少 net-snmp 源問(wèn)題
yum -y install net-snmp-devel
缺少libevent 源
yum -y install libevent-devel
缺少 go 環(huán)境(如果是第一代 agent,無(wú)此問(wèn)題)
yum -y install golang
經(jīng)過(guò)上面的步驟編譯就完成了,如下圖
安裝
需要注意的是,本文環(huán)境編譯了 agent2,agent2 是采用了 go 環(huán)境,需要通過(guò) go 來(lái)下載一些庫(kù),國(guó)內(nèi)是無(wú)法通過(guò) go 下載庫(kù),因此需要設(shè)置代理,否則會(huì)卡在下圖
設(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
php 環(huán)境
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
安裝 nginx
yum -y install nginx
Nginx 操作部分
創(chuàng)建 zabbix 相關(guān)配置文件
首先將 Zabbix 前端文件移動(dòng)到 /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 取消注釋
啟動(dòng) nginx
systemctl enable nginx
systemctl start nginx
訪(fǎng)問(wèn)前端
發(fā)現(xiàn)前端顯示為 502,猜測(cè)是由于 php-fpm 沒(méi)開(kāi)
啟動(dòng) php-fpm
systemctl enable php-fpm
systemctl start php-fpm
再次訪(fǎng)問(wèn)前端
發(fā)現(xiàn)依然是 502
查看 nginx 日志
通過(guò)日志可以發(fā)現(xiàn) socket 文件不存在,所以需要?jiǎng)?chuàng)建一個(gè) php-fpm 的配置
tail -f /var/log/nginx/error.log
創(chuàng)建 zabbix php 相關(guān)配置文件
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
重啟 php-fpm 服務(wù)
systemctl restart php-fpm
訪(fǎng)問(wèn)正常
前端部分
php 部分安裝
通過(guò)前端的診斷,根據(jù)報(bào)錯(cuò)內(nèi)容去安裝相應(yīng)的 php 擴(kuò)展插件
yum -y install php-mbstring php-bcmath php-pgsql php-gd php-xml
如不需要LDAP,這個(gè)地方可以忽略
重啟相關(guān)服務(wù)
systemctl restart php-fpm nginx
此時(shí)可以進(jìn)入數(shù)據(jù)庫(kù)配置部分了
數(shù)據(jù)庫(kù)配置及導(dǎo)入相關(guān)文件
創(chuàng)建用戶(hù)及數(shù)據(jù)庫(kù)
sudo -u postgres createuser --pwprompt zabbix
sudo -u postgres createdb -O zabbix zabbix
導(dǎo)入數(shù)據(jù)庫(kù)相關(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 的驗(yàn)證方式
重啟數(shù)據(jù)庫(kù)
systemctl restart postgresql-13
前端數(shù)據(jù)庫(kù)配置
這里需要注意的是架構(gòu)部分填 public 即可,如下圖
剩余前端配置
填寫(xiě)對(duì)應(yīng)時(shí)區(qū)和實(shí)例名稱(chēng)
如果出現(xiàn)下圖問(wèn)題,基本是目錄權(quán)限問(wèn)題,碰到此問(wèn)題修改目錄權(quán)限或者下載配置文件拷貝至提示目錄即可
默認(rèn)用戶(hù)名密碼是Admin/zabbix
由于 Zabbix Server 沒(méi)起來(lái),導(dǎo)致前端顯示 Zabbix server 未啟動(dòng)的警告提示
Zabbix 配置
- 程序文件路徑為/app/zabbix/sbin/下
- 配置文件路徑為/app/zabbix/etc/下
制作 Zabbix Server 守護(hù)文件
[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
制作 zabbix agent2 守護(hù)文件
[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
啟動(dòng)組件
systemctl restart zabbix-server zabbix-agent2
最終效果
首頁(yè)服務(wù)正常
圖形正常
dashboard
寫(xiě)在最后
辛苦各位朋友能看到這里了,篇幅是比較長(zhǎng)的,如果是完全編譯的話(huà)更費(fèi)勁,當(dāng)然針對(duì)一些完全沒(méi)有外網(wǎng)的朋友相對(duì)來(lái)說(shuō)更加的麻煩,有空我會(huì)出一個(gè)完全離線(xiàn)編譯的版本。
網(wǎng)頁(yè)題目:Zabbix隨筆:6.0LTS源碼安裝
本文地址:http://www.dlmjj.cn/article/cogehhi.html


咨詢(xún)
建站咨詢(xún)
