環境准備:
| 操作系統 | CentOS 6.8 2.6.32-642.11.1.el6.x86_64 |
| zabbix server | 172.16.10.150 |
| zabbix agent | 172.16.10.152 |
一、zabbix server 端安裝部署
1、快速部署lamp環境:
yum -y install httpd httpd-devel mysql mysql-server mysql-devel php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml php-bcmath
2、lamp安裝完成檢查
# rpm –qa php httpd mysql
php-5.3.3-48.el6_8.x86_64
mysql-5.1.73-7.el6.x86_64
httpd-2.2.15-55.el6.centos.2.x86_64
注:安裝zabbix3.0以上版本php需要使用5.4以上版本,因此,如果lamp環境使用yum安裝的話,需要將php升級到5.4版本以上。
3、將php 5.3 升級到 php 5.4步驟
3.1 安裝(epel、remi) yum源:
# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm
warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
... ########################################### [100%]
1:epel-release warning: /etc/yum.repos.d/epel.repo created as /etc/yum.repos.d/epel.repo.rpmnew
########################################### [100%]
# wget httprpms.famillecollet.com/enterprise/remi-release-6.rpm
# rpm -ivh remi-release-6.rpm
warning: remi-release-6.rpm: Header V4 DSA/SHA1 Signature, key ID 00f97f56: NOKEY
Preparing... ########################################### [100%]
1:remi-release ########################################### [100%]
3.2 修改 (/etc/yum.repos.d/remi.repo) yum 配置文件,將enabled選項設置為1
name=Remi's RPM repository for Enterprise Linux 6 - $basearch
#baseurl= http://rpms.remirepo.net/enterprise/6/remi/$basearch/
mirrorlist= http://rpms.remirepo.net/enterprise/6/remi/mirror
enabled=1 # 此選項默認值為0,需要修改為1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
yum 源安裝完成,接下來我們就可以進行升級php了。
3.3 升級php5.3到5.4版本
yum update PHP*
4.3 升級完成檢查php版本
# rpm -qa php
php-5.4.45-12.el6.remi.x86_64
升級后發現php版本已經是5.4了,這樣就可以安裝zabbix 3.0以上版本了,接下我來們啟動http、mysql服務,驗證下我們的lamp環境吧。
4、驗證LAMP環境是否可以正常運行
4.1 啟動apache、mysql服務
# /etc/init.d/httpd start
# /etc/init.d/mysqld start
4.2 創建php測試文件
在/var/www/html/目錄下創建index.php測試文件,驗證LAMP環境是否正常。
<?php
phpinfo();
?>
4.3 通過瀏覽器訪問測試 http://172.16.10.150/index.php
通過測試結果來看,我們的LAMP環境已經准備好了,接下來我們就要開始zabbix service的安裝了。
5、zabbix server 端安裝
5.1 創建zabbix用戶和組
# groupadd zabbix
# useradd -g zabbix zabbix -s /sbin/nologin
5.2 創建zabbix數據庫及zabbix帳號
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zbpass';
Query OK, 0 rows affected (0.00 sec)
5.3 解壓zabbix-3.2.2安裝包,並導入sql
# tar -xf zabbix-3.2.2.tar.gz
# cd zabbix-3.2.2
# cd database/mysql/
# ls
data.sqlimages.sqlschema.sql
# mysql -uzabbix -pzbpass zabbix < schema.sql
# mysql -uzabbix -pzbpass zabbix < images.sql
# mysql -uzabbix -pzbpass zabbix < data.sql
以上3個sql導入時順序不能顛倒,否則會報錯。
5.4 安裝zabbix所需依賴的軟件包
yum install -y net-snmp net-snmp-devel curl curl-devel libxml2 libxml2-devel libevent-devel
5.5 安裝zabbix
# cd /usr/local/src/zabbix-3.2.2
# ./configure --enable-server --enable-agent --with-mysql --enable-java--enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
# make && make install
編譯過程中報錯: checking for net-snmp-config... /usr/bin/net-snmp-config
checking for main in -lnetsnmp... yes
checking for localname in struct snmp_session... yes
checking for javac... no
configure: error: Unable to find "javac" executable in path 解決方法: 因為編譯安裝zabbix服務器沒有安裝java環境,根據錯誤提示,無法的到javac中的可執行文件的路徑,所以問題很快就可以定位了,我們安裝下java環境就ok了。由於安裝系統時所選擇的包不同,在編譯的時候可能還會有其它的報錯提示,大家可以根據錯誤提示,來定位自己的問題。
5.6 創建zabbix日志目錄,並設置相應權限,便於排查問題
mkdir /var/log/zabbix
chown -R zabbix.zabbix /var/log/zabbix
5.7 編輯zabbix_server配置文件(/usr/local/etc/zabbix_server.conf)修改如下內容
# egrep -v "^#|^$" /usr/local/etc/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zbpass
AlertScriptsPath=/usr/local/etc/zabbix/alertscripts
5.8 創建自定義腳本目錄,設置權限,目錄下的腳本,可以被zabbix調用
# mkdir /usr/local/etc/zabbix/alertscripts -pv
# chown zabbix.zabbix -R /usr/local/etc/zabbix
5.9 編輯zabbix_agentd配置文件(/usr/local/etc/zabbix_agentd.conf)修改如下內容
# egrep -v "^$|^#" /usr/local/etc/zabbix_agentd.conf
LogFile=/var/log/zabbix/zabbix_agentd.log
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server
5.10 修改php.ini文件(/etc/php.ini)
sed -i 's/post_max_size = 8M/post_max_size = 32M/g' /etc/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /etc/php.ini
sed -i 's/;date.timezone =/date.timezone =PRC/' /etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 600/g' /etc/php.ini
sed -i 's/max_input_time = 60/max_input_time = 600/g' /etc/php.ini
sed -i 's/memory_limit = 128M/memory_limit = 256M/g' /etc/php.ini
5.11 拷貝zabbix服務端、客戶端啟動腳本到/etc/init.d目錄下
# cd /usr/local/src/zabbix-3.2.2/misc/
# cp init.d/tru64/zabbix_server /etc/init.d/
# cp init.d/tru64/zabbix_agentd /etc/init.d/
# chmod +x /etc/init.d/zabbix_*
5.12 修改zabbix_server,zabbix_agentd啟動腳本,使其支持chkconfig配置服務
vim /etc/init.d/zabbix_server
#!/bin/sh下面一行添加
#chkconfig: 345 95 95
#description: Zabbix_Server
vim /etc/init.d/zabbix_agentd
#!/bin/sh下面一行添加
#chkconfig: 345 95 95
#description: Zabbix_agentd
5.13 添加到系統服務
chkconfig zabbix_server on
chkconfig zabbix_agentd on
5.14 啟動zabbix服務
/etc/init.d/zabbix_server start
/etc/init.d/zabbix_agentd start
5.15 檢查zabbix服務狀態
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 16479/zabbix_agentd
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 16421/zabbix_server
tcp 0 0 :::10050 :::* LISTEN 16479/zabbix_agentd
tcp 0 0 :::10051 :::* LISTEN 16421/zabbix_server
# netstat -nltp | grep zabbix
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 16479/zabbix_agentd
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 16421/zabbix_server
tcp 0 0 :::10050 :::* LISTEN 16479/zabbix_agentd
tcp 0 0 :::10051 :::* LISTEN 16421/zabbix_server
5.16 拷貝zabbix web程序到 WEB 服務目錄下
# mkdir /var/www/html/zabbix
# cp –rf /usr/local/src/zabbix-3.2.2/frontends/php/* /var/www/html/zabbix/
5.17、重啟apache服務
/etc/init.d/httpd restart
5.18 通過http://IP/zabbix 進行圖形化安裝zabbix
zabbix server 服務端已經安裝好了,下面我們再看看,如何安裝zabbix agent 客戶端吧!










