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

为什么要离线部署Zabbix?

我突然发现公司的测试环境中的机器是只连内网、不连外网的,所以我只能在离线环境中部署 Zabbix。相较于联网环境,离线环境部署Zabbix的总体流程是一样的,但还是有些小坑和一些需要注意的地方。所以我就从离线部署的角度再写一遍流程,并且我之后剩余组件的部署全都是离线的,方便大家在实际的企业环境中操作。

先准备一台可以联网的开发机

首先,我们需要准备一台可以联网、并且与生产环境中操作系统版本相同的主机或者虚拟机。比如你需要将 Zabbix 部署在企业测试环境中,可测试环境不联网,那么你可以申请一台可以联网的开发机,这一般都是被允许的。

我们需要现在这台联网的开发机上进行操作。

首先,安装 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相应的rpm包

下面注意了,我们不是直接安装,而是通过参数“–downloadonly”下载并保存 Zabbix 后端及其依赖的 rpm 包。

yum install --downloadonly --downloaddir=/zabbix_repo zabbix-server-mysql zabbix-agent  zabbix-agent2  zabbix-java-gateway zabbix-js zabbix-get zabbix-sender  net-snmp centos-release-scl  createrepo

这边需要注意一下,有三个可能出错的地方。

第一个是通过参数“–downloadonly”只会对之前没有安装过的软件生效。比如说你之前安装过 zabbix-server-mysql,那么你是无法再次下载并保存它的 rpm 包的,系统会提示你已经安装过这个包了。如果你想下载这个包及其相关的包,那么你就需要先把这个包和相关的包卸载干净。

第二个是我的后端是 MariaDB,所以我下载的是“zabbix-server-mysql”。如果你的后端是其他的数据库,那么请根据数据库的名称下载相应的包,例如“zabbix-server-pgsql”。

第三个是如果不用阿里云的源而是用 Zabbix 官方的国外源,那么可能会因为网络问题而导致下载失败。所以我还是建议用阿里云的源。

接下来安装 centos-release-scl 软件选集。

yum install centos-release-scl -y

编辑源的配置文件,并开启 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 前端及其依赖的 rpm 包。

yum install --downloadonly --downloaddir=/zabbix_repo  zabbix-web-mysql-scl zabbix-apache-conf-scl -y

注意一下,我自己的前端是 Apache,后端数据库是 MariaDB,所以下载的包是 mysql 和 apache 版本的。如果你是其他的数据库和前端,那么根据名称下载相应的包即可,例如“zabbix-web-pgsql-scl”和“zabbix-nginx-conf-scl”。

制作yum镜像

我们仍然在可以联网的开发机上操作。我们先安装 createrepo,然后创建镜像并且打包。

yum install createrepo -y
createrepo /zabbix_repo
cd /
tar czf zabbix_repo.tar.gz -c /zabbix_repo

这时我们会在根目录下的到一个 Zabbix 源的集合包,名为“zabbix_repo.tar.gz”。

接下来我们需要把这包上传到需要我们实际部署的不联网的测试环境中。

有的企业环境中只允许用自研的 SSH 客户端,不允许通过其他方式连接服务器,这时候就没法用图形化文件传输工具了。如果不知道如何通过命令行上传本地文件和从服务器下载本地文件,可以看下文章最下面的“通过命令行上传/下载文件”,用的是 ZModem 协议

离线安装 Zabbix服务端

首先,将“zabbix_repo.tar.gz”解压到根目录下。

tar -xvf zabbix_repo.tar.gz -C /

这里有人自己解压的时候习惯的参数“-zxvf”会报错。

报错:
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now

错误原因是这个压缩文件并不包含 gzip 格式,所以解压参数不能带“z”。这里就用我上面写的“-xvf”参数解压就好了。

接下来备份并且删除原有的 yum 源文件,指令最后的分号不要忘记了。

find /etc/yum.repos.d/ -name *.repo -exec mv {} {}.bak \;

这时我们就可以看到 /etc/yum.repos.d/ 文件夹下的所有源文件都带上了后缀“.bak”,这样它们就不起作用了,同时文件内容没变,相当于起到了备份的作用。

新增源文件“zabbix.repo”。

tee /etc/yum.repos.d/zabbix.repo <<EOL
[zabbix]
name=zabbix
baseurl=file:///zabbix_repo
gpgcheck=0
enabled=1
EOL

现在,我们就可以在这台不联网的机器上离线安装 Zabbix 服务端和客户端了,流程和上一章的在线安装是一样的。

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

这边会报错,说安装 zabbix-server-mysq 要先安装 fping。这里我们去目录 /etc/yum.repos.d 下把里面的文件 epel.repo 恢复一下,就是把它的后缀“.bak”去掉,然后清空一下缓存即可。记得安装完“zabbix-server-mysql”和“zabbix-agent”要把文件 epel.repo 重新变为备份,即再加上后缀“.bak”。

mv /etc/yum.repos.d/epel.repo.bak /etc/yum.repos.d/epel.repo
yum clean all
yum install zabbix-server-mysql zabbix-agent -y
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak

之后安装 centos-release-scl 软件选集,并且删除它在目录 /etc/yum.repos.d 下的源文件,别忘了最后的分号。

yum install centos-release-scl -y
find /etc/yum.repos.d/ -name CentOS-SCLo*.repo -exec mv {} {}.bak \;

最后安装 Zabbix 前端及其组件。

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

特别注意一下,这里 Zabbix 及其相关组件就全部安装完成了。这时候要把目录 /etc/yum.repo.d 下的源文件恢复原状,所有之前我们加上“.bak”后缀作为备份的全部去掉,并且给我们自己新建的源文件“zabbix.repo”加上“.bak”后缀使其失效。

离线安装MariaDB数据库

MariaDB 官方下载地址:https://mariadb.org/download/

先去官网下载 MariaDB 的安装包,记得下载最新的稳定版,别下载测试版(Beta)。

安装包的格式应该是“tar.gz”,我们先把它解压到 /usr/local 目录下。

tar -zxvf MariaDB安装包名称.tar.gz -C /usr/local

由于解压后 MariaDB 的目录名是带版本号的,所以我们用软连接让它的名称符合要求。

cd /usr/local
ln -s MariaDB文件夹名称/ mysql

现在 MariaDB 就安装完成了。

配置Zabbix及MariaDB

到此,离线版的所有软件安装就完成了。至于配置方面,和在线版肯定是完全一样的,下面给出流程,具体的操作和指令看上一章(【Zabbix系列】第二章:部署Zabbix服务端)就行。

  1. 设置 MariaDB 为开机自启,并且启动 MariaDB。
  2. 配置 MariaDB,使之与 Zabbix 连通。
  3. 用 root 用户登陆 MariaDB,并且新建 zabbix 数据库和 zabbix 用户,再将数据库权限赋予用户 zabbix。
  4. 将 Zabbix 的数据导入 MariaDB。
  5. 修改 Zabbix 配置文件里面相应数据库的用户密码。
  6. 修改 Zabbix 配置文件里的时区。
  7. 启动所有相关服务。
  8. 通过“ip/zabbix”访问 Zabbix 的前端页面。

可能会遇到的错误:rh-php72-php-fpm 启动失败

我自己是遇到了一个错误,使用下面这条命令在启动 rh-php72-php-fpm 的时候启动失败了。

systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
报错:
Job for rh-php72-php-fpm.service failed because the control process exited with error code. See "systemctl status rh-php72-php-fpm.service" and "journalctl -xe" for details.

我们按照报错提供的指令继续查下去,看看是哪里出了问题。

systemctl status rh-php72-php-fpm.service
报错:
Jun 15 17:17:16 *.site systemd[1]: Starting The PHP FastCGI Process Manager...
Jun 15 17:17:16 *.site php-fpm[17851]: [15-Jun-2021 17:17:16] ERROR: unable to bind listening socket for address '127.0.0.1:9...se (98)
Jun 15 17:17:16 *.site php-fpm[17851]: [15-Jun-2021 17:17:16] ERROR: FPM initialization failed
Jun 15 17:17:16 *.site systemd[1]: rh-php72-php-fpm.service: main process exited, code=exited, status=78/n/a
Jun 15 17:17:16 *.site systemd[1]: Failed to start The PHP FastCGI Process Manager.
Jun 15 17:17:16 *.site systemd[1]: Unit rh-php72-php-fpm.service entered failed state.
Jun 15 17:17:16 *.site systemd[1]: rh-php72-php-fpm.service failed.

还是看不出什么问题,所以去系统日志里面看一下,地址是 /var/log/messages。

Jun 15 16:26:21 * php-fpm: [15-Jun-2021 16:26:21] ERROR: unable to bind listening socket for address '127.0.0.1:9000': Address already in use (98)
Jun 15 16:26:21 * php-fpm: [15-Jun-2021 16:26:21] ERROR: FPM initialization failed
Jun 15 16:26:21 * systemd: rh-php72-php-fpm.service: main process exited, code=exited, status=78/n/a
Jun 15 16:26:21 * systemd: Failed to start The PHP FastCGI Process Manager.
Jun 15 16:26:21 * systemd: Unit rh-php72-php-fpm.service entered failed state.
Jun 15 16:26:21 * systemd: rh-php72-php-fpm.service failed.

这里就能明显看出问题了,是9000端口被占用了。我们用 lsof(list open file) 指令查看一下端口在被谁占用。

lsof -i:9000

找到后要确认一下,是不是有人在用这个进程,如果没人用就就通过指令“kill 进程ID”结束这个进程,从而释放9000端口。这个时候我们再次开启 rh-php72-php-fpm 就没问题了。

通过命令行上传/下载文件

Linux 中的上传和下载指令:rz 和 sz,用的都是 ZModem 协议

如果没有这个工具的的话,就装一下,挺好用的。

yum install lrzsz -y

rz 就是 receive ZModem,从字面意思我们就能理解是服务器接受文件,也就是我们上传文件到服务器。我们在命令行输入完 rz 后,会出现一个弹窗,里面是本机的目录,我们在本机目录里选择想要上传到服务器的文件就好了。多选可以批量上传。

# 从本机接受(receive)文件
rz
# 从本机接受(receive)文件,强制覆盖同名文件
rz -y

sz 就是 send ZModem,从字面意思看就是服务器发送文件,也就是我们从服务器上下载文件。我们用这条指令的时候,需要在 sz 后面跟上我们想要下载到本地的文件的名字。然后也会出现一个弹窗,让我们选择下载到本地的地址。

# 将文件从服务器发送(send)到本机
sz 文件名
# 将文件从服务器发送(send)到本机,强制覆盖同名文件
sz -y 文件名

林皓伟

《【Zabbix系列】第三章:离线部署Zabbix服务端》有 15 条评论
  1. Thank you for sharing excellent informations. Your website is so cool. I am impressed by the details that you have on this website. It reveals how nicely you understand this subject. Bookmarked this web page, will come back for more articles. You, my friend, ROCK! I found just the info I already searched all over the place and just could not come across. What a great site. Darius Lipani

  2. I loved as much as you will receive carried out right here. The sketch is tasteful, your authored material stylish. nonetheless, you command get bought an nervousness over that you wish be delivering the following. unwell unquestionably come further formerly again since exactly the same nearly very often inside case you shield this increase. Cornell Strite

  3. Very good point which I had quickly initiate efficient initiatives without wireless web services. Interactively underwhelm turnkey initiatives before high-payoff relationships. Holisticly restore superior interfaces before flexible technology. Completely scale extensible relationships through empowered web-readiness. Anton Abdella

  4. I was curious if you ever thought of changing the structure of your site? 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 1 or two pictures. Maybe you could space it out better? Ira Picchetti

  5. I precisely wanted to thank you very much once again. I do not know the things that I could possibly have handled in the absence of these solutions shown by you about such a subject. It had been a scary situation in my circumstances, but being able to see the very skilled technique you handled it took me to weep for contentment. Now i am grateful for your support and wish you find out what a great job that you are accomplishing instructing the rest using your webpage. I know that you have never got to know any of us. Ahmad Mcroberts

  6. This is the perfect blog for anybody who wants to understand
    this topic. You know so much its almost tough to argue with you (not
    that I personally will need to…HaHa). You definitely put a brand new spin on a
    subject that has been written about for decades. Wonderful stuff, just wonderful!

    my webpage :: vpn special code

  7. Thank you so much for providing individuals with remarkably brilliant chance to read critical reviews from here. It is often very useful and also stuffed with a good time for me personally and my office co-workers to visit your web site on the least three times a week to study the fresh secrets you have got. And definitely, I am just usually pleased with the dazzling pointers you serve. Some 4 facts in this article are definitely the best I have had. Robert Centano

  8. I was wondering if you ever considered changing the page layout 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 1 or 2 pictures. Maybe you could space it out better? Ted Simonds

  9. Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your webpage? My website is in the very same area of interest as yours and my users would genuinely benefit from a lot of the information you provide here. Please let me know if this ok with you. Appreciate it! Newton Moltrie

  10. Thanks for the suggestions shared on the blog. One more thing I would like to talk about is that fat loss is not all about going on a dietary fads and trying to lose as much weight that you can in a couple of weeks. The most effective way to shed weight is by having it gradually and right after some basic tips which can assist you to make the most out of your attempt to shed pounds. You may learn and already be following these tips, however reinforcing knowledge never affects. Brett Schwing

  11. There are certainly a lot of information like that to consider. That is an excellent point to bring up. I offer the thoughts over as general ideas however clearly there are concerns like the one you raise where the most vital thing will be operating in truthful good faith. I don?t know if finest techniques have arised around points like that, however I am sure that your job is clearly identified as an up for grabs. Both young boys and also women feel the effect of simply a moment?s enjoyment, for the rest of their lives. Hyman Candlish

  12. carta credito de carros de luxo consorcio de automovel de luxo cartas credito de carros de luxo consorcios de carros de luxo consorcio de carro de luxo carta credito de veiculo de luxo carta de credito de veiculos de luxo carta de credito de carro de luxo consorcio de carros de luxo consorcio de carros de luxo consorcio de carros de luxo consorcios de carro de luxo cartas de credito de carros de luxo carta credito de veiculos de luxo carta credito de automoveis de luxo carta de credito de automoveis de luxo. Bobbie Luquin

  13. The next time I read a blog, I hope that it does not fail me as much as this particular one. I mean, Yes, it was my choice to read through, nonetheless I genuinely thought you would probably have something useful to say. All I hear is a bunch of crying about something that you can fix if you were not too busy looking for attention. Hung Carasquillo

  14. Can I simply say what a aid to search out somebody who actually is aware of what theyre speaking about on the internet. You definitely know the way to deliver a problem to gentle and make it important. Extra folks must read this and perceive this side of the story. I cant believe youre no more common since you undoubtedly have the gift. Man Pietrini

发表回复

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