1. 程式人生 > 實用技巧 >ubuntu-編譯安裝zabbix-4.0.18

ubuntu-編譯安裝zabbix-4.0.18

編譯安裝zabbix-4.0.18

1、cd /usr/local/src

2、wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.0.18/zabbix-4.0.18.tar.gz/download

3、apt-get 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 -y
#解決依賴環境,apt安裝會自動解決所依賴的環境,如php,但原始碼編譯需要自己解決這些依賴

資料庫伺服器需要進行建立賬號及授權:
root@test:~# mysql
mysql> create database zabbix_server character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix_server.* to dong@"192.168.3.%" identified by 'linux';
#對於Zabbix server和proxy守護程序以及Zabbix前端,必須需要一個數據庫。但是Zabbix agent並不需要。

4、tar xvf zabbix-4.0.18.tar.gz

5、useradd zabbix

6、cd zabbix-4.0.18

7、./configure --prefix=/apps/zabbinx-server --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --enable-java
#編譯zabbix server、agent,指定zabbix使用mysql,指定無客戶端監控通過snmp協議,開啟對url的監控以及java伺服器的監控

8、make && make install

9、vim /apps/zabbinx-server/etc/zabbix_server.conf
DBHost=192.168.3.203
DBName=zabbix_server
DBUser=dong
DBPassword=linux

10、cd /usr/local/src/zabbix-4.0.18/database/mysql

11、mysql -udong -plinux -h192.168.3.203 zabbix_server < schema.sql
    mysql -udong -plinux -h192.168.3.203 zabbix_server < images.sql
	mysql -udong -plinux -h192.168.3.203 zabbix_server < data.sql
#將初始化資料庫表結構的sql指令碼匯入zabbix_server資料庫中

12、mkdir /var/www/html/zabbix

13、cd /usr/local/src/zabbix-4.0.18/frontends/php

14、cp -a ./* /var/www/html/zabbix/
#zabbix的前端使用PHP編寫的,所以必須執行在支援PHP的Web伺服器上;把所有php程式碼拷貝到指定目錄下

15、vim /etc/php/7.2/apache2/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
#不修改這些php引數,在zabbix web介面進行環境檢查時,會提示錯誤

16、systemctl restart apach2
#在apache中,php只是apache的一個功能擴充套件模組,所以重啟apache服務即可

17、/apps/zabbinx-server/sbin/zabbix_agentd
#zabbix server預設監控的是本身,所以需要把zabbix agent起來,客戶端埠是11050

18、/apps/zabbinx-server/sbin/zabbix_server -c /apps/zabbix-server/etc/zabbix_server.conf
#啟動zabbix server

19、瀏覽器訪問http://192.168.3.200/zabbix,進行相關的配置
20、編譯安裝,不會把zabbix web配置的引數自動生成一個配置檔案,需要手動下載下來,然後上傳到指定目錄下
21、cd /var/www/html/zabbix/conf/

22、rz

zabbix-server以service檔案方式啟動

1、root@test:~# vim /lib/systemd/system/zabbix-server.service
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target   #啟動單元指定這三個即可,不需要依賴於別的服務,如果本機沒有mysql等服務,則不要寫

[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
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

2、vim /apps/zabbix-server/etc/zabbix_server.conf
PidFile=/apps/zabbix-server/run/zabbix_server.pid
#配置檔案中也需要修改pid檔案的路徑

3、mkdir /apps/zabbix-server/run

4、chown zabbix.zabbix /apps/zabbix-server/ -R   
#需要修改編譯安裝目錄的所有者及所有組,否則使用者沒有許可權在run目錄下生成pid檔案及無法記錄日誌等

5、systemctl daemon-reload

6、systemctl start zabbix-server

7、systemctl enable zabbix-server

zabbix-agent以service方式啟動

1、root@test:/apps# vim /lib/systemd/system/zabbix-agent.service
[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=/tmp/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.target

2、vim /apps/zabbix-server/etc/zabbix_agentd.conf
PidFile=/tmp/zabbix_agentd.pid

3、systemctl daemon-reload

4、systemctl start zabbix-agent.service

5、systemctl enable zabbix-agent

注意事項

對於沒有agent的裝置採集資料(如交換機、路由器、防火牆等),需要使用snmp協議;監控網路裝置,通常是使用snmp協議監控的;IPMI協議是監控硬體伺服器使用的,伺服器需要有IPMI介面,主要採集CPU溫度及風扇轉速等;

zabbix通過web介面對資料進行展示;