天天看點

容器centos7安裝zabbix

使用特權模式啟動一個centos容器

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 "  > /etc/locale.conf && echo " >> /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"]

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

安裝zabbix倉庫

[[email protected] ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
[[email protected] ~]# yum clean all
           

安裝server和agent

安裝 Software Collections,便于後續安裝插件

修改倉庫為enable

[[email protected] 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等

下載下傳資料庫

[[email protected] ~]# yum install mariadb mariadb-server -y
[[email protected] ~]# systemctl enable mariadb 
[[email protected] ~]# vi /etc/my.cnf
port=13306
           

初始化資料庫

[[email protected] ~]# 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庫和使用者并授權

MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> create user [email protected] identified by 'linux';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all privileges on zabbix.* to [email protected];
Query OK, 0 rows affected (0.00 sec)
           

初始化zabbix庫,導入sql

[[email protected] ~]# 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時區

[[email protected] ~]# vi /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
php_value[date.timezone] = Asia/Shanghai
           

修改主zabbix配置檔案

[[email protected] ~]# vim /etc/zabbix/zabbix_server.conf
DBPassword=password
ListenPort=10040 因為主控端已使用
           

啟動服務

[[email protected] ~]# systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
[[email protected] ~]# systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
           

建構新鏡像

停止
[[email protected] ~]# docker stop centos
centos
打包
[[email protected] ~]# docker commit centos centos:v1
啟動新鏡像
[[email protected] ~]# 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
           

配置中文

[[email protected] ~]# cd /usr/share/zabbix/assets/fonts
[[email protected] fonts]# mv graphfont.ttf graphfont.ttf.back
[[email protected] fonts]# ln -s /root/simkai.ttf /usr/share/zabbix/assets/fonts/graphfont.ttf
[[email protected] fonts]# ll
lrwxrwxrwx 1 root root 16 Sep 26 07:14 graphfont.ttf -> /root/simkai.ttf