码迷,mamicode.com
首页 > 其他好文 > 详细

zabbix 2.2.2在centos 6.3 x86_64上的安装

时间:2016-02-18 13:52:28      阅读:308      评论:0      收藏:0      [点我收藏+]

标签:

zabbix 2.2.2在centos 6.3 x86_64上的安装

 
更新五月 03, 2014
 
 
# 依赖环境
yum install -y php-mbstring mysql-devel libcurl-devel net-snmp-devel php-xml libiconv php-gd* php-bcmath php-mysql
 
# 下载并解压缩zabbix server 2.2.2
#下载地址 http://www.zabbix.com/download.php
tar xzf zabbix-2.2.2.tar.gz
cd zabbix-2.2.2

# 增加用户和组.
groupadd zabbix
useradd -g zabbix zabbix
 
 
#
# 将初始数据导入mysql中
#

# 安装mysql server
yum install mysql-server

# 执行zabbix_server带的数据库脚本(非zabbix proxy)
shell> mysql -uroot -p
mysql> create database zabbix character set utf8;
mysql> grant all on zabbix.* to zabbixuser@localhost identified by ‘db2203‘;
mysql> flush privileges;
mysql> quit
shell> mysql -uroot -p zabbix < database/mysql/schema.sql
# stop here if you are creating database for Zabbix proxy
shell> mysql -uroot -p zabbix < database/mysql/images.sql
shell> mysql -uroot -p zabbix < database/mysql/data.sql
 
 
 
 
#
# 安装zabbix server程序
#

# 安装依赖库
yum install libcurl-devel mysql-devel net-snmp-devel
 
# 如果没有安装mysql-devel包,则建立一个快捷方式
#cd /usr/lib64/mysql
#ln -s libmysqlclient.so.18 libmysqlclient.so

# 编译zabbix server(for mysql)
./configure --prefix=/opt/zabbix --enable-server --enable-agent --with-mysql --disable-ipv6 --with-net-snmp --with-libcurl
make install
#报错自行解决

# 编译zabbix client(非必须),官网有2.0.6的多个os的agent
./configure --enable-agent --enable-static --prefix=/opt/zabbix





#
# 安装zabbix server的其他设置
#

# 创建zabbix server的日志目录
mkdir -p /opt/log/zabbix/
chown zabbix:zabbix /opt/log/zabbix


# 创建pid文件存放目录
mkdir /var/run/zabbix -p
chown zabbix:zabbix /var/run/zabbix
 
#
# 修改服务端配置文件/opt/zabbix/etc/zabbix_server.conf
#
 
# 指定zabbix_server的日志文件路径
LogFile=/opt/log/zabbix/zabbix_server.log
 
# 指定日志文件大小(MB),超过后自动轮询
LogFileSize=100
 
# 指定pid文件位置
PidFile=/opt/run/zabbix_server.pid
 
# 指定数据库名为zabbix
DBName=zabbix
 
# 指定数据库用户为zabbisuser
 
DBUser=zabbixuser
 
#指定数据库密码
DBpasswd=XXXXXXXXXXX   

# 启动zabbix server
/opt/zabbix/sbin/zabbix_server -c /opt/zabbix/etc/zabbix_server.conf
启动没有进程看日志信息/opt/log/zabbix/zabbix_server.log
 
# 添加到开机启动里
echo "/opt/zabbix/sbin/zabbix_server -c /opt/zabbix/etc/zabbix_server.conf" >> /etc/rc.local

#错误:
运行:     /opt/zabbix/sbin/zabbix_server -c /opt/zabbix/etc/zabbix_server.conf
/opt/zabbix/sbin/zabbix_server: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
 
 find / -name libiconv.so*
/usr/local/lib/libiconv.so
/usr/local/lib/libiconv.so.2
/usr/local/lib/libiconv.so.2.5.0
 
[root@vpn etc]# echo "/usr/local/lib/">>/etc/ld.so.conf
[root@vpn etc]# ldconfig
 
#错误2:
运行:   /opt/zabbix/sbin/zabbix_server -c /opt/zabbix/etc/zabbix_server.conf 
/opt/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
 
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.16 
ldconfig
 
 
 
# 授权pid 创建文件目录的权限(启动之后没有进程 跟此项有关系):
mkdir /opt/run/
chown -R zabbix.zabbix /opt/run


#
# 在zabbix server上安装nginx+php
#

# 安装apache prefork版,较稳定(用nginx代替)
#apt-get install apache2-mpm-prefork

# 安装php
yum install php php-gd php-gmp php-mysql php-fpm.x86_64 php-bcmath.x86_64 php-xml.x86_64 php-mbstring.x86_64 php-pecl-apc(php加速模块apc)
 
#安装nginx
先执行rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
yum install nginx
 
# 新增文件/etc/nginx/conf.d/zabbix.conf,内容如下:

server {
listen 60080;
server_name localhost;

#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
access_log /dev/null main;
error_log /dev/null;

location / {
root /opt/website/zabbix;
index index.html index.htm index.php;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /opt/website/zabbix$fastcgi_script_name;
include fastcgi_params;
}
}

 

# 并且在/etc/nginx/conf.d中将default.conf改名

mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.old

 

# 修改/etc/nginx/fastcgi_params,将SERVER_SOFTWARE改成如下,去掉nginx版本号显示

#fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param SERVER_SOFTWARE nginx;

 

# 备份nginx.conf 并修改/etc/nginx/nginx.conf的内容:

user nginx;
worker_processes 1;

#error_log /var/log/nginx/error.log warn;
error_log /dev/null;

pid /var/run/nginx.pid;


events {
worker_connections 2048;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"‘;

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

gzip on;

server_tokens off;

include /etc/nginx/conf.d/*.conf;
}

 


# 修改/etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
time zone=Asia/Shanghai (如果没有,则修改date.timezone =Asia/Shanghai)
或者:
date.timezone =Asia/Shanghai
 
# 添加到/etc/php.ini最后

; php apc module
extension=apc.so
apc.enabled = 1
apc.cache_by_default = on
apc.shm_segments = 1
apc.shm_size = 128
apc.ttl = 7200
apc.user_ttl = 7200
apc.num_files_hint = 1024
apc.write_lock = On
apc.gc_ttl=3600
apc.ttl=0

 

 

#启动nginx

service nginx start

 

#启动php-fpm

service php-fpm start

#报错自行解决

 

# 将zabbix站点文件放到/opt/website/zabbix/下

mkdir -p /opt/website/zabbix

cp -rf frontends/php/* /opt/website/zabbix/

 

# 首次访问,以执行zabbix自安装程序

在浏览器中输入:http://ip地址:60080/,这将启动zabbix安装程序,按照它的提示解决问题。

默认用户 :  Admin       zabbix

 

最后,如果出现如下错误:

Configuration file
"/opt/website/zabbix/conf/zabbix.conf.php"
created: Fail

需要临时给与/opt/website/zabbix/conf/这个目录以写权限:

chmod 777 /opt/website/zabbix/conf/

 

然后重试成功后再去掉写权限:chmod go-w /opt/website/zabbix/conf

#
# 短信接口
 
#
 
 
 
 
#客户端安装
#下载原包
wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.2.2/zabbix-2.2.2.tar.gz
 
#添加zabbix用户
groupadd zabbix
 
useradd -g zabbix zabbix
 
#安装
./configure --enable-agent --prefix=/opt/zabbix
make install
 

#修改/opt/zabbix/etc/zabbix_agentd.conf中的两个参数,其他使用默认

Server:修改为zabbix服务器的IP地址

Hostname:修改为本机的机器名

 

#启动zabbix客户端

/opt/zabbix/sbin/zabbix_agentd

启动报错如:/opt/zabbix/sbin/zabbix_agentd: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory

执行

#echo ‘/usr/local/lib‘ >> /etc/ld.so.conf;ldconfig

检查端口是否启动成功

#netstat -an | grep 10050

 

在服务器端测试连接

/opt/zabbix/bin/zabbix_get -s 113.31.17.239 -k "agent.version"

/opt/zabbix/bin/zabbix_get -s 113.31.17.239 -k "system.uptime"

/opt/zabbix/bin/zabbix_get -s 113.31.17.239 -k "net.if.in[eth0]"

返回2.2.2之类的,说明客户端已成功启动

 

#自启动脚本

vi /etc/rc.d/init.d/zabbix_agentd

chmod +x /etc/rc.d/init.d/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="/opt/zabbix/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 $?

 

 

#测试 

#chkconfig --add zabbix_agentd

#chkconfig zabbix_agentd on

 

 

 

#邮件报警设置

#安装sendmail

yum install senmail

service sendmail start

netstat -nalp|grep 25

 

#修改系统一些配置,目的是让邮件发送过来的时候以@zabbixemail.ntalker.com结尾。这样有些POP3可以通过接收

#修改hosts

vi /etc/hosts

修改为

127.0.0.1 zabbixemail.ntalker.com localhost

 

#修改

vi /etc/mail/access

修改为

Connect:localhost.localdomain     RELAY

Connect:localhost                           RELAY

Connect:127.0.0.1

Connect:zabbixemail.ntalker.com RELAY

 

#修改

vi /etc/mail/local-host-names 

增加域名

echo zabbixemail.ntalker.com >> 

 

#测试sendmail环节,目的是确定服务器发送邮件功能是否正常。

telnet 127.0.0.1 25

 

 

技术分享
或者使用域名然后做邮件发送测试
telnet zabbixemail.ntalker.com 25
技术分享
 
#收到测试邮件后到zabbix管理界面设置 
 
《administrator》---《media type 》--《create media type》
 
技术分享
 
技术分享
 
 
《configuration》---《actions》--《create actons》
 
技术分享
 
acton中 name用baojing(随便)
勾选recovery message(报警修复后会发送修复邮件)
其余都可以选择默认60
技术分享
 
 
operations中300秒表示5分钟发送一次邮件
<to>选择0表示间隔5分钟不停发送邮件
type表示发送模式
选择admin组 选择admin用户
update之后save
 
技术分享
 
《administrator》--《users》--选择《users》
技术分享
 
编辑admin 添加邮件
技术分享
 
 
测试报警环节(略)
 
 


--------------------------------------------------------------------------------------------------------------------------------------
 
zabbix  页面中文乱码解决办法:
 
# 进入zabbix的web目录下fonts
cd /opt/website/zabbix/fonts/
mv DejaVuSans.ttf DejaVuSans.ttf_bak
 
# windows 的控制面板\所有控制面板项\字体
选择自己喜欢的字体: 这里选择了“新宋体常规” simsun.ttc     上传simsun.ttc 到/opt/website/zabbix/fonts/
mv /opt/website/zabbix/fonts/simsun.ttc  /opt/website/zabbix/fonts/DejaVuSans.ttf
 
# 重启zabbix进程刷新页面即可。
 
技术分享
 
 
 
 
 
 
 
 
 
 
 
 

zabbix 2.2.2在centos 6.3 x86_64上的安装

标签:

原文地址:http://www.cnblogs.com/lixiuran/p/5197848.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!