centos6.5 搭建zabbix3.0

一.搭建LAMP平台

注意zabbix3.0需要php5.4以上的版本

(1)安装依赖包

httpd和mysql安装过程省略

rpm -e httpd --nodeps

 

yum -y install mysql-devel gcc gcc-c++ autoconf httpd-manual mod_perl mod_auth_mysql mysql-connector-odbc libdbi-dbd-mysql net-snmp-devel curl-devel unixODBC-devel java-devel openldap openldap-devel ncurses-devel

 

2)安装源码包LAMP

php编译参数

./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql --with-openssl --enable-sockets --enable-sysvshm --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml --with-mhash --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-curl --with-gd --with-gettext --enable-bcmath --enable-opcache

 

cp php.ini-development  /etc/php.ini

 

 

建议用源码包安装PHP

 

 

 

修改php.ini  因为zabbix的运行环境要求,否则zabbix 的环境检测室无法通过的

 

 vim /etc/php.ini

440 max_execution_time = 300

449 max_input_time = 300

457 memory_limit = 128M

706 always_populate_raw_post_data = -1 #去掉注释

729 post_max_size = 16M

946 date.timezone = Asia/Shanghai    #启用并修改

1586 mbstring.func_overload = 1       #启用并修改

 

 

4.修改php配置文件(用sed修改上边的参数)

 

sed -i "s@;date.timezone =@date.timezone = Asia/Shanghai@g" /etc/php.ini

sed -i "s@max_execution_time = 30@max_execution_time = 300@g" /etc/php.ini
sed -i "s@post_max_size = 8M@post_max_size = 32M@g" /etc/php.ini

sed -i "s@max_input_time = 60@max_input_time = 300@g" /etc/php.ini

sed -i "s@memory_limit = 128M@memory_limit = 128M@g" /etc/php.ini

sed -i "s@;mbstring.func_overload = 0@ambstring.func_overload = 2@g" /etc/php.ini

 

5、启动httpdmysql

/etc/init.d/httpd start

/etc/init.d/mysqld start

 

6、编译安装zabbix

useradd -s /sbin/nologin zabbix

mkdir /etc/zabbix /var/log/zabbix

chown -R zabbix.zabbix /var/log/zabbix/

 

更改系统时间,系统时间和北京时间一致

date 041211482017

tar xf zabbix-3.0.4.tar.gz  -C /usr/src/

cd /usr/src/zabbix-3.0.4/

 

./configure --prefix=/usr/local/zabbix --sysconfdir=/etc/zabbix/ \

--enable-server \

--enable-proxy\

 --enable-agent\

 --enable-ipv6\

 --with-mysql=/usr/bin/mysql_config\

 --with-net-snmp\

 --with-libcurl\

 --with-unixodbc\

 --with-ldap \

--enable-java

 

make && make install

 

 

复制启动脚本

cp misc/init.d/fedora/core/zabbix_* /etc/init.d/

编辑启动脚本,更改安装路径

sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_server

 sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_agentd

 

7.修改zabbix的主配置文件

cd /etc/zabbix/

cp zabbix_server.conf zabbix_server.conf.origin

vim  zabbix_server.conf

39 LogFile=/var/log/zabbix/zabbix_server.log

87 DBName=zabbix

103 DBUser=zabbix

112  DBPassword=zabbix

120  DBSocket=/tmp/mysql.sock

128  DBPort=3306

77  DBHost=localhost

 

可以用sed修改

sed -i "s@DBUser=root@DBUser=zabbix@g" /etc/zabbix/zabbix_server.conf
sed -i "s@#DBPassword=@DBPassword=zabbix@g" /etc/zabbix/zabbix_server.conf
sed -i "s@# DBPassword=@DBPassword=zabbix@g" /etc/zabbix/zabbix_server.conf
sed -i "s@ # DBSocket=/tmp/mysql.sock@ DBSocket=/tmp/mysql.sock@g" /etc/zabbix/zabbix_server.conf

sed -i "s@# DBPort=3306@DBPort=3306 @g" /etc/zabbix/zabbix_server.conf

sed -i "s@# DBHost=localhost@DBHost=localhost@g" /etc/zabbix/zabbix_server.conf

 

cp zabbix_agentd.conf zabbix_agentd.conf.origin

编辑agentd.conf的配置文件

vim zabbix_agentd.conf

 LogFile=/var/log/zabbix/zabbix_agentd.log

 91 Server=127.0.0.1,192.168.3.10    #服务端IP

 132 ServerActive=192.168.3.10:10051   #服务端IP,固定端口

 264 Include=/etc/zabbix/zabbix_agentd.conf.d/     #自定义配置文件的路径

 280 UnsafeUserParameters=1   #自定义脚本功能,1为开启

 

8.导入数据库文件

cd /usr/src/zabbix-3.0.4/

mysqladmin -u root password '123123'

 

登录mysql创建数据库,并且授权

mysql> create database zabbix character set utf8;

Query OK, 1 row affected (0.02 sec)

mysql> grant all on zabbix.* to 'zabbix'@localhost identified by 'zabbix';

Query OK, 0 rows affected (0.03 sec)

mysql> flush privileges;        #刷新权限

Query OK, 0 rows affected (0.00 sec)

 

mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql

mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql

mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql

 

 

9、部署php页面

cd /usr/src/zabbix-3.0.4/

cp -rf frontends/php/ /usr/local/httpd/htdocs/zabbix/

chown -R apache:apache /usr/local/httpd/htdocs/zabbix/

 

 10、通过浏览器测试

http://192.168.3.10/zabbix/setup.php

 

 password: zabbix

将下载的文件上传到

/usr/local/httpd/htdocs/zabbix/conf

chown -R zabbix:zabbix zabbix.conf.php

 

 

默认登录的用户名:admin

密码为:zabbix

 

将页面修改为中文

在主页的右上角

 

这样就可以改为中文了.

 

 

报错1:进入到监控界面后,底部会出现错误

 

 

 

这说明你zabbix server端口没有启动

[root@CentOS6-node1 tmp]# netstat -anptu |grep zabbix

tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      43793/zabbix_agentd

tcp        0      0 0.0.0.0:10051               0.0.0.0:*                   LISTEN      44154/zabbix_server

tcp        0      0 :::10050                    :::*                        LISTEN      43793/zabbix_agentd

tcp        0      0 :::10051                    :::*                        LISTEN      44154/zabbix_server

 

请查看是否能够找到mysqlmysql.sock文件

vim /etc/zabbix/zabbix_server.conf

DBSocket=/tmp/mysql.sock

 

 

报错2.  zabbix启动失败

[root@localhost zabbix]# /etc/init.d/zabbix_server restart

Shutting down zabbix_server:                               [失败]

Starting zabbix_server:  /usr/local/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlcli: cannot open shared object file: No such file or directory

                                                           [失败]

解决办法:

ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/

 

报错3:

 

图形中的文字乱码

解决办法:

首先进入windows的字体包目录

C:\Windows\Fonts

将"华文细黑"复制到服务端的

cd /usr/local/httpd/htdocs/zabbix/fonts

 

mv DejaVuSans.ttf DejaVuSans.ttf.bak

mv simhei.ttf DejaVuSans.ttf

 

此时就不会乱码了

 

二、配置被监控端(192.168.3.11)

1.

service iptables stop

setenforce 0

[root@CentOS6-node1 ~]# grep "zabbix" /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

 

2.安装zabbix_agentd代理程序

useradd -s /sbin/nologin zabbix

mkdir /etc/zabbix /var/log/zabbix

chown -R zabbix.zabbix /var/log/zabbix/

tar xf zabbix-2.0.12.tar.gz  -C /usr/src/

cd /usr/src/zabbix-2.0.12/

./configure --prefix=/usr/local/zabbix --sysconfdir=/etc/zabbix/ \

--enable-agent

make && make install

 

cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/

cd /etc/zabbix

cp zabbix_agentd.conf zabbix_agentd.conf.origin

vim zabbix_agentd.conf

21 LogFile=/var/log/zabbix/zabbix_agentd.log

82 Server=127.0.0.1,192.168.3.10    #服务端IP

123 ServerActive=192.168.3.10:10051   #服务端IP,固定端口

229 UnsafeUserParameters=1   #自定义脚本功能,1为开启

 

创建软链接

ln -s /usr/local/zabbix/sbin/zabbix_agentd  /usr/local/sbin/

启动服务

/etc/init.d/zabbix_agentd start

 

3.再服务端添加监控机器

1.添加主机

 

2.创建主机

 

3)创建模板

如果不添加模板的话,不会出图

 

 

 

 

 

 

posted @ 2017-04-14 22:10  借风拥你  阅读(238)  评论(0编辑  收藏  举报