定制zabbix-server-postgresql 6.2.6的docker镜像

本文指导如何定制打包zabbix的server程序包,以便后期迁移到国产操作系统openeuler上运行。

一、准备Centos8容器环境

1、打包环境为Centos8stream最小化安装环境,已调通外部网络。

[root@localhost opt]# cat /etc/redhat-release 
CentOS Stream release 8

2、首先在Centos8stream最小化系统中安装docker

[root@localhost ~]# yum install docker -y
Last metadata expiration check: 0:02:07 ago on 2023年01月11日 星期三 13时14分24秒.
Dependencies resolved.
=========================================================================================
 Package               Architecture   Version                       Repository      Size
=========================================================================================
Installing:
 docker-engine         x86_64         2:18.09.0-311.oe2203          update          38 M
Installing dependencies:
 libcgroup             x86_64         0.42.2-2.oe2203               update          97 k
 tar                   x86_64         2:1.34-1.oe2203               OS             785 k

Transaction Summary
=========================================================================================
Install  3 Packages

Total size: 39 M
Installed size: 163 M
Downloading Packages:
[SKIPPED] tar-1.34-1.oe2203.x86_64.rpm: Already downloaded                              
[SKIPPED] docker-engine-18.09.0-311.oe2203.x86_64.rpm: Already downloaded               
[SKIPPED] libcgroup-0.42.2-2.oe2203.x86_64.rpm: Already downloaded                      
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                 1/1 
  Running scriptlet: libcgroup-0.42.2-2.oe2203.x86_64                                1/3 
  Installing       : libcgroup-0.42.2-2.oe2203.x86_64                                1/3 
  Running scriptlet: libcgroup-0.42.2-2.oe2203.x86_64                                1/3 
  Running scriptlet: tar-2:1.34-1.oe2203.x86_64                                      2/3 
  Installing       : tar-2:1.34-1.oe2203.x86_64                                      2/3 
  Running scriptlet: tar-2:1.34-1.oe2203.x86_64                                      2/3 
  Installing       : docker-engine-2:18.09.0-311.oe2203.x86_64                       3/3 
  Running scriptlet: docker-engine-2:18.09.0-311.oe2203.x86_64                       3/3 
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.

  Verifying        : tar-2:1.34-1.oe2203.x86_64                                      1/3 
  Verifying        : docker-engine-2:18.09.0-311.oe2203.x86_64                       2/3 
  Verifying        : libcgroup-0.42.2-2.oe2203.x86_64                                3/3 

Installed:
  docker-engine-2:18.09.0-311.oe2203.x86_64       libcgroup-0.42.2-2.oe2203.x86_64      
  tar-2:1.34-1.oe2203.x86_64                     

Complete!

3、接下来拉取centos最新的镜像包

[root@localhost ~]# docker pull centos:latest
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Resolved "centos" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
Trying to pull quay.io/centos/centos:latest...
Getting image source signatures
Copying blob 7a0437f04f83 skipped: already exists  
Copying config 300e315adb done  
Writing manifest to image destination
Storing signatures
300e315adb2f96afe5f0b2780b87f28ae95231fe3bdd1e16b9ba606307728f55

4、通过docker images指令可以看到包已正常下载。

[root@localhost ~]# docker images                           
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
REPOSITORY                TAG         IMAGE ID      CREATED         SIZE
quay.io/centos/centos     latest      300e315adb2f  2 years ago     217 MB

5、现在启动一个名为centos-zbxsvr的容器

[root@localhost ~]# docker run -itd --name centos-zbxsvr centos:latest
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
a5c7a3702a22e87ca7a4bf1539983e41d4a7cc17cc7c767d62a630b2e58802d6
[root@localhost ~]# docker ps
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
CONTAINER ID  IMAGE                         COMMAND     CREATED         STATUS             PORTS       NAMES
a5c7a3702a22  quay.io/centos/centos:latest  /bin/bash   11 seconds ago  Up 11 seconds ago              centos-zbxsvr
[root@localhost ~]# docker exec -it centos-zbxsvr /bin/bash
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
[root@a5c7a3702a22 /]# ls
bin  etc   lib    lost+found  mnt  proc  run   srv  tmp  var
dev  home  lib64  media       opt  root  sbin  sys  usr
[root@a5c7a3702a22 /]# cat /etc/redhat-release 
CentOS Linux release 8.3.2011

可以看到,当前容器为CentOS Linux release 8.3.2011版本。

二、在容器内安装zabbix-server程序

1、准备yum源(本步接上一步,在容器内操作)

[root@a5c7a3702a22 yum.repos.d]# ls
CentOS-Linux-AppStream.repo          CentOS-Linux-HighAvailability.repo
CentOS-Linux-BaseOS.repo             CentOS-Linux-Media.repo
CentOS-Linux-ContinuousRelease.repo  CentOS-Linux-Plus.repo
CentOS-Linux-Debuginfo.repo          CentOS-Linux-PowerTools.repo
CentOS-Linux-Devel.repo              CentOS-Linux-Sources.repo
CentOS-Linux-Extras.repo             zabbix-agent2-plugins.repo
CentOS-Linux-FastTrack.repo          zabbix.repo
[root@a5c7a3702a22 yum.repos.d]# rm CentOS-Linux-* -rf
[root@a5c7a3702a22 yum.repos.d]# vi os.repo
[root@a5c7a3702a22 yum.repos.d]# vi baseos.repo
[root@a5c7a3702a22 yum.repos.d]# cat /etc/yum.repos.d/os.repo 
[os]
name=os
baseurl=http://mirrors.163.com/centos/8-stream/AppStream/x86_64/os/
enable=1
gpgcheck=0
[root@a5c7a3702a22 yum.repos.d# cat /etc/yum.repos.d/baseos.repo 
[baseos]
name=baseos
baseurl=http://mirrors.163.com/centos/8-stream/BaseOS/x86_64/os/
enbale=1
gpgcheck=0
[root@a5c7a3702a22 yum.repos.d]# rpm -Uvh https://repo.zabbix.com/zabbix/6.2/rhel/8/x86_64/zabbix-release-6.2-3.el8.noarch.rpm
Retrieving https://repo.zabbix.com/zabbix/6.2/rhel/8/x86_64/zabbix-release-6.2-3.el8.noarch.rpm
warning: /var/tmp/rpm-tmp.wx3vWU: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:zabbix-release-6.2-3.el8         ################################# [100%]
[root@a5c7a3702a22 yum.repos.d]# ls -l /etc/yum.repos.d/ 
total 16
-rw-r--r--. 1 root root 106 Jan 11 05:42 baseos.repo
-rw-r--r--. 1 root root 101 Jan 11 05:41 os.repo
-rw-r--r--. 1 root root 230 Sep 14 13:05 zabbix-agent2-plugins.repo
-rw-r--r--. 1 root root 628 Sep 14 13:05 zabbix.repo

2、安装zabbix-server

[root@a5c7a3702a22 yum.repos.d]# dnf install zabbix-server-pgsql zabbix-sql-scripts
Failed to set locale, defaulting to C.UTF-8
baseos                                                   1.5 MB/s |  26 MB     00:17    
os                                                       2.0 MB/s |  27 MB     00:13    
Last metadata expiration check: 0:00:04 ago on Wed Jan 11 05:42:46 2023.
Dependencies resolved.
=========================================================================================
 Package                Arch      Version                  Repository               Size
=========================================================================================
Installing:
 zabbix-server-pgsql    x86_64    6.2.6-release1.el8       zabbix                  1.7 M
 zabbix-sql-scripts     noarch    6.2.6-release1.el8       zabbix                  7.2 M
Installing dependencies:
 OpenIPMI-libs          x86_64    2.0.31-3.el8             baseos                  509 k
 fping                  x86_64    3.16-1.el8               zabbix-non-supported     51 k
 libevent               x86_64    2.1.8-5.el8              baseos                  253 k
 libpq                  x86_64    13.5-1.el8               os                      198 k
 libssh                 x86_64    0.9.6-5.el8              baseos                  216 k
 libssh-config          noarch    0.9.6-5.el8              baseos                   20 k
 libtool-ltdl           x86_64    2.4.6-25.el8             baseos                   58 k
 net-snmp-libs          x86_64    1:5.8-26.el8             baseos                  827 k
 unixODBC               x86_64    2.3.7-1.el8              os                      458 k

Transaction Summary
=========================================================================================
Install  11 Packages

Total download size: 11 M
Installed size: 26 M
Is this ok [y/N]: y
Downloading Packages:
(1/11): libssh-0.9.6-5.el8.x86_64.rpm                    447 kB/s | 216 kB     00:00    
(2/11): libevent-2.1.8-5.el8.x86_64.rpm                  476 kB/s | 253 kB     00:00    
(3/11): libssh-config-0.9.6-5.el8.noarch.rpm             185 kB/s |  20 kB     00:00    
(4/11): libtool-ltdl-2.4.6-25.el8.x86_64.rpm             368 kB/s |  58 kB     00:00    
(5/11): OpenIPMI-libs-2.0.31-3.el8.x86_64.rpm            713 kB/s | 509 kB     00:00    
(6/11): libpq-13.5-1.el8.x86_64.rpm                      461 kB/s | 198 kB     00:00    
(7/11): unixODBC-2.3.7-1.el8.x86_64.rpm                  825 kB/s | 458 kB     00:00    
(8/11): net-snmp-libs-5.8-26.el8.x86_64.rpm              1.1 MB/s | 827 kB     00:00    
(9/11): fping-3.16-1.el8.x86_64.rpm                       16 kB/s |  51 kB     00:03    
(10/11): zabbix-server-pgsql-6.2.6-release1.el8.x86_64.r  74 kB/s | 1.7 MB     00:23    
(11/11): zabbix-sql-scripts-6.2.6-release1.el8.noarch.rp  47 kB/s | 7.2 MB     02:38    
-----------------------------------------------------------------------------------------
Total                                                     73 kB/s |  11 MB     02:39     
warning: /var/cache/dnf/zabbix-ec9d61101606006d/packages/zabbix-server-pgsql-6.2.6-release1.el8.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Zabbix Official Repository - x86_64                      1.6 MB/s | 1.7 kB     00:00    
Importing GPG key 0xA14FE591:
 Userid     : "Zabbix LLC <packager@zabbix.com>"
 Fingerprint: A184 8F53 52D0 22B9 471D 83D0 082A B56B A14F E591
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
Is this ok [y/N]: y
Key imported successfully
warning: /var/cache/dnf/zabbix-non-supported-fd580106adc78ca9/packages/fping-3.16-1.el8.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 79ea5ed4: NOKEY
Zabbix Official Repository (non-supported) - x86_64      1.3 MB/s | 1.3 kB     00:00    
Importing GPG key 0x79EA5ED4:
 Userid     : "Zabbix SIA <packager@zabbix.com>"
 Fingerprint: FBAB D5FB 2025 5ECA B22E E194 D13D 58E4 79EA 5ED4
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                 1/1 
  Installing       : net-snmp-libs-1:5.8-26.el8.x86_64                              1/11 
  Installing       : OpenIPMI-libs-2.0.31-3.el8.x86_64                              2/11 
  Installing       : fping-3.16-1.el8.x86_64                                        3/11 
  Installing       : libpq-13.5-1.el8.x86_64                                        4/11 
  Installing       : libtool-ltdl-2.4.6-25.el8.x86_64                               5/11 
  Running scriptlet: libtool-ltdl-2.4.6-25.el8.x86_64                               5/11 
  Installing       : unixODBC-2.3.7-1.el8.x86_64                                    6/11 
  Running scriptlet: unixODBC-2.3.7-1.el8.x86_64                                    6/11 
  Installing       : libssh-config-0.9.6-5.el8.noarch                               7/11 
  Installing       : libssh-0.9.6-5.el8.x86_64                                      8/11 
  Installing       : libevent-2.1.8-5.el8.x86_64                                    9/11 
  Running scriptlet: zabbix-server-pgsql-6.2.6-release1.el8.x86_64                 10/11 
  Installing       : zabbix-server-pgsql-6.2.6-release1.el8.x86_64                 10/11 
  Running scriptlet: zabbix-server-pgsql-6.2.6-release1.el8.x86_64                 10/11 
  Installing       : zabbix-sql-scripts-6.2.6-release1.el8.noarch                  11/11 
  Running scriptlet: zabbix-sql-scripts-6.2.6-release1.el8.noarch                  11/11 
  Verifying        : OpenIPMI-libs-2.0.31-3.el8.x86_64                              1/11 
  Verifying        : libevent-2.1.8-5.el8.x86_64                                    2/11 
  Verifying        : libssh-0.9.6-5.el8.x86_64                                      3/11 
  Verifying        : libssh-config-0.9.6-5.el8.noarch                               4/11 
  Verifying        : libtool-ltdl-2.4.6-25.el8.x86_64                               5/11 
  Verifying        : net-snmp-libs-1:5.8-26.el8.x86_64                              6/11 
  Verifying        : libpq-13.5-1.el8.x86_64                                        7/11 
  Verifying        : unixODBC-2.3.7-1.el8.x86_64                                    8/11 
  Verifying        : zabbix-server-pgsql-6.2.6-release1.el8.x86_64                  9/11 
  Verifying        : zabbix-sql-scripts-6.2.6-release1.el8.noarch                  10/11 
  Verifying        : fping-3.16-1.el8.x86_64                                       11/11 

Installed:
  OpenIPMI-libs-2.0.31-3.el8.x86_64                                                      
  fping-3.16-1.el8.x86_64                                                                
  libevent-2.1.8-5.el8.x86_64                                                            
  libpq-13.5-1.el8.x86_64                                                                
  libssh-0.9.6-5.el8.x86_64                                                              
  libssh-config-0.9.6-5.el8.noarch                                                       
  libtool-ltdl-2.4.6-25.el8.x86_64                                                       
  net-snmp-libs-1:5.8-26.el8.x86_64                                                      
  unixODBC-2.3.7-1.el8.x86_64                                                            
  zabbix-server-pgsql-6.2.6-release1.el8.x86_64                                          
  zabbix-sql-scripts-6.2.6-release1.el8.noarch                                           

Complete!

3、检查安装情况

[root@a5c7a3702a22 yum.repos.d]# rpm -qa |grep zabbix
zabbix-sql-scripts-6.2.6-release1.el8.noarch
zabbix-release-6.2-3.el8.noarch
zabbix-server-pgsql-6.2.6-release1.el8.x86_64

4、测试运行情况

[root@a5c7a3702a22 yum.repos.d]# cd /
[root@a5c7a3702a22 /]# /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf   
[root@a5c7a3702a22 init.d]# ps -ef |grep zabbix_server                              
zabbix       154       1  0 06:07 ?        00:00:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
root         156      16  0 06:07 pts/1    00:00:00 grep --color=auto zabbix_server
[root@a5c7a3702a22 /]# ls /var/log/zabbix/                                    
zabbix_server.log
[root@a5c7a3702a22 init.d]# cat /var/log/zabbix/zabbix_server.log 
   154:20230111:060736.263 Starting Zabbix Server. Zabbix 6.2.6 (revision 6981d8b729a).
   154:20230111:060736.263 ****** Enabled features ******
   154:20230111:060736.263 SNMP monitoring:           YES
   154:20230111:060736.263 IPMI monitoring:           YES
   154:20230111:060736.263 Web monitoring:            YES
   154:20230111:060736.263 VMware monitoring:         YES
   154:20230111:060736.263 SMTP authentication:       YES
   154:20230111:060736.263 ODBC:                      YES
   154:20230111:060736.263 SSH support:               YES
   154:20230111:060736.263 IPv6 support:              YES
   154:20230111:060736.263 TLS support:               YES
   154:20230111:060736.263 ******************************
   154:20230111:060736.263 using configuration file: /etc/zabbix/zabbix_server.conf
   154:20230111:060736.264 [Z3001] connection to database 'zabbix' failed: [0] could not connect to server: Connection refused
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?

   154:20230111:060736.264 database is down: reconnecting in 10 seconds
[root@a5c7a3702a22 /]# ^C

可见服务器程序能正常启动。

三、检查容器状态和服务开放情况

1、通过docker ps指令查看容器运行状态

[root@localhost opt]# docker ps
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
CONTAINER ID  IMAGE                         COMMAND               CREATED         STATUS             PORTS                     NAMES
aa283c7d9c8d  localhost/zabbixsrvpg:v6.2.6  sh -c /usr/sbin/z...  37 seconds ago  Up 38 seconds ago  0.0.0.0:10051->10051/tcp  centos-zbxsvr

2、通过netstat指令查看服务端口运行情况

[root@localhost opt]# netstat -an |grep :10051
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN     
[root@localhost opt]# netstat -antup |grep :10051
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      6035/conmon  

3、通过docker logs查看容器运行日志

[root@localhost opt]# docker logs -f centos-zbxsvr
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Starting Zabbix Server. Zabbix 6.2.6 (revision 6981d8b729a).
Press Ctrl+C to exit.

^C

三、保存容器为新的镜像

[root@localhost opt]# docker save -o zabbixsrvpg-v6.2.6.tar zabbixsrvpg:v6.2.6    
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Copying blob 2653d992f4ef done  
Copying blob 6953f81cfe2b done  
Copying config 69efc09a47 done  
Writing manifest to image destination
Storing signatures
[root@localhost opt]# ll zabbixsrvpg-v6.2.6.tar 
-rw-r--r--. 1 root root 359762944 1月  11 03:35 zabbixsrvpg-v6.2.6.tar
[root@localhost opt]# 

至此zabbix-server服务器postgresql数据库V6.2.6的docker离线镜像即打包制作完成。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

代先生.重庆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值