CentOS 6.5上安装Zabbix 2.4.8
环境说明主机名角色IP地址
zabbix.contoso.comzabbix server192.168.49.129
zabbix-db.contoso.commysql server192.168.49.133
一、环境准备
以其中一台为例,两台都需要完成以下准备工作:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 关闭iptables
# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
# 禁用selinux
# getenforce
Disabled
# 添加时间同步定时任务
# crontab -l
0 * * * * /usr/sbin/ntpdate 210.72.145.44 64.147.116.229 time.nist.gov
# 修改主机名
# hostname
zabbix.contoso.com
# 安装必要的依赖包
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb krb5-devel libidn libidn-devel openssl openssl-devel
二、编译安装zabbix
以下操作在zabbix server(zabbix.contoso.com)上完成:
1
2
3
4
5
6
mkdir -p /opt/tools
cd /opt/tools/
wget http://prdownloads.sourceforge.net/zabbix/zabbix-2.4.8.tar.gz?download
tar -zxf zabbix-2.4.8.tar.gz
cd zabbix-2.4.8
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-net-snmp --with-mysql --with-libcurl
如果编译中出现下面的错误:
1)configure: error: MySQL library not found
解决方法:yum install mysql-devel -y
2)configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config
解决方法:yum install net-snmp-devel -y
另外,编译成功的标志是,结尾出现下面的字样:
1
2
3
4
5
6
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <http://www.zabbix.com> *
***********************************************************
最后,使用make install进行安装:
1
make && make install
三、安装MySQL数据库
以下操作在MySQL server(zabbix-db.contoso.com)上进行:
1、安装MySQL 5.6.16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
yum -y install make gcc-c++ cmake bison-develncurses-devel
mkdir -p /opt/tools
cd /opt/tools/
wget wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.16.tar.gz
tar -zxf mysql-5.6.16.tar.gz
cd mysql-5.6.16
cmake \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
> -DMYSQL_DATADIR=/usr/local/mysql/data \
> -DSYSCONFDIR=/etc \
> -DWITH_MYISAM_STORAGE_ENGINE=1 \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_MEMORY_STORAGE_ENGINE=1 \
> -DWITH_READLINE=1 \
> -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
> -DMYSQL_TCP_PORT=3306 \
> -DENABLED_LOCAL_INFILE=1 \
> -DWITH_PARTITION_STORAGE_ENGINE=1 \
> -DEXTRA_CHARSETS=all \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci
make && make install
2、初始化MySQL数据库
1
2
3
4
5
6
7
8
9
10
11
12
# 创建用户并授权
groupadd mysql
useradd -g mysql mysql
chown -R mysql:mysql /usr/local/mysql
# 运行初始化脚本进行初始化
# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
# 数据库配置和启动脚本修改
# mv /etc/my.cnf /etc/my.cnf.bak #如果不把/etc/my.cnf改名,后面启动编译安装的MySQL会出错
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
3、启动MySQL服务
1
2
3
4
5
6
7
8
9
10
11
# /etc/init.d/mysqld start
Starting MySQL.... SUCCESS!
# ps -ef|grep mysql
root 16925 10 05:24 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/zabbix-db.contoso.com.pid
mysql 17033169254 05:24 pts/0 00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/zabbix-db.contoso.com.err --pid-file=/usr/local/mysql/data/zabbix-db.contoso.com.pid
root 17064 10500 05:25 pts/0 00:00:00 grep mysql
# netstat -lnt|grep 3306
tcp 0 0 :::3306 :::* LISTEN
# lsof -i :3306
COMMAND PIDUSER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld17033 mysql 10uIPv660027 0t0TCP *:mysql (LISTEN)
4、添加MySQL路径到环境变量
1
2
echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
source /etc/profile
5、向MySQL数据库中导入zabbix数据
1)设置MySQL中的root用户密码
1
mysqladmin -u root password "123456"#给mysql中的root用户设置密码
2)将zabbix安装文件中的mysql数据拷贝到MySQL server(zabbix-db.contoso.com)中
注:该步骤要在zabbix.contoso.com上完成
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# cd /opt/tools/zabbix-2.4.8/database/mysql/
# ll
total 2988
-rw-r--r-- 1 1000 1000972946 Apr 20 05:57 data.sql
-rw-r--r-- 1 1000 1000 1978341 Apr 20 05:51 images.sql
-rw-r--r-- 1 1000 1000104816 Apr 20 05:57 schema.sql
# scp data.sql images.sql schema.sql root@192.168.49.133:/tmp/
The authenticity of host '192.168.49.133 (192.168.49.133)' can't be established.
RSA key fingerprint is f9:ce:14:5d:cd:bb:3c:b4:0d:0b:fc:21:3a:92:43:6b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.49.133' (RSA) to the list of known hosts.
root@192.168.49.133's password:
data.sql 100%950KB 950.1KB/s 00:00
images.sql 100% 1932KB 1.9MB/s 00:00
schema.sql 100%102KB 102.4KB/s 00:00
3)将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
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.16 Source distribution
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.04 sec)
mysql> create database zabbix;
Query OK, 1 row affected (0.03 sec)
mysql> use zabbix;
Database changed
mysql> source /tmp/schema.sql;
Query OK, 0 rows affected (0.48 sec)
...
mysql> source /tmp/images.sql;
Query OK, 1 row affected (0.03 sec)
...
mysql> source /tmp/data.sql;
Query OK, 0 rows affected (0.00 sec)
...
mysql> show tables;
+-----------------------+
| Tables_in_zabbix |
+-----------------------+
| acknowledges |
| actions |
| alerts |
| application_template|
| applications |
| auditlog |
| auditlog_details |
| autoreg_host |
| conditions |
| config |
| dbversion |
| dchecks |
| dhosts |
| drules |
| dservices |
| escalations |
| events |
| expressions |
| functions |
| globalmacro |
| globalvars |
| graph_discovery |
| graph_theme |
| graphs |
| graphs_items |
| group_discovery |
| group_prototype |
| groups |
| history |
| history_log |
| history_str |
| history_text |
| history_uint |
| host_discovery |
| host_inventory |
| hostmacro |
| hosts |
| hosts_groups |
| hosts_templates |
| housekeeper |
| httpstep |
| httpstepitem |
| httptest |
| httptestitem |
| icon_map |
| icon_mapping |
| ids |
| images |
| interface |
| interface_discovery |
| item_condition |
| item_discovery |
| items |
| items_applications |
| maintenances |
| maintenances_groups |
| maintenances_hosts |
| maintenances_windows|
| mappings |
| media |
| media_type |
| opcommand |
| opcommand_grp |
| opcommand_hst |
| opconditions |
| operations |
| opgroup |
| opmessage |
| opmessage_grp |
| opmessage_usr |
| optemplate |
| profiles |
| proxy_autoreg_host |
| proxy_dhistory |
| proxy_history |
| regexps |
| rights |
| screens |
| screens_items |
| scripts |
| service_alarms |
| services |
| services_links |
| services_times |
| sessions |
| slides |
| slideshows |
| sysmap_element_url |
| sysmap_url |
| sysmaps |
| sysmaps_elements |
| sysmaps_link_triggers |
| sysmaps_links |
| timeperiods |
| trends |
| trends_uint |
| trigger_depends |
| trigger_discovery |
| triggers |
| user_history |
| users |
| users_groups |
| usrgrp |
| valuemaps |
+-----------------------+
104 rows in set (0.08 sec)
mysql> GRANT ALL ON zabbix.* TO 'zbxuser'@'192.168.49.%' IDENTIFIED BY 'zbx@123456';
Query OK, 0 rows affected (0.09 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)
mysql> quit
Bye
四、安装php和apache
1
# yum -y install php php-devel curl curl-devel net-snmp net-snmp-devel perl-DBI php-mysql php-mbstring php-gd php-xml php-bcmath httpd
五、配置zabbix server
1、创建zabbix用户
1
2
3
# useradd zabbix
# id zabbix
uid=500(zabbix) gid=500(zabbix) groups=500(zabbix)
2、编辑zabbix server配置文件
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
# cp /usr/local/zabbix/etc/zabbix_server.conf /usr/local/zabbix/etc/zabbix_server.conf.bak
# vi /usr/local/zabbix/etc/zabbix_server.conf
# diff /usr/local/zabbix/etc/zabbix_server.conf.bak /usr/local/zabbix/etc/zabbix_server.conf
68c68
< # DBHost=localhost
---
> DBHost=192.168.49.133 #修改数据库主机(可以是IP或主机名),前提是数据库和zabbix不在同一台server上
92c92
< # DBUser=
---
> DBUser=zbxuser #修改默认的数据库授权用户
94c94
< DBUser=root
---
> #DBUser=root
102c102
< # DBPassword=
---
> DBPassword=zbx@123456#填写数据库用户的密码
109a110
> DBSocket=/var/lib/mysql/mysql.sock#指定mysql的socket文件位置
117c118
< # DBPort=3306
---
> DBPort=3306#修改MySQL端口号
3、拷贝zabbix前端web目录到apache目录
1
2
3
# cp -r /opt/tools/zabbix-2.4.8/frontends/php /var/www/html/
# mv /var/www/html/php /var/www/html/zabbix
# chown -R apache:apache /var/www/html/
4、生成并修改zabbix server启动脚本
1
2
3
4
5
6
#从zabbix安装文件的目录中拷贝脚本到/etc/init.d/下
# cp -r /opt/tools/zabbix-2.4.8/misc/init.d/fedora/core/* /etc/init.d/
#因为脚本中的zabbix根目录是/usr/local,所以需要修改为/usr/local/zabbix
#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
5、启动zabbix server并检查状态
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
58
59
60
61
62
# /etc/init.d/zabbix_server start
Starting zabbix_server:
# ps -ef|grep zabbix
zabbix 17274 10 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server
zabbix 17275172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: configuration syncer
zabbix 17276172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: db watchdog
zabbix 17277172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #1
zabbix 17278172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #2
zabbix 17279172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #3
zabbix 17280172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #4
zabbix 17281172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #5
zabbix 17282172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: unreachable poller #1
zabbix 17283172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #1
zabbix 17284172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #2
zabbix 17285172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #3
zabbix 17286172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #4
zabbix 17287172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #5
zabbix 17288172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: icmp pinger #1
zabbix 17289172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: alerter
zabbix 17290172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: housekeeper
zabbix 17291172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: timer #1
zabbix 17292172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: http poller #1
zabbix 17293172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: discoverer #1
zabbix 17294172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: history syncer #1
zabbix 17295172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: history syncer #2
zabbix 17296172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: history syncer #3
zabbix 17297172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: history syncer #4
zabbix 17298172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: escalator
zabbix 17299172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: proxy poller #1
zabbix 17300172740 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: self-monitoring
root 17302 10690 07:52 pts/0 00:00:00 grep zabbix
# netstat -lnt|grep 10051
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN
# lsof -i :10051
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
zabbix_se 17274 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17275 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17276 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17277 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17278 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17279 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17280 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17281 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17282 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17283 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17284 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17285 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17286 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17287 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17288 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17289 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17290 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17291 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17292 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17293 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17294 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17295 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17296 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17297 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17298 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17299 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
zabbix_se 17300 zabbix 4uIPv433770 0t0TCP *:zabbix-trapper (LISTEN)
6、启动httpd服务
1
2
3
4
# /etc/init.d/httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for zabbix.contoso.com
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
7、设置开机启动
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# zabbix-db上设置开机启动mysql
# chkconfig --add mysqld
# chkconfig mysqld on
# chkconfig --list|grep mysqld
mysqld 0:off1:off2:on3:on4:on5:on6:off
#zabbix server上设置开机启动zabbix_server和httpd服务
# chkconfig --add zabbix_server
# chkconfig zabbix_server on
# chkconfig --list|grep zabbix
zabbix_server0:off1:off2:on3:on4:on5:on6:off
# chkconfig httpd on
# chkconfig --list|grep httpd
httpd 0:off1:off2:on3:on4:on5:on6:off
六、在浏览器中进行图形界面配置zabbix
打开浏览器,输入http://zabbix_server_ip/zabbix,如果上面的步骤无误就会出现上面的画面。
这里是必要安装条件检查,上面有一些php的参数默认是不正确的,需要进行调整,至于调整的值都有显示。修改的方法如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# cp /etc/php.ini /etc/php.ini.bak$(date +%F)
# vi /etc/php.ini
# diff /etc/php.ini.bak2016-10-06 /etc/php.ini
440c440
< max_execution_time = 30
---
> max_execution_time = 300
449c449
< max_input_time = 60
---
> max_input_time = 300
729c729
< post_max_size = 8M
---
> post_max_size = 16M
946a947
> date.timezone = Asia/Shanghai
注意,php.ini修改完成后,上面的错误刷新之后仍然存在,需要重启httpd和zabbix server服务。
1
2
3
4
5
6
7
8
9
# /etc/init.d/mysqld restart
Shutting down MySQL.... SUCCESS!
Starting MySQL..... SUCCESS!
#
# /etc/init.d/httpd restart
Stopping httpd:
Starting httpd: httpd: apr_sockaddr_info_get() failed for zabbix.contoso.com
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0. for ServerName
再次进行必要条件检查,可以看到目前所有的条件都已经满足,全部都是OK就可以进行下一步了。
配置数据库连接,根据需要输入数据库的相关信息,然后点击下面的按钮进行连接测试,如果测试通过,再进行下一步。
这一步是zabbix server的详细信息,可以根据实际情况进行修改,但是注意端口一定要正确。
配置结束,给出安装前的配置总结,确认就开始安装了。
安装的过程会比较快,这是安装完成的画面。
好的,成功出现登录界面,默认的登录账号为admin,密码zabbix。
页:
[1]