Zabbix-監(jiān)控

zabbix編譯安裝

1:解決依賴關(guān)系

CentOS:

yum install gcc libxml2-devel net-snmp net-snmp-devel curl curl-devel php phpbcmath php-mbstring 
mariadb mariadb-devel -y

Ubuntu:

apt update
apt-get  -y install apache2 apache2-bin apache2-data apache2-utils fontconfig 
config fonts-dejavu-core fping libapache2-mod-php libapache2-mod-php7.2 
libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libfontconfig1 libgd3  libiksemel3 
libjbig0 libjpeg-turbo8 libjpeg8 liblua5.2-0 libodbc1 libopenipmi0  libsensors4 libsnmp-base 
libsnmp30 libsodium23 libssh2-1 libtiff5 libwebp6 libxpm4 php-bcmath php-common php-gd php-ldap 
php-mbstring php-mysql php-xml php7.2-bcmath php7.2-cli php7.2-common php7.2-gd php7.2-json 
php7.2-ldap php7.2-mbstring php7.2-mysql php7.2-opcache php7.2-readline  php7.2-xml snmpd 
ssl-cert ttf-dejavu-core libmysqlclient-dev libxml2-dev libxml2 snmp libsnmp-dev 
libevent-dev openjdk-8-jdk curl libcurl4-openssl-dev

2:下載源碼包和編譯安裝:

2.1:下載源碼:

zabbx.com的zabbix sources目錄下載源碼包并且創(chuàng)建啟動(dòng)zabbix的普通用戶和組

cd /usr/local/src
groupadd -g 1001 zabbix  #創(chuàng)建zabbix組
useradd -u 1001 -g 1001 zabbix #創(chuàng)建zabbix用戶
wget https://cdn.zabbix.com/zabbix/sources/stable/4.0/zabbix-4.0.43.tar.gz
tar xvf zabbix-4.0.43.tar.gz -C /apps/zabbix-server
cd zabbix-4.0.43/

2.2:編譯安裝:

./configure --prefix=/apps/zabbix_server --enable-server --enable-agent 
--with-mysql --with-net-snmp --with-libcurl --with-libxml2 --enable-java
make install

3:數(shù)據(jù)庫初始化:

3.1:創(chuàng)建數(shù)據(jù)庫并授權(quán)

數(shù)據(jù)庫服務(wù)器執(zhí)行命令:

apt update
apt install mysql-server mysql-client```
vim /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address=0.0.0.0 #修改mysql配置綁定地址
systemctl restart mysql
create database zabbix_server character set utf8 collate utf8_bin;
grant all privileges on zabbix_server.* to zabbix@"10.0.7.%" identified by '123456';
flush privileges;

3.2:導(dǎo)入數(shù)據(jù)庫

zabbix-server服務(wù)器執(zhí)行命令:

apt install mysql-client #安裝mysql客戶端命令,用于測試zabbix 數(shù)據(jù)庫賬號(hào)權(quán)限
mysql -uzabbix -p123456 -h10.0.7.104 #測試權(quán)限
cd /usr/local/src/zabbix-4.0.43/database/mysql
mysql -uzabbix -pmagedu.zabbix -h172.31.0.104 zabbix_server < schema.sql
mysql -uzabbix -pmagedu.zabbix -h172.31.0.104 zabbix_server < images.sql
mysql -uzabbix -pmagedu.zabbix -h172.31.0.104 zabbix_server < data.sql

4:編輯zabbix server配置文件:

vim /apps/zabbix_server/etc/zabbix_server.conf
grep "^[a-Z]" /apps/zabbix_server/etc/zabbix_server.conf
###配置文件內(nèi)容
LogFile=/tmp/zabbix_server.log 
DBHost=172.31.0.104
DBName=zabbix_server
DBUser=zabbix
DBPassword=123456
DBPort=3306
Timeout=4
LogSlowQueries=3000

5:配置web界面:

5.1:拷貝web界面程序:

mkdir /var/www/html/zabbix -p
cd /usr/local/src/zabbix-4.0.43/frontends/php/
cp -a . /var/www/html/zabbix/

5.2:訪問web界面:

image.png

解決當(dāng)前報(bào)錯(cuò):

vim /etc/php/7.2/apache2/php.ini
###
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
###
systemctl restart apache2

5.3:數(shù)據(jù)庫配置:

image.png

5.4:zabbix server 配置:

image.png

5.5:信息確認(rèn):

image.png

5.6:創(chuàng)建配置文件:

需要手動(dòng)下載配置文件并上傳至zabbix server的 /var/www/html/zabbix/conf/zabbix.conf.php路徑

image.png

5.7:刷新頁面:

配置文件上傳成功后刷新web頁面驗(yàn)證是否生效,然后在生效后點(diǎn)finish即可完成zabbix server 的初始化。
登錄界面:

image.png

6:啟動(dòng)zabbix agent:

/apps/zabbix_server/sbin/zabbix_agentd

7:zabbix server與agent啟動(dòng)文件:

通過service啟動(dòng)文件啟動(dòng)zabbix server與zabbix agent。

7.1:zabbix server啟動(dòng)腳本:

###先停止當(dāng)前zabbix server進(jìn)程
pkill zabbix_server
vim /lib/systemd/system/zabbix-server.service
###文件內(nèi)容
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target
[Service]
Environment="CONFFILE=/apps/zabbix_server/etc/zabbix_server.conf"
EnvironmentFile=-/etc/default/zabbix-server
Type=forking
Restart=on-failure
PIDFile=/apps/zabbix_server/run/zabbix_server.pid#run目錄需自己創(chuàng)建,配置文件也需修改
KillMode=control-group
ExecStart=/apps/zabbix_server/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=infinity
[Install]
WantedBy=multi-user.target

zabbix_server.conf配置文件默認(rèn)是以普通用戶zabbix啟動(dòng),
必須修改zabbix server安裝目錄的屬主和屬組才能啟動(dòng),也可以修改允許root啟動(dòng),放開注釋設(shè)置為1即可用root啟動(dòng)

image.png

啟動(dòng)zabbix_server

chown -R zabbix:zabbix /apps/zabbix_server#zabbix普通用戶權(quán)限修改后啟動(dòng)
systemctl daemon-reload
systemctl enable --now zabbix-server.service

7.2:zabbix agent啟動(dòng)腳本:

###先停止當(dāng)前zabbix_agent進(jìn)程
pkill zabbix_agentd
vim /lib/systemd/syste[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target
[Service]
Environment="CONFFILE=apps/zabbix_server/etc/zabbix_agentd.conf"
EnvironmentFile=-/etc/default/zabbix-agent
Type=forking
Restart=on-failure
PIDFile=/apps/zabbix_server/run/zabbix_agentd.pid#配置文件也需修改
KillMode=control-group
ExecStart=/apps/zabbix_server/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=zabbix
Group=zabbix
[Install]
WantedBy=multi-user.targetm/zabbix-agent.service

啟動(dòng)zabbix_agent

systemctl daemon-reload
systemctl enable --now zabbix-agent.service

8:Web界面中文菜單環(huán)境:

8.1:ubuntu系統(tǒng)安裝中文語言環(huán)境:

安裝并設(shè)置中文簡體語言環(huán)境

###安裝簡體中文語言環(huán)境
apt-get install language-pack-zh*
###增加中文語言環(huán)境變量
vim /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
LANG="zh_CN.UTF-8"
###重新設(shè)置本地配置
sudo dpkg-reconfigure locales

按空格選中后回車確認(rèn)

image.png

image.png

systemctl restart apache2

8.1:監(jiān)控項(xiàng)與亂碼:

當(dāng)前系統(tǒng)有些監(jiān)控項(xiàng)部分顯示有亂碼,使由于web界面顯示為中文但是系統(tǒng)沒有>>相關(guān)字體支持,因此需要相關(guān)字體的支持才能正常顯示

8.1.1:上傳字體文件:

  • 在Windows上找到控制面板-->字體-->楷體(或者其他個(gè)人喜歡的中文字體),然后將字體拷貝到windows系統(tǒng)其他目錄,比如拷貝至windows當(dāng)前用戶的桌面。
    image.png
  • 上傳字體到zabbix web目錄:
# pwd
/var/www/html/zabbix/assets/fonts #上傳楷體字體文件到這里
chown zabbix.zabbix ./* #更改權(quán)限為zabbix用戶和組
  • 修改zabbix文件調(diào)用新字體:
# pwd
/var/www/html/zabbix
vim include/defines.inc.php
#70 define('ZBX_GRAPH_FONT_NAME', 'DejaVuSans'); // font file name
70 define('ZBX_GRAPH_FONT_NAME', 'simkai'); // font file name
#111 define('ZBX_FONT_NAME', 'DejaVuSans');
111 define('ZBX_FONT_NAME', 'simkai');
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容