zabbix部署

记录下自己部署zabbix平台的步骤,涉及X86架构和arm架构两种。新增加docker-compose方式安装。



X86架构yum方式安装

X86架构部署


centos7安装zabbix5

记录的是centos7.6安装部署zabbix5.0.1版本

server安装

1、安装阿里云zabbix源

rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
yum clean all

2、安装软件包

yum install zabbix-server-mysql zabbix-agent -y
yum install centos-release-scl -y
yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y
yum install mariadb-server -y

3、数据库准备

yum install mariadb-server -y
#开机自启
systemctl enable --now mariadb
#安全初始化
mysql_secure_installation
#创建数据库
mysql -u root -p
#sql命令
create database zabbix character set utf8 collate utf8_bin;
create user zabbix@localhost identified by 'zabbix';
grant all privileges on zabbix.* to zabbix@localhost;
#导入zabbix表结构
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -pzabbix zabbix

4、服务启动准备
配置文件准备/etc/zabbix/zabbix_server.conf

#时区准备
 echo 'php_value[date.timezone] = Asia/Shanghai' >> /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
#字体库准备
yum install google-noto-sans-simplified-chinese-fonts.noarch -y
mv /etc/alternatives/zabbix-web-font /etc/alternatives/zabbix-web-font_bak
ln -s /usr/share/fonts/google-noto/NotoSansSC-Regular.otf /etc/alternatives/zabbix-web-font

5、服务启动

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

agent安装

1、安装阿里云zabbix源

rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm

2、安装

yum install zabbix-agent -y

3、配置文件准备
配置文件/etc/zabbix/zabbix_agentd.conf

4、启动服务

systemctl restart  zabbix-agent
systemctl enable  zabbix-agent

agent2安装

1、安装阿里云zabbix源

rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm

2、删除zabbix-agent,安装zabbix-agent2

yum remove zabbix-agent -y
yum install zabbix-agent2.x86_64 -y

3、配置zabbix-agent2
配置文件/etc/zabbix/zabbix_agent2.conf

server_IP="XX.XX.XX.XX"
echo $server_IP
sudo sed -i 's/^ServerActive=127.0.0.1/ServerActive='$server_IP'/' /etc/zabbix/zabbix_agent2.conf
sudo sed -i 's/^Server=127.0.0.1/Server='$server_IP'/' /etc/zabbix/zabbix_agent2.conf
localname=`hostname`
sudo sed -i 's/^Hostname=Zabbix server/Hostname='$localname'/' /etc/zabbix/zabbix_agent2.conf

4、启动服务,设置自启

service zabbix-agent2 restart 
service zabbix-agent2 status 
systemctl enable zabbix-agent2

5、当需要使用zabbix2监控docker服务时,需要将zabbix用户加到docker组,否则会出现Docker: Service is down的问题提示

usermod -a -G docker zabbix
service zabbix-agent2 restart

X86架构docker-compose方式安装

centos7安装最新版本zabbix-server

基本环境准备

1、配置selinux、防火墙、设置时区

#关闭防火墙
systemctl stop firewalld.service;
systemctl disable firewalld.service;
#设置时区
timedatectl set-timezone "Asia/Shanghai";
service rsyslog restart;
hwclock;

2、安装docker服务

#获取yum源
sudo yum-config-manager --add-repo  http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo;
#安装服务
yum install docker-ce docker-ce-cli -y;
systemctl restart docker ;
systemctl enable  docker ;

网络不好的可以提前下载下来镜像

docker pull mariadb:latest
docker pull zabbix/zabbix-web-nginx-mysql:latest
docker pull zabbix/zabbix-web-nginx-mysql:latest
docker pull zabbix/zabbix-web-nginx-mysql:latest

3、pip安装docker-compose服务

#获取pip,python版本是2.7.5
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py;
python get-pip.py;
#安装docker-compose
pip install docker-compose

路径准备、配置文件准备

·1、创建数据路径

mkdir -p /data/docker/mysql-data
mkdir -p /data/docker/zabbix

2、创建compose路径

mkdir -p /data/zabbix-compose/

3、创建配置文件zabbix.yml
端口按照自身环境需求更改,我这里改成了2万段内的端口

version: '3'
services: 
 
  zabbix_mysql:
    container_name: "zabbix_mysql"
    restart: "always"
    image: mariadb
    ports:
      - "23306:3306"
    volumes:
      - /data/docker/mysql-data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: "mysqlpss123"
      MYSQL_USER: "zabbix"
      MYSQL_PASSWORD: "mysqlpss123"
      MYSQL_DATABASE: "zabbix"
 
  zabbix_server:
    container_name: "zabbix_server"
    restart: "always"
    image: zabbix/zabbix-server-mysql
    ports:
      - "10051:10051"
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /data/docker/zabbix:/usr/lib/zabbix
    depends_on:
      - zabbix_mysql
    links:
      - zabbix_mysql:mysql
    environment:
      DB_SERVER_HOST: "mysql"
      MYSQL_USER: "zabbix"
      MYSQL_DATABASE: "zabbix"
      MYSQL_PASSWORD: "mysqlpss123"
 
  zabbix_nginx_web:
    container_name: "zabbix_nginx_web"
    restart: "always"
    image: zabbix/zabbix-web-nginx-mysql
    ports:
      - "28443:443"
      - "20080:8080"
    depends_on:
      - zabbix_mysql
      - zabbix_server
    links:
      - zabbix_mysql:mysql
      - zabbix_server:zabbix_server
    environment:
      DB_SERVER_HOST: "mysql"
      MYSQL_USER: "zabbix"
      MYSQL_PASSWORD: "mysqlpss123"
      MYSQL_DATABASE: "zabbix"
      ZBX_SERVER_HOST: "zabbix_server"
      PHP_TZ: "Asia/Shanghai"
 
 zabbix_agent:
    image: zabbix/zabbix-agent
    links: 
      - zabbix_server:zabbix_server
    container_name: zabbix-agent
    restart: always
    depends_on:
      - zabbix_server
    environment:
      - ZBX_HOSTNAME=Zabbix server
      - ZBX_SERVER_HOST=zabbix_server

服务启动

1、服务启动

cd /data/zabbix-compose/
docker-compose -f zabbix.yml  up -d

2、服务查看

cd /data/zabbix-compose/
docker-compose -f zabbix.yml ps

在这里插入图片描述

访问页面、配置zabbix server监控

初始用户名:Admin
初始密码:zabbix
配置主机,修改Zabbix server链接方式,修改为DNS链接
在这里插入图片描述


ARM架构yum方式安装

centos7安装zabbix40

server安装

1、安装源准备/etc/yum.repos.d/epel.repo

cat /etc/yum.repos.d/epel.repo 

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0

2、安装

yum clean all
yum makecache
#由于数据库使用mariadb,所以不安装pgsql相关软件包
yum install zabbix40-server.noarch zabbix40-server-mysql.aarch64  zabbix40-web.noarch zabbix40-web-mysql.noarch 

3、mariadb安装并配置innodb_strict_mode,使用中科大的源
安装源准备/etc/yum.repos.d/MariaDB.repo

cat /etc/yum.repos.d/MariaDB.repo

[mariadb]
name = MariaDB
baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.2/centos7-aarch64/
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
#安装
yum clean all
yum makecache
yum install MariaDB-server.aarch64 MariaDB-client.aarch64
#修改配置
#/etc/my.cnf增加下列配置,否则会出现Row size too large (> 8126)问题
[mysqld]
innodb_strict_mode = 0
#启动服务
systemctl start mariadb
systemctl enable mariadb
systemctl status mariadb
#安全配置
mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

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


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

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

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] N
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y

 - Dropping test database...
   ... Success!
 - Removing privileges on test database...
   ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

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

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

4、数据库配置

#创建zabbix用户及数据库
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
#初始化表,一定要按准许执行
mysql -uroot -p --default-character-set=utf8 zabbix</usr/share/zabbix-mysql/schema.sql
mysql -uroot -p --default-character-set=utf8 zabbix</usr/share/zabbix-mysql/images.sql
mysql -uroot -p --default-character-set=utf8 zabbix</usr/share/zabbix-mysql/data.sql

5、zabbix服务启动

systemctl start zabbix-server
systemctl enable zabbix-server
systemctl status zabbix-server

6、httpd服务启动

#配置时区
vim /etc/php.ini
date.timezone = Asia/Shanghai
#启动httpd
systemctl enable  httpd
systemctl start httpd
systemctl status httpd

字体问题处理
字体文件都在 /usr/share/zabbix/assets/fonts/目录下,解决方式参考下方链接
https://www.cnblogs.com/zhenxing06/p/13704864.html


# 总结 不同架构不同版本的部署方式不同,需要根据实际物理环境选择部署方式。
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐