天天看點

zabbix-3.0.4安裝部署

zabbix是一個基于WEB界面的提供分布式系統監視以及網絡監視功能的企業級的開源解決方案,由一個國外的團隊持續維護更新,軟體可以自由下載下傳使用,運作團隊靠提供收費的技術支援赢利,官方網站:http://www.zabbix.com官方文檔:http://www.zabbix.com/documentation/2.0/manual/quickstart。Zabbix通過C/S模式采集資料,通過B/S模式在web端展示和配置。zabbix server可以通過SNMP,zabbix agent,ping,端口監視等方法提供對遠端伺服器/網絡狀态的監視,資料收集等功能。zabbix agent需要安裝在被監視的目标伺服器上,它主要完成對硬體資訊或與作業系統有關的記憶體,CPU等資訊的收集。zabbix server可以單獨監視遠端伺服器的服務狀态;同時也可以與zabbix agent配合,可以輪詢zabbix agent主動接收監視資料(trapping方式),同時還可被動接收zabbix agent發送的資料(trapping方式)。另外zabbix server還支援SNMP (v1,v2),可以與SNMP軟體(例如:net-snmp)等配合使用。

<a href="http://s4.51cto.com/wyfs02/M01/86/FE/wKiom1fQk1XDQ_Z5AADeQ6M4T0o052.png" target="_blank"></a>

zabbix的主要特點:   

- 安裝與配置簡單,學習成本低

- 支援多語言(包括中文)   

- 免費開源   

- 自動發現伺服器與網絡裝置   

- 分布式監視以及WEB集中管理功能   

- 可以無agent監視   

- 使用者安全認證和柔軟的授權方式   

- 通過WEB界面設定或檢視監視結果   

- email等通知功能等等  

Zabbix主要功能:    

- CPU負荷   

- 記憶體使用   

- 磁盤使用   

- 網絡狀況   

- 端口監視   

- 日志監視

一.安裝LNMP環境

參考:http://pvbutler.blog.51cto.com/7662323/1845685

二.Zabbix服務端安裝

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

<code>[root@Zabbix_Server Tools]</code><code># tar zxvf zabbix-3.0.4.tar.gz </code>

<code>[root@Zabbix_Server Tools]</code><code># cd zabbix-3.0.4/database/mysql/</code>

<code>[root@Zabbix_Server mysql]</code><code># ls</code>

<code>data.sql  images.sql  schema.sql</code>

<code>[root@Zabbix_Server mysql]</code><code># mysql -u root -pZabbix</code>

<code>mysql&gt; create database zabbix character </code><code>set</code> <code>utf8;    </code><code>#建立資料庫zabbix,并且資料庫編碼使用utf8</code>

<code>Query OK, 1 row affected (0.00 sec)</code>

<code>mysql&gt; insert into mysql.user(Host,User,Password) values(</code><code>'localhost'</code><code>,</code><code>'zabbix'</code><code>,password(</code><code>'zabbix'</code><code>));</code>

<code>ERROR 1364 (HY000): Field </code><code>'ssl_cipher'</code> <code>doesn't have a default value</code>

<code>mysql&gt; quit;</code>

<code>[root@Zabbix_Server mysql]</code><code># vim /app/mysql/my.cnf </code>

<code>#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 指定了嚴格模式,為了安全,嚴格模式禁止通過insert 這種形式直接修改mysql庫中的user表進行添加新使用者</code>

<code>sql_mode=NO_ENGINE_SUBSTITUTION    </code><code>#将配置檔案中的STRICT_TRANS_TABLES删掉   </code>

<code>[root@Zabbix_Server mysql]</code><code># service mysqld restart</code>

<code>mysql&gt; insert into mysql.user(Host,User,Password) values(</code><code>'localhost'</code><code>,</code><code>'zabbix'</code><code>,password(</code><code>'zabbix'</code><code>));     </code><code>#建立賬戶zabbix,密碼zabbix</code>

<code>Query OK, 1 row affected, 3 warnings (0.00 sec)</code>

<code>mysql&gt; flush privileges;     </code><code>#重新整理系統授權表</code>

<code>Query OK, 0 rows affected (0.00 sec)</code>

<code>mysql&gt; grant all on zabbix.* to </code><code>'zabbix'</code><code>@</code><code>'localhost'</code> <code>identified by </code><code>'zabbix'</code> <code>with grant option;    </code><code>#允許賬戶zabbix能從本機連接配接到資料庫zabbix</code>

<code>mysql&gt; flush privileges;</code>

<code>mysql&gt; use zabbix;     </code><code>#進入資料庫,按照順序進行導入,否則會出錯。</code>

<code>Database changed</code>

<code>mysql&gt; </code><code>source</code> <code>/usr/local/Tools/zabbix-3</code><code>.0.4</code><code>/database/mysql/schema</code><code>.sql</code>

<code>...</code>

<code>Query OK, 0 rows affected (0.05 sec)</code>

<code>Records: 0  Duplicates: 0  Warnings: 0</code>

<code>mysql&gt; </code><code>source</code> <code>/usr/local/Tools/zabbix-3</code><code>.0.4</code><code>/database/mysql/images</code><code>.sql</code>

<code>Query OK, 1 row affected (0.01 sec)</code>

<code>mysql&gt; </code><code>source</code> <code>/usr/local/Tools/zabbix-3</code><code>.0.4</code><code>/database/mysql/data</code><code>.sql</code>

<code>Query OK, 0 rows affected (0.01 sec)</code>

<code>mysql&gt; </code><code>exit</code><code>;</code>

<code>Bye</code>

<code>[root@Zabbix_Server mysql]</code><code># ln -s /usr/lib64/mysql/libmysqlclient.so.16.0.0 /usr/lib64/mysql/libmysqlclient.so    #32位系統為/usr/lib/mysql,注意系統版本同,檔案版本可能不一樣,這裡是16.0.0</code>

<code>[root@Zabbix_Server mysql]</code><code># ln -s /usr/lib64/mysql/libmysqlclient_r.so.16.0.0 /usr/lib64/mysql/libmysqlclient_r.so</code>

<code>[root@Zabbix_Server mysql]</code><code># cd /usr/local/Tools/zabbix-3.0.4</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># groupadd zabbix</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># useradd -g zabbix zabbix -s /sbin/nologin </code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># yum -y install mysql-devel mysql-community-devel unixODBC-devel libssh2-devel OpenIPMI-devel net-snmp-devel curl-devel net-snmp-libs net-snmp-utils</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># chkconfig snmpd on</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># ./configure --prefix=/app/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-unixodbc --with-ssh2 --with-openipmi --with-openssl</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># make &amp;&amp; make install</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># cp /usr/local/Tools/zabbix-3.0.4/misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># cp /usr/local/Tools/zabbix-3.0.4/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># chmod +x /etc/rc.d/init.d/zabbix_*</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># chkconfig zabbix_server on</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># chkconfig zabbix_agentd on</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># vim /etc/rc.d/init.d/zabbix_server </code>

<code>        </code><code>BASEDIR=</code><code>/app/zabbix</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># vim /etc/rc.d/init.d/zabbix_agentd</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># cp /app/zabbix/etc/zabbix_server.conf{,bak}</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># ln -s /app/zabbix/sbin/* /usr/local/sbin/</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># ln -s /app/zabbix/bin/* /usr/local/bin/</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># vim /app/zabbix/etc/zabbix_server.conf</code>

<code>LogFile=</code><code>/app/zabbix/logs/zabbix_server</code><code>.log</code>

<code>PidFile=</code><code>/app/zabbix/pid/zabbix_server</code><code>.pid</code>

<code>DBName=zabbix</code>

<code>DBUser=zabbix</code>

<code>DBPassword=zabbix</code>

<code>ListenIP=localhost</code>

<code>CacheSize=1024M    </code><code>#根據伺服器性能修改,太小後面會報out of memory</code>

<code>AlertScriptsPath=</code><code>/app/zabbix/alertscripts</code>    <code>#zabbix運作腳本存放目錄</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># cp /app/zabbix/etc/zabbix_agentd.conf{,bak}</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># vim /app/zabbix/etc/zabbix_agentd.conf</code>

<code>LogFile=</code><code>/app/zabbix/logs/zabbix_agentd</code><code>.log</code>

<code>Include=</code><code>/app/zabbix/etc/zabbix_agentd</code><code>.conf.d/</code>

<code>UnsafeUserParameters=1    </code><code>#啟用自定義key</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># mkdir -p /app/zabbix/logs</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># touch /app/zabbix/logs/zabbix_agentd.log</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># touch /app/zabbix/logs/zabbix_server.log</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># mkdir /app/zabbix/pid</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># touch /app/zabbix/pid/zabbix_server.pid</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># chmod 766 /app/zabbix/pid/*</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># chmod 766 /app/zabbix/logs/*</code>

--with-libxml2 用來解析調用SOAP接口傳回的XML,

--with-libcurl用來調用vcenter的SOAP接口。

如果沒有mysql_config,需要安裝yum install mysql-devel

配置web站點

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># rm -rf /app/nginx/html/*</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># cp -r /usr/local/Tools/zabbix-3.0.4/frontends/php/* /app/nginx/html/</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># chown www.www -R /app/nginx/html/</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># service zabbix_agentd start</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># tail /app/zabbix/logs/zabbix_server.log </code>

<code> </code><code>21858:20160906:072015.723 Ez Texting notifications:  YES</code>

<code> </code><code>21858:20160906:072015.724 ODBC:                      YES</code>

<code> </code><code>21858:20160906:072015.724 SSH2 support:              YES</code>

<code> </code><code>21858:20160906:072015.724 IPv6 support:              YES</code>

<code> </code><code>21858:20160906:072015.724 TLS support:               YES</code>

<code> </code><code>21858:20160906:072015.724 ******************************</code>

<code> </code><code>21858:20160906:072015.724 using configuration </code><code>file</code><code>: </code><code>/app/zabbix/etc/zabbix_server</code><code>.conf</code>

<code> </code><code>21858:20160906:072015.730 current database version (mandatory</code><code>/optional</code><code>): 03000000</code><code>/03000000</code>

<code> </code><code>21858:20160906:072015.730 required mandatory version: 03000000</code>

<code> </code><code>21858:20160906:072015.735 listener failed: cannot resolve address [[localhost]:10051]: [-2] Name or service not known</code>

<code>#ListenIP=localhost</code>

<code>ListenIP=127.0.0.1</code>

<code>[root@Zabbix_Server logs]</code><code># service zabbix_server start</code>

<code>[root@Zabbix_Server logs]</code><code># netstat -ntlp |grep zabbix</code>

<code>tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      22490</code><code>/zabbix_agentd</code> 

<code>tcp        0      0 127.0.0.1:10051             0.0.0.0:*                   LISTEN      22419</code><code>/zabbix_server</code> 

<code>tcp        0      0 :::10050                    :::*                        LISTEN      22490</code><code>/zabbix_agentd</code> 

<code>[root@Zabbix_Server logs]</code><code>#</code>

修改php配置檔案參數

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># cp /app/php/etc/php.ini{,bak}</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># vim /app/php/etc/php.ini</code>

<code>post_max_size = 16M</code>

<code>max_execution_time = 300</code>

<code>max_input_time = 300</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># cp /app/php/etc/php-fpm.conf{,bak}</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># vim /app/php/etc/php-fpm.conf</code>

<code>request_terminate_timeout = 300</code>

<code>[root@Zabbix_Server zabbix-3.0.4]</code><code># service php-fpm restart</code>

安裝web

在浏覽器裡直接輸入IP位址http://192.168.100.176安裝

<a href="http://s3.51cto.com/wyfs02/M00/86/E0/wKioL1fOF3Dg4QA_AACU3ItbNp0923.png" target="_blank"></a>

下一步,提示:PHP option "always_populate_raw_post_data" must be set to "-1"

修改php.ini中always_populate_raw_post_data = -1

<code>[root@Zabbix_Server conf]</code><code># vim /app/php/etc/php.ini</code>

<code>always_populate_raw_post_data = -1</code>

<code>[root@Zabbix_Server conf]</code><code># service php-fpm restart</code>

重新整理頁面,下一步

<a href="http://s2.51cto.com/wyfs02/M00/86/E0/wKioL1fOGYKTI_ZjAAB3ez_EBDc459.png" target="_blank"></a>

配置MySQL資料庫資訊

Database:MySQL

Database host:localhost

Database port:0 use default port 3306

Database name:zabbix

User:zabbix

Password:zabbix

<a href="http://s5.51cto.com/wyfs02/M01/86/E0/wKioL1fOGiXR-f4IAABdeGu4J9A897.png" target="_blank"></a>

直接下一步

<a href="http://s5.51cto.com/wyfs02/M02/86/E0/wKioL1fOGmWR3e-eAACMP_ZVJyg386.png" target="_blank"></a>

檢查一下設定情況,沒問題直接Next

<a href="http://s1.51cto.com/wyfs02/M00/86/E0/wKioL1fOGsXg3xo1AABmoKPkN4Y784.png" target="_blank"></a>

<a href="http://s1.51cto.com/wyfs02/M01/86/E1/wKiom1fOGsXg95m_AAAxypicUAc979.png" target="_blank"></a>

預設Username: Admin、Password: zabbix

<a href="http://s4.51cto.com/wyfs02/M01/86/E0/wKioL1fOG4DTb7swAADaVx4nlSc315.png" target="_blank"></a>

Zabbix主要的配置檔案兩個:“zabbix_server.conf”負責伺服器端的設定;“zabbix_agent.conf”用來設定用戶端代理參數;“zabbix_proxy.conf”用來設定分布式的部署。Zabbix_server.conf參數除了保證服務正常運作外還涉及該伺服器的性能,如果參數設定不合理可能會導緻zabbix添加主機不正常、代理端資料無法正常收集或是zabbix伺服器性能嚴重下降,經常報告CPU占用過高或是IO占用過高等問題。

zabbix_server.conf

DBName=zabbix                            zabbix所屬資料庫名稱

DBUser=zabbix                            zabbix所屬資料庫使用者

DBPassword=www.xxxxxx.com                zabbix資料庫密碼

StartPollers=30                         輪詢的初始值(0-1000)

StartIPMIPollers=4                       IPMI輪詢的初始值(0-1000)

StartPollersUnreachable=30               輪詢不可達的主機數(包括IPMI 0-1000)

StartTrappers=8                         捕獲的初始值(0-1000)

StartPingers=4                          ping的初始值(0-1000)

StartDiscoverers=0                      自動發現的初始值(0-250)

CacheSize=384M                          緩存大小

CacheUpdateFrequency=300                緩存更新的頻率

StartDBSyncers=8                        資料庫同步時間

TrendCacheSize=128M                     總趨勢緩存大小

AlertScriptsPath=/usr/bin               腳本的存放位置

LogSlowQueries=1000                     日志慢查詢設定

檢視Zabbix版本号:

<code>[root@Zabbix_Server ~]</code><code># /app/zabbix/bin/zabbix_get -V</code>

<code>zabbix_get (Zabbix) 3.0.4</code>

<code>Revision 61185 15 July 2016, compilation </code><code>time</code><code>: Sep  5 2016 14:28:41</code>

<code>Copyright (C) 2016 Zabbix SIA</code>

<code>License GPLv2+: GNU GPL version 2 or later &lt;http:</code><code>//gnu</code><code>.org</code><code>/licenses/gpl</code><code>.html&gt;.</code>

<code>This is </code><code>free</code> <code>software: you are </code><code>free</code> <code>to change and redistribute it according to</code>

<code>the license. There is NO WARRANTY, to the extent permitted by law.</code>

<code>[root@Zabbix_Server ~]</code><code>#</code>

本文轉自 justin_peng 51CTO部落格,原文連結:http://blog.51cto.com/ityunwei2017/1846630,如需轉載請自行聯系原作者