从零开始在centos8上部署zabbix5.0

一、安装一台centos8的服务器

本文使用一台 8核CPU 8G内存 200G硬盘的虚拟机,使用centos8.3的镜像。

下图是zabbix官方推荐的配置。大家可以根据实际需求更改服务器的配置。

1、挂载镜像,正常安装。

2、安装过程默认英文语言。

3、安装过程,选择基础服务器配置。

语言记得添加简体中文

时区选择上海。

软件选择服务器不带GUI。使用zabbix时GUI没必要,空耗性能。拓展都不勾选。

分区默认自动分区。

配置完root密码后开始安装系统。本文后续的命令均由root账户操作

二、基础设置

1、配置IP

给新装的服务器配置静态IP。

进入对应网卡的配置文件。

vi /etc/sysconfig/network-scripts/ifcfg-ens160

ip和网关根据自己实际的运行坏境配置。

重启网卡

nmcli connection reload

可以ping网关测试以下网络是否成功联通。

2、(可选)修改SSH默认远程端口

进入ssh的配置文件。

vim /etc/ssh/sshd_config

将默认的#Port 22更改为自定义的端口。我这里改为55555端口。

启动防火墙并开放ssh新的远程端口。

重启ssh和防火墙服务。

systemctl start firewalld
firewall-cmd --permanent --add-port=55555/tcp
systemctl restart sshd
systemctl restart firewalld.service

检测新的端口是否已经开放。

[root@localhost ~]# firewall-cmd --permanent --query-port=55555/tcp
yes

3、(可选)开启防火墙,打开ssh和zabbix需要的端口

防火墙建议最好是开启,提高服务器的安全性

以下是zabbix需要开放的端口,如果不对的欢迎指出

firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=3000/tcp
firewall-cmd --permanent --add-port=3306/tcp
firewall-cmd --permanent --add-port=4505/tcp
firewall-cmd --permanent --add-port=4506/tcp
firewall-cmd --permanent --add-port=10050/tcp
firewall-cmd --permanent --add-port=10051/tcp

如果你需要开启smtp邮件报警,也可以打开对应端口。我这里使用126邮件报警。

firewall-cmd --permanent --add-port=25/tcp     //不开SSL
firewall-cmd --permanent --add-port=465/tcp    //开SSL

最后,记得重启防火墙。

设置防火墙开机启动。

systemctl enable firewalld.service

查看已开放的端口。

[root@localhost ~]# firewall-cmd --zone=public --list-ports
55555/tcp 4505/tcp 4506/tcp 10051/tcp 10050/tcp 3000/tcp 3306/tcp 80/tcp 465/tcp

三、关闭selinux

selinux会对zabbix的运行造成干扰,可以对其配置进行修改保持开启。最简单的就是选择关闭。

想保持开启的,可以参考zabbix服务器在SELinux开启下的处理_selinux zabbix_lpc1162303536的博客-CSDN博客

我这里选择关闭它们。

[root@localhost ~]# systemctl disable --now firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
setenforce: SELinux is disabled
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

四、部署zabbix

下面的安装过程需要通外网。部署完成后可以关闭外网,仅在内网使用。

A)安装zabbix

zabbix官方源

[root@localhost ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/8/x86_64/zabbix-release-5.0-1.el8.noarch.rpm
Retrieving https://repo.zabbix.com/zabbix/5.0/rhel/8/x86_64/zabbix-release-5.0-1.el8.noarch.rpm
warning: /var/tmp/rpm-tmp.BsFuRy: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:zabbix-release-5.0-1.el8         ################################# [100%]

替换为阿里云zabbix源

[root@localhost ~]# sed -i '3c baseurl=http://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/8/$basearch/' /etc/yum.repos.d/zabbix.repo

安装zabbix

dnf -y install zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-agent

B)安装数据库

1、下载数据库并初始化

安装Apache和MariaDB并启动

[root@localhost ~]# dnf install -y @httpd @mariadb
[root@localhost ~]# systemctl enable --now httpd mariadb

数据库根用户添加密码及安全设置

[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.

设置数据库root账户密码

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] 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.

是否允许root远程登录。根据自己需求选择

Disallow root login remotely? [Y/n] n
 ... 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.

是否移除test数据库

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!

2、配置远程登陆

登录数据库,输入上一步配置的密码

mysql -uroot -p

接着继续执行mysql语句,将将root用户的host字段设为'%':

MariaDB [(none)]> use mysql;
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 [mysql]> update user set host='%' where user='root';

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.001 sec)

MariaDB [mysql]> exit
Bye

如果第二步设置报错(如下),查看下数据库的host信息,host已经有了%这个值,所以直接运行下一步命令

MariaDB [mysql]> update user set host='%' where user='root';
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'
MariaDB [mysql]> select host from user where user = 'root';
+-----------------------+
| host                  |
+-----------------------+
| %                     |
| 127.0.0.1             |
| ::1                   |
| localhost.localdomain |
+-----------------------+
4 rows in set (0.001 sec)

MariaDB [mysql]>flush privileges;

3、关闭MySQL主机查询dns

MySQL会反向解析远程连接地址的dns记录,如果MySQL主机无法连接外网,则dns可能无法解析成功,导致第一次连接MySQL速度很慢,所以在配置中可以关闭该功能。

给/etc/my.cnf文件,添加配置

[root@localhost ~]# echo "[mysqld]
> skip-name-resolve" >> /etc/my.cnf
[root@localhost ~]#

4、重启数据库

systemctl restart mysqld

C)安装zabbix数据库

1、登录数据库

mysql -uroot -p

在数据库主机上运行以下内容

MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> create user zabbix@localhost identified by 'password';       //我这里设置密码为password 根据需要自行更改
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
MariaDB [(none)]> quit;

2、在 Zabbix 服务器主机上导入初始架构和数据。

系统将提示您输入新创建的密码,我这里即password

zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

3、为 Zabbix 服务器配置数据库

编辑文件 /etc/zabbix/zabbix_server.conf

[root@localhost ~]# sed -i 's/# DBPassword=/DBPassword=password/' /etc/zabbix/zabbix_server.conf

4、为 Zabbix 前端配置 PHP

编辑文件 /etc/php-fpm.d/zabbix.conf,添加上海时区

[root@localhost ~]# sed -i '$a php_value[date.timezone] = Asia/Shanghai' /etc/php-fpm.d/zabbix.conf

5、启动 Zabbix 服务器和代理进程

启动 Zabbix 服务器和代理进程,使其在系统启动时启动。

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

D)配置 Zabbix 前端

连接到新安装的 Zabbix 前端:

http://server_ip_or_name /zabbix

开始配置zabbix网页

全部绿色的OK,点击“Next step”

输入zabbix数据库密码,我这里是password


输入zabbix平台的自定义名称,这个随便写了

最后确认信息

部署完成

默认的用户是Admin,密码为zabbix,该用户是超级用户,输入登录信息后,点击Sign In按钮,进行登录


可以看到zabbix的界面

E)完善配置

1、修改管理员账户的密码和语言

点击左下角的User settings,将Language改成中文Chinese。

左侧,管理->用户->选择Admin账户

别名即登录账户,下方可以修改密码

2、添加中文字体

当我们在中文界面查看图形的时候,发现图形上的中文都是方框,如下图

而在英文界面查看,显示是正常的,如下图

这是中文字符集不兼容的原因,我们需要手动导入字体到服务器

首先,找一台win系统的电脑,进入C:\Windows\Fonts目录,这里面是window系统存放字体的地方

随便选择一个喜欢的中文字体,拖到本机的桌面。

根据不同的字形,有些字体只有一个文件,有些有多个文件。

无论是一个文件的字体还是多个文件的字体,我们只需要一个即可。

后续不再赘述,上传完成之后的使用时,.TTF需要把后缀改成小写的.ttf.ttc不需要更改后缀

可以使用任意方式将字体文件上传至zabbix的服务器。

我这里用scp直接上传。注意,如果前面修改了SSH的端口,这里的-P参数,P大写

C:\WINDOWS\system32> scp -P 55555 D:/Desktop/msyhbd.ttc root@10.100.1.159:/usr/share/zabbix/assets/fonts/

root@10.100.1.159's password:
msyhbd.ttc                                              100%   16MB  11.0MB/s   00:01

C:\WINDOWS\system32>

/usr/share/zabbix/assets/fonts/目录是zabbix默认存放字体的位置。

接下来我们回到服务器端。

进入字体存放目录。

[root@localhost ~]# cd /usr/share/zabbix/assets/fonts/
[root@localhost fonts]# ls
graphfont.ttf  msyhbd.ttc

可以看到,graphfont.ttf是默认的字体文件。

可以修改配置来直接引用我们上传的字体文件,不过那样过于繁琐,我这里选择直接覆盖。

[root@localhost fonts]# cp graphfont.ttf graphfont.ttf.bak       //防止意外,备份文件
[root@localhost fonts]# ls
graphfont.ttf  graphfont.ttf.bak  msyhbd.ttc
[root@localhost fonts]# \cp msyhbd.ttc graphfont.ttf             //忽略覆盖警告,直接覆盖
[root@localhost fonts]#

不需要重启任何服务,回到页面,可以看到图形上的中文已经可以看到了。

3、修改默认内存设置

zabbix默认的内存是设置的很低的,我们需要手动调整。

否则内存溢出后,页面下方会不断报警zabbix server is not running

[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf

把原来的 # CacheSize=8M 前面的#注释去掉,将8M修改为2048M,这个2048M根据服务器性能修改

### Option: CacheSize
#       Size of configuration cache, in bytes.
#       Shared memory size for storing host, item and trigger data.
#
# Mandatory: no
# Range: 128K-64G
# Default:
 CacheSize=2048M

重启zabbix服务。

systemctl restart zabbix_server
systemctl restart httpd
systemctl restart zabbix_agent

  • 3
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值