Zabbix源碼安裝(LNMP)

實驗環境:CentOS 6.5(最小化安裝)

Zabbix Install Scripts:https://yunpan.cn/crF5YFDkRqsGh  訪問密碼 cfd7


安裝包下載地址:

http://down.51cto.com/data/2214893


[root@CentOS software]# yum -y install gcc gcc-c++ make

安裝PHP:

[root@CentOS software]# yum -y install libxml2 libxml2-devel libjpeg-devel libpng-devel bzip2-devel libcurl-devel gd-devel
[root@CentOS software]# tar -jxvf php-5.3.8.tar.bz2 &>/dev/null
[root@CentOS software]# cd php-5.3.8
[root@CentOS php-5.3.8]# ./configure --prefix=/usr/local/php --with-bz2 --with-curl --enable-ftp --enable-sockets --enable-bcmath --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local/photo --with-png-dir=/usr/local/photo --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64
[root@CentOS php-5.3.8]# make &&make install
[root@CentOS php-5.3.8]# cp php.ini-production /usr/local/php/lib/php.ini
[root@CentOS php-5.3.8]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@CentOS ~]# sed -i '/max_execution_time/s/30/300/' /usr/local/php/lib/php.ini
[root@CentOS ~]# sed -i '/post_max_size/s/8/16/' /usr/local/php/lib/php.ini
[root@CentOS ~]# sed -i '/max_input_time/s/60/300/' /usr/local/php/lib/php.ini
[root@CentOS ~]# sed -i '/^;date.timezone/adate.timezone \= \"Asia\/Shanghai\"' /usr/local/php/lib/php.ini
[root@CentOS ~]# sed -i '/^\;date\.timezone \=/d' /usr/local/php/lib/php.ini

注:如果PHP的時區不是"Asia/Shanghai",則在安裝Zabbix的時候會出現下面的報錯信息

--with-config-file-path=PATH這個參數可以指定php.ini文件的位置,默認在PREFIX/lib目錄下

wKioL1cjTZ_wh0ZCAAB4wrJVpQ4344.png

wKioL1cjTZ_iIIXfAAAwB5hr9kc401.png

wKiom1cjTNKxPz7oAAAY16a_dNM428.png

[root@CentOS ~]# /usr/local/php/bin/php -i |grep date.timezone
date.timezone => Asia/Shanghai => Asia/Shanghai
[root@CentOS ~]#
[root@CentOS ~]# sed -i '/run\/php-fpm.pid/s/^;//g' /usr/local/php/etc/php-fpm.conf
[root@CentOS ~]# sed -i '/^;pm.min_spare_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf
[root@CentOS ~]# sed -i '/^;pm.max_spare_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf
[root@CentOS ~]# sed -i '/^;pm.start_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf
[root@CentOS ~]# sed -i '/^listen/s/127.0.0.1/0.0.0.0/g' /usr/local/php/etc/php-fpm.conf
[root@CentOS ~]# /usr/local/php/sbin/php-fpm
[root@CentOS ~]# echo "/usr/local/php/sbin/php-fpm" >>/etc/rc.local
[root@CentOS ~]# netstat -anp|grep php-fpm
tcp        0      0  0 0.0.0.0 9000              0.0.0.0:*                   LISTEN      106728/php-fpm      
unix  3      [ ]         STREAM     CONNECTED     98463  106728/php-fpm      
unix  3      [ ]         STREAM     CONNECTED     98462  106728/php-fpm      
[root@CentOS ~]#
[root@CentOS ~]# ps -ef|grep php|grep -v grep
root      30167      1  0 05:01 ?        00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nobody    30168  30167  0 05:01 ?        00:00:00 php-fpm: pool www          
nobody    30169  30167  0 05:01 ?        00:00:00 php-fpm: pool www
···    
[root@CentOS ~]#

安裝Nginx:

[root@CentOS software]# tar -jxvf pcre-8.12.tar.bz2 &>/dev/null
[root@CentOS software]# cd pcre-8.12
[root@CentOS pcre-8.12]# ./configure &&make &&make install
[root@CentOS software]# tar -zxvf zlib-1.2.7.tar.gz &>/dev/null
[root@CentOS software]# cd zlib-1.2.7
[root@CentOS zlib-1.2.7]# ./configure &&make &&make install
[root@CentOS software]# tar -zxvf openssl-1.0.1c.tar.gz &>/dev/null
[root@CentOS software]# cd openssl-1.0.1c
[root@CentOS openssl-1.0.1c]# ./config &&make &&make install
[root@CentOS software]# tar -zxvf nginx-1.6.2.tar.gz &>/dev/null
[root@CentOS software]# cd nginx-1.6.2
[root@CentOS nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-pcre=/software/pcre-8.12 --with-zlib=/software/zlib-1.2.7 --with-openssl=/software/openssl-1.0.1c --with-http_stub_status_module
[root@CentOS nginx-1.6.2]# make &&make install
[root@CentOS nginx-1.6.2]# chmod 775 /etc/init.d/nginx
[root@CentOS nginx-1.6.2]# chkconfig --add nginx
[root@CentOS nginx-1.6.2]# chkconfig nginx on
[root@CentOS nginx-1.6.2]# /etc/init.d/nginx start
Starting nginx:                                            [  OK  ]
[root@CentOS nginx-1.6.2]#

安裝mysql:

[root@CentOS software]# yum -y install mysql*
[root@CentOS software]# /etc/init.d/mysqld start
Starting mysqld:                                           [  OK  ]
[root@CentOS software]# chkconfig mysqld on
[root@CentOS software]# mysqladmin -uroot password redhat
[root@CentOS software]# mysql -uroot -predhat
mysql>
[root@CentOS software]#

安裝Zabbix:

[root@CentOS software]# yum -y install net-snmp net-snmp-devel libxml2-devel libcurl-devel
[root@CentOS software]# tar -zxvf zabbix-2.0.14.tar.gz &>/dev/null
[root@CentOS software]# cd zabbix-2.0.14
[root@CentOS zabbix-2.0.14]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2           //libcurl監控web
[root@CentOS zabbix-2.0.14]# make &&make install
zabbix server一般充當兩個角色:server、angent,所以上面的配置參數也同時加上了–enable-agent。
備註:請安裝好MySQL,snmp,curl開發庫。
root@CentOS software]# useradd -s /sbin/nologin zabbix

初始化數據庫:

[root@CentOS software]# mysql -uroot -predhat
mysql> create database zabbix default charset utf8;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on zabbix.* to [email protected] identified by 'zabbix';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>

zabbix server與proxy需要數據庫,angent不需要。尤其要注意的是proxy只需要導入一個sql文件,而server一共要導入3個sql文件。我當時在搭建proxy的時候導入了3個sql,導致出現報錯。後來才發現proxy只需要導入一個表結構即可

[root@CentOS zabbix-2.0.14]# mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql
[root@CentOS zabbix-2.0.14]# mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql
[root@CentOS zabbix-2.0.14]# mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql
[root@CentOS zabbix-2.0.14]# cp misc/init.d/fedora/core/zabbix_* /etc/init.d/
[root@CentOS zabbix-2.0.14]# chmod 775 /etc/init.d/zabbix_*
[root@CentOS ~]# sed -i '/LogFile/s/tmp/var\/log/' /usr/local/zabbix/etc/zabbix_server.conf
[root@CentOS ~]# sed -i '/^DBUser\=/s/root/zabbix/' /usr/local/zabbix/etc/zabbix_server.conf
[root@CentOS ~]# sed -i '/DBPassword\=$/s/^#//g' /usr/local/zabbix/etc/zabbix_server.conf
[root@CentOS ~]# sed -i '/DBPassword\=$/s/^[ \t]//g' /usr/local/zabbix/etc/zabbix_server.conf
[root@CentOS ~]# sed -i '/DBPassword\=$/s/\=/&zabbix/g' /usr/local/zabbix/etc/zabbix_server.conf
[root@CentOS ~]# sed -i -e '/DBPort\=/s/^#//g' /usr/local/zabbix/etc/zabbix_server.conf -e '/DBPort\=/s/^[ \t]//g' /usr/local/zabbix/etc/zabbix_server.conf
[root@Zabbix ~]# sed -i '/^Server/s/127.0.0.1/192.168.100.241/g' /usr/local/zabbix/etc/zabbix_agent.conf
[root@Zabbix ~]# sed -i '/^Server/s/127.0.0.1/192.168.100.241/g' /usr/local/zabbix/etc/zabbix_agentd.conf
[root@Zabbix ~]# sed -i "/^ServerActive/s/127.0.0.1/${remote_ip}:10051/g" /usr/local/zabbix/etc/zabbix_agentd.conf
[root@Zabbix ~]# sed -i "/^Hostname/s/Zabbix server/${remote_ip}/g" /usr/local/zabbix/etc/zabbix_agentd.conf
mkdir /usr/local/nginx/html/zabbix
[root@CentOS ~]# cat /usr/local/zabbix/etc/zabbix_agent.conf|grep Server|grep -v ^#
Server=192.168.100.241            //服務端的IP
[root@CentOS ~]# cat /usr/local/zabbix/etc/zabbix_agent.conf|grep UnsafeUser
### Option: UnsafeUserParameters
# UnsafeUserParameters=0
[root@CentOS ~]#

默認是不啓用自定義腳本功能的,要自定義key,需開啓,設置爲 1

[root@CentOS ~]# mkdir /usr/local/nginx/html/zabbix
[root@CentOS ~]# cp -rf /software/zabbix-2.0.14/frontends/php/* /usr/local/nginx/html/zabbix/
[root@CentOS ~]# chown zabbix:zabbix /usr/local/nginx/html/zabbix/ -R
[root@CentOS ~]# chmod o+w /usr/local/nginx/html/zabbix/conf
[root@CentOS ~]# ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
[root@CentOS ~]# touch /var/log/zabbix_server.log
[root@CentOS ~]# chown zabbix:zabbix /var/log/zabbix_server.log
[root@CentOS ~]# chmod 775 /var/log/zabbix_server.log
[root@CentOS ~]# /etc/init.d/zabbix_server start
Starting zabbix_server:                                    [  OK  ]
[root@CentOS ~]# /etc/init.d/zabbix_agentd start
Starting zabbix_agentd:                                    [  OK  ]
[root@CentOS ~]# chkconfig --add zabbix_server
[root@CentOS ~]# chkconfig --add zabbix_agentd
[root@CentOS ~]# chkconfig zabbix_server on
[root@CentOS ~]# chkconfig zabbix_agentd on
[root@CentOS ~]# chkconfig --list|grep zabbix
zabbix_agentd  0:off1:off2:on3:on4:on5:on6:off
zabbix_server  0:off1:off2:on3:on4:on5:on6:off
[root@CentOS ~]#
[root@CentOS ~]# ps -ef|grep zabbix|grep -v grep
zabbix    12929      1  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12931  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12932  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12933  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12934  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12935  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12936  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12937  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12938  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12939  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12940  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12941  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12942  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12943  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12944  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12945  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12946  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12947  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12948  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12949  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12961  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12962  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12963  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12964  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12965  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12966  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12967  12929  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_server
zabbix    12994      1  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_agentd
zabbix    12995  12994  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_agentd
zabbix    12996  12994  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_agentd
zabbix    12997  12994  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_agentd
zabbix    12998  12994  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_agentd
zabbix    12999  12994  0 01:56 ?        00:00:00 /usr/local/sbin/zabbix_agentd
[root@CentOS ~]# netstat -tunlp|grep zabbix
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      12994/zabbix_agentd
tcp        0      0 0.0.0.0:10051               0.0.0.0:*                   LISTEN      12929/zabbix_server
[root@CentOS ~]#
[root@CentOS ~]# touch /usr/local/nginx/logs/zabbix.access.log
[root@CentOS conf]# /etc/init.d/nginx reload
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Reloading nginx:                                           [  OK  ]
[root@CentOS conf]#
[root@CentOS ~]# sed -i '/^\:OUTPUT/a\-A INPUT \-p tcp \-m state \-\-state NEW \-m tcp \-\-dport 80 \-j ACCEPT' /etc/sysconfig/iptables
[root@CentOS ~]# /etc/init.d/iptables restart
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]
[root@CentOS ~]#

訪問:http://192.168.100.241/zabbix/

wKiom1cjTj-CbrtJAAMIE1wiAlY723.png

wKioL1cjTw2xInjVAAEOwV9UufE072.png

wKiom1cjTkCxMxqqAADnl6LHKDU076.png

wKioL1cjTw_QjxYfAADSTdeGxnA540.png

wKioL1cjTxPjTn3vAADqBRnOkGY125.png

wKioL1cjTxSRC5W5AADkoOjG0eE092.png

wKiom1cjTkeCH2TLAAE-6asczEc726.png

wKiom1cjTkiTA_1TAAC5alknrXg653.png

基於LNMP的Zabbix安裝完成

更改Zabbix語言:Profile---User---Language:

wKioL1cjT2GQcq8cAABrT0xA_OA492.png

PHP探針:
[root@CentOS phpinfo]# cat index.php
<?php
phpinfo();
?>
[root@CentOS phpinfo]#

Zabbix Agent安裝:

[root@Client software]# yum -y install gcc gcc-c++ make net-snmp net-snmp-devel libxml2-devel libcurl-devel
[root@Client software]# tar -zxvf zabbix-2.0.14.tar.gz &>/dev/null
[root@Client software]# cd zabbix-2.0.14
[root@Client zabbix-2.0.14]# ./configure --prefix=/usr/local/zabbix --enable-agent
[root@Client zabbix-2.0.14]# make &&make install
[root@Client software]# useradd -s /sbin/nologin zabbix
[root@Client etc]# grep -v ^# zabbix_agentd.conf|grep -v ^$
PidFile=/tmp/zabbix_agentd.pid
LogFile=/var/log/zabbix_agentd.log               //修改日誌存儲路徑
DebugLevel=4                                     //開啓DEBUG
EnableRemoteCommands=0                           //允許遠程執行命令
Server=192.168.1.10                              //允許那臺機器訪問本機key
ListenPort=10050                                 //監聽端口
StartAgents=8                                    //啓動的客戶端進程數
ServerActive=192.168.1.10:10051                  //主動監控,服務端的ip及端口
Hostname=Client.example.com                      //客戶端的主機名和在WEB添加主機名時一致
Timeout=30                                       //超時時間
UnsafeUserParameters=1                           //用戶自定義的key
[root@Client etc]#
[root@Client ~]# tail -n 2 /etc/hosts
192.168.1.10Zabbix.example.com Zabbix
192.168.1.11Client.example.com Client
[root@Client ~]# cp /software/zabbix-2.0.14/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
[root@Client ~]# ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
[root@Client ~]# touch /var/log/zabbix_agentd.log
[root@Client ~]# chown -R zabbix:zabbix /var/log/zabbix_agentd.log
[root@Client ~]# chmod -R 775 /var/log/zabbix_agentd.log
[root@Client ~]# /etc/init.d/zabbix_agentd start
Starting zabbix_agentd:                                    [  OK  ]
[root@Client ~]# chkconfig --add zabbix_agentd
[root@Client ~]# chkconfig zabbix_agentd on
[root@Client ~]# netstat -anp|grep zabbix
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      10660/zabbix_agentd
[root@Client ~]# 
[root@Client ~]# grep 100 /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 10051 -j ACCEPT
[root@Client ~]#

10051爲Zabbix Server的Listen Port

10050爲Zabbix Agent的Listen Port

測試端口是否正常:

wKiom1cjTv2A6jnnAAAjzMRKiSQ874.png

wKioL1cjT8ySwDm9AADG5J2PCZE329.png

wKioL1cjT8zBOJ3MAADKfuW5uco966.png

wKiom1cjTv-TcJaqAACqGcQFhSU289.png

wKiom1cjTwDBoXZbAADkoZjpSxE351.png

wKioL1cjT87DqX4gAAE068zVHHI648.png



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章