环境说明
主机名 | 角色 | IP地址 |
zabbix.contoso.com | zabbix server | 192.168.49.129 |
zabbix-db.contoso.com | mysql server | 192.168.49.133 |
一、环境准备
以其中一台为例,两台都需要完成以下准备工作:
# 关闭iptables [root@zabbix ~]# 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 [root@zabbix ~]# getenforce Disabled # 添加时间同步定时任务 [root@zabbix ~]# crontab -l 0 * * * * /usr/sbin/ntpdate 210.72.145.44 64.147.116.229 time.nist.gov # 修改主机名 [root@zabbix ~]# 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)上完成:
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
另外,编译成功的标志是,结尾出现下面的字样:
*********************************************************** * Now run 'make install' * * * * Thank you for using Zabbix! * * <http://www.zabbix.com> * ***********************************************************
最后,使用make install进行安装:
make && make install
三、安装MySQL数据库
以下操作在MySQL server(zabbix-db.contoso.com)上进行:
1、安装MySQL 5.6.16
yum -y install make gcc-c++ cmake bison-devel ncurses-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数据库
# 创建用户并授权 groupadd mysql useradd -g mysql mysql chown -R mysql:mysql /usr/local/mysql # 运行初始化脚本进行初始化 [root@zabbix-db mysql-5.6.16]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql # 数据库配置和启动脚本修改 [root@zabbix-db mysql-5.6.16]# mv /etc/my.cnf /etc/my.cnf.bak #如果不把/etc/my.cnf改名,后面启动编译安装的MySQL会出错 [root@zabbix-db mysql-5.6.16]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@zabbix-db mysql-5.6.16]# chmod +x /etc/init.d/mysqld
3、启动MySQL服务
[root@zabbix-db mysql-5.6.16]# /etc/init.d/mysqld start Starting MySQL.... SUCCESS! [root@zabbix-db mysql-5.6.16]# ps -ef|grep mysql root 16925 1 0 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 17033 16925 4 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 1050 0 05:25 pts/0 00:00:00 grep mysql [root@zabbix-db mysql-5.6.16]# netstat -lnt|grep 3306 tcp 0 0 :::3306 :::* LISTEN [root@zabbix-db mysql-5.6.16]# lsof -i :3306 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 17033 mysql 10u IPv6 60027 0t0 TCP *:mysql (LISTEN)
4、添加MySQL路径到环境变量
echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile source /etc/profile
5、向MySQL数据库中导入zabbix数据
1)设置MySQL中的root用户密码
mysqladmin -u root password "123456" #给mysql中的root用户设置密码
2)将zabbix安装文件中的mysql数据拷贝到MySQL server(zabbix-db.contoso.com)中
注:该步骤要在zabbix.contoso.com上完成
[root@zabbix zabbix-2.4.8]# cd /opt/tools/zabbix-2.4.8/database/mysql/ [root@zabbix mysql]# ll total 2988 -rw-r--r-- 1 1000 1000 972946 Apr 20 05:57 data.sql -rw-r--r-- 1 1000 1000 1978341 Apr 20 05:51 p_w_picpaths.sql -rw-r--r-- 1 1000 1000 104816 Apr 20 05:57 schema.sql [root@zabbix mysql]# scp data.sql p_w_picpaths.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 p_w_picpaths.sql 100% 1932KB 1.9MB/s 00:00 schema.sql 100% 102KB 102.4KB/s 00:00
3)将zabbix相关的数据导入到MySQL数据库中
[root@zabbix-db mysql-5.6.16]# 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/p_w_picpaths.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 | | p_w_picpaths | | 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
[root@zabbix mysql]# 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用户
[root@zabbix mysql]# useradd zabbix [root@zabbix mysql]# id zabbix uid=500(zabbix) gid=500(zabbix) groups=500(zabbix)
2、编辑zabbix server配置文件
[root@zabbix mysql]# cp /usr/local/zabbix/etc/zabbix_server.conf /usr/local/zabbix/etc/zabbix_server.conf.bak [root@zabbix mysql]# vi /usr/local/zabbix/etc/zabbix_server.conf [root@zabbix mysql]# 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目录
[root@zabbix mysql]# cp -r /opt/tools/zabbix-2.4.8/frontends/php /var/www/html/ [root@zabbix mysql]# mv /var/www/html/php /var/www/html/zabbix [root@zabbix mysql]# chown -R apache:apache /var/www/html/
4、生成并修改zabbix server启动脚本
#从zabbix安装文件的目录中拷贝脚本到/etc/init.d/下 [root@zabbix mysql]# cp -r /opt/tools/zabbix-2.4.8/misc/init.d/fedora/core/* /etc/init.d/ #因为脚本中的zabbix根目录是/usr/local,所以需要修改为/usr/local/zabbix [root@zabbix mysql]# sed -i 's#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g' /etc/init.d/zabbix_server [root@zabbix mysql]# sed -i 's#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g' /etc/init.d/zabbix_agentd
5、启动zabbix server并检查状态
[root@zabbix mysql]# /etc/init.d/zabbix_server start Starting zabbix_server: [ OK ] [root@zabbix mysql]# ps -ef|grep zabbix zabbix 17274 1 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server zabbix 17275 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: configuration syncer [waiting 60 sec for processes] zabbix 17276 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: db watchdog [synced alerts config in 0.040259 sec, idle 60 sec] zabbix 17277 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #1 [got 0 values in 0.000003 sec, idle 5 sec] zabbix 17278 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #2 [got 0 values in 0.000006 sec, idle 5 sec] zabbix 17279 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #3 [got 0 values in 0.000005 sec, idle 5 sec] zabbix 17280 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #4 [got 0 values in 0.000003 sec, idle 5 sec] zabbix 17281 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #5 [got 0 values in 0.000002 sec, idle 5 sec] zabbix 17282 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: unreachable poller #1 [got 0 values in 0.000003 sec, idle 5 sec] zabbix 17283 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #1 [processed data in 0.000000 sec, waiting for connection] zabbix 17284 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #2 [processed data in 0.000000 sec, waiting for connection] zabbix 17285 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #3 [processed data in 0.000000 sec, waiting for connection] zabbix 17286 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #4 [processed data in 0.000000 sec, waiting for connection] zabbix 17287 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #5 [processed data in 0.000000 sec, waiting for connection] zabbix 17288 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: icmp pinger #1 [got 0 values in 0.000008 sec, idle 5 sec] zabbix 17289 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: alerter [sent alerts: 0 success, 0 fail in 0.001585 sec, idle 30 sec] zabbix 17290 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: housekeeper [startup idle for 30 minutes] zabbix 17291 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: timer #1 [processed 0 triggers, 0 events in 0.000000 sec, 0 maintenances in 0.000000 sec, idle 30 sec] zabbix 17292 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: http poller #1 [got 0 values in 0.001478 sec, idle 5 sec] zabbix 17293 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: discoverer #1 [processed 0 rules in 0.000770 sec, idle 60 sec] zabbix 17294 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: history syncer #1 [synced 0 items in 0.000003 sec, idle 5 sec] zabbix 17295 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: history syncer #2 [synced 0 items in 0.000002 sec, idle 5 sec] zabbix 17296 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: history syncer #3 [synced 0 items in 0.000001 sec, idle 5 sec] zabbix 17297 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: history syncer #4 [synced 0 items in 0.000003 sec, idle 5 sec] zabbix 17298 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: escalator [processed 0 escalations in 0.001206 sec, idle 3 sec] zabbix 17299 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: proxy poller #1 [exchanged data with 0 proxies in 0.000006 sec, idle 5 sec] zabbix 17300 17274 0 07:52 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: self-monitoring [processed data in 0.000007 sec, idle 1 sec] root 17302 1069 0 07:52 pts/0 00:00:00 grep zabbix [root@zabbix mysql]# netstat -lnt|grep 10051 tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN [root@zabbix mysql]# lsof -i :10051 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME zabbix_se 17274 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17275 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17276 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17277 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17278 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17279 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17280 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17281 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17282 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17283 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17284 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17285 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17286 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17287 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17288 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17289 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17290 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17291 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17292 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17293 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17294 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17295 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17296 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17297 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17298 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17299 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN) zabbix_se 17300 zabbix 4u IPv4 33770 0t0 TCP *:zabbix-trapper (LISTEN)
6、启动httpd服务
[root@zabbix mysql]# /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 [ OK ]
7、设置开机启动
# zabbix-db上设置开机启动mysql [root@zabbix-db mysql-5.6.16]# chkconfig --add mysqld [root@zabbix-db mysql-5.6.16]# chkconfig mysqld on [root@zabbix-db mysql-5.6.16]# chkconfig --list|grep mysqld mysqld 0:off1:off2:on3:on4:on5:on6:off #zabbix server上设置开机启动zabbix_server和httpd服务 [root@zabbix mysql]# chkconfig --add zabbix_server [root@zabbix mysql]# chkconfig zabbix_server on [root@zabbix mysql]# chkconfig --list|grep zabbix zabbix_server 0:off1:off2:on3:on4:on5:on6:off [root@zabbix mysql]# chkconfig httpd on [root@zabbix mysql]# chkconfig --list|grep httpd httpd 0:off1:off2:on3:on4:on5:on6:off
六、在浏览器中进行图形界面配置zabbix
打开浏览器,输入http://zabbix_server_ip/zabbix,如果上面的步骤无误就会出现上面的画面。
这里是必要安装条件检查,上面有一些php的参数默认是不正确的,需要进行调整,至于调整的值都有显示。修改的方法如下:
[root@zabbix mysql]# cp /etc/php.ini /etc/php.ini.bak$(date +%F) [root@zabbix mysql]# vi /etc/php.ini [root@zabbix mysql]# 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服务。
[root@zabbix-db mysql-5.6.16]# /etc/init.d/mysqld restart Shutting down MySQL.... SUCCESS! Starting MySQL..... SUCCESS! [root@zabbix-db mysql-5.6.16]# [root@zabbix mysql]# /etc/init.d/httpd restart Stopping httpd: [ OK ] 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 ]
再次进行必要条件检查,可以看到目前所有的条件都已经满足,全部都是OK就可以进行下一步了。
配置数据库连接,根据需要输入数据库的相关信息,然后点击下面的按钮进行连接测试,如果测试通过,再进行下一步。
这一步是zabbix server的详细信息,可以根据实际情况进行修改,但是注意端口一定要正确。
配置结束,给出安装前的配置总结,确认就开始安装了。
安装的过程会比较快,这是安装完成的画面。
好的,成功出现登录界面,默认的登录账号为admin,密码zabbix。