- A+
Zabbix官方安装文档:https://www.zabbix.com/download?zabbix=3.4&os_distribution=centos&os_version=6&db=MySQL
1. 系统环境
[root@linux-node1 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@linux-node1 ~]# uname -r
3.10.0-327.28.2.el7.x86_64
[root@linux-node1 ~]# vim /etc/selinux/config
SELINUX=disabled
[root@linux-node1 ~]# setenforce 0
setenforce: SELinux is disabled
[root@linux-node1 ~]# hostname -I
192.168.56.11
[root@linux-node1 ~]# hostname
linux-node1
2. 环境准备
配置zabbix3.2的YUM源(需要将zabbix-server端与zabbix-agent端都要配置)
[root@linux-node1 ~]# vim /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http://mirrors.aliyun.com/zabbix/zabbix/3.2/rhel/7/x86_64/
enabled=1
gpgcheck=0
[zabbix-non-supported]
name=Zabbix Official Repository non-supported -
$basearch
baseurl=http://mirrors.aliyun.com/zabbix/zabbix/3.2/rhel/7/x86_64/
enabled=1
gpgcheck=0
说明:zabbix的官方源:http://repo.zabbix.com/zabbix/2.2/rhel/6/x86_64/ 这里换成阿里云的源,这样比较快
3. 安装部署
3.1 zabbix-server安装部署
1. 安装zabbix-server相关软件包
yum -y install zabbix-server-mysql zabbix-web-mysql mariadb mariadb-server
2. 启动mariadb数据库
systemctl start mariadb
systemctl enable mariadb
3. 创建初始数据库通过以下命令在 MySQL 上创建 Zabbix 数据库和用户并授权
[root@linux-node1 ~]# mysql
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by '123456';
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> quit
Bye
#创建zabbix数据库并创建用户zabbix设置密码为123456
4. 现在导入zabbix自带的初始模式和数据;请务必插入正确的版本3.2.*,系统提示您输入新创建的密码
[root@linux-node1 ~]# zcat /usr/share/doc/zabbix-server-mysql-3.2.*/create.sql.gz | mysql -uzabbix -p zabbix #<== 这里的zabbix是zabbix数据库
Enter password: 123456 #<== 输入设置的zabbix用户密码
5.在 zabbix_server.conf 中编辑服务器主机,名称,用户和密码,如下所示,其中 DBPassword是您设置的创建初始数据库的密码:
[root@linux-node1 ~]# vim /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName =zabbix
DBUser=zabbix
DBPassword=123456
[root@linux-node1 ~]# grep '^[DB]' /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName =zabbix
DBUser=zabbix
DBPassword=123456
6. 启动zabbux-server服务,并设置开机自启动
systemctl start zabbix-server
systemctl enable zabbix-server
systemctl status zabbix-server
7. Zabbix frontend 的 Apache 配置文件位于/etc/httpd/conf.d/zabbix.conf 中。一些 PHP 设置已配置。但是有必要取消注释“ date.timezone”设置,并为您设置正确的时区
[root@linux-node1 ~]# vim
/etc/httpd/conf.d/zabbix.conf
12 <IfModule mod_php5.c>
13 php_value max_execution_time 300
14 php_value memory_limit 128M
15 php_value post_max_size 16M
16 php_value upload_max_filesize 2M
17 php_value max_input_time 300
18 php_value always_populate_raw_post_data -1
19 # php_value date.timezone Europe/Riga
20 php_value date.timezone Asia/Shanghai #<== 将时区设置为上海
21 </IfModule>
8. 启动Apache Web服务器
systemctl start httpd
systemctl enable httpd
9. 现在就可以登录Web界面进行设置:http://192.168.56.11/zabbix/setup.php
10. 如下配置链接zabbix数据库的参数,输入zabbix数据库的密码
11. 最后确认zabbix配置参数,如果无误则下一步
安装成功!
12. 进入登录界面,
用户名:Admin
密码:zabbix
mysql登录用户名查看修改:
[root@linux-node1 ~]# mysql
MariaDB [(none)]> USE zabbix
MariaDB [zabbix]> SELECT * FROM users;
+--------+--------+---------+-----------------+-----------------------------------------------+
| userid | alias | name | surname | passwd |
+--------+--------+---------+-----------------+-----------------------------------------------+
| 1 | Admin | Zabbix | Administrator | 5fce1b3e34b520afeffb37ce08c7cd66 |
| 2 | guest | | | d41d8cd98f00b204e9800998ecf8427e |
+--------+--------+---------+-----------------+-----------------------------------------------+
#如下为zabbix登录用户Admin设置新密码:
MariaDB [zabbix]> update users set passwd=md5("123456") where userid='1';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [zabbix]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
#注:这时在Web界面退出登录再登录时原密码就不能用了,当然Web界面也是可以更改密码的,在数据库里面是防止密码忘记之后的操作
界面登录如下:
3.2 zabbix-agent安装部署
1. 安装zabbix-agent
yum -y install zabbix-agent
2. zabbix_agent安装配置
[root@linux-node1 ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.56.11 #<== 用于被动模式,数据获取(server端去获取agent端)
ServerActiver=192.168.56.11 #<== 用于主动模式,数据提交(agent主动向server提交)
#快速修改如下:
sed -i 's#^Server=127.0.0.1#Server=192.168.56.11#g' /etc/zabbix/zabbix_agentd.conf
sed -i 's#ServerActive=127.0.0.1#ServerActive=192.168.56.11#g' /etc/zabbix/zabbix_agentd.conf
3. 启动zabbix-agent服务
[root@linux-node1 ~]# systemctl start zabbix-agent
[root@linux-node1 ~]# systemctl enable zabbix-agent
[root@linux-node1 ~]# netstat -lntup|grep 10050
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 4049/zabbix_agentd
tcp6 0 0 :::10050 :::* LISTEN 4049/zabbix_agentd
启动错误总结:
报错:
[root@linux-node1 ~]# systemctl start zabbix-agent
Job for zabbix-agent.service failed because the control process exited with error code. See "systemctl status zabbix-agent.service" and "journalctl -xe" for details.
原因:zabbix配置文件zabbix_agentd.conf配置文件修改错误
4. 登录zabbix-Web界面将zabbix-agent加入监控
如下稍作修改:
5. 启动zabbix-agent监控
稍等一下,检查zabbix-agent是否监控成功,( 出现以下绿色的部分则表示监控成功)