普拉多VX

人生一路,不问来时,不知归期

0%

zabbix 5.0 详细安装步骤

zabbix

老牌监控系统,自我运维生涯开始用过nagios、icinga、cacti(仙人掌)、zabbix。唯有zabbix在中小规模监控环境中值得推荐,无论是安装,配置,还是报警、绘图。结合第三方报警也好,适配性都特别好。
目前还可以集合grafana作图形可视化,中小型企业运维监控软件首选zabbix。如果有能力二次开发或者有兴趣也可以研究下小米开源的open-falcon、滴滴改进的Nightingale、Talkingdata开源的OWL等

5.0版本貌似最近才更新没多久,我们部署起来看看有啥变化没,话说回来。从2.0到3.0确实好看了不少,今天看看5.0长啥样,话不多说,开干!

5.0新功能参考 https://www.zabbix.com/cn/whats_new_5_0

准备环境

准备环境

  • Centos 7.8
  • PHP 7.2 +
  • Apache 1.3.12 +
  • Mysql or MariaDB 5.7+

具体要求参考一下链接 https://www.zabbix.com/documentation/current/manual/installation/requirements

硬件条件参考下表

安装

关闭selinux

1
2
3
4
5
6
7
8
9
10
11
12
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@localhost ~]# systemctl disable --now firewalld
[root@localhost ~]# 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
[root@localhost ~]#

安装zabbix源

1
2
3
4
5
6
7
8
9
10
11
[root@localhost ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
Retrieving https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
warning: /var/tmp/rpm-tmp.vw5pXe: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-release-5.0-1.el7 ################################# [100%]
[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base epel extras updates zabbix zabbix-non-supported
Cleaning up list of fastest mirrors
[root@localhost ~]#

安装server和agnet

1
[root@localhost ~]# yum -y install zabbix-server-mysql zabbix-agent

因某些不能说的原因安装可能会出现如下情况

1
2
3
4
5
6
http://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-server-mysql-5.0.3-1.el7.x86_64.rpm: [Errno 14] curl#18 - "transfer closed with 1461988 bytes remaining to read"
Trying other mirror.


Error downloading packages:
zabbix-server-mysql-5.0.3-1.el7.x86_64: [Errno 256] No more mirrors to try.

换成阿里源

1
2
3
4
5
[root@localhost ~]# sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base epel extras updates zabbix zabbix-non-supported
Cleaning up list of fastest mirrors

再次执行安装

安装前端组建

1
[root@localhost ~]# yum install centos-release-scl -y

启用zabbix前端源,编辑配置文件 /etc/yum.repos.d/zabbix.repo 修改enabled为1

1
2
3
4
5
6
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

软件包安装,包括httpd php web组件等

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
[root@localhost ~]# yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y 
...
Installing:
zabbix-apache-conf-scl noarch 5.0.3-1.el7 zabbix-frontend 13 k
zabbix-web-mysql-scl noarch 5.0.3-1.el7 zabbix-frontend 12 k
Installing for dependencies:
apr x86_64 1.4.8-5.el7 base 103 k
apr-util x86_64 1.5.2-6.el7 base 92 k
audit-libs-python x86_64 2.8.5-4.el7 base 76 k
checkpolicy x86_64 2.5-8.el7 base 295 k
dejavu-fonts-common noarch 2.33-6.el7 base 64 k
dejavu-sans-fonts noarch 2.33-6.el7 base 1.4 M
fontpackages-filesystem noarch 1.44-8.el7 base 9.9 k
httpd x86_64 2.4.6-93.el7.centos base 2.7 M
httpd-tools x86_64 2.4.6-93.el7.centos base 92 k
libX11 x86_64 1.6.7-2.el7 base 607 k
libX11-common noarch 1.6.7-2.el7 base 164 k
libXau x86_64 1.0.8-2.1.el7 base 29 k
libXpm x86_64 3.5.12-1.el7 base 55 k
libcgroup x86_64 0.41-21.el7 base 66 k
libjpeg-turbo x86_64 1.2.90-8.el7 base 135 k
libsemanage-python x86_64 2.5-14.el7 base 113 k
libwebp x86_64 0.3.0-7.el7 base 170 k
libxcb x86_64 1.13-1.el7 base 214 k
libxslt x86_64 1.1.28-5.el7 base 242 k
mailcap noarch 2.1.41-2.el7 base 31 k
policycoreutils-python x86_64 2.5-34.el7 base 457 k
python-IPy noarch 0.75-6.el7 base 32 k
rh-php72 x86_64 1-2.el7 centos-sclo-rh 4.3 k
rh-php72-php-bcmath x86_64 7.2.24-1.el7 centos-sclo-rh 60 k
rh-php72-php-cli x86_64 7.2.24-1.el7 centos-sclo-rh 2.9 M
rh-php72-php-common x86_64 7.2.24-1.el7 centos-sclo-rh 680 k
rh-php72-php-fpm x86_64 7.2.24-1.el7 centos-sclo-rh 1.5 M
rh-php72-php-gd x86_64 7.2.24-1.el7 centos-sclo-rh 151 k
rh-php72-php-json x86_64 7.2.24-1.el7 centos-sclo-rh 54 k
rh-php72-php-ldap x86_64 7.2.24-1.el7 centos-sclo-rh 59 k
rh-php72-php-mbstring x86_64 7.2.24-1.el7 centos-sclo-rh 553 k
rh-php72-php-mysqlnd x86_64 7.2.24-1.el7 centos-sclo-rh 166 k
rh-php72-php-pdo x86_64 7.2.24-1.el7 centos-sclo-rh 101 k
rh-php72-php-pear noarch 1:1.10.5-1.el7 centos-sclo-rh 357 k
rh-php72-php-process x86_64 7.2.24-1.el7 centos-sclo-rh 62 k
rh-php72-php-xml x86_64 7.2.24-1.el7 centos-sclo-rh 160 k
rh-php72-php-zip x86_64 7.2.24-1.el7 centos-sclo-rh 90 k
rh-php72-runtime x86_64 1-2.el7 centos-sclo-rh 1.1 M
scl-utils x86_64 20130529-19.el7 base 24 k
setools-libs x86_64 3.3.8-4.el7 base 620 k
zabbix-web noarch 5.0.3-1.el7 zabbix-frontend 3.1 M
zabbix-web-deps-scl noarch 5.0.3-1.el7 zabbix-frontend 13 k

安装数据库

安装并设置开机启动

1
2
[root@localhost ~]# yum install mariadb-server -y
[root@localhost ~]# systemctl enable --now mariadb

初始化数据库

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
[root@localhost ~]# mysql_secure_installation

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: #新密码
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] #移除匿名用户
... skipping.

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] n #使用禁用root远程连接
... skipping.

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 #删除测试数据库
- 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!

创建zabbix所需要的数据库及用户并设置密码 zabbix123

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@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>
MariaDB [(none)]>
MariaDB [(none)]>
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> create user zabbix@localhost identified by 'zabbix123';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit
Bye

导入初始数据

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
[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
Enter password:
[root@localhost ~]# mysql -u root -p #检查是否导入成功
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use zabbix
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [zabbix]> show tables;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
| auditlog |
.......

修改配置文件

配置数据库密码 /etc/zabbix/zabbix_server.conf

1
DBPassword=zabbix123

修改php时区 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf,修改成Asia/Shanghai 并且去掉前面的注释

1
php_value[date.timezone] = Asia/Shanghai

设置开机启动

1
2
[root@localhost ~]# systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
[root@localhost ~]# systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm

初始化

登录系统http://x.x.x.x/zabbix

开始初始化

检查环境

配置数据库

确认server详情

安装确认

安装完成

登录系统账户密码 Admin ,默认密码zabbix

系统页面,默认是英文,可以在个人中心切换语言

zabbix 乱码问题

将Win10操作系统C:\Windows\Fonts目录下的任意字体 上传字体文件到fonts目录下

1
2
3
4
5
6
7
[root@localhost fonts]# pwd
/usr/share/zabbix/assets/fonts
[root@localhost fonts]# ll
total 11512
lrwxrwxrwx 1 root root 33 Sep 18 16:34 graphfont.ttf -> /etc/alternatives/zabbix-web-font
-r-xr-xr-x 1 root root 11787328 Sep 18 17:05 simkai.ttf
[root@localhost fonts]#

编辑配置文件 /usr/share/zabbix/include/defines.inc.php

1
2
3
4
5
6
7
 81 define('ZBX_GRAPH_FONT_NAME',           'simkai'); // font file name
122 define('ZBX_FONT_NAME', 'simkai');
```

重启
```bash
[root@localhost fonts]# systemctl restart zabbix-server

参考资料