3212ed 发表于 2016-1-12 08:26:01

Centos7.1安装部署Zabbix2.2.6步骤详解

zabbix简介
zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案,由一个国外的团队持续维护更新,软件可以自由下载使用,运作团队靠提供收费的技术支持赢利。zabbix由2部分构成,zabbix server与可选组件zabbix agent。zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能。zabbix agent需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。zabbix server可以单独监视远程服务器的服务状态;同时也可以与zabbix agent配合,可以轮询zabbix agent主动接收监视数据(trapping方式),同时还可被动接收zabbix agent发送的数据(trapping方式)。另外zabbix server还支持SNMP (v1,v2),可以与SNMP软件(例如:net-snmp)等配合使用。

zabbix的主要特点:   
- 安装与配置简单,学习成本低
- 支持多语言(包括中文)   
- 免费开源   
- 自动发现服务器与网络设备   
- 分布式监视以及WEB集中管理功能   
- 可以无agent监视   
- 用户安全认证和柔软的授权方式   
- 通过WEB界面设置或查看监视结果   
- email等通知功能等等  

Zabbix主要功能:    
- CPU负荷   
- 内存使用   
- 磁盘使用   
- 网络状况   
- 端口监视   
- 日志监视

Zabbix安装:
一.安装LNMP环境
参考:http://www.iyunv.com/thread-162840-1-1.html


二.Zabbix服务端安装
Server:10.15.44.18
zabbix下载、安装编译环境、组件
1
2
3
4
5
6
7
# mkdir /app
# cd /app/
# wget
# yum -y install gcc gcc-c++ autoconf curl curl-devel net-snmp net-snmp-devel perl-DBI
# tar zxvf zabbix-2.2.6.tar.gz
# groupadd zabbix
# useradd -s /sbin/nologin -g zabbix zabbix




   创建、导入zabbix数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# cd zabbix-2.2.6/database/mysql/   #进入mysql数据库创建脚本目录
# ls
data.sqlimages.sqlschema.sql
# mysql -u root -pREDHAT
Welcome to the MySQL monitor.Commands end with ; or \g.

mysql> create database zabbix character set utf8;#创建数据库zabbix,并且数据库编码使用utf8
Query OK, 1 row affected (0.03 sec)

mysql> insert into mysql.user(Host,User,Password) values('localhost','zabbix',password('123456'));    #新建账户zabbix,密码123456
Query OK, 1 row affected, 3 warnings (0.02 sec)

mysql> flush privileges;    #刷新系统授权表
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by '123456' with grant option;   #允许账户zabbix能从本机连接到数据库zabbix
Query OK, 0 rows affected (0.02 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> use zabbix    #进入数据库,按照顺序导入脚本文件到zabbix数据库,否则会出错。
mysql> source /app/zabbix-2.2.6/database/mysql/schema.sql
mysql> source /app/zabbix-2.2.6/database/mysql/images.sql
mysql> source /app/zabbix-2.2.6/database/mysql/data.sql
mysql> exit
Bye
#




    或者以下方式导入脚本到数据库

1
2
3
# mysql -uzabbix -p123456 -hlocalhost zabbix < /app/zabbix-2.2.6/database/mysql/schema.sql
# mysql -uzabbix -p123456 -hlocalhost zabbix < /app/zabbix-2.2.6/database/mysql/images.sql
# mysql -uzabbix -p123456 -hlocalhost zabbix < /app/zabbix-2.2.6/database/mysql/data.sql




    安装zabbix

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# cd /app/zabbix-2.2.6
# ./configure --prefix=/app/zabbix --enable-server --enable-agent --with-net-snmp --with-libcurl --enable-proxy --with-mysql=/usr/bin/mysql_config
# make
In file included from db.c:22:
../../../include/zbxdb.h:65:20: error: mysql.h: No such file or directory
../../../include/zbxdb.h:66:21: error: errmsg.h: No such file or directory
../../../include/zbxdb.h:67:27: error: mysqld_error.h: No such file or directory
In file included from db.c:22:
../../../include/zbxdb.h:179: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
../../../include/zbxdb.h:180: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
../../../include/zbxdb.h:182: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘zbx_db_fetch’
db.c:38: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
db.c:165: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
db.c: In function ‘is_recoverable_mysql_error’:
db.c:180: error: ‘conn’ undeclared (first use in this function)
db.c:180: error: (Each undeclared identifier is reported only once
db.c:180: error: for each function it appears in.)
db.c:182: error: ‘CR_CONN_HOST_ERROR’ undeclared (first use in this function)
db.c:183: error: ‘CR_SERVER_GONE_ERROR’ undeclared (first use in this function)
db.c:184: error: ‘CR_CONNECTION_ERROR’ undeclared (first use in this function)
db.c:185: error: ‘CR_SERVER_LOST’ undeclared (first use in this function)
db.c:186: error: ‘CR_UNKNOWN_HOST’ undeclared (first use in this function)
db.c:187: error: ‘ER_SERVER_SHUTDOWN’ undeclared (first use in this function)
db.c:188: error: ‘ER_ACCESS_DENIED_ERROR’ undeclared (first use in this function)
db.c:189: error: ‘ER_ILLEGAL_GRANT_FOR_TABLE’ undeclared (first use in this function)
db.c:190: error: ‘ER_TABLEACCESS_DENIED_ERROR’ undeclared (first use in this function)
db.c:191: error: ‘ER_UNKNOWN_ERROR’ undeclared (first use in this function)
db.c: In function ‘zbx_db_connect’:
db.c:294: error: ‘conn’ undeclared (first use in this function)
db.c:296: error: ‘CLIENT_MULTI_STATEMENTS’ undeclared (first use in this function)
db.c: In function ‘zbx_db_close’:
db.c:559: error: ‘conn’ undeclared (first use in this function)
db.c: In function ‘zbx_db_vexecute’:
db.c:1019: error: ‘conn’ undeclared (first use in this function)
db.c: At top level:
db.c:1149: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
db.c:1478: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
db.c:1607: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘zbx_db_fetch’
make: *** Error 1
make: Leaving directory `/app/zabbix-2.2.6/src/libs/zbxdb'
make: *** Error 1
make: Leaving directory `/app/zabbix-2.2.6/src/libs'
make: *** Error 1
make: Leaving directory `/app/zabbix-2.2.6/src'
make: *** Error 1
#   zabbix编译时找不到mysql.h文件,需要安装 mysql-devel包
root@localhost zabbix-2.2.6]# yum install mysql-devel -y
# make
checking for mysql_config... /usr/bin/mysql_config
checking for main in -lmysqlclient ... no
configure: error: Not found mysqlclient library
# ln -s /usr/lib64/mysql/libmysqlclient.so.16.0.0 /usr/lib64/mysql/libmysqlclient.so#32位系统为/usr/lib/mysql,注意系统版本同,文件版本可能不一样,这里是16.0.0
# ln -s /usr/lib64/mysql/libmysqlclient_r.so.16.0.0 /usr/lib64/mysql/libmysqlclient_r.so
# make
# make install
# ln -s /app/zabbix/sbin/* /usr/local/sbin/
# ln -s /app/zabbix/bin/* /usr/local/bin/




    修改zabbix配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# cd /app/zabbix/etc/
# cp zabbix_server.conf zabbix_server.confbak
# vim zabbix_server.conf
LogFile=/app/zabbix/logs/zabbix_server.log
PidFile=/app/zabbix/pid/zabbix_server.pid
DBHost=localhost
DBName=zabbix          #数据库名称
DBUser=zabbix          #数据库用户名
DBPassword=123456      #数据库密码
ListenIP=127.0.0.1   #数据库ip地址
AlertScriptsPath=/app/zabbix/alertscripts    #zabbix运行脚本存放目录
# cp zabbix_agent.conf zabbix_agent.confbak
# vim zabbix_agent.conf
Include=/app/zabbix/etc/zabbix_agent.conf.d/
Server=127.0.0.1
UnsafeUserParameters=1      #启用自定义key
LogFile=/app/zabbix/logs/zabbix_agentd.log
# mkdir ../logs
# touch ../logs/zabbix_server.log
# touch ../logs/zabbix_agentd.log
# mkdir ../pid
# touch ../pid/zabbix_server.pid
# mkdir alertscripts
# chmod 777 ../logs/zabbix_*
# chmod 777 ../pid/zabbix_server.pid




    添加开机启动脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
# cd /app/zabbix-2.2.6/misc/init.d/fedora/core/
# cp zabbix_server /etc/rc.d/init.d/zabbix_server
# cp zabbix_agentd /etc/rc.d/init.d/zabbix_agentd
# chmod +x /etc/rc.d/init.d/zabbix_*
# chkconfig --add zabbix_server
# chkconfig --add zabbix_agentd
# chkconfig zabbix_server on
# chkconfig zabbix_agentd on
# vim /etc/rc.d/init.d/zabbix_server
      BASEDIR=/app/zabbix
# vim /etc/rc.d/init.d/zabbix_agentd         
      BASEDIR=/app/zabbix      
#




   添加zabbix服务对应的端口

1
2
3
4
5
6
7
# cp /etc/services /etc/servicesbak
# vim /etc/services   #文末添加以下4行
zabbix-agent    10050/tcp               # Zabbix Agent
zabbix-agent    10050/udp               # Zabbix Agent
zabbix-trapper10051/tcp               # Zabbix Trapper
zabbix-trapper10051/udp               # Zabbix Trapper
#




   配置web站点
/usr/share/nginx/html/为Nginx默认站点目录 nginx为Nginx运行账户

1
2
3
4
5
6
7
# cp -r /app/zabbix-2.2.6/frontends/php /usr/share/nginx/html/zabbix
# chown nginx:nginx -R /usr/share/nginx/html/zabbix/
# service zabbix_server start
Starting zabbix_server:                                    
# service zabbix_agentd start
Starting zabbix_agentd:                                    
#




    修改php配置文件参数

1
2
3
4
5
6
7
8
9
10
11
# cp /etc/php.ini /etc/php.inibak2
# vim /etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
# cp /etc/php-fpm.conf /etc/php-fpm.confbak
# vim /etc/php-fpm.conf
request_terminate_timeout = 300
# service php-fpm reload
Reloading php-fpm:                                       
#




   安装web
在浏览器中打开:http://10.15.44.18/zabbix/setup.php
(无法打开页面将php.ini中的open_basedir注释掉,或者修改成open_basedir = /usr/share/nginx/html/:/tmp/)

Next

检查系统环境设置,必须全部都为ok,才能继续Next

配置MySQL数据库信息
Database:MySQL
Database host:127.0.0.1
Database port:use default port
Database name:zabbix
User:zabbix
Password:123456
Test connection   #测试数据库连接是否正常,显示ok表示通过
测试OK后点击Next继续

默认,Next

检查一下设置情况,没问题直接Next

下载配置文件,并把他放置在conf/ 目录下,Finish安装完成

默认账号:用户名 admin 密码 zabbix
注:如下报错是因为zabbix数据未导入MYSQL数据库:




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# netstat -tunpl | grep zabbix
tcp      0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      2026/zabbix_agentd
# sestatus
SELinux status:               disabled
# tail -50f zabbix_server.log
2044:20160111:101348.978 connection to database 'zabbix' failed: Access denied for user 'zabbix'@'localhost' (using password: YES)
2044:20160111:101348.978 Database is down. Reconnecting in 10 seconds.
2044:20160111:101358.978 connection to database 'zabbix' failed: Access denied for user 'zabbix'@'localhost' (using password: YES)
2044:20160111:101358.978 Database is down. Reconnecting in 10 seconds.
# mysql -u root -p
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by '123456';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
# service mysqld restart
Stopping mysqld:                                          
Starting mysqld:                                          
# service nginx restart
Stopping nginx:                                          
Starting nginx:                                          
# netstat -tunpl | grep zabbix
tcp      0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      2026/zabbix_agentd
tcp      0      0 0.0.0.0:10051               0.0.0.0:*                   LISTEN      4383/zabbix_server
#






更改zabbix让web页面支持简体中文显示

1
2
3
4
5
6
# cp locales.inc.php locales.inc.phpbak
# vim locales.inc.php
                'zh_CN' => array('name' => _('Chinese (zh_CN)'),      'display' => false),
                修改为
                              'zh_CN' => array('name' => _('Chinese (zh_CN)'),      'display' => true),
#




替换监控图像上系统默认的字体
默认字体不支持中文,如果不替换,图像上会显示乱码,在Windows系统中的C:\Windows\Fonts目录中复制出一个中文字体文件,例如“微软雅黑”,把字体文件“微软雅黑”出来,此时文件名显示为msyh.ttf,再把msyh.ttf上传到zabbix站点根目录下fonts文件夹中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# cd /usr/share/nginx/html/zabbix/fonts/
# ls
DejaVuSans.ttf
# rz
# ls
DejaVuSans.ttfmsyh.ttf
# cp DejaVuSans.ttf DejaVuSans.ttfBAK
# cp msyh.ttf DejaVuSans.ttf
cp: overwrite `DejaVuSans.ttf'? y
#cd /usr/share/nginx/html/zabbix/include/
# cat defines.inc.php|egrep -in "ZBX_FONT_NAME|ZBX_GRAPH_FONT_NAME"         #调用DejaVuSans.ttf配置文件
43:define('ZBX_GRAPH_FONT_NAME',      'DejaVuSans'); // font file name
90:define('ZBX_FONT_NAME', 'DejaVuSans');
#




登陆zabbix,点击右侧Profile,将Language修改为Chinese(zh_CN) 即简体中文后点Save 保存,退出站点,重新登录之后,默认界面已经是中文显示




页: [1]
查看完整版本: Centos7.1安装部署Zabbix2.2.6步骤详解