ZabbixServer的安裝(只有源碼裝zabbix才能裝支持java)
搭建自定義yum倉庫並安裝支持包

yum -y install createrepo #下載依賴關系命令 createrepo rpm #生成依賴關系 vim /etc/yum.repos.d/cccc.repo #創建yum源指定安裝包 [rpm] name=rpm baseurl=file:///root/rpm/ gpgcheck=0 enabled=1 yum -y install pcre pcre-devel zlib-devel libaio libaio-devel libxml2 libxml2-devel bzip2-devel openssl openssl-devel net-snmp-devel net-snmp curl-devel gd gcc gcc-c++ make libjpeg-devel libpng-devel libcurl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker mysql-devel net-snmp-utils #如果下一步出現問題,請注釋掉yum配置文件里的本地光盤源 yum -y install libvpx-devel gd-devel
編譯安裝LNMP環境 (編譯過程看不懂 看前邊博客各項安裝)
安裝nginx
useradd -s /sbin/nologin -M www tar xf nginx-1.10.2.tar.gz -C /usr/src/ cd /usr/src/nginx-1.10.2/ ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module && make && make install ln -s /usr/local/nginx/sbin/* /usr/local/sbin/ cd /usr/local/nginx/conf/ egrep -v "^$|#" nginx.conf.default > nginx.conf vim nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.php index.html index.htm; } location = /nginx-status { stub_status on; access_log off; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } } nginx -t 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
安裝mysql
tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz -C /usr/local/ cd /usr/local/ mv mysql-5.5.32-linux2.6-x86_64 mysql cd mysql/ /bin/cp support-files/my-small.cnf /etc/my.cnf useradd -s /sbin/nologin -M mysql chown -R mysql.mysql data /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql cp support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld /etc/init.d/mysqld start Starting MySQL.. SUCCESS!
安裝libmcrypt
tar xf libmcrypt-2.5.8.tar.gz -C /usr/src/ cd /usr/src/libmcrypt-2.5.8/ ./configure && make && make install
安裝GD
tar xf GD-2.18.tar.gz -C /usr/src/
yum install perl-ExtUtils-Embed -y
cd /usr/src/GD-2.18/ perl Makefile.PL make && make install
安裝PHP
tar xf php-5.6.30.tar.gz -C /usr/src/ cd /usr/src/php-5.6.30/ ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-bz2 --with-curl --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --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 --enable-bcmath make && make install cp php.ini-development /usr/local/php/etc/php.ini vim /usr/local/php/etc/php.ini 372 max_execution_time = 300 382 max_input_time = 300 393 memory_limit = 256M 660 post_max_size = 32M 702 always_populate_raw_post_data = -1 820 upload_max_filesize = 16M 936 date.timezone =Asia/Shanghai cd /usr/local/php/etc/ cp php-fpm.conf.default php-fpm.conf vim php-fpm.conf 149 user = www 150 group = www
安裝zabbix server端
編譯安裝zabbix服務器
useradd zabbix -s /sbin/nologin -M tar xf zabbix-3.2.4.tar.gz -C /usr/src/ cd /usr/src/zabbix-3.2.4/ ./configure --prefix=/usr/local/zabbix --with-mysql --with-net-snmp --with-libcurl --enable-server --enable-agent --enable-proxy --with-libxml2 make && make install #由於zabbix啟動腳本路徑默認指向的是/usr/local/sbin路徑,因此,需要提前建立軟連接: ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/ ln -s /usr/local/zabbix/bin/* /usr/local/bin/
配置zabbix的mysql環境
Zabbix服務器和mysql安裝到一台服務器上,首先需要手動創建zabbix數據庫,操作如下: mysqladmin -uroot password '123456' mysql -uroot -p123456 -e 'create database zabbix character set utf8;' mysql -uroot -p123456 -e "grant all privileges on zabbix.* to zabbix@'localhost' identified by '123456';" mysql -uroot -p123456 -e 'flush privileges;' #如下數據的導入順序不可以錯 mysql -uzabbix -p123456 zabbix < /usr/src/zabbix-3.2.4/database/mysql/schema.sql mysql -uzabbix -p123456 zabbix < /usr/src/zabbix-3.2.4/database/mysql/images.sql mysql -uzabbix -p123456 zabbix < /usr/src/zabbix-3.2.4/database/mysql/data.sql
安裝Zabbix web GUI
- Zabbix web是php代碼編寫的,因此需要有php環境,前面已經安裝好了lnmp,因此可以直接使用。
- 默認的nginx安裝的根目錄為/ usr / local / nginx / html,因此,只需要Zabbix web的代碼放到此目錄即可。
- Zabbix web的代碼在Zabbix源碼包中的frontends / php目錄下,將這個php目錄拷貝到/ usr / local / nginx / html /目錄下並改名zabbix即可完成Zabbix web端的安裝。
- 在瀏覽器輸入http:// IP / zabbix,然后會檢查zabbix web運行環境是否滿足,並提供連接數據庫的相關信息即可,最后將連接數據庫相關信息都存入文件zabbix / conf / zabbix.conf。 PHP中,這樣就可以登錄ZABBIX的網絡平台了。
- 默認的ZABBIX平台登錄用戶名為管理員,密碼為ZABBIX。
復制zabbix web目錄到nginx web根目錄下
cp -rp /usr/src/zabbix-3.2.4/frontends/php /usr/local/nginx/html/zabbix cd /usr/local/nginx/html/ chown -R www.www zabbix ll -d zabbix/ drwxr-xr-x. 13 www www 4096 Feb 27 2017 zabbix/
啟動nginx服務及php-fpm
/usr/local/nginx/sbin/nginx netstat -antup | grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 8439/nginx /usr/local/php/sbin/php-fpm netstat -antup | grep php-fpm tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 8522/php-fpm
登錄web根據提示生成zabbix.conf.php配置文件
在瀏覽器輸入:IP/zabbix







zabbix server的配置
zabbix_server.conf配置
通過源碼安裝方式將zabbix安裝到/ usr / local / zabbix下面,zabbix server的配置文件為/usr/local/zabbix/etc/zabbix_server.conf
#將zabbix_server.conf文件內容修改成如下所示: vim /usr/local/zabbix/etc/zabbix_server.conf 12 ListenPort=10051 #zabbix server監聽端口 38 LogFile=/tmp/zabbix_server.log #zabbix server日志路徑 87 DBName=zabbix #zabbix server連接MySQL數據庫的數據庫名 103 DBUser=zabbix #zabbix server連接MySQL數據庫的用戶名 111 DBPassword=123123 #zabbix server連接MySQL數據庫的密碼 118 DBSocket=/tmp/mysql.sock #MySQL的實例文件位置 136 StartPollers=5 #用於設置zabbix server服務啟動時啟動Pollers(主動收集數據進程)的數量,數量越多,則服務端吞吐能力越強,同時對系統資源消耗越大 165 StartTrappers=10 #用於設置zabbix server服務啟動時啟動Trappers(負責處理Agentd推送過來的數據的進程)的數量。Agentd為主動模式時,zabbix server需要設置這個值大一些。 181 StartDiscoverers=10 #用於設置zabbix server服務啟動時啟動Discoverers進程的數量,如果zabbix監控報Discoverers進程忙時,需要提高該值。 297 ListenIP=0.0.0.0 #zabbix server啟動的監聽端口對哪些ip開放,Agentd為主動模式時,這個值建議設置為0.0.0.0 447 AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts
#zabbix server運行腳本存放目錄,一些供zabbix server使用的腳本,都可以放在這里。
添加相關服務和端口到系統配置文件
編輯/ etc / services中文件,在最后添加以下代碼:
vim /etc/services zabbix-agent 10050/tcp # Zabbix Agent zabbix-agent 10050/udp # Zabbix Agent zabbix-trapper 10051/tcp # Zabbix Trapper zabbix-trapper 10051/udp # Zabbix Trapper
其中,10051是zabbix server的監聽端口,10050是zabbix agent的監聽端口。
添加管理維護腳本
從ZABBIX源碼包雜項/ init.d /的fedora的/ CORA /目錄中找到zabbix_server和zabbix_agentd,然后復制到的/etc/init.d目錄下,由於我們的zabbix_agnetd采用轉的安裝方式,會自動添加啟動腳本,所以在此處,我們不進行zabbix_agentd的啟動腳本的復制。
cp /usr/src/zabbix-3.2.4/misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix_server chmod +x /etc/init.d/zabbix_server chkconfig zabbix_server on
啟動zabbix_server端進程
/etc/init.d/zabbix_server start netstat -antup | grep zabbix_server tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 9319/zabbix_server
zabbix_agent的安裝與配置
zabbix agent端的安裝建議采用rpm包方式安裝,可從http://repo.zabbix.com/zabbix/3.2/下載zabbix的agent端rpm包,版本與zabbix server端保持一致,安裝如下:
wget http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-agent-3.2.4-1.el6.x86_64.rpm rpm -ivh zabbix-agent-3.2.4-1.el6.x86_64.rpm
安裝完成后,zabbix agent端已經安裝完成了,zabbix agent端的配置目錄位於/ etc / zabbix下,可在此目錄進行配置文件的修改。
特別提示:
- zabbix server的源碼包本身就包含了zabbix server端和zabbix agent端,因此,zabbix服務器端無需再安裝zabbix agent的rpm包。
- 然而zabbix agent的rpm包是為了方便在服務器上進行快速安裝而設計的快捷安裝包。
- 因此為了統一,監控端和被監控端的zabbix agent我們都用rpm的安裝方式
修改zabbix agent端的配置文件
#將內容修改為如下所示: vim /etc/zabbix/zabbix_agentd.conf 13 PidFile=/var/run/zabbix/zabbix_agentd.pid #進程pid存放路徑 32 LogFile=/var/log/zabbix/zabbix_agentd.log #zabbix agent日志存放路徑 95 Server=127.0.0.1,192.168.0.220 #指定zabbix server端IP地址 103 ListenPort=10050 #指定agentd的監聽端口 120 StartAgents=3 #指定啟動agentd進程數量。設置0表示關閉 136 ServerActive=192.168.0.220:10051 #啟用agnetd主動模式,啟動主動模式后,agentd將主動將收集到的數據發送到zabbix server端,Server Active后面指定的IP就是zabbix server端IP 147 Hostname=192.168.0.220 #需要監控的主機名或者IP地址,agent裝在哪寫哪的IP 265 Include=/etc/zabbix/zabbix_agentd.d/ #相關配置都可以放到此目錄下,自動生效 284 UnsafeUserParameters=1 #啟用agent端自定義item功能,設置此參數為1后,就可以使用UserParameter指令了。UserParameter用於自定義item
啟動zabbix_agent端進程
/etc/init.d/zabbix-agent start netstat -antup | grep zabbix_agent tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 1322/zabbix_agentd tcp 0 0 :::10050 :::* LISTEN 1322/zabbix_agentd chkconfig zabbix-agent on
設置開機自啟動
chkconfig mysqld on chkconfig zabbix_server on
vim /etc/rc.local
mkdir /var/run/zabbix
chown root:zabbix /var/run/zabbix
chmod 0775 /var/run/zabbix
/usr/local/sbin/nginx
/usr/local/php/sbin/php-fpm
/etc/init.d/zabbix-agent stop
解決zabbix-agent重啟無法創建PID問題
mkdir /var/run/zabbix chown root:zabbix /var/run/zabbix chmod 0775 /var/run/zabbix
測試zabbix server監控
如何知道zabbix server監控已經生效呢,可通過zabbix server上的zabbix_get命令來完成,在zabbix服務器上執行如下命令即可進行測試:
/usr/local/zabbix/bin/zabbix_get -s 192.168.50.166 -p 10050 -k "system.uptime" -s 是指定zabbix agent端的IP地址 -p 是指定zabbix agent端的監聽端口 -k 是監控項,即item 如果有輸出結果,表面zabbix server可以從zabbix agent獲取數據,配置成功。
具體操作如下:
#在監控端zabbix_server端進行如下操作 /usr/local/zabbix/bin/zabbix_get -s 192.168.50.166 -p 10050 -k "system.uptime" 1953 #有數據顯示就代表監控正常
自定義一個監控項
在zabbix agent配置文件里定義這個監控項
vim /etc/zabbix/zabbix_agentd.conf 264 Include=/etc/zabbix/zabbix_agentd.d/ #我們發現zabbix_agentd.d目錄已經默認被include進入了主配置文件。
由於zabbix_agentd.conf配置文件默認導入了所有zabbix_agentd.d目錄下的內容,因此我們可以將監控項定義到zabbix_agentd.d目錄下。
參考模版,自己定義監控項的獲取命令
vim /etc/zabbix/zabbix_agentd.d/監控名.conf UserParameter=MEM,free |awk 'NR==2{print $NF}' 固定格式 自定義監控key鍵, 監控命令(查看總內存)
/etc/init.d/zabbix-agent restart
在zabbix server端測試獲取自定義的監控項信息
/usr/local/zabbix/bin/zabbix_get -s 192.168.50.166 -p 10050 -k "MEM" 1801368
