閱讀目錄:
1. 關閉防火牆
2. 安裝Zabbix下載源
3. ZabbixClient --- 安裝zabbix-agent代理
4. ZabbixServer --- 安裝zabbix-server服務
5. ZabbixServer --- 配置zabbix-server的數據庫
6. ZabbixServer --- 配置zabbix-server的服務參數
7. ZabbixServer --- 使用zabbix-server
8. 登錄Zabbix的Web端
9. 在Web配置zabbix監控agent
10. 安裝Grafana以及Zabbix插件
11. 登錄Grafana並且配置
序章:
Zabbix的一個很優秀的分布式監控服務器, 它有兩部分組成:
1. “zabbix-server”用來收集並且在web端展示數據
2. “zabbix-agent”用來采集數據,發送給server
在安裝Zabbix時,用了3台虛擬機來測試監控的數據是否正常采集、展示:
Server:
ZabbixServer --- IP : 192.168.246.133
Client:
ZabbixClient_1 --- IP : 192.168.246.134
ZabbixClient_2 --- IP : 192.168.246.135
1. 關閉防火牆
Linux的防火牆是咱們新手的噩夢,很多情況會出現能ping通,但是訪問不了Web頁面。所以開始就干掉它!
[root@localhost ~]# /etc/init.d/iptables stop iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Flushing firewall rules: [ OK ] iptables: Unloading modules: [ OK ]// 開機關閉防火牆
[root@localhost ~]# chkconfig iptables off
2. 安裝Zabbix下載源
zabbix官方提供了下載源,直接執行下面命令,下載安裝就可以了
# rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
提示安裝成功后,查看Linux下載源,是否正確安裝,如果安裝成功,Linux下會有zabbix.repo源文件
[root@localhost Desktop]# ll /etc/yum.repos.d/ total 28 -rw-r--r--. 1 root root 1991 Aug 4 00:13 CentOS-Base.repo -rw-r--r--. 1 root root 647 Aug 4 00:13 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 289 Aug 4 00:13 CentOS-fasttrack.repo -rw-r--r--. 1 root root 630 Aug 4 00:13 CentOS-Media.repo -rw-r--r--. 1 root root 6259 Aug 4 00:13 CentOS-Vault.repo -rw-r--r--. 1 root root 401 Sep 11 2014 zabbix.repo
3. ZabbixClient --- 安裝zabbix-agent代理
分別在ZabbixClient_1與ZabbixClient_2安裝並配置如下設置:
關閉防火牆
[root@localhost Desktop]# /etc/init.d/iptables stop
[root@localhost Desktop]# chkconfig iptables off
安裝Zabbix官方下載源
[root@localhost Desktop]# rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
安裝zabbix-agent,在下載的時候,會自動安裝zabbix-agent的基礎依賴包
[root@localhost Desktop]# yum install zabbix-agent
進入zabbix-agent的Config文件
[root@localhost Desktop]# vim /etc/zabbix/zabbix_agentd.conf
配置zabbix-agent的參數,主要修改Server的IP和Hostname,
Server=192.168.246.133 Hostname=localhost
啟動zabbix-agent
[root@localhost Desktop]# /etc/init.d/zabbix-agent start
4. ZabbixServer --- 安裝zabbix-server服務
關閉防火牆
[root@localhost Desktop]# /etc/init.d/iptables stop
[root@localhost Desktop]# chkconfig iptables off
安裝Zabbix官方下載源
[root@localhost Desktop]# rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
通過zabbix提供的下載源,下載並安裝zabbix-server-mysql和zabbix-web-mysql,這個兩個mysql數據庫是用來存放采集到的數據,Zabbix的web端會通過這些數據,來展示繪圖。而zabbix-get則是用來收集數據的指令。
# yum install zabbix-server-mysql zabbix-web-mysql zabbix-get
在下載這兩個包的時候,會提示你安裝基礎依賴包,其中這些基礎包中,還有zabbix-server的服務端的包,選擇“y”繼續即可。
================================================================================ Package Arch Version Repository Size ================================================================================ Installing: zabbix-server-mysql x86_64 2.4.6-1.el6 zabbix 1.5 M zabbix-web-mysql noarch 2.4.6-1.el6 zabbix 14 k Installing for dependencies: OpenIPMI-libs x86_64 2.0.16-14.el6 base 473 k fping x86_64 2.4b2-16.el6 zabbix-non-supported 31 k iksemel x86_64 1.4-2.el6 zabbix-non-supported 47 k net-snmp x86_64 1:5.5-54.el6_7.1 updates 308 k php-bcmath x86_64 5.3.3-46.el6_6 updates 39 k php-mbstring x86_64 5.3.3-46.el6_6 updates 459 k php-mysql x86_64 5.3.3-46.el6_6 updates 86 k zabbix x86_64 2.4.6-1.el6 zabbix 161 k zabbix-server x86_64 2.4.6-1.el6 zabbix 22 k zabbix-web noarch 2.4.6-1.el6 zabbix 4.5 M Updating for dependencies: net-snmp-libs x86_64 1:5.5-54.el6_7.1 updates 1.5 M php x86_64 5.3.3-46.el6_6 updates 1.1 M php-cli x86_64 5.3.3-46.el6_6 updates 2.2 M php-common x86_64 5.3.3-46.el6_6 updates 529 k php-gd x86_64 5.3.3-46.el6_6 updates 111 k php-pdo x86_64 5.3.3-46.el6_6 updates 79 k php-xml x86_64 5.3.3-46.el6_6 updates 107 k Transaction Summary ================================================================================
5. ZabbixServer --- 配置zabbix-server的數據庫
啟動mysql,我的CentOS在安裝的時候,就把mysql的軟件給安裝了,如果沒有mysql,則需要去安裝mysql,我這里就直接啟動mysql就可以了
# /etc/init.d/mysqld start
成功啟動mysql的話,輸入mysql,就可以進入mysql的命令行了。進入命令行,創建zabbix數據庫
[root@localhost ~]# mysql mysql> create database zabbix; Query OK, 1 row affected (0.00 sec)
在mysql中,查看剛剛創建的zabbix是否創建成功,如下圖數據庫中,有zabbix代表已經創建成功
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | | zabbix | +--------------------+ 4 rows in set (0.00 sec)
接下要要執行zabbix官方提供是sql語句。在安裝基礎依賴包的時候,已經在文件里面了。現在可以直接執行
[root@localhost ~]# cd /usr/share/doc/zabbix-server-mysql-2.4.6/create/ [root@localhost create]# mysql -uroot zabbix < schema.sql [root@localhost create]# mysql -uroot zabbix < images.sql [root@localhost create]# mysql -uroot zabbix < data.sql
6. ZabbixServer --- 配置zabbix-server的服務參數
配置在以下路徑里面 :
# vim /etc/zabbix/zabbix_server.conf
如果沒有特殊需要的話,使用默認配置就可以了,我的mysql賬戶是root,所以需要修改DBuser
LogFile=/var/log/zabbix/zabbix_server.log LogFileSize=0 PidFile=/var/run/zabbix/zabbix_server.pid DBName=zabbix DBUser=root DBSocket=/var/lib/mysql/mysql.sock StartPollers=5 CacheSize=256M SNMPTrapperFile=/var/log/snmptt/snmptt.log AlertScriptsPath=/usr/lib/zabbix/alertscripts ExternalScripts=/usr/lib/zabbix/externalscripts
修改zabbix的時區,有些系統並不是北京時間,如果是國外的時間,在展示出來的圖的時間就是錯的,為了保守起見,設置一下zabbix的時區
# vim /etc/httpd/conf.d/zabbix.conf
修改以下字段
php_value date.timezone Asia/Shanghai
修改zabbix的php的時區
# vim /etc/php.ini
修改以下字段
date.timezone = Asia/Shanghai
啟動Zabbix服務,啟動httpd:
[root@localhost create]# /etc/init.d/zabbix-server start
[root@localhost create]# /etc/init.d/httpd start
7. 使用zabbix-get
安裝好了zabbix-agent和zabbix-server。在Server端試試能不能收到agent端的數據,可以使用zabbix-get。在安裝mysql的時候,已經將zabbix-get安裝過了。可以使用zabbix_get -help命令來查看該命令怎么使用
[root@localhost create]# zabbix_get -help Zabbix get v2.4.6 (revision 54796) (10 August 2015) usage: zabbix_get [-hV] -s <host name or IP> [-p <port>] [-I <IP address>] -k <key> Options: -s --host <host name or IP> Specify host name or IP address of a host -p --port <port number> Specify port number of agent running on the host. Default is 10050 -I --source-address <IP address> Specify source IP address -k --key <key of metric> Specify key of item to retrieve value for -h --help Display help information -V --version Display version number Example: zabbix_get -s 127.0.0.1 -p 10050 -k "system.cpu.load[all,avg1]"
測試是否能收到數據,使用以下命令,發現是可以收到的。
[root@localhost create]# zabbix_get -s 192.168.246.134 -p 10050 -k "system.uname" Linux localhost.localdomain 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64// 測試是否可以收到CPU的數據
[root@localhost create]# zabbix_get -s 192.168.246.134 -p 10050 -k "system.cpu.load" 0.020000
8. 登錄Zabbix的Web端
在Server端,啟動Zabbix服務,啟動httpd:
[root@localhost create]# /etc/init.d/zabbix-server start
[root@localhost create]# /etc/init.d/httpd start
登錄Zabbix的Web客戶端,在瀏覽器中輸入“http://192.168.246.133/zabbix/index.php”,默認會跳轉至Zabbix的setup引導頁面:
點擊Next
點擊Next
點擊Test connection,否則無法點擊Next, 測試連接成功后,點擊Next
設置端口,可以直接使用默認設置的端口10051
點擊Next
點擊Next
點擊Finish,完成初始化引導
輸入默認的賬號密碼,賬號:admin, 密碼zabbix
9. 在Web配置zabbix監控agent
點擊下圖的Create host
按下圖配置,主意要輸入agent的IP和端口,端口默認是10050
點擊select,選擇Linux OS和zabbix Server的模板,點擊Select->Add->Add,如下圖
添加了以后就已經自動啟動了,可以點擊Graphs,查看是否有數據過來
點擊CPU jumps
點擊preview
就可以看到agent那邊有數據傳過來了
10. 安裝Grafana
在ZabbixServer服務器上,安裝Grafana
yum install https://grafanarel.s3.amazonaws.com/builds/grafana-2.1.1-1.x86_64.rpm
下載Grafana的Zabbix插件,在git上下載,如果無法運行下面命令的話,可以先“# yum install git”安裝這個命令
[root@localhost ~]# git clone https://github.com/linglong0820/grafana-zabbix
將插件復制到Grafana文件下
[root@localhost ~]# cp -r grafana-zabbix/zabbix/ /usr/share/grafana/public/app/plugins/datasource/
啟動Grafana
[root@localhost ~]# service grafana-server start
[root@localhost ~]# chkconfig grafana-server on
11. 登錄Grafana並且配置
啟動Grafana后,在瀏覽器中輸入“http://192.168.246.133:3000/login”就可以看到頁面了。
輸入默認用戶名和密碼,用戶名:admin, 密碼:admin, 點擊登錄
按如下配置
【主意1】Zabbix的API地址為“http://192.168.246.133/zabbix/api_jsonrpc.php”,其中IP的安裝zabbix-server的服務器IP
【主意2】Zabbix的API賬號密碼就是Zabbix的Web端登錄賬號和密碼,賬號:admin, 密碼zabbix
點擊Add后,點擊Test Connection測試是否可以連接。提示“Success”說明連接成功,點擊Save
點擊Dashboard,去主目錄設置, 點擊new,新建一個Home
新建一個Graph
點擊下列紅框處->選擇Edit->選擇數據庫ZabbixClient
然后配置一下,就可以出現華麗麗的數據了,下圖都是官方的示意圖: