一、zabbix安装环境
zabbix的安装配置是个较繁杂的过程,它是基于lamp或lnmp,只不过之前装的lamp架构可能无法满足zabbix的需求,比如某些php的扩展,所以我建议重装php。
1、查看linux的版本信息
[root@localhost ~]# lsb_release -a
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.3 (Final)
Release: 6.3
Codename: Final2、mysql的版本信息
mysql> select version();
+------------------+
| version() |
+------------------+
| 5.6.10-debug-log |
+------------------+
1 row in set (0.00 sec)3、PHP版本信息
[root@localhost ~]# php -v
PHP 5.3.27 (cli) (built: Nov 18 2013 10:08:05)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies4、Apache版本信息
[root@localhost bin]# /usr/local/apache2/bin/httpd -v
Server version: Apache/2.2.23 (Unix)
Server built: Oct 28 2013 02:38:35二、zabbix 服务端的安装
1、下载zabbix的源码包并解压
wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.2.0/zabbix-2.2.0.tar.gz
[root@localhost softs]# tar xf zabbix-2.2.0.tar.gz -C /usr/src/
[root@localhost src]# cd zabbix-2.2.0/
2、建立相应的用户组与用户
[root@localhost zabbix-2.2.0]# groupadd -r zabbix
[root@localhost zabbix-2.2.0]# useradd -g zabbix -s /sbin/nologin zabbix3、登录mysql ,创建zabbix用户并授权
[root@localhost zabbix-2.2.0]# mysql -u root -p******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4773
Server version: 5.6.10-debug-log Source distribution
…………
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> create database zabbix; ###新建zabbix数据库
Query OK, 1 row affected (0.01 sec)
mysql> grant all on zabbix.* to zabbix@localhost identified by 'zabbix'; ###创建zabbix用户
Query OK, 0 rows affected (0.16 sec)
mysql> flush privileges; #刷新授权表及时生效
Query OK, 0 rows affected (0.00 sec)4、导入zabbix自带的几个sql脚本
[root@localhost ~]# cd /usr/src/zabbix-2.2.0/
[root@localhost zabbix-2.2.0]# cd database/
[root@localhost database]# ls
ibm_db2 Makefile.in oracle sqlite3
Makefile.am mysql postgresql
[root@localhost database]# cd mysql/
[root@localhost mysql]# ls
data.sql images.sql schema.sql
[root@localhost mysql]# mysql -u root -p123456 zabbix < schema.sql
[root@localhost mysql]# mysql -u root -p123456 zabbix < images.sql
[root@localhost mysql]# mysql -u root -p123456 zabbix < data.sql 5、安装几个需要的软件包
[root@localhost zabbix-2.2.0]# yum install curl curl-devel net-snmp net-snmp-devel perl-DBI php-gd php-xml php-bcmath -y
6、查看php的所有的modules,看是否包括了安装zabbix所需要的bcmath ,mbstring ,sockets, gd ,gd PNG support ,gd JPEG support ,gd FreeType support ,libxml,xmlwriter, xmlreader ,ctype , session ,gettext这些模块
[root@localhost zabbix-2.2.0]# php -m ###查看已经支持的php模块
[PHP Modules]
bz2
Core
ctype
curl
date
dom
ereg
fileinfo
filter
ftp
gd
hash
iconv
json
ldap
libxml
mbstring
mysql
mysqli
openssl
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
SPL
SQLite
sqlite3
standard
tokenizerxml
xmlreader
xmlwriter
zip
zlib我的php模块还少几个,所以我打补丁补全
安装gettext 模块
[root@localhost ~]# cd /usr/src/php-5.3.27/ext/gettext/
[root@localhost gettext]# phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626[root@localhost gettext]# ./configure --with-php-config=/usr/local/bin/php-config
[root@localhost gettext]# make
[root@localhost gettext]# make install
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20090626/[root@localhost gettext]# ls modules/
gettext.so修改php的配置文件php.ini,添加扩展模块
[root@localhost local]# vi /usr/local/lib/php.ini
extension=gettext.so ###增加 这一行
bcmath模块安装
[root@localhost bcmath]# phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626[root@localhost bcmath]# ./configure --with-php-config=/usr/local/bin/php-config
[root@localhost bcmath]# make
[root@localhost bcmath]# make install
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20090626/
[root@localhost bcmath]# ls modules/
bcmath.so修改php的配置文件php.ini,添加扩展模块
[root@localhost local]# vi /usr/local/lib/php.ini
extension= bcmath.so ###增加 这一行
sockets模块安装
[root@localhost ext]# cd sockets/
[root@localhost sockets]# phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626[root@localhost sockets]# ./configure --with-php-config=/usr/local/bin/php-config
[root@localhost sockets]# make
[root@localhost sockets]# make install
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20090626/
Installing header files: /usr/local/include/php/[root@localhost sockets]# ls modules/
sockets.so修改php的配置文件php.ini,添加扩展模块
[root@localhost local]# vi /usr/local/lib/php.ini
extension=sockets.so ###增加 这一行
扩展安装完成后重启apache
[root@localhost sockets]# /etc/init.d/apache restart
查看php模块发现目前已经出现了三个模块
7、安装、配置zabbix
[root@localhost ~]# cd /usr/src/zabbix-2.2.0/
[root@localhost zabbix-2.2.0]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-proxy --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl
[root@localhost ~]# make
[root@localhost ~]# make install
修改/etc/services,添加下面几行
zabbix-agent 10050/tcp #zabbix agent
zabbix-agent 10050/udp #zabbix agent
zabbix-trapper 10051/tcp #zabbix trapper
zabbix-trapper 10051/udp #zabbix trapper
修改zabbix的配置文件[root@localhost zabbix-2.2.0]# vi /usr/local/zabbix/etc/zabbix_server.conf
[root@localhost zabbix-2.2.0]# cat /usr/local/zabbix/etc/zabbix_server.conf | grep -v ^# | grep -v ^$
LogFile=/tmp/zabbix_server.log
DBName=zabbix
DBUser=zabbix
DBPassword=zabbixDBSocket=/var/run/mysqld/mysql5.socket
做几个软连接
[root@localhost ~]# ln -s /usr/local/zabbix/bin/* /usr/bin/
[root@localhost ~]# ln -s /usr/local/zabbix/sbin/* /usr/sbin/[root@localhost ~]# cd /usr/src/zabbix-2.2.0/
[root@localhost ~]# cp /usr/src/zabbix-2.2.0/misc/init.d/fedora/core/* /etc/init.d/
[root@localhost ~]# vi /etc/init.d/zabbix_server
BASEDIR=/usr/local/zabbix ##########修改这行
[root@localhost ~]# vi /etc/init.d/zabbix_agentd
BASEDIR=/usr/local/zabbix ##########修改这行
[root@localhost frontends]# cp /usr/src/zabbix-2.2.0/frontends /var/www/zabbix/ -r
[root@localhost frontends]# chown daemon.daemon /var/www/ -R
[root@localhost frontends]# chown 777 /var/www/zabbix/conf
8、新建虚拟主机
[root@localhost ~]# cd /usr/local/apache2/conf/extra/
[root@localhost extra]# vi httpd-vhosts.conf
修改apache的主配置文件,开启8008端口
[root@localhost conf]# vi /usr/local/apache2/conf/httpd.conf
#Listen 12.34.56.78:80
Listen 80
Listen 8008然后重启apache的服务
[root@localhost ~]# /etc/init.d/apache restart
[root@localhost conf]# lsof -i:8008
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 1814 root 8w IPv6 107091 0t0 TCP *:8008 (LISTEN)
httpd 2887 daemon 8u IPv6 107091 0t0 TCP *:8008 (LISTEN)
httpd 2888 daemon 8u IPv6 107091 0t0 TCP *:8008 (LISTEN)
httpd 2889 daemon 8u IPv6 107091 0t0 TCP *:8008 (LISTEN)
httpd 2890 daemon 8u IPv6 107091 0t0 TCP *:8008 (LISTEN)
httpd 2891 daemon 8u IPv6 107091 0t0 TCP *:8008 (LISTEN)
httpd 2892 daemon 8u IPv6 107091 0t0 TCP *:8008 (LISTEN)
9、启动zabbix服务
[root@localhost lib]# /etc/init.d/zabbix_agentd start
Starting zabbix_agentd: [ OK ][root@localhost lib]# /etc/init.d/zabbix_server start
Starting zabbix_server: /usr/local/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
[FAILED]解决方法
[root@localhost ~]# locate libmysqlclient.so.18
/usr/local/mysql/lib/libmysqlclient.so.18
/usr/local/mysql/lib/libmysqlclient.so.18.0.0
/usr/src/mysql-5.6.10/libmysql/libmysqlclient.so.18
/usr/src/mysql-5.6.10/libmysql/libmysqlclient.so.18.0.0[root@localhost ~]# echo "/usr/local/mysql/lib" >> /etc/ld.so.conf
[root@localhost ~]# ldconfig
[root@localhost lib]# /etc/init.d/zabbix_server start
Starting zabbix_server: [ OK ][root@localhost lib]# /etc/init.d/snmpd restart
Stopping snmpd: [FAILED]
Starting snmpd: [ OK ][root@localhost ~]# /etc/init.d/mysql5 restart
Shutting down MySQL.. [ OK ]
Starting MySQL... [ OK ][root@localhost ~]# /etc/init.d/apache restart
三、页面配置zabbix
1、打开浏览器访问页面http://127.0.0.1:8008
2、zabbix检查zabbix的php环境
可以看到php的配置有些问题,所以需要改php的配置文件
[root@localhost ~]# vi /usr/local/lib/php.ini
将对应的配置文件改成zabbix所需要的参数值
memory_limit = 128M
max_execution_time = 300
max_input_time = 300
date.timezone =Asia/Shanghai
重启apache服务
[root@localhost lib]# /etc/init.d/apache restart
3、然后再次刷新浏览器页面,重新查看php的环境,然后下一步
4、填写对应的数据库信息,然后next
5、zabbix的ip、端口以及主机名的设置
6、配置信息预览
7、安装
8、登录 默认用户名admin密码zabbix
9、登录的页面信息
10、发现有个错误
然后查证后是iptables的问题,所以建议先关闭iptables
四、linux zaibbix客户端的安装
1、下载客户端软件
[root@localhost soft]# wget http://www.zabbix.com/downloads/2.2.0/zabbix_agents_2.2.0.linux2_6.amd64.tar.gz
下载时候需要注意查看客户机的内核信息,从官网选择相应的软件包
2、客户端的相关设置
[root@localhost soft]# tar xf zabbix_agents_2.2.0.linux2_6.amd64.tar.gz ###解压
[root@localhost soft]# mkdir /etc/zabbix/
[root@localhost soft]# mv bin/zabbix_get /usr/bin/
[root@localhost soft]# mv bin/zabbix_sender /usr/bin/
[root@localhost soft]# mv sbin/zabbix_agent /usr/bin/
[root@localhost soft]# mv sbin/zabbix_agentd /usr/bin/
[root@localhost soft]# cd conf/
[root@localhost conf]# mv zabbix_agentd.conf /etc/zabbix/3、修改zabbix_agentd.conf
Hostname=zabbix-client1 ###这里的hostname要与客户端的hostname一致,而且与监控主机中的名字一致!!
ServerActive=192.168.254.153 ####zabbix server的ip
Server=192.168.254.153####zabbix server的ip
[root@localhost zabbix-2.2.0]# groupadd -r zabbix
[root@localhost zabbix-2.2.0]# useradd -g zabbix -s /sbin/nologin zabbix
4、启动客户端进程
[root@localhost conf]# zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf ####指定配置文件启动
[root@localhost conf]# ps -ef | grep zabbix ####查看是否启动
zabbix 1474 1 0 17:20 ? 00:00:00 zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
zabbix 1475 1474 0 17:20 ? 00:00:00 zabbix_agentd: collector [idle 1 sec]
zabbix 1476 1474 0 17:20 ? 00:00:00 zabbix_agentd: listener #1 [waiting for connection]
zabbix 1477 1474 0 17:20 ? 00:00:00 zabbix_agentd: listener #2 [waiting for connection]
zabbix 1478 1474 0 17:20 ? 00:00:00 zabbix_agentd: listener #3 [waiting for connection]
zabbix 1479 1474 0 17:20 ? 00:00:00 zabbix_agentd: active checks #1 [idle 1 sec]
root 1488 1374 0 17:28 pts/0 00:00:00 grep zabbix
[root@localhost tmp]# lsof -i:10050 #####查看开启侦听的端口
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
zabbix_ag 9106 zabbix 4u IPv4 277432 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag 9107 zabbix 4u IPv4 277432 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag 9108 zabbix 4u IPv4 277432 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag 9109 zabbix 4u IPv4 277432 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag 9110 zabbix 4u IPv4 277432 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag 9111 zabbix 4u IPv4 277432 0t0 TCP *:zabbix-agent (LISTEN)
5、配置 server页面
Configuration -----> Hosts ------->Create host