1. 程式人生 > >Zabbbix 3.4.7安裝說明

Zabbbix 3.4.7安裝說明

zabbix 安裝

1 環境說明
CentOS Linux 6.9 x86_64
Nginx 1.12.2
php 5.6.33
mysql 5.7.20
LNMP環境安裝可參考之前博文http://blog.51cto.com/66585/2068620進行。以下安裝均以之前環境為後續。

1.1 安裝約定:
源碼路徑:/usr/loacl/src
安裝路徑:/usr/local/
Zabbix 源碼下載:
https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.4.7/zabbix-3.4.7.tar.gz/download

2 安裝準備
2.1 系統環境:
yum install gcc gcc-c++ autoconf php-mysql mod_ssl mod_perl mod_auth_mysql php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc php-bcmath mysql-connector-odbc mysql-devel libdbi-dbd-mysql net-snmp-devel curl-devel unixODBC-devel OpenIPMI-devel java-devel autoconf mod_ssl mod_perl mod_auth_mysql net-snmp-devel curl-devel unixODBC-devel OpenIPMI-devel

2.2 zabbix用戶
groupadd zabbix -g 201
useradd -g zabbix -u 201 -m zabbix -s /bin/false

2.3 php 配置
vim /etc/php.ini
date.timezone = Asia/Shanghai
max_execution_time = 300
post_max_size = 32M
max_input_time=300
memory_limit = 128M

3 導入zabbix數據庫
連接數據庫(若DB與應用服務器不在同一臺機器上,需要到DB Server登陸)
mysql -uroot -ppassword
mysql> create database zabbix character set utf8 collate utf8_bin;

mysql> grant all privileges on zabbix.* to ‘zabbix‘@‘%‘ identified by ‘password‘;
mysql> FLUSH PRIVILEGES;
mysql> quit;

測試連接:

mysql -u zabbix -p password Zabbix

若可以正常進入數據庫,即可開始執行導入數據庫的腳本。
進入zabbix源碼目錄
cd /usr/local/src/zabbix-3.4.7
mysql -u zabbix -ppassword zabbix < ./database/mysql/schema.sql
mysql -u zabbix -ppassword zabbix < ./database/mysql/images.sql

mysql -u zabbix -ppassword zabbix < ./database/mysql/data.sql

檢查是否生成zabbix 數據庫文件
cd /mydata/mysql/zabbix/

4 Zabbix安裝
4.1 Zabbix安裝
cd /usr/local/src
tar xf zabbix-3.4.7.tar.gzip
cd zabbix-3.4.7
./configure --prefix=/usr/local/zabbix --sysconfdir=/etc/zabbix --enable-server --enable-proxy --enable-agent --with-mysql --with-net-snmp --with-openipmi --with-unixodbc --with-ldap --with-ssh2 --enable-ipv6 --with-libcurl --with-libxml2 --enable-java

make
make install

如果出現錯誤,請檢查以上步驟是否正確,缺少依賴包,請使用yum install 進行安裝

4.2 日誌配置
mkdir /var/log/zabbix
chown zabbix.zabbix /var/log/zabbix

4.3 Zabbix Server agentd 配置

Zabbix Server配置:
[root@zabbixserver ~]# egrep -v "(#|^$)" /etc/zabbix/zabbix_server.conf
ListenPort=10051
LogFile=/var/log/zabbix/zabbix_server.log
DBHost=zabbixdb.tommy.com # 如果DB與APP在不同的機器上,需要配置DBHost
DBName=zabbix
DBUser=root
DBPassword=password
DBPort=3306
StartPollers=100
StartIPMIPollers=10
StartPreprocessors=3
StartTrappers=20
StartPingers=100
StartDiscoverers=120
StartHTTPPollers=1
StartAlerters=3
StartVMwareCollectors=2
VMwareFrequency=60
VMwarePerfFrequency=60
VMwareCacheSize=8M
VMwareTimeout=10
MaxHousekeeperDelete=5000
CacheSize=512M
CacheUpdateFrequency=60
StartDBSyncers=16
HistoryCacheSize=1024M
HistoryIndexCacheSize=128M
TrendCacheSize=512M
ValueCacheSize=8M
Timeout=4
UnavailableDelay=60
UnreachableDelay=15
AlertScriptsPath=/etc/zabbix/alertscripts
ExternalScripts=/etc/zabbix/externalscripts
FpingLocation=/usr/local/fping/sbin/fping
LogSlowQueries=3000
User=zabbix

Zabbix agentd配置
[root@zabbixserver ~]# egrep -v "(#|^$)" /etc/zabbix/zabbix_agentd.conf
LogFile=/var/log/zabbix/zabbix_agentd.log
Server=127.0.0.1,10.1.18.134
ServerActive=10.1.18.134:10051
Hostname=Zabbix server
Include=/etc/zabbix/zabbix_agentd.conf.d/
UnsafeUserParameters=1 #默認是不啟用自定義腳本功能的,要自定義key,需開啟,設置為1

工作模式:

Server 是采用被動工作模式,允許訪問的ip 地址,server 端要獲取數據
ServerActive 是采用主動工作模式,將數據上傳到哪臺服務器,需要填寫server 的端口,默認是10051,語法是ip1,ip2 可以填寫多個server端,中間用逗號隔開。

4.4 拷貝service 啟動腳本
cp misc/init.d/fedora/core/zabbix* /etc/init.d/
chmod 755 /etc/init.d/zabbix
*

修改啟動文件:
vim /etc/init.d/zabbix_server
vim /etc/init.d/zabbix_agentd

修改內容:
BASEDIR=/usr/local/zabbix

設置為開機啟動;
chkconfig zabbix_server on
chkconfig zabbix_agentd on

啟動服務:

service zabbix_server start
service zabbix_agentd start

報錯:

Starting Zabbix Server: /opt/app/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory [FAILED]

解決辦法:
vim /etc/ld.so.conf 加入
/usr/local/mysql/lib
[root@zabbix_server sbin]# ldconfig -v
此錯誤為本機未配置mysql庫文件。

5 網頁端
5.1 復制網頁文件
cp -r /usr/local/src/zabbix-3.4.7/frontends/php/ /www/zabbix/

配置 http server #此處為nginx

server {
listen 80;
server_name localhost;
location / {
root /www/zabbix;
index index.php index.html index.htm;
}

   # redirect server error pages to the static page /50x.html

    #

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
     location ~ \.php$ {
    root /www/zabbix;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
      # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
}

配置完成後,刷新Nginx配置文件

server nginx reload

5.2 通過瀏覽器初始化Zabbix
瀏覽器輸入http://192.168.1.112/setup.php

Php配置檢查,如有不滿足條件項目,修改/etc/php.ini對應參數即可。

註意數據庫配置

目錄無法寫入,/www/zabbix 的文件權限需要修改,

Chown -R nginx:nginx /www/zabbix

或者依照提示,下載zabbix.config.php文件進行編輯即可。

至此,Zabbix服務器安裝完成。

Zabbbix 3.4.7安裝說明