記錄一次基於LNMP環境下的Zabbix3.0部署

前言:

    公司現需要部署一個Zabbix來監控線上環境,但是線上服務器資源有限,無法部署到其中任意一臺。那怎麼辦呢?於是查閱一番資料,獲取解決思路:

    1.線下環境使用一臺服務器做爲Zabbix Server,線上環境任意一臺搭建***,將所有服務器連接到一起,組成一個安全的局域網環境。

    2.線下環境使用一臺服務器作爲Zabbix Server,使用路由做端口映射,將內網Zabbix Server的10050-10051端口映射出去。

    一番比較下,各方面表明:使用第二個思路是最符合實際的。下面是部署Zabbix的一個過程記錄。



一、環境檢測

    

1.Mysql    

     Welcome to the MySQL monitor.  Commands end with ; or \g.

     Your MySQL connection id is 20416

     Server version: 5.5.47 MySQL Community Server (GPL)


2.PHP

    PHP Version 5.3.3


3.Nginx

    nginx version: nginx/1.8.0


二、編譯升級軟件版本

    經過檢查發現,現有的環境當中,PHP版本不滿足新版zabbix要求,需要做一個升級。但由於Zabbix Server是開發人員用於測試的服務器,需要多個PHP版本共存,遂:


安裝libiconv

mkdir -p /usr/local/setup
cd /usr/local/setup
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make && make install
cd ..


安裝libmcrypt

wget http://iweb.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install
cd ..


安裝mhash

tar jxvf mhash-0.9.3.tar.bz2
cd mhash-0.9.3
./configure
make && make install
cd ..


安裝mcrypt

wget http://iweb.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure
make && make install
cd ..


安裝PHP 5.5.5

wget http://mirrors.sohu.com/php/php-5.5.5.tar.gz
tar zxvf php-5.5.5.tar.gz
cd php-5.5.5

正式編譯,注意安裝路徑不能與舊版本路徑相同

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
make && make install


修改fpm配置php-fpm.conf.default文件名稱

mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf


複製php.ini配置文件

cp php.ini-production /usr/local/php/etc/php.ini


複製php-fpm啓動腳本到init.d,因爲不想與原來的php啓動服務衝突,特改爲php-fpm2

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm2


賦予執行權限

chmod +x /etc/init.d/php-fpm2


添加爲啓動項

chkconfig --add php-fpm2


啓動php-fpm

service php-fpm2 start


在PHP5.5配置文件

vim /usr/local/php/etc/php-fpm.conf

 

修改:

listen = 127.0.0.1:端口號

端口號不能與5.3重複

在Nginx上的配置文件中 修改:

fastcgi_pass
127.0.0.1:端口號


OK,到這裏PHP多個版本就不會起衝突,直接在nginx上指定不同端口號就能隨意切換PHP版本了。


二、Zabbix Server安裝


  1. 建立一個用於zabbix的用戶

useradd zabbix
passwd zabbix


2.到官網找到Zabbix Server源碼安裝包

tar -zxvf /usr/local/src/zabbix-3.0.3.tar.gz 
cd zabbix-3.0.3 
./configure --prefix=/usr/local/zabbix/ --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --enable-java
make && make install


3.MySQL導入SQL語句

mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by '<password>';
mysql> flush privileges;
mysql> quit;
按照SQL語句順序導入SQL:
shell> mysql -uzabbix -p<password> zabbix < database/mysql/schema.sql
shell> mysql -uzabbix -p<password> zabbix < database/mysql/images.sql
shell> mysql -uzabbix -p<password> zabbix < database/mysql/data.sql



4.修改zabbix.conf

DBName=zabbix #數據庫名稱 
DBUser=zabbix #數據庫用戶名 
DBPassword=jiayuan.com #數據庫密碼 
ListenIP=localhost #數據庫ip地址 
AlertScriptsPath=****/zabbix/alertscripts #zabbix運行腳本存放目錄


5.修改PHP.ini


PHP option post_max_size 16M
PHP option max_execution_time 300
PHP option max_input_time 300
PHP time zone Asia/Shanghai


6.將前端文件拷貝到nginx站點目錄下

cd /usr/local/src/zabbix-3.0.3/frontends/
cp -rf php /usr/local/nginx/zabbix


三、前端配置

這一步比較容易,直接next.不行直接修改配置文件,具體自行百度。


四、客戶端agent安裝

 wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.3/zabbix-3.0.3.tar.gz
 tar zxf zabbix-3.0.3.tar.gz
 cd zabbix-3.0.3
 ./configure --prefix=/usr/local/zabbix_agent --enable-agent ; make install


cp /usr/local/src/zabbix-3.0.3/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/      
sed -i 's#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix_agent#' /etc/init.d/zabbix_agentd # 修改 Agent 安裝路徑
grep -vP '^#|^$' /usr/local/zabbix_agent/etc/zabbix_agentd.conf  # 調整配置文件
LogFile=/tmp/zabbix_agentd.log
Server=xx.xx.xx.xx      # Zabbix Server IP ( 被動模式,客戶端被動 )
ServerActive=127.0.0.1       # 主動模式,如果使用也填 Zabbix Server IP ,不使用可以註釋掉
Hostname=xx.xx.xx.xx    # 本身 IP ,Zabbix Server 添加主機時需要使用,不一定是 IP 
Include=/usr/local/zabbix_agent/etc/zabbix_agentd.conf.d/*.conf   # 加載自定義的監控配置文件
UnsafeUserParameters=1 # 允許自定義 Key
service zabbix_agentd start
chkconfig --add zabbix_agentd
chkconfig --level 35 zabbix_agentd on
iptables -A INPUT -s 'Zabbix Server IP' -p tcp --dport 10050 -j ACCEPT # 由於是客戶端被動模式,所以要開放端口供 Zabbix Server 連接


五、路由映射端口


    將端口映射出去,不同型號路由配置略有不同,思路是一樣的,自行摸索就行。若是採用映射的方法,上面客戶端中指定server地址後面需要加端口號。

wKiom1djacaT2o4lAAAz0pVHKh4769.png-wh_50

如連接不上,檢查防火牆是否放通,ZabbixServer端口是10051 agent端口是10050。


zabbix到此部署完成。

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