监视服务器Zabbix安装配置以及常见问题
关于Zabbix
对于服务器架设管理人员来说,Zabbix是一款功能强大而且免费的监视系统。
Zabbix可以时时刻刻监视我们服务器的运行状态,包括CPU,MEMORY,HDD等。通过创建事件驱动,当硬件达到某设定临界值(比如CPU使用高达90%)时还可以发邮件通知管理者。
Zabbix还可以监视日志,这个非常有用,当我们系统出现异常时,我们可以及时了解系统出现哪些问题,在客户抱怨之前修复改善系统,不至于等到系统快瘫痪了才发现问题。
另外,Zabbix2.4支持中文界面了。
Zabbix安装
详细安装步骤参看官方文档。
源代码安装:
https://www.zabbix.com/documentation/2.4/manual/installation/install
安装包安装:
https://www.zabbix.com/documentation/2.4/manual/installation/install_from_packages
数据库配置:
不管是源代码安装还是安装包安装,我们都需要配置数据库。
https://www.zabbix.com/documentation/2.4/manual/appendix/install/db_scripts
常见问题
1,通过源代码安装,可能会出现zabbix_server,zabbix_agentd不能正常启动,不能正常停止的问题。解决方法为自己编写启动停止脚本,参看下面的脚本。
2,图形界面乱码问题,解决方法参考下面[修复图形界面的乱码]。
Zabbix server启动停止脚本
#!/bin/bash
#
# chkconfig: - 55 45
# description: zabbix_server
# probe: false
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up. If you are running without a network, comment this out.
[ "${NETWORKING}" = "no" ] && exit 0
RETVAL=0
progdir="/usr/local/sbin/"
prog="zabbix_server"
start() {
# Start daemons.
if [ -n "`/sbin/pidof $prog`" ]; then
echo -n "$prog: already running"
failure $"$prog start"
echo
return 1
fi
echo -n $"Starting $prog: "
# we can't seem to use daemon here - emulate its functionality
su -c $progdir$prog - $USER
RETVAL=$?
usleep 100000
if [ -z "`/sbin/pidof $progdir$prog`" ]; then
RETVAL=1
fi
[ $RETVAL -ne 0 ] && failure $"$prog startup"
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog && success $"$prog startup"
echo
return $RETVAL
}
stop() {
RETVAL=0
pid=
# Stop daemons.
echo -n $"Stopping $prog: "
pid=`/sbin/pidof -s $prog`
if [ -n "$pid" ]; then
kill -TERM $pid
else
failure $"$prog stop"
echo
return 1
fi
RETVAL=$?
[ $RETVAL -ne 0 ] && failure $"$prog stop"
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog && success $"$prog stop"
echo
return $RETVAL
}
restart() {
stop
sleep 5
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
condrestart)
[ -f /var/lock/subsys/$prog ] && restart
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart}"
exit 1
esac
exit $?
Zabbix agentd启动停止脚本
#!/bin/bash
#
# chkconfig: - 55 45
# description: zabbix_agentd
# probe: false
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up. If you are running without a network, comment this out.
[ "${NETWORKING}" = "no" ] && exit 0
RETVAL=0
progdir="/usr/local/sbin/"
prog="zabbix_agentd"
start() {
# Start daemons.
if [ -n "`/sbin/pidof $prog`" ]; then
echo -n "$prog: already running"
failure $"$prog start"
echo
return 1
fi
echo -n $"Starting $prog: "
# we can't seem to use daemon here - emulate its functionality
su -c $progdir$prog - $USER
RETVAL=$?
usleep 100000
if [ -z "`/sbin/pidof $progdir$prog`" ]; then
# The child processes have died after fork()ing, e.g.
# because of a broken config file
RETVAL=1
fi
[ $RETVAL -ne 0 ] && failure $"$prog startup"
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog && success $"$prog startup"
echo
return $RETVAL
}
stop() {
RETVAL=0
pid=
# Stop daemons.
echo -n $"Stopping $prog: "
pid=`/sbin/pidof -s $prog`
if [ -n "$pid" ]; then
kill -TERM $pid
else
failure $"$prog stop"
echo
return 1
fi
RETVAL=$?
[ $RETVAL -ne 0 ] && failure $"$prog stop"
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog && success $"$prog stop"
echo
return $RETVAL
}
restart() {
stop
# wait for forked daemons to die
usleep 1000000
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
condrestart)
[ -f /var/lock/subsys/$prog ] && restart
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart}"
exit 1
esac
exit $?
修复图形界面的乱码
使用默认的字体的话,内存使用,CPU使用图形界面的中文将会出现乱码。
解决方法就是替换默认字体。
在百度上搜索下载FZLTCHJW.TTF,将其上传到前台PHP的fonts目录
编辑前台PHP的defines.inc.php文件
//define('ZBX_GRAPH_FONT_NAME', 'DejaVuSans'); // font file name
define('ZBX_GRAPH_FONT_NAME', 'FZLTCHJW'); // font file name

