一、安裝擴展源
[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
根據頁面上的提示更改相關配置
[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】
自定義Name--->Next
Finish,跳轉到登錄頁面,默認的管理員用戶:admin 密碼:zabbix
由於前面添加了zabbix用戶,沒有修改相應的配置文件/etc/zabbix/zabbix_server.conf,導致zabbix-server沒有啓動
查看日誌文件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
七、添加監控客戶端主機
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
添加主機:Host name(自定義)--->Visible name(自定義)--->Groups(添加一個組)--->IP address--->Save
添加模板:Host list--->sh_ming--->Templates--->add--->Template OS Linux(選擇一個模板)--->Select--->Save
自定義模板:Configuration--->Create template--->Template--->Template name(自定義)--->Visible name(自定義)--->Groups(Templates)---Save
拷貝項目:MySQL Items--->Copy Select to--->my_tem
查看:Templates list
八、配置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
創建user:
創建action:
Action:name(自定義)
Operations: