nawawa001 发表于 2019-1-25 13:11:11

zabbix安装一(debian)

我的博客已迁移到xdoujiang.com请去那边和我交流
一、基础环境说明
1、zabbix官网
www.zabbix.com
2、zabbix介绍
Zabbix is the ultimate enterprise-level software designed for monitoring availability
and performance of IT infrastructure components. Zabbix is open source and comes at no cost.
3、版本和ip
1)serverA
cat /etc/debian_version
7.8
ifconfig|awk -v RS="Bcast:" '{print $NF}'|awk -F: '/addr/{print $2}'
192.168.1.124
2)serverB
cat /etc/debian_version
6.0.10
ifconfig|awk -v RS="Bcast:" '{print $NF}'|awk -F: '/addr/{print $2}'
192.168.1.122
4、共安装三部分内容
1)安装zabbix-server(1-9)
2)安装zabbix-web前端(1-3)
3)安装zabbix-agent(1-10)
5、参考
https://www.zabbix.com/documentation/2.2/manual/
zabbix监控系统深度实践(书)
http://www.zabbix.net.cn/(社区)
二、安装zabbix-server(1-9步骤)serverA
1、下载并解压zabbix
1)下载
axel -n 10 http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.2.9/zabbix-2.2.9.tar.gz
2)解压
tar zxvf zabbix-2.2.9.tar.gz
2、编译三部曲(安装在/opt/zabbix)
cd zabbix-2.2.9
1)./configure --enable-server --enable-agent --with-mysql --with-libxml2 --with-net-snmp --with-openipmi --with-libcurl --with-unixodbc --prefix=/opt/zabbix
2)make
3)make install
编译参数说明
--enable-server         Turn on build of Zabbix server(支持server)
--enable-agent          Turn on build of Zabbix agent and client utilities(支持agent)
--with-mysql[=ARG]      use MySQL client library ,optionally specify path to mysql_config(支持mysql功能)
--with-libxml2[=ARG]    use libxml2 client library ,optionally specify path to xml2-config
--with-net-snmp[=ARG]   use Net-SNMP package ,optionally specify path to net-snmp-config(支持snmp监控)
--with-openipmi[=DIR]   Include OPENIPMI support .DIR is the OPENIPMI base install directory,
default is to search through a number of common places for the OPENIPMI files.(支持ipmi)
--with-libcurl[=DIR]    use cURL package , optionally specify path to curl-config
--with-unixodbc[=ARG]   use ODBC driver against unixODBC package ,optionally specify
full path to odbc_config binary.
从2.2.0版本开始支持virtual machine监控 编译的时候加上--with-libxml2 and --with-libcurl
Support of monitoring VMware environments is available in Zabbix starting with version 2.2.0.
For virtual machine monitoring to work, Zabbix should be compiled with the --with-libxml2 and --with-libcurl compilation options.
编译时提示需要安装的包
1)configure: error: no acceptable C compiler found in $PATH
需要安装apt-get -y install gcc
2)configure: error: MySQL library not found
需要安装apt-get -y install libghc6-hsql-mysql-dev
3)configure: error: LIBXML2 library not found
需要安装apt-get -y install libxml2-dev
4)configure: error: unixODBC library not found
需要安装apt-get -y install unixodbc-dev
5)configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config
需要安装apt-get -y install libsnmp-dev
6)configure: error: Invalid OPENIPMI directory - unable to find ipmiif.h
需要安装apt-get -y install libopenipmi-dev
7)configure: error: Curl library not found
需要安装apt-get -y install libghc6-curl-dev
8)make命令
需要安装apt-get -y install make
9)编译完成后将相关命令进行软链接操作
设置命令的快捷方式(软链接)
ln -s /opt/zabbix/bin/* /usr/local/bin/
ln -s /opt/zabbix/sbin/* /usr/local/sbin/
ll /usr/local/bin
lrwxrwxrwx 1 root staff 26 May 29 08:47 zabbix_get -> /opt/zabbix/bin/zabbix_get
lrwxrwxrwx 1 root staff 29 May 29 08:47 zabbix_sender -> /opt/zabbix/bin/zabbix_sender
ll /usr/local/sbin
lrwxrwxrwx 1 root staff 29 May 29 08:47 zabbix_agent -> /opt/zabbix/sbin/zabbix_agent
lrwxrwxrwx 1 root staff 30 May 29 08:47 zabbix_agentd -> /opt/zabbix/sbin/zabbix_agentd
lrwxrwxrwx 1 root staff 30 May 29 08:47 zabbix_server -> /opt/zabbix/sbin/zabbix_server
3、相关数据库配置
1)安装mysql-server
apt-get -y install mysql-server-5.5
2)建zabbix库(root密码是redhat)
mysql -uroot -p"redhat" -S /var/run/mysqld/mysqld.sock -e "create database zabbix character set utf8 collate utf8_bin;"
3)授权(我这边mysql是监听在192.168.1.124)
grant all privileges on zabbix.* to zabbix@"192.168.1.124" identified by '123456';
flush privileges;
4)使用zabbix用户导入sql语句 按照这个顺序来
1)mysql -uzabbix -p"123456" -h"192.168.1.124" zabbix < /root/zabbix-2.2.9/database/mysql/schema.sql
2)mysql -uzabbix -p"123456" -h"192.168.1.124" zabbix < /root/zabbix-2.2.9/database/mysql/images.sql
3)mysql -uzabbix -p"123456" -h"192.168.1.124" zabbix < /root/zabbix-2.2.9/database/mysql/data.sql
4、创建用户
1)建zabbix组
groupadd zabbix
2)添加zabbix用户并加入到zabbix组
useradd -s /bin/false -g zabbix -m zabbix
5、修改配置让zabbix server连接上mysql
1)先备份下需要修改的文件
cp /opt/zabbix/etc/zabbix_server.conf /opt/zabbix/etc/zabbix_server.conf.bak
2)修改配置
cat /opt/zabbix/etc/zabbix_server.conf |egrep -v "^$|^#"
ListenPort=10051
LogFile=/var/log/zabbix_server/zabbix_server.log
PidFile=/var/log/zabbix_server/zabbix_server.pid
DBHost=192.168.1.124
DBName=zabbix
DBUser=zabbix
DBPassword=123456
ListenIP=192.168.1.124
AlertScriptsPath=${datadir}/zabbix/alertscripts
6、修改启动脚本
1)复制模板的脚本
cp /root/zabbix-2.2.9/misc/init.d/debian/zabbix-server /etc/init.d/
2)修改脚本内容
diff /root/zabbix-2.2.9/misc/init.d/debian/zabbix-server /etc/init.d/zabbix-server
10c10
< PID=/tmp/$NAME.pid
---
> PID=/var/log/zabbix_server/$NAME.pid
3)给脚本执行权限
chmod +x /etc/init.d/zabbix-server
7、建目录并做日志切割处理
1)建目录
mkdir /var/log/zabbix_server
2)把目录权限交给zabbix
chown zabbix:zabbix /var/log/zabbix_server -R
3)日志切割
cat /etc/logrotate.d/zabbix_server
/var/log/zabbix_server/zabbix_server.log{
    daily
    rotate 7
    compress
    missingok
    notiempty
    create 0640 zabbix zabbix
    shardscripts
}
8、启动zabbix-server服务
1)/etc/init.d/zabbix-server start
Starting Zabbix server daemon: zabbix_server
2)查看zabbix_server启动日志
cat /var/log/zabbix_server/zabbix_server.log
43736:20150529:095819.674 Starting Zabbix Server. Zabbix 2.2.9 (revision 52686).
43736:20150529:095819.674 ****** Enabled features ******
43736:20150529:095819.674 SNMP monitoring:         YES
43736:20150529:095819.674 IPMI monitoring:         YES
43736:20150529:095819.674 WEB monitoring:            YES
43736:20150529:095819.675 VMware monitoring:         YES
43736:20150529:095819.675 Jabber notifications:       NO
43736:20150529:095819.675 Ez Texting notifications:YES
43736:20150529:095819.675 ODBC:                      YES
43736:20150529:095819.675 SSH2 support:               NO
43736:20150529:095819.675 IPv6 support:               NO
43736:20150529:095819.675 ******************************
43736:20150529:095819.675 using configuration file: /opt/zabbix/etc/zabbix_server.conf
43736:20150529:095819.686 current database version (mandatory/optional): 02020000/02020001
43736:20150529:095819.686 required mandatory version: 02020000
43740:20150529:095819.721 server #2 started
43739:20150529:095819.722 server #1 started
43742:20150529:095819.724 server #4 started
43741:20150529:095819.735 server #3 started
43743:20150529:095819.739 server #5 started
43745:20150529:095819.743 server #7 started
43744:20150529:095819.748 server #6 started
43749:20150529:095819.756 server #8 started
43752:20150529:095819.763 server #10 started
43751:20150529:095819.764 server #9 started
43755:20150529:095819.774 server #11 started
43756:20150529:095819.775 server #12 started
43757:20150529:095819.776 server #13 started
43761:20150529:095819.781 server #14 started
43762:20150529:095819.782 server #15 started
43764:20150529:095819.786 server #16 started
43764:20150529:095819.786 executing housekeeper
43766:20150529:095819.799 server #17 started
43767:20150529:095819.801 server #18 started
43771:20150529:095819.815 server #20 started
43774:20150529:095819.823 server #22 started
43773:20150529:095819.825 server #21 started
43770:20150529:095819.827 server #19 started
43778:20150529:095819.837 server #23 started
43764:20150529:095819.842 housekeeper
43780:20150529:095819.845 server #24 started
43781:20150529:095819.846 server #25 started
43736:20150529:095819.849 server #0 started
43783:20150529:095819.851 server #26 started
3)查看zabbix-server进程
root@192.168.1.124:~# ps aux |grep zabbix
zabbix    437360.00.3 1610163552 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server
zabbix    437390.00.2 1610242628 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: configuration syncer
zabbix    437400.00.1 1610161992 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: db watchdog
zabbix    437410.00.3 1628403276 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: poller #1
zabbix    437420.00.3 1628403276 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: poller #2
zabbix    437430.00.3 1628403276 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: poller #3
zabbix    437440.00.3 1628403276 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: poller #4
zabbix    437450.00.3 1628403276 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: poller #5
zabbix    437490.00.3 1628403276 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: unreachable poller #1
zabbix    437510.00.1 1610161992 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: trapper #1
zabbix    437520.00.1 1610161992 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: trapper #2
zabbix    437550.00.1 1610161992 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: trapper #3
zabbix    437560.00.1 1610161992 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: trapper #4
zabbix    437570.00.1 1610161992 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: trapper #5
zabbix    437610.00.1 1613402008 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: icmp pinger #1
zabbix    437620.00.1 1610161992 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: alerter
zabbix    437640.00.2 1612642256 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: housekeeper
zabbix    437660.00.2 1610162248 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: timer #1
zabbix    437670.00.2 1610162244 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: http poller #1
zabbix    437700.00.3 1625163276 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: discoverer #1
zabbix    437710.00.1 1610161992 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: history syncer #1
zabbix    437730.00.1 1610161992 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: history syncer #2
zabbix    437740.00.1 1610161992 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: history syncer #3
zabbix    437780.00.1 1610161992 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: history syncer #4
zabbix    437800.00.1 1610161992 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: escalator
zabbix    437810.00.1 1610161996 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: proxy poller #1
zabbix    437830.00.1 1610161772 ?      S    09:58   0:00 /usr/local/sbin/zabbix_server: self-monitoring
root      437910.00.0   7836   888 pts/1    S+   10:01   0:00 grep --color=auto zabbix
4)查看zabbix监听端口
netstat -tupnl |grep zabbix
tcp      0      0 192.168.1.124:10051   0.0.0.0:*               LISTEN      43736/zabbix_server
9、将zabbix-server加入到开机启动
1)使用update-rc.d命令
update-rc.d zabbix-server defaults
2)查看下是否在开机启动里了
runlevel
N 2
ll /etc/rc2.d/
lrwxrwxrwx 1 root root23 May 29 10:17 S02zabbix-server -> ../init.d/zabbix-server
三、安装zabbix-web前端
1、安装apache2和php
1)apt-get -y install apache2-mpm-worker
2)apt-get -y install php5
2、将源码包里的网站内容复制到网站目录下
1)mkdir /var/www/zabbix
2)cp -a zabbix-2.2.9/frontends/php/ /var/www/zabbix/
3)chown www-data /var/www/zabbix/ -R
3、使用域名访问的话需要修改windows的hosts文件(默认情况在C:\Windows\System32\drivers\etc)
http://www.testzabbix.com/zabbix/就出现以下网站了http://s3.运维网.com/wyfs02/M01/6E/16/wKiom1VzAQKijcRoAAGA7BbP9XI405.jpg

1)点php目录就可以到下一步http://s3.运维网.com/wyfs02/M00/6E/16/wKiom1VzAWbgWVJrAANedPhsE4o454.jpg
2)点next后出现红字部分http://s3.运维网.com/wyfs02/M01/6E/12/wKioL1VzAzzx0E1TAAQQ4SjgDgY891.jpg
根据红字提示接下来解决
3)先备份下原配置文件
cp /etc/php5/apache2/php.ini /etc/php5/apache2/php.ini.bak
4)修改/etc/php5/apache2/php.ini内容如下
max_execution_time = 300
max_input_time = 300
post_max_size = 16M
date.timezone = Asia/Shanghai
5)安装php5-mysql和php5-gd包
apt-get -y install php5-mysqlapt-get -y install php5-gd
6)上述全部完成后就可以看到下面图片了http://s3.运维网.com/wyfs02/M00/6E/16/wKiom1VzAtqStxFrAAMtxI0jID8988.jpg
7)填写对应的DB信息http://s3.运维网.com/wyfs02/M01/6E/17/wKiom1VzA7Xgl0NKAANGUCTcs4I558.jpg

8)接下来nexthttp://s3.运维网.com/wyfs02/M01/6E/17/wKiom1VzA-bBLRcFAAJD78YQDqo396.jpg
9)接下来nexthttp://s3.运维网.com/wyfs02/M02/6E/12/wKioL1VzBaqivbBsAAKyz_oQbq0177.jpg
10)接下来nexthttp://s3.运维网.com/wyfs02/M02/6E/17/wKiom1VzBDLCHijxAAIm1dZJJVQ359.jpg
11)默认账户(Admin)和密码zabbixhttp://s3.运维网.com/wyfs02/M00/6E/12/wKioL1VzBe2jiO3pAAJLe6eP3nY027.jpg

12)登录成功的图http://s3.运维网.com/wyfs02/M01/6E/12/wKioL1VzBm6RuvRKAAVnAcO0qLE993.jpg
13)更改默认登录zabbix密码(md5加密的)http://s3.运维网.com/wyfs02/M01/6E/17/wKiom1VzBOyQizXbAALfE1q-zFU628.jpg
先使用openssl md5加密字符串echo -n "123123"|openssl md5
update zabbix.users set passwd='4297f44b13955235245b2497399d7a93' where userid = 1;
也可以update zabbix.users set passwd=MD5('123123') where userid=1;
四、安装zabbix-agent(1-9步骤)(serverB)
1、解压
tar zxvf zabbix-2.2.9.tar.gz
2、编译安装
cd zabbix-2.2.9
1)./configure --enable-agent --prefix=/opt/zabbix
2)make
3)make install
3、软链接
ln -s /opt/zabbix/bin/* /usr/local/bin/
ln -s /opt/zabbix/sbin/* /usr/local/sbin/
4、创建zabbix用户
1)groupadd zabbix
2)useradd -s /bin/false -g zabbix zabbix
5、配置
cp /opt/zabbix/etc/zabbix_agentd.conf /opt/zabbix/etc/zabbix_agentd.conf.bak
sed -i 's!# PidFile=/tmp/zabbix_agentd.pid!PidFile=/var/log/zabbix_agent/zabbix_agentd.pid!g' /opt/zabbix/etc/zabbix_agentd.conf
sed -i 's!LogFile=/tmp/zabbix_agentd.log!LogFile=/var/log/zabbix_agent/zabbix_agentd.log!g' /opt/zabbix/etc/zabbix_agentd.conf
sed -i "s/Server=127.0.0.1/Server=192.168.1.124/g" /opt/zabbix/etc/zabbix_agentd.conf
sed -i "s/# ListenPort=10050/ListenPort=10050/g" /opt/zabbix/etc/zabbix_agentd.conf
sed -i "s/# ListenIP=0.0.0.0/ListenIP=192.168.1.122/g" /opt/zabbix/etc/zabbix_agentd.conf
sed -i "s/ServerActive=127.0.0.1/ServerActive=192.168.1.124/g" /opt/zabbix/etc/zabbix_agentd.conf
sed -i 's!# Include=/usr/local/etc/zabbix_agentd.conf.d/!Include=/opt/zabbix/etc/zabbix_agentd.conf.d/!g' /opt/zabbix/etc/zabbix_agentd.conf
cp /root/zabbix-2.2.9/misc/init.d/debian/zabbix-agent /etc/init.d/
sed -i 's!PID=/tmp/$NAME.pid!PID=/var/log/zabbix_agent/$NAME.pid!g' /etc/init.d/zabbix-agent
6、创建目录及配置日志轮转
mkdir /var/log/zabbix_agent
chown zabbix:zabbix /var/log/zabbix_agent
cat/etc/logrotate.d/zabbix_agent
/var/log/zabbix_agent/zabbix_agentd.log{
    daily
    rotate 7
    compress
    missingok
    notiempty
    create 0640 zabbix zabbix
    shardscripts
}
7、启动zabbix-agent服务
/etc/init.d/zabbix-agent start
Starting Zabbix agent daemon: zabbix_agentd
8、查看启动日志及端口监听和进程
1)cat /var/log/zabbix_agent/zabbix_agentd.log
8844:20150607:133047.412 no active checks on server : host not found
8839:20150607:133243.287 Got signal . Exiting ...
8839:20150607:133243.293 Zabbix Agent stopped. Zabbix 2.2.9 (revision 52686).
8868:20150607:133243.314 Starting Zabbix Agent . Zabbix 2.2.9 (revision 52686).
8868:20150607:133243.315 using configuration file: /opt/zabbix/etc/zabbix_agentd.conf
8872:20150607:133243.316 agent #3 started
8871:20150607:133243.317 agent #2 started
8873:20150607:133243.317 agent #4 started
8870:20150607:133243.318 agent #1 started
8869:20150607:133243.318 agent #0 started
8873:20150607:133243.325 no active checks on server : host not monitored
2)查看监听情况
netstat -tupnl|grep zabbix
tcp      0      0 192.168.1.122:10050   0.0.0.0:*               LISTEN      8868/zabbix_agentd
3)查看进程
ps -ef |grep zabbix
zabbix    8868   10 13:32 ?      00:00:00 /usr/local/sbin/zabbix_agentd
zabbix    886988680 13:32 ?      00:00:01 /usr/local/sbin/zabbix_agentd: collector
zabbix    887088680 13:32 ?      00:00:00 /usr/local/sbin/zabbix_agentd: listener #1
zabbix    887188680 13:32 ?      00:00:00 /usr/local/sbin/zabbix_agentd: listener #2
zabbix    887288680 13:32 ?      00:00:00 /usr/local/sbin/zabbix_agentd: listener #3
zabbix    887388680 13:32 ?      00:00:00 /usr/local/sbin/zabbix_agentd: active checks #1
root      888113040 13:35 pts/0    00:00:00 grep --color=auto zabbix
9、将zabbix-agent加入到开机启动
update-rc.d zabbix-agent defaults
10、测试
1)zabbix_get是一个用来与zabbix agent通信并从zabbix agent获取所需信息的程序。
zabbix_get -s 192.168.1.122 -p 10050 -k "system.cpu.load"
0.070000
-s --host         Specify host name or IP address of a host
-p --port               Specify port number of agent running on the host. Default is 10050
-k --key            Specify key of item to retrieve value for
2)使用telnet命令
telnet 192.168.1.122 10050
Trying 192.168.1.122...
Connected to 192.168.1.122.
Escape character is '^]'.
Connection closed by foreign host.  




页: [1]
查看完整版本: zabbix安装一(debian)