CentOS 7.2 安装部署 Zabbix 3.0.4 详解

2018/07 作者:ihunter 0 0


来源:https://www.linuxidc.com/Linux/2016-11/137671.htm

下载地址:https://www.zabbix.com/download


服务端的安装

一、安装环境

1.1、环境准备

系统版本Zabbix版本Mariadb版本
CentOS Linux release 7.2.1511 (Core)zabbix-3.0.4mariadb-5.5.50-1.el7_2.x86_64

1.2、安装基础环境

1
2
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
yum install mysql-devel gcc net-snmp-devel curl-devel perl-DBI php-gd php-mysql php-bcmath php-mbstring php-xml -y 

二、服务端安装

2.1 安装配置数据库

1
yum -y install mariadb-server

2.2 设置开机自启动

1
systemctl enable mariadb

2.3 启动数据库

1
systemctl start mariadb

2.4 初始化数据库 

1
mysql_secure_installation

详细输出解析:

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
[root@zabbix-server src]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
 
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
 
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
 
Enter current password for root (enter for none):
OK, successfully used password, moving on...
 
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
 
Set root password? [Y/n] Y
New password:                              #设置数据库root密码
Re-enter new password:                    #再次输入
Password updated successfully!
Reloading privilege tables..
... Success!
  
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
 
Remove anonymous users? [Y/n] Y    #删除匿名用户
... Success!
 
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
 
Disallow root login remotely? [Y/n] Y  #禁止root远程登陆数据库
... Success!
 
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
 
Remove test database and access to it? [Y/n] Y  #删除test测试库
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
 
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
 
Reload privilege tables now? [Y/n] Y    #刷新数据库表
... Success!
 
Cleaning up...
 
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
 
Thanks for using MariaDB!

2.5 创建zabbix数据库、用户并设置密码

1
2
mysql -uroot -p123456 -"create database zabbix default character set utf8 collate utf8_bin;" 
mysql -uroot -p123456 -"grant all on zabbix.* to 'zabbix'@'%' identified by '123456';"

2.6 登陆测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@zabbix-server src]# mysql -uzabbix -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 5.5.50-MariaDB MariaDB Server
 
Copyright (c) 20002016, Oracle, MariaDB Corporation Ab and others.
 
Type 'help;' or '\h' for helpType '\c' to clear the current input statement.
 
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| zabbix |
+--------------------+
2 rows in set (0.00 sec)
 
MariaDB [(none)]> use zabbix
Database changed
MariaDB [zabbix]> show tables;
Empty set (0.01 sec)
 
MariaDB [zabbix]> Bye

三、安装zabbix服务端

3.1 yum安装zabbix服务

1
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-get

3.2 导入数据表结构

1
2
cd /usr/share/doc/zabbix-server-mysql-3.0.4/
zcat create.sql.gz | mysql -uzabbix -p123456 zabbix

3.3 备份并修改zabbix配置文件

配置数据库:

1
2
3
4
5
6
cp /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf_$(date +%F)
[root@zabbix-server ~]# diff /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf_2016-08-23
115c115
< DBPassword=123456
---
# DBPassword=

定义时区:

1
2
3
4
5
6
cp /etc/httpd/conf.d/zabbix.conf /etc/httpd/conf.d/zabbix.conf_$(date +%F)
[root@zabbix-server ~]# diff /etc/httpd/conf.d/zabbix.conf /etc/httpd/conf.d/zabbix.conf_2016-08-23
19c19
<      php_value date.timezone Asia/Chongqing
---
>        # php_value date.timezone Europe/Riga

3.4 设置开机自启动,启动zabbix服务器端

1
2
systemctl enalble zabbix-server
systemctl restart zabbix-server

3.5 设置开机自启动,启动apache

1
2
systemctl enable httpd
systemctl start httpd


四、web界面安装zabbix

4.1 访问地址http://192.168.0.125/zabbix/setup.php配置zabbix


 注:下图中的所有配置必须都为ok才可以。


 注:下图配置zabbix的一些数据库相关信息,按照自己的填写即可。


 注:Name为别名设置,可填写

 注:zabbix默认登录用户名为Admin(A为大写,),密码为zabbix。

 注:下图进入登录界面


4.2 设置字体显示为中文

注:3.0.4默认的中文显示配置文件里面是开启的,无需重新设置,只需要如下图选择即可


五、总结

  到这里,Zabbix服务器端的配置部署完毕,下篇文章部署Zabbix客户端的配置及其一些常用应用的监控。


客户端的安装和添加监控机


一、查看客户端环境

1
2
3
4
[root@mysql-server ~]# cat /etc/RedHat-release
CentOS Linux release 7.2.1511 (Core)
[root@mysql-server ~]# uname -r
3.10.0-327.28.2.el7.x86_64

二、部署zabbix-agent

2.1 安装zabbix-agent

1
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-agent-3.0.4-1.el7.x86_64.rpm

2.2 备份并更改zabbix-agent配置文件

cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf_$(date +%-i  /etc/zabbix/-i  /etc/zabbix/

2.3 加入开机自启动并启动zabbix客户端

1
2
systemctl enable zabbix-agent
systemctl start zabbix-agent

三、添加客户机的监控

3.1 界面操作:配置--主机---创建主机


 3.2 填写客户机信息


 3.3 选择模板


 3.4 添加主机,查看添加的情况


注:看到ZBX变成绿色字体后说明成功添加,这个时候查看图形信息即可。

3.5 查看模板自带的监控信息项


 四、总结

我们可以看到3.0.4模板自带的监控项有:

  • CPU概况

  • 网卡流量

  • 内存情况(物理和虚拟)

  • 负载信息

  • 磁盘使用情况

但是这些信息是不完善的,接下来需要添加tcp连接信息、磁盘io等zabbix默认没有的监控信息。


监控Linux客户端的TCP连接数

一、客户端操作

1.1 书写配置脚本

1
2
3
4
5
[root@mysql-server zabbix]# cd /etc/zabbix/
[root@mysql-server zabbix]# cat /etc/zabbix/tcp.sh
#!/bin/bash
NUM=$(/usr/sbin/ss -s| grep -oP "(?<=$1 )\d+")
echo ${NUM:-555}

1.2 备份并更改客户端配置文件

1
2
3
4
5
6
[root@mysql-server zabbix]# cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf_$(date +%F)
[root@mysql-server zabbix]# diff /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf_2016-08-23
< UnsafeUserParameters=1
< UserParameter=tcp[*],sh /etc/zabbix/tcp.sh $1
---
# UserParameter=

1.3 重启zabbix-agent服务

1
systemctl restart zabbix-agent

二、配置zabbix模板

2.1 添加应用集

操作:配置---模板,选择Template-OS-Linux里面的应用集


 

2.2 创建应用集


 

2.3 创建监控项

 



 

2.4 添加监控图形

 

 2.5 查看刷新查看之前添加的客户点监控图形信息


 

 2.6 配置触发器

根据自己的需求配置即可。


赞(2) 更多分享

上篇: 企业级监控系统:Zabbix详细安装配置教程
下篇: Zabbix实现微信报警