版权声明:本文为博主原创文章,转载请注明出处:https://twocups.cn/index.php/2021/06/14/38/

Zabbix 5.0官方中文文档:https://www.zabbix.com/documentation/5.0/zh/manual

Zabbix 版本选择

截至目前,Zabbix 最新的稳定版本是5.0 LTS,官方支持五年。而其他的非稳定版只支持六个月,所以我们还是选择5.0的版本。

环境要求

Zabbix 要求官方文档:https://www.zabbix.com/documentation/5.0/zh/manual/installation/requirements

官方文档里都是中文,环境要求自己看一下,硬件配置也不能过低。软件方面,数据库、PHP 和相应的插件之后我们会再装。所以只要确认一下 Apache 的版本在1.3.12以上就可以直接开始部署了。

服务端部署

首先,要清楚自己机器的名字和对外ip地址。

# 查询机器名字
hostname
# 查询对外ip
ifconfig

有的教程里面会要求关闭防火墙,这是担心机器之间可能会不连通。所以只要保证各台机器之间能够连通就行了。当然,在实际的企业环境中也不可能随意关闭防火墙的。不过我还是说一下关闭防火墙的方法。

# 关闭防火墙selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
# 禁止防火墙开机自启,同时现在就关闭防火墙
systemctl disable --now firewalld
# 重启
reboot

接下来获取 Zabbix 官方源。

rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/8/x86_64/zabbix-release-5.0-1.el8.noarch.rpm

但是,由于国内获取 Zabbix 官方源不方便,可以换成阿里云的源。

# 从阿里云获取zabbix官方源
rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
# 把刚下载的zabbix官方源中的zabbix地址全部换程阿里云的地址
sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
# 清空缓存
yum clean all

之后,安装 zabbix serverzabbix agent

yum install zabbix-server-mysql zabbix-agent -y

接下来安装软件 Software Collections (SCL)。SCL 可以让同一个操作系统上安装多个版本的软件,而不会影响到整个系统的安装包。SCL 的软件都安装在/opt/rh目录下。

举个例子,我为了 Zabbix 要安装5.4版本的 PHP,可我又不想改动我已经安装在系统中的高版本 PHP。这个时候就可以让 Zabbix 去依赖 SCL 中5.4版本的 PHP,而不会影响系统正在使用的高版本 PHP 了。

yum install centos-release-scl -y

之前我们下载的 Zabbix 源中默认是不会下载 Zabbix 前端的,所以需要我们去修改一下。

# 进入zabbix源
vim /etc/yum.repos.d/zabbix.repo
​
# 下面是文件/etc/yum.repos.d/zabbix.repo中的内容
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$b
asearch/frontend
enabled=1 # 这里原来是0,我们将其修改为1,表示需要下载zabbix前端
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

然后安装 Zabbix 前端环境

yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y

到此为止,Zabbix 服务端本身就安装完成了。接下来,我们再安装一下与 Zabbix 连接的后端数据库。

数据库我们直接用系统自带的 MariaDB。有人可能不清楚,我就提一下。MariaDB 是 MySQL 的一个分支。当年 MySQL 被 Oracle 收购,有被闭源的可能,所以社区用分支的方式来规避这个风险,就是 MariaDB。MariaDB 可以看作是 MySQL 的替代品,很多地方还反而比 MySQL 要强,现在是由开源社区在维护。

# 安装MariaDB
yum install mariadb-server -y
# 设置MariaDB为开机自启,并且现在启动MariaDB
systemctl enable --now mariadb

接下来配置 MariaDB,使之与 Zabbix 连通。

# 数据库初始化
mysql_secure_installation

数据库初始化的时候会有很多选项:输入当前root密码(没有所以直接回车),设置root密码,移除匿名用户☑️,不允许root远程登录✖️,移除测试数据库☑️,重载表权限☑️。

接下来,用 root 用户登录 MariaDB。

mysql -uroot -p

并且新建 zabbix 数据库和 zabbix 用户,并将数据库权限赋予用户 zabbix。

create database zabbix character set utf8 collate utf8_bin;
create user zabbix@localhost identified by '你想给用户zabbix设置的密码';
grant all privileges on zabbix.* to zabbix@localhost;
flush privileges;
quit;

将 Zabbix 的数据导入 MariaBD,用户为 zabbix,数据库为 zabbix。

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

修改 Zabbix 配置文件里相应数据库的用户密码。

# 修改配置文件
vim /etc/zabbix/zabbix_server.conf
​
# 以下是配置文件/etc/zabbix/zabbix_server.conf里的内容
DBPassword=这里填写你刚才设置的用户zabbix的密码

修改 Zabbix 配置文件里的时区。

# 修改配置文件
vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
​
# 以下是配置文件/etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf里的内容
php_value[date.timezone] = Asia/Shanghai

注意以下,配置文件里“php_value[date.timezone] = Asia/Shanghai”这行前面是有一个分号和空格的,注释用的。我们要去掉分号和空格,否则时区这行不起作用。

全都配置好后,我们就启动所有相关服务。

systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm

之后,我们就可以通过“ip/zabbix”访问 Zabbix 的前端页面了。

第一次进入我们会看见引导页面。

第一页是欢迎我们使用 Zabbix 5.0,我们直接下一步即可。

第二页是提醒我们检查 Zabbix 所有组件是否正常的,每个组件后面应该都是OK,代表正常,我们继续下一步。

第三页需要我们输入后端数据库用户 zabbix 的密码,输入后下一步。

第四页是主机和端口,默认localhost和10051,没问题就下一步。

以上页面我们全部填写和确认完毕后,会显示成功安装页面。之后我们输入账号和密码即可登录。

# 登录账号,注意这个A是大写
Admin
# 登录密码
zabbix

登录之后,我们就可以看到安装完成之后的 Zabbix 服务端首页了。

林皓伟

《【Zabbix系列】第二章:部署Zabbix服务端》有 12 条评论
  1. I together with my pals happened to be viewing the excellent ideas found on your web page then at once I had an awful feeling I had not thanked you for those tips. Those boys were totally warmed to read through all of them and now have definitely been using these things. Thanks for simply being indeed considerate and also for selecting such great resources millions of individuals are really needing to be aware of. Our own honest regret for not expressing appreciation to you earlier. Roland Rathe

  2. Thanks for your own work on this website. My mum take interest in setting aside time for research and it is simple to grasp why. We notice all relating to the powerful way you provide very helpful tips and hints via your website and therefore strongly encourage response from visitors on this subject matter while our own simple princess is without a doubt studying so much. Take pleasure in the rest of the year. Your performing a tremendous job. Micah Besse

  3. Do you mind if I quote a few of your articles as long as I provide credit and sources back to your website? My blog site is in the exact same area of interest as yours and my users would genuinely benefit from some of the information you present here. Please let me know if this okay with you. Cheers! Harry Bilotti

  4. In opinion, the top three paid opinion sites are Cashcrate, Fusioncash and Cashlagoon. Cashcrate is a great paid survey website which offers many surveys and offers to finish. The site is well organised which implies that you may find what you’re looking for. Its referral system is truly like the one Cashcrate has. Bobbie Plowe

  5. I too enjoy my time outside. Since working from home due to the pandemic, I ramped up my gardenng, basically doubled the size of my vegetable garden. I have not bought a tomato or pepper in 3 months, rather, can eat them directly from my yard, plus will be able to pull some from my freezer and enjoy them in soups and stir fries over the winter! I love the simple process of nurturing the soil, planting, weeding, tending and harvesting. Very relaxing and wholesome. Cornell Labeau

  6. Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.| Boris Jasik

  7. Today, there are actually many nationwide relocating providers and far away moving companies around the United States involving various sizes and shapes. In small towns and areas, family-operated relocating firms are rather prominent. This is actually mostly since they individually recognize the owners and understand that they can place leave on their relocation companies. Having said that, a lot of our company must take care of finding good quality best-rated nationally moving companies to hire from square one. Zane Warnasch

  8. I must show my love for your kindness giving support to individuals who should have assistance with this one issue. Your real dedication to getting the message all over was astonishingly good and have always made somebody just like me to arrive at their targets. Your new warm and friendly report implies a whole lot a person like me and a whole lot more to my peers. Thanks a ton; from everyone of us. Jan Olien

  9. I was wondering if you ever considered changing the structure of your website? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having one or two images. Maybe you could space it out better? Rosario Barela

  10. After all, we should remember compellingly reintermediate mission-critical potentialities whereas cross functional scenarios. Phosfluorescently re-engineer distributed processes without standardized supply chains. Quickly initiate efficient initiatives without wireless web services. Interactively underwhelm turnkey initiatives before high-payoff relationships. Holisticly restore superior interfaces before flexible technology. Jamison Blancett

发表回复

您的电子邮箱地址不会被公开。