zabbix监控(一)基础配置

1050阅读 0评论2015-01-29 浮生凤年
分类:LINUX

一、YUM安装zabbix 

rpm -ivh 

1、安装LAMP环境 
# yum -y install mysql mysql-server  httpd php 
# chkconfig mysqld on
# chkconfig httpd on

2、创建Zabbix运行的用户 
# groupadd zabbix 
# useradd -g zabbix zabbix 
3、安装Zabbix Web所需的依赖包 
# yum -y install mysql-devel gcc net-snmp-devel curl-devel perl-DBI php-gd php-mysql php-bcmath php-mbstring php-xml 
安装fping 
#cd /opt
#wget -c  
# tar xvf fping-3.4.tar.gz 
# cd fping-3.4 
# ./configure 
# make && make install 
# chown root:zabbix /usr/local/sbin/fping 
# chmod 4710 /usr/local/sbin/fping 

4、安装 
#cd /opt
wget -c %20Latest%20Stable/2.0.6/zabbix-2.0.6.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fzabbix%2F%3Fsource%3Ddlp&ts=1367916060&use_mirror=ncu
# tar xvf zabbix-2.0.6.tar.gz 
# cd zabbix-2.0.6 
# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-proxy --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl 
#echo $? 
#make && make install 
#echo $? 

二、Zabbix Server配置与启动 
1、创建Zabbix数据库和Mysql用户 
#service mysqld start
#mysqladmin -uroot password 'xxxxx'
#mysql -uroot -pxxxxxx
mysql> create schema zabbix character set utf8; 
Query OK, 1 row affected (0.03 sec) 

mysql> create user 'zabbix'@'127.0.0.1' identified by 'xxxx'; 
Query OK, 0 rows affected (0.00 sec) 

mysql> grant all on zabbix.* to 'zabbix'@'127.0.0.1'; 
Query OK, 0 rows affected (0.00 sec) 

mysql> flush privileges; 
Query OK, 0 rows affected (0.00 sec) 
2、导入Zabbix数据库初始数据 
#cd zabbix-2.0.12/database/mysql 
# mysql -uroot -picebox zabbix < schema.sql 
# mysql -uroot -picebox zabbix < images.sql 
#mysql -uroot -picebox zabbix < data.sql 
3、配置Zabbix配置文件 
# cd /usr/local/zabbix/etc
# cp zabbix_server.conf zabbix_server.conf.bak
# cat >zabbix_server.conf< > ListenPort=10051 
> LogFile=/usr/local/zabbix/logs/zabbix_server.log 
> PidFile=/usr/local/zabbix/logs/zabbix_server.pid 
> DBHost=127.0.0.1        (此处不支持localhost)
> DBName=zabbix 
> DBUser=zabbix 
> DBPassword=xxxxx
> DBPort=3306 
> DBSocket=/var/lib/mysql/mysql.sock 
> FpingLocation=/usr/local/sbin/fping 
> EOF 

4、配置Zabbix服务。 
# cd /opt/src/zabbix-2.0.12 
# cp misc/init.d/fedora/core5/zabbix_server /etc/init.d/ 
# mkdir -p /usr/local/zabbix/logs 
# chown -R zabbix:zabbix /usr/local/zabbix/ 
# vim /etc/init.d/zabbix_server     #修改增加蓝色字体 
RETVAL=0 
prog="Zabbix Server" 
#ZABBIX_BIN="/usr/local/sbin/zabbix_server" 
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_server" 
CONF_FILE="/usr/local/zabbix/etc/zabbix_server.conf" 

if [ ! -x ${ZABBIX_BIN} ] ; then 
echo -n "${ZABBIX_BIN} not installed! " 
# Tell the user this has skipped 
exit 5 
fi 
start() {
        echo -n $"Starting $prog: "                                              
        daemon $ZABBIX_BIN -c $CONF_FILE                                        
        RETVAL=$?                                                                
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix_agentd                
        echo                                                                    
}


5、开启Zabbix安全限制(若未开防火墙,可跳过此步骤) 
#iptables -A INPUT -p tcp -m tcp --dport 10051 -j ACCEPT 
#service iptables save 

6、启停Zabbix server: 
#service zabbix_server start 
#service zabbix_server stop 

7、配置开机自启动 
#chkconfig --add zabbix_server 
#chkconfig --level 35 zabbix_server on 

8、查看日志是否报错
# cd /usr/local/zabbix/logs
# tail -f zabbix_server.log 

三、配置Zabbix Web服务端 
1、将Zabbix Web文件复制到Apache Web目录中 
#cd zabbix-2.0.12 
# cp -ra frontends/php/* /var/www/html 

2、Apache配置 
# vim /etc/httpd/conf/httpd.conf (修改如下内容) 
ServerName 127.0.0.1:80 

3、PHP配置 
# vim /etc/php.ini (以下标红添加,标蓝修改) 
date.timezone=Asia/Shanghai         #php5.3版本,地区首字母必须大写
mbstring.func_overload=2 

post_max_size=16M 
max_execution_time=300 
max_input_time=300 


4、Zabbix web安装 
#service httpd start
访问web界面,按照步骤提示依次进行安装 

默认登录用户名admin,密码zabbix,登录后修改密码:Adminstration->Users->Admin->Change Password


四、安装Zabbix Agent
1、安装软件
#cd /opt
wget -c %20Latest%20Stable/2.0.6/zabbix-2.0.6.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fzabbix%2F%3Fsource%3Ddlp&ts=1367916060&use_mirror=ncu

%20Latest%20Stable/2.0.6/zabbix-2.0.6.tar.gz
# tar xvf zabbix-2.0.6.tar.gz 
# cd zabbix-2.0.6
# ./configure --prefix=/opt/svr/zabbix --enable-agent 
#echo $? 
#make && make install 
#echo $? 
# cp misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/    ##为下面配置init做准备

2、配置zabbix_agentd
# groupadd zabbix 
# useradd -g zabbix zabbix 
# mkdir -p /opt/svr/zabbix/logs 

# cd /opt/svr/zabbix/etc
# cp zabbix_agentd.conf zabbix_agentd.conf.bak
# cat >zabbix_agentd.conf<
PidFile=/opt/svr/zabbix/logs/zabbix_agentd.pid
LogFile=/opt/svr/zabbix/logs/zabbix_agentd.log
Server=127.0.0.1
ListenPort=10050
ServerActive=127.0.0.1
Hostname=zabbix_server            #同Web的host相同名称,本人喜欢用IP地址
Timeout=15
Include=/opt/svr/zabbix/etc/zabbix_agentd.conf.d/        #监控mysql,MPM插件时用此项

#以下为自定义监控
UnsafeUserParameters=1

Userparameter=user.shell[*].sh  $1
# chown -R zabbix:zabbix /opt/svr/zabbix/ 

3、配置启动脚本
# vim /etc/init.d/zabbix_agentd #修改增加以下蓝色字体
#ZABBIX_BIN="/opt/svr/sbin/zabbix_agentd"
ZABBIX_BIN="/opt/svr/zabbix/sbin/zabbix_agentd"
CONF_FILE="/opt/svr/zabbix/etc/zabbix_agentd.conf"
~~~~~~~~~~~~
start() {
        echo -n $"Starting $prog: "                                              
        daemon $ZABBIX_BIN -c $CONF_FILE                                        
        RETVAL=$?                                                                
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix_agentd                
        echo                                                                    
}

4、开启Zabbix安全限制(若未开防火墙,可跳过此步骤) 
#iptables -A INPUT -p tcp -m tcp --dport 10050 -j ACCEPT 
#service iptables save 

5、启停Zabbix agentd: 
#service zabbix_agentd start 
#service zabbix_agentd stop 
#/etc/init.d/zabbix_agentd start

6、配置开机自启动 
#chkconfig --add zabbix_agentd 
#chkconfig --level 35 zabbix_agentd on 

7、检测Zabbix Agent是否正常工作
/opt/svr/zabbix/sbin/zabbix_agentd -c /opt/svr/zabbix/etc/zabbix_agentd.conf -t system.uptime
system.uptime                                 [u|689960]

参考:《深入浅出MySQL》
上一篇:基于nosql的"新型"游戏服务器框架
下一篇:没有了