docker-commpose传送门: zbx_server || zbx_web || zbx_mysq || zbx_gateway.


使用特权模式启动一个centos容器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
FROM centos:centos7.9.2009
WORKDIR /root/
RUN rm -f /etc/yum.repos.d/*
ADD ./CentOS-Base.repo /etc/yum.repos.d/
ADD ./sql /root/
ADD ./simkai.ttf /root/
RUN yum clean all \
&& yum makecache \
&& yum install wget less curl gcc gcc-c++ vim kde-l10n-Chinese net-tools -y

RUN yum reinstall glibc-common -y
RUN echo " LANG=zh_CN.UTF-8" > /etc/locale.conf && echo "LANG=zh_CN.UTF-8" >> /etc/environment \
&& echo "LC_ALL=" >> /etc/environment
CMD ["source", "/etc/environment"]
CMD ["localedef", "-v", "-c", "-i", "zh_CN", "-f", "UTF-8", "zh_CN.UTF-8"]

[root@zabbix centos]# docker build . -t harbor.od.com/public/centos7:latest
1
docker run -itd --name centos --privileged=true -p 777:777 centos7:latest /usr/sbin/init

安装zabbix仓库

1
2
[root@0e5c10ce59d6 ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
[root@0e5c10ce59d6 ~]# yum clean all

安装server和agent

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

安装 Software Collections,便于后续安装插件

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

修改仓库为enable

1
2
3
4
5
[root@0e5c10ce59d6 yum.repos.d]# vi zabbix.repo 
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1

下载前端插件 php等

1
[root@0e5c10ce59d6 ~]# yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y

下载数据库

1
2
3
4
[root@0e5c10ce59d6 ~]# yum install mariadb mariadb-server -y
[root@0e5c10ce59d6 ~]# systemctl enable mariadb
[root@51b54d60dff6 ~]# vi /etc/my.cnf
port=13306

初始化数据库

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

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!

Remove anonymous users? [Y/n] Y
... Success!

Disallow root login remotely? [Y/n] Y
... Success!

Remove test database and access to it? [Y/n]
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reload privilege tables now? [Y/n]
... Success!

Cleaning up...
Thanks for using MariaDB!

创建zabbix库和用户并授权

1
2
3
4
5
6
7
8
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 'linux';
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)

初始化zabbix库,导入sql

1
2
3
4
5
6
7
[root@0e5c10ce59d6 ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

容器centos没找到sql压缩包,使用源码包sql导入
MariaDB [zabbix]> use zabbix;
MariaDB [(none)]> source /root/schema.sql
MariaDB [(none)]> source /root/images.sql
MariaDB [(none)]> source /root/data.sql

修改php时区

1
2
[root@51b54d60dff6 ~]# vi /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
php_value[date.timezone] = Asia/Shanghai

修改主zabbix配置文件

1
2
3
[root@51b54d60dff6 ~]# vim /etc/zabbix/zabbix_server.conf
DBPassword=password
ListenPort=10040 因为宿主机已使用

启动服务

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

构建新镜像

1
2
3
4
5
6
7
8
9
10
11
12
停止
[root@zabbix ~]# docker stop centos
centos
打包
[root@zabbix ~]# docker commit centos centos:v1
启动新镜像
[root@zabbix ~]# docker run -itd --name centos-1 --privileged=true -p 10040:10040 -p 10041:10041 -p 777:777 centos:v1 /usr/sbin/init
10041 zabbix-server
10040 zabbix-agent
777 httpd
13306 mariadb
username/password Admin/zabbix

配置中文

1
2
3
4
5
[root@e148c0d2458d ~]# cd /usr/share/zabbix/assets/fonts
[root@e148c0d2458d fonts]# mv graphfont.ttf graphfont.ttf.back
[root@e148c0d2458d fonts]# ln -s /root/simkai.ttf /usr/share/zabbix/assets/fonts/graphfont.ttf
[root@e148c0d2458d fonts]# ll
lrwxrwxrwx 1 root root 16 Sep 26 07:14 graphfont.ttf -> /root/simkai.ttf