【Zabbix】Linux監控軟件安裝與配置(三)

一、安裝擴展源

[root@www ~]# rpm -ivh http://mirrors.ustc.edu.cn/fedora/epel/6/i386/epel-release-6-8.noarch.rpm

二、安裝LAMP環境

[root@www ~]# yum -y install httpd mysql mysql-libs php php-mysql mysql-server php-bcmath php-gd php-mbstring

三、安裝zabbix服務(zabbix2.0版本)

[root@www ~]# yum -y install zabbix20 zabbix20-agent zabbix20-server  zabbix20-server-mysql zabbix20-web zabbix20-web-mysql net-snmp-devel

四、啓動服務

[root@www ~]# service mysqld start
[root@www ~]# service httpd start
[root@www ~]# service zabbix-server start
Starting Zabbix server:                                    [  OK  ]
[root@www ~]# service zabbix-agent start
Starting Zabbix agent:                                     [  OK  ]

[root@www ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1281/sshd           
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1015/master         
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      4796/zabbix_agentd  
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      4594/mysqld         
tcp        0      0 :::80                       :::*                        LISTEN      2712/httpd          
tcp        0      0 :::22                       :::*                        LISTEN      1281/sshd           
tcp        0      0 ::1:25                      :::*                        LISTEN      1015/master         
tcp        0      0 :::10050                    :::*                        LISTEN      4796/zabbix_agentd

五、配置mysql

1、增加或修改以下配置

[root@www ~]# vim /etc/my.cnf
[mysqld]
character_set_server = utf8

[mysql]
default-character-set = utf8
[root@www ~]# service mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

2、創建zabbix數據庫

[root@www ~]# mysql -uroot -p -e "create database zabbix"

3、創建授權zabbix數據庫用戶

[root@www ~]# mysql -uroot -p -e "grant all on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix';"

4、導入zabbix數據庫

[root@www ~]# ls /usr/share/zabbix-mysql/
data.sql  images.sql  schema.sql  upgrades
[root@www ~]# mysql -uroot -p --default-character-set=utf8 zabbix < /usr/share/zabbix-mysql/schema.sql 
[root@www ~]# mysql -uroot -p --default-character-set=utf8 zabbix < /usr/share/zabbix-mysql/images.sql 
[root@www ~]# mysql -uroot -p --default-character-set=utf8 zabbix < /usr/share/zabbix-mysql/data.sql

六、安裝zabbix網頁端

http://192.168.1.21/zabbix

wKioL1aQ0uXBHJ6mAAFV8xGBepA456.jpg

根據頁面上的提示更改相關配置

wKioL1aQ0zXRdjT6AAGmJoikgXw293.jpg

[root@www ~]# vim /etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
[root@www ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

刷新頁面,【Next】

wKiom1aQ1Hax1tp1AAFC5n83LCg058.jpg

wKioL1aQ1ZOA1R4hAAE7SbWG4rc628.jpg   Test connection --->Next

wKioL1aQ1p7RMatYAAEF2MEBCos813.jpg

自定義Name--->Next

wKiom1aQ1sLDD5PZAAE4bOBDa9Q891.jpgwKioL1aQ1xHxH5anAAD3x1-T7dU603.jpgFinish,跳轉到登錄頁面,默認的管理員用戶:admin 密碼:zabbix

wKioL1aQ1_7Bt23mAAE1jO2WXZM723.jpg

由於前面添加了zabbix用戶,沒有修改相應的配置文件/etc/zabbix/zabbix_server.conf,導致zabbix-server沒有啓動

wKiom1aQ2cnB1IUNAAFSfwVSD7A055.jpg


查看日誌文件zabbix_server日誌(提示沒有設置zabbix數據庫密碼)

[root@www ~]# tail /var/log/zabbix/zabbix_server.log 
  6153:20160109:180057.467 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO)
  6153:20160109:180057.467 Database is down. Reconnecting in 10 seconds.
  6153:20160109:180107.470 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO)
  6153:20160109:180107.470 Database is down. Reconnecting in 10 seconds.
  6153:20160109:180117.473 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO)
  6153:20160109:180117.473 Database is down. Reconnecting in 10 seconds.
  6153:20160109:180127.474 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO)
  6153:20160109:180127.474 Database is down. Reconnecting in 10 seconds.
  6153:20160109:180137.476 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO)
  6153:20160109:180137.476 Database is down. Reconnecting in 10 seconds.

修改/etc/zabbix/zabbix_server.conf配置文件

[root@www ~]# vim /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix   #默認是註釋的
DBSocket=/var/lib/mysql/mysql.sock


重啓啓動zabbix-server服務

[root@www ~]# service zabbix-server restart
Shutting down Zabbix server:                               [  OK  ]
Starting Zabbix server:                                    [  OK  ]
[root@www ~]# netstat -ntlp |grep zabbix
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      6106/zabbix_agentd  
tcp        0      0 0.0.0.0:10051               0.0.0.0:*                   LISTEN      6888/zabbix_server  
tcp        0      0 :::10050                    :::*                        LISTEN      6106/zabbix_agentd  
tcp        0      0 :::10051                    :::*                        LISTEN      6888/zabbix_server

wKioL1aQ3CzToRSDAAFAOH6JU7Q759.jpg


七、添加監控客戶端主機

1、安裝zabbix20-agent

[root@sh ~]# yum -y install zabbix20-agent

2、配置zabbix_agentd.conf 文件

[root@sh ~]# vim /etc/zabbix_agentd.conf 
Server=192.168.1.21
ServerActive=0.0.0.0:10050
Hostname=sh_zabbix  #自定義名稱

3、啓動zabbix-agent

[root@sh ~]# /etc/init.d/zabbix-agent start
Starting Zabbix agent:                                     [  OK  ]

4、服務端測試

[root@www ~]# zabbix_get -s 192.168.1.251 -p10050 -k "system.hostname"
sh.huangmingming.com


5、web界面下配置

Configuration--->Hosts--->Create hosts

wKiom1aQ5tWCFF2uAAD6PR9C2kI333.jpg

添加主機:Host name(自定義)--->Visible name(自定義)--->Groups(添加一個組)--->IP address--->Save

wKioL1aQ6g-xdD0aAAEoZ8PxQbg125.jpg

添加模板:Host list--->sh_ming--->Templates--->add--->Template OS Linux(選擇一個模板)--->Select--->Save

wKioL1aQ6oLiW_IqAAEjjvfUjIs253.jpg

wKioL1aQ7PeS11bqAAEambT7Bk4055.jpg

自定義模板:Configuration--->Create template--->Template--->Template name(自定義)--->Visible name(自定義)--->Groups(Templates)---Save

wKioL1aQ7_WCEgpLAADDnMefalQ670.jpg

拷貝項目:MySQL Items--->Copy Select to--->my_tem

wKioL1aQ8c-jcs9VAAIBcxBfOxc287.jpg

wKiom1aQ8iOzsFMAAACpQxEWeYo931.jpg

查看:Templates list

wKioL1aQ8pySV9xaAAEJIK_do_o452.jpg


八、配置zabbix郵件告警

1、安裝sendmail,使用sendmail發送郵件

[root@www ~]# yum install sendmail
[root@www ~]# /etc/init.d/postfix restart
Shutting down postfix:                                     [  OK  ]
Starting postfix:                                          [  OK  ]
[root@www ~]# mail -s "test11" [email protected] </etc/inittab 
[root@www ~]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
1E86460728*    1347 Sat Jan  9 19:57:03  [email protected]
                                         [email protected]
-- 1 Kbytes in 1 Request.

2、編寫腳本

[root@www ~]# mkdir /home/zabbix_mail/bin/ -p
[root@www ~]# vim /home/zabbix_mail/bin/baojing.sh
#!/bin/bash
echo "$3" |/bin/mail -s "$2" $1

[root@www ~]# chmod a+x /home/zabbix_mail/bin/baojing.sh

3、修改zabbix_server.conf文件

[root@www ~]# vim /etc/zabbix_server.conf
AlertScriptsPath=/home/zabbix_mail/bin
ExternalScripts=/home/zabbix_mail/bin

4、zabbix服務端web頁面配置

Administration--->Media types--->Create Media type--->Type(script)--->Save

wKioL1aQ-0rzT8mIAADEU6vDS1g101.jpg

創建user:

wKiom1aQ_JDgUX3dAAEJ48mhnT0143.jpg

wKioL1aQ_yGQoKi_AADjhYveq34723.jpgwKiom1aQ_wzxu41iAAD5sOwEcEM239.jpg

創建action:

wKioL1aQ_8vSTHiuAADsYiOdKms569.jpg

Action:name(自定義)

wKioL1aRAM-jfeBkAAD4YeSN3Qw595.jpg

Operations:

wKiom1aRAMLwal6DAAEA740dDQg942.jpg

wKioL1aRAtygjRiRAAEHPMEBE9U066.jpg


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