一、环境描述
-
虚拟机配置
CPU:单核
内存:2 GB
硬盘:120 GB
IP:10.24.17.206 -
操作系统
版本:CentOS 6.6 x86_64
安装方式:Minimal -
虚拟化环境
VMware Workstation 12.1.0 -
MySQL
版本:mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
安装方式:TAR压缩包 -
nginx
版本:nginx-1.10.1.tar.gz
安装方式:编译源码安装 -
PHP
版本:php-5.6.22.tar.gz
安装方式:编译源码安装 -
Java
版本:jdk-8u51-linux-x64.gz
安装方式:TAR压缩包 -
Zabbix
版本:zabbix-2.4.8.tar.gz
安装方式:编译源码安装
二、安装MySQL
按照《在CentOS上安装MySQL数据库》的步骤进行安装。
三、安装nginx
按照《在CentOS上安装nginx服务器》的步骤进行安装。
四、安装PHP
按照《在CentOS上安装PHP》的步骤进行安装。
五、安装Java
按照《在CentOS上安装Java》的步骤进行安装。
六、从源码编译安装Zabbix
1. 下载Zabbix源码包
在Shell中运行以下命令:
cd /root/Downloads
wget http://tenet.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.4.8/zabbix-2.4.8.tar.gz
2. 安装依赖包
在Shell中运行以下命令,安装编译时必须的依赖包:
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/iksemel-1.4-2.el6.x86_64.rpm
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/iksemel-devel-1.4-2.el6.x86_64.rpm
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/fping-2.4b2-10.el6.x86_64.rpm
wget http://cdn.mysql.com//Downloads/Connector-ODBC/5.3/mysql-connector-odbc-5.3.6-1.el6.x86_64.rpm
yum --disablerepo=* --enablerepo=c6-media localinstall -y iksemel-1.4-2.el6.x86_64.rpm iksemel-devel-1.4-2.el6.x86_64.rpm fping-2.4b2-10.el6.x86_64.rpm mysql-connector-odbc-5.3.6-1.el6.x86_64.rpm
yum --disablerepo=* --enablerepo=c6-media install -y OpenIPMI OpenIPMI-devel libssh2 libssh2-devel libcurl libcurl-devel net-snmp net-snmp-devel libxml2 libxml2-devel openldap openldap-devel unixODBC unixODBC-devel
3. 解压缩Zabbix源码包
在Shell中运行以下命令:
tar xvzf zabbix-2.4.8.tar.gz
cd zabbix-2.4.8
4. 创建用户账户
在Shell中运行以下命令,创建用户和组:
groupadd zabbix
useradd -g zabbix zabbix
5. 创建Zabbix数据库
在Shell中运行以下命令,登录MySQL命令行:
mysql -uroot -p
在MySQL命令行中运行以下命令,创建Zabbix数据库:
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'zabbix';
FLUSH PRIVILEGES;
quit
若要安装Zabbix Server,则在Shell中运行以下命令,建立服务端数据库的表结构(本文会安装Zabbix Server):
cd /root/Downloads/zabbix-2.4.8/database/mysql/
mysql -uroot -p zabbix < schema.sql
mysql -uroot -p zabbix < images.sql
mysql -uroot -p zabbix < data.sql
若要安装Zabbix Proxy,则在Shell中运行以下命令,建立代理器数据库的表结构(本文不会安装Zabbix Proxy):
cd /root/Downloads/zabbix-2.4.8/database/mysql/
mysql -uroot -p zabbix < schema.sql
若要安装Zabbix Agent,因为探针不需要数据库,所以不用建立数据库的表结构(本文也会安装Zabbix Agent)。
6. 配置源码
Zabbix Server/Proxy/Agent的编译配置选项有所不同,如下所示:
-
若要编译安装Zabbix Server,则需要使用
--enable-server
选项(本文会安装Zabbix Server)。 -
若要编译安装Zabbix Proxy,则需要使用
--enable-proxy
选项(本文不会安装Zabbix Proxy)。 -
若要编译安装Zabbix Agent,则需要使用
--enable-agent
选项(本文也会安装Zabbix Agent)。
本文会安装Zabbix的服务端和探针,编译配置选项如下所示:
cd /root/Downloads/zabbix-2.4.8
./configure --prefix=/usr/local/Zabbix --enable-server --enable-agent --enable-java --enable-ipv6 --with-mysql --with-jabber --with-libxml2 --with-unixodbc --with-net-snmp --with-ssh2 --with-openipmi --with-ldap --with-libcurl --with-iconv --with-iconv-include --with-iconv-lib
上述选项的具体含义,请参考《Zabbix 2.4.8源码配置选项解析》。
7. 编译安装
在Shell中运行以下命令:
make install
七、配置Zabbix后台
1. 将Zabbix Server配置为自启动服务
在Shell中运行以下命令,新建自启动脚本:
mkdir -p /usr/local/Zabbix/lock
vi /etc/init.d/zabbix-server
在上述文件中输入以下内容:
#!/bin/sh
#
# chkconfig: - 85 15
# description: Zabbix server daemon
# config: /usr/local/Zabbix/etc/zabbix_server.conf
#
### BEGIN INIT INFO
# Provides: zabbix
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Default-Start:
# Default-Stop: 0 1 2 3 4 5 6
# Short-Description: Start and stop Zabbix server
# Description: Zabbix server
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
if [ -x /usr/local/Zabbix/sbin/zabbix_server ]; then
exec=/usr/local/Zabbix/sbin/zabbix_server
else
exit 5
fi
prog=${exec##*/}
conf=/usr/local/Zabbix/etc/zabbix_server.conf
if [ -f /etc/sysconfig/zabbix-server ]; then
. /etc/sysconfig/zabbix-server
fi
lockfile=/usr/local/Zabbix/lock/zabbix-server
start()
{
echo -n $"Starting Zabbix server: "
daemon $exec -c $conf
rv=$?
echo
[ $rv -eq 0 ] && touch $lockfile
return $rv
}
stop()
{
echo -n $"Shutting down Zabbix server: "
killproc $prog
rv=$?
echo
[ $rv -eq 0 ] && rm -f $lockfile
return $rv
}
restart()
{
stop
start
}
case "$1" in
start|stop|restart)
$1
;;
force-reload)
restart
;;
status)
status $prog
;;
try-restart|condrestart)
if status $prog >/dev/null ; then
restart
fi
;;
reload)
action $"Service ${0##*/} does not support the reload action: " /bin/false
exit 3
;;
*)
echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"
exit 2
;;
esac
在Shell中运行以下命令:
chkconfig zabbix-server on
chmod 755 /etc/init.d/zabbix-server
2. 将Zabbix Agent配置为自启动服务
在Shell中运行以下命令,新建自启动脚本:
vi /etc/init.d/zabbix-agent
在上述文件中输入以下内容:
#!/bin/sh
#
# chkconfig: - 86 14
# description: Zabbix agent daemon
# processname: zabbix_agentd
# config: /usr/local/Zabbix/etc/zabbix_agentd.conf
#
### BEGIN INIT INFO
# Provides: zabbix-agent
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Should-Start: zabbix zabbix-proxy
# Should-Stop: zabbix zabbix-proxy
# Default-Start:
# Default-Stop: 0 1 2 3 4 5 6
# Short-Description: Start and stop Zabbix agent
# Description: Zabbix agent
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
if [ -x /usr/local/Zabbix/sbin/zabbix_agentd ]; then
exec=/usr/local/Zabbix/sbin/zabbix_agentd
else
exit 5
fi
prog=${exec##*/}
conf=/usr/local/Zabbix/etc/zabbix_agentd.conf
if [ -f /etc/sysconfig/zabbix-agent ]; then
. /etc/sysconfig/zabbix-agent
fi
lockfile=/usr/local/Zabbix/lock/zabbix-agent
start()
{
echo -n $"Starting Zabbix agent: "
daemon $exec -c $conf
rv=$?
echo
[ $rv -eq 0 ] && touch $lockfile
return $rv
}
stop()
{
echo -n $"Shutting down Zabbix agent: "
killproc $prog
rv=$?
echo
[ $rv -eq 0 ] && rm -f $lockfile
return $rv
}
restart()
{
stop
start
}
case "$1" in
start|stop|restart)
$1
;;
force-reload)
restart
;;
status)
status $prog
;;
try-restart|condrestart)
if status $prog >/dev/null ; then
restart
fi
;;
reload)
action $"Service ${0##*/} does not support the reload action: " /bin/false
exit 3
;;
*)
echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"
exit 2
;;
esac
在Shell中运行以下命令:
chkconfig zabbix-agent on
chmod 755 /etc/init.d/zabbix-agent
3. 配置PHP
在Shell中运行以下命令,配置php.ini文件:
vi /usr/local/PHP/etc/php.ini
在上述文件中配置以下参数:
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
always_populate_raw_post_data = -1
4. 配置unixODBC
在Shell中运行以下命令,创建软链接:
ln -s /usr/lib64/libmyodbc5w.so /usr/lib64/libmyodbc5.so
ln -s /usr/local/MySQL/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
在Shell中运行以下命令,创建ODBC数据源配置文件:
vi /etc/odbc.ini
上述文件的内容如下所示:
[localhost]
Description = MySQL Localhost Database
Driver = MySQL
Server = 127.0.0.1
User = zabbix
Password = zabbix
Port = 3306
Database = zabbix
在Shell中运行以下命令,测试ODBC数据源配置:
isql -v localhost
若上述命令返回信息如下图所示,则表示ODBC数据源配置正确(若配置正确,则可以使用quit
命令退出SQL命令行):
若要利用unixODBC监控其他MySQL数据,则只要仿照该文件中的localhost
部分配置即可。
5. 配置Zabbix服务端
在Shell中运行以下命令,配置Zabbix Server:
vi /usr/local/Zabbix/etc/zabbix_server.conf
在上述文件中配置以下参数:
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/usr/local/MySQL/sock/mysql.sock
6. 安装Zabbix前端页面
在Shell中运行以下命令,安装前端页面:
mkdir -p /home/www/zabbix
cp -a /root/Downloads/zabbix-2.4.8/frontends/php/* /home/www/zabbix/
chown -R nginx.nginx /home/www/zabbix
7. 重启服务器
在Shell中运行以下命令,重启服务器:
reboot
八、配置Zabbix前端页面
在WEB浏览器中访问如下URL:
http://10.24.17.206/zabbix
进入Zabbix前端安装页面的首页,如下图所示:
点击“Next”按钮,进入必要条件检查页面,如下图所示:
若各项配置检查无误,则点击“Next”按钮,进入数据库连接配置页面,如下图所示:
数据库连接配置完成之后,必须首先点击“Test Connection”按钮,确保配置无误之后,才能点击“Next”按钮,进入Zabbix服务端详情页面,如下图所示:
填写好服务端主机的IP、端口号和主机名之后,点击“Next”按钮,进入安装前预览页面,如下图所示:
确认安装配置信息无误之后,点击“Next”按钮,进入安装结束页面,如下图所示:
点击“Finish”按钮,Zabbix前端页面便安装完成了。此时,会自动跳转到Zabbix的登录页面,如下图所示:
默认的用户名和密码分别是Admin和zabbix,进入Zabbix监控的首屏,如下图所示:
进入首屏之后,点击首屏菜单中的“Configuration → Hosts”,进入主机配置页面,如下图所示:
由上图可知,作为Zabbix服务端的这台主机监控状态为“Disabled”,也就是没有对自己进行监控。此时,可以点击红色的“Disabled”,使监控状态变为绿色的“Enabled”,过几分钟刷新页面之后,便会发现Availability栏中的Z图标也会变绿,这就表明这台服务器目前是可用状态,如下图所示:
至此,在CentOS上通过编译源码来安装Zabbix的过程已经顺利结束,接下来只要在待监控的服务器上安装Zabbix探针,并进行相应的配置就可以了!
继续啊