目录
操作环境:VMware Workstation
操作系统:Centos 6.5
前言
最近在学习Zabbix,发现这个监控系统对于初学者还真是不好装,期间遇到了好多问题,去网上搜了好长时间,也看了好多博客,最后终于安装成功,故把详细命令和遇到的一些坑给总结一下。以下介绍两种安装方式,分别是编译安装和yum安装
编译安装
1、获取zabbix安装包
#可去下面地址中去获取最新版本的Zabbix安装包,建议用迅雷下载而不用wget获取(wget获取速度太慢了,迅雷下载后用rz上传到Centos系统中)
#https://sourceforge.net/projects/zabbix/files/latest/download?source=files
#由于更新原因,现在最新的版本已经不是3.4.3。有些命令在粘贴复制的时候需要自己手动改版本号
#解压
tar -zxvf zabbix-3.4.3.tar.gz
- 1
- 2
- 3
- 4
- 5
2、安装mysql5.6,由于Centos6.5默认安装的版本是5.1的,故要先卸载再安装5.6版本的
yum remove mysql*
- 1
引导mysql5.6的yum源
#vim /etc/yum.repos.d/mysql.repo
#写入一下内容
[mysql56]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
#vim /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
#导入gpgcheck文件,去官网复制然后粘贴,由于内容太长这里就不列出来了
#(https://dev.mysql.com/doc/refman/5.6/en/checking-gpg-signature.html)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
安装mysql5.6
yum install mysql-community-server
- 1
若有报错:warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY
gpg --import /etc/pki/rpm-gpg/RPM*
rpm --import /etc/pki/rpm-gpg/RPM*
- 1
- 2
编辑mysql的配置文件并添加一下内容
#vim my.cnf
[mysqld]
innodb_file_per_table=1
- 1
- 2
- 3
- 4
3、安装php5.6和Apache服务
2018-04-12补充说明
今天我测试了一下下面安装的php56 yum源(rpm 安装的latest.rpm),有点问题,我看了生成的三个repo文件,里面的mirrolist都是https的,于是我进浏览器测试访问,结果访问失败,故我把三个repo文件里面的https全部替换为http,再次测试就成功了。yum源也可以正常访问。若是有出现此类情况的网友可以参照这种方法解决。
#获取yum源
rpm -ivh http://repo.webtatic.com/yum/el6/latest.rpm
#安装下列所有包
yum -y install httpd php56w php56w-gd php56w-mysqlnd php56w-bcmath php56w-mbstring php56w-xml php56w-ldap
#编辑php的ini文件(vim /etc/php.ini)并修改一下内容,注意date.timezone一定要写对,否则在配置完zabbix后,显示的界面全部报错
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
always_populate_raw_post_data = -1
#配置/etc/httpd/conf/httpd.conf
DocumentRoot "/var/www/html/zabbix"
<Directory "/var/www/html/zabbix">
ServerName 127.0.0.1
DirectoryIndex index.html index.html.var index.php
#设置web前端
mkdir /var/www/html/zabbix
cp -a zabbix-3.4.3/frontends/php/ /var/www/html/zabbix
#设置apache的执行和所有者
chown -R apache:apache /var/www/html/zabbix
#赋予可执行权限
chmod +x /var/www/html/zabbix/conf/
- 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
4、创建zabbix用户和组
groupadd zabbix
useradd -g zabbix zabbix
- 1
- 2
5、编译并安装zabbix
cd zabbix-3.4.3/
./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --enable-java --with-net-snmp --with-libcurl --with-libxml2 --with-unixodbc --with-ssh2 --with-openipmi --with-openssl --prefix=/usr/local/zabbix
#可能会出现以下的报错信息,建议直接全部安装
yum install gcc* mysql-devel libxml2-devel net-snmp* java* curl-devel -y
#(1)configure: error: in `/zabbix/zabbix-3.4.3':
#configure: error: no acceptable C compiler found in $PATH
yum install gcc* -y
#(2)configure: error: MySQL library not found
yum install mysql-devel -y
#(3)configure: error: LIBXML2 library not found
yum install libxml2-devel -y
#(4)configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config
yum install net-snmp* -y
#(5)configure: error: Unable to find "javac" executable in path
yum install java* -y
#在装java*的时候,我看到要安装1个多G的东西,于是我就改成了javac*,发现后来编译还是出错,所以还是老老实实装java*吧,虽然装的包有点多,但至少能编译成功啊!
#(6)configure: error: Curl library not found
yum install curl-devel -y
#以上是在编译的过程中可能会报错的信息及解决方法,当然也可能还有其它报错这里没列举出来,有问题找度娘,没毛病!
#编译成功会出现
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <http://www.zabbix.com> *
***********************************************************
make install
- 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
6、修改配置文件zabbix_server.conf
#vim /usr/local/zabbix/etc/zabbix_server.conf
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
- 1
- 2
- 3
- 4
- 5
7、添加Zabbix服务器和Zabbix代理启动脚本
cp zabbix-3.4.3/misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix_server
cp zabbix-3.4.3/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix_agentd
#修改 /etc/init.d/zabbix_server /etc/init.d/zabbix_agentd的BASEDIR=/usr/local/为BASEDIR=/usr/local/zabbix
sed -i 's#BASEDIR=/usr/local/#BASEDIR=/usr/local/zabbix#g' /etc/init.d/zabbix_{server,agentd}
- 1
- 2
- 3
- 4
- 5
8、创建zabbix数据库并把导入一些sql表
#进入数据库,刚装的mysql密码为空,直接回车就行
mysql
mysql>CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
mysql>GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost IDENTIFIED BY 'zabbix';
mysql>SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| zabbix |
+--------------------+
4 rows in set (0.00 sec)
mysql>use zabbix;
mysql>source zabbix-3.4.3/database/mysql/schema.sql;
mysql>source zabbix-3.4.3/database/mysql/images.sql;
mysql>source zabbix-3.4.3/database/mysql/data.sql;
mysql>show tables;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
| auditlog |
| auditlog_details |
| autoreg_host |
| conditions |
| config |
| corr_condition |
| corr_condition_group |
| corr_condition_tag |
| corr_condition_tagpair |
| corr_condition_tagvalue |
| corr_operation |
| correlation |
| dashboard |
| dashboard_user |
| dashboard_usrgrp |
| dbversion |
| dchecks |
| dhosts |
| drules |
| dservices |
| escalations |
| event_recovery |
| event_tag |
| 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 |
| httpstep_field |
| httpstepitem |
| httptest |
| httptest_field |
| httptestitem |
| icon_map |
| icon_mapping |
| ids |
| images |
| interface |
| interface_discovery |
| item_application_prototype |
| item_condition |
| item_discovery |
| item_preproc |
| items |
| items_applications |
| maintenances |
| maintenances_groups |
| maintenances_hosts |
| maintenances_windows |
| mappings |
| media |
| media_type |
| opcommand |
| opcommand_grp |
| opcommand_hst |
| opconditions |
| operations |
| opgroup |
| opinventory |
| opmessage |
| opmessage_grp |
| opmessage_usr |
| optemplate |
| problem |
| problem_tag |
| profiles |
| proxy_autoreg_host |
| proxy_dhistory |
| proxy_history |
| regexps |
| rights |
| screen_user |
| screen_usrgrp |
| screens |
| screens_items |
| scripts |
| service_alarms |
| services |
| services_links |
| services_times |
| sessions |
| slides |
| slideshow_user |
| slideshow_usrgrp |
| slideshows |
| sysmap_element_trigger |
| sysmap_element_url |
| sysmap_shape |
| sysmap_url |
| sysmap_user |
| sysmap_usrgrp |
| sysmaps |
| sysmaps_elements |
| sysmaps_link_triggers |
| sysmaps_links |
| task |
| task_acknowledge |
| task_close_problem |
| task_remote_command |
| task_remote_command_result |
| timeperiods |
| trends |
| trends_uint |
| trigger_depends |
| trigger_discovery |
| trigger_tag |
| triggers |
| users |
| users_groups |
| usrgrp |
| valuemaps |
| widget |
| widget_field |
+----------------------------+
140 rows in set (0.00 sec)
mysql>\q
- 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
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
9、启动所有服务,并设置开机自启
#启动Apache服务
service httpd start
#启用mysql服务
service mysqld start
/etc/init.d/zabbix_server start
/etc/init.d/zabbix_agentd start
#设置开机自启
chkconfig httpd on
chkconfig mysqld on
chkconfig --add /etc/init.d/zabbix_server
chkconfig --add /etc/init.d/zabbix_agentd
chkconfig zabbix_server on
chkconfig zabbix_agentd on
#查看端口号80、3306、10050(zabbix_agentd)、10051(zabbix_server)是否监听
ss -tnul
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
10、浏览器访问zabbix页面并进行初始化
默认用户名:Admin
密码:zabbix
yum安装
1、引导zabbix3.4的yum源
rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/6/x86_64/zabbix-release-3.4-1.el6.noarch.rpm
- 1
2、安装mysql5.6,由于Centos6.5默认安装的版本是5.1的,故要先卸载再安装5.6版本的
yum remove mysql*
- 1
引导mysql5.6的yum源
#vim /etc/yum.repos.d/mysql.repo
#写入一下内容
[mysql56]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
#vim /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
#导入gpgcheck文件,去官网复制然后粘贴,由于内容太长这里就不列出来了
#(https://dev.mysql.com/doc/refman/5.6/en/checking-gpg-signature.html)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
安装mysql5.6
yum install mysql-community-server
- 1
若有报错:warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY
gpg --import /etc/pki/rpm-gpg/RPM*
rpm --import /etc/pki/rpm-gpg/RPM*
- 1
- 2
编辑mysql的配置文件并添加一下内容
#vim my.cnf
[mysqld]
innodb_file_per_table=1
- 1
- 2
- 3
- 4
创建zabbix数据库并把导入一些sql表
#进入数据库,刚装的mysql密码为空,直接回车就行
mysql
mysql>CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
mysql>GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost IDENTIFIED BY 'zabbix';
mysql>SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| zabbix |
+--------------------+
4 rows in set (0.00 sec)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
3、安装php5.6和Apache服务
#获取yum源
rpm -ivh http://repo.webtatic.com/yum/el6/latest.rpm
#安装下列所有包
yum -y install httpd php56w php56w-gd php56w-mysqlnd php56w-bcmath php56w-mbstring php56w-xml php56w-ldap
#编辑php的ini文件(vim /etc/php.ini)并修改一下内容,注意date.timezone一定要写对,否则在配置完zabbix后,显示的界面全部报错
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
always_populate_raw_post_data = -1
#配置/etc/httpd/conf/httpd.conf
DocumentRoot "/var/www/html/zabbix"
<Directory "/var/www/html/zabbix">
ServerName 127.0.0.1
DirectoryIndex index.html index.html.var index.php
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
4、创建zabbix用户和组
groupadd zabbix
useradd -g zabbix zabbix
- 1
- 2
5、yum安装zabbix
若一台服务器上即是zabbix_server又是zabbix_agent和web Server则需要安装以下程序包
yum install zabbix zabbix-agent zabbix-get zabbix-sender zabbix-server zabbix-server-mysql zabbix-web zabbix-web-mysql -y
- 1
若服务器是zabbix_server
yum install zabbix zabbix-get zabbix-server zabbix-server-mysql zabbix-sender -y
- 1
若服务器是zabbix_agent
yum install zabbix zabbix-agent zabbix-get zabbix-sender -y
- 1
若服务器是web Server
yum install zabbix zabbix-get zabbix-sender zabbix-web zabbix-web-mysql -y
- 1
6、往数据库中导入一些数据
cd /usr/share/doc/zabbix-server-mysql-3.4.3/create/
#把下面三个表给导入zabbix数据库中
mysql zabbix < schema.sql
mysql zabbix < images.sql
mysql zabbix < data.sql
- 1
- 2
- 3
- 4
- 5
- 6
7、修改/etc/zabbix/zabbix_server.conf 和 zabbix_agentd.conf
#若是本机
DBHost=localhost
#若不是本机
DBHost=x.x.x.x
#设置数据库用户名和密码,可自己在数据库中设置用户和密码
DBUser=
DBPassword=
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
8、浏览器访问zabbix页面并进行初始化,详见上面步骤
总结:两种安装方法大同小异,核心思想还是一样的,就是在安装的时候可能会遇到很多坑,有报错又解决不了就找度娘吧,一般都能解决的!
END!
参考博客:
http://blog.csdn.net/mingjie1212/article/details/54619461
http://blog.csdn.net/mingjie1212/article/details/52704987
http://blog.csdn.net/linux_player_c/article/details/52287921
zabbix深度了解
转载至https://blog.csdn.net/mr_rsq/article/details/78457587