V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
wsgzao
V2EX  ›  程序员

Zabbix 3.x 升级到 Zabbix 4.x

  •  
  •   wsgzao ·
    wsgzao · 2018-11-02 11:18:23 +08:00 · 3431 次点击
    这是一个创建于 2219 天前的主题,其中的信息可能已经有所发展或是发生改变。

    前言

    Zabbix 目前已经发布 4.0 LTS 长期支持版,虽然很多插件还停留在 3.4 版本比如 Grafana,但是还是要提前做好准备。生产环境建议暂时保持在 3.4 版本,因为在 4.0 版本中很多语法发生改变,建议仔细评估。最重要的事情提醒三遍,不要忘记备份,不要忘记备份,不要忘记备份。

    Zabbix 3.x 升级到 Zabbix 4.x

    更新历史

    2018 年 11 月 01 日 - 初稿

    阅读原文 - https://wsgzao.github.io/post/zabbix-upgrade/

    扩展阅读

    Zabbix - https://www.zabbix.com/


    官方文档

    https://www.zabbix.com/documentation/4.0/manual/installation/upgrade_notes_400

    https://www.zabbix.com/documentation/3.4/zh/manual/installation/upgrade

    https://www.zabbix.com/download

    Zabbix 升级步骤

    备份数据库

    # 数据库全备时间比较长且文件交大,建议压缩或者使用 xtrabackup
    mysqldump -uzabbix -pzabbix --opt --skip-lock-tables --database zabbix > zabbix.sql
    mysqldump -uzabbix -pzabbix --opt --skip-lock-tables --database zabbix | gzip > zabbix_`date +'%Y%m%d%H%M%S'`.sql.gz
    

    CentOS

    # 停止服务
    service zabbix-server stop
    service zabbix-agent stop
    service httpd stop
    
    # 备份 zabbix 文件
    mkdir /opt/zabbix-backup/
    cp /etc/zabbix/zabbix_server.conf /opt/zabbix-backup/
    cp /etc/httpd/conf.d/zabbix.conf  /opt/zabbix-backup/
    cp -R /usr/share/zabbix/ /opt/zabbix-backup/
    cp -R /usr/share/doc/zabbix-* /opt/zabbix-backup/
    
    # 升级 zabbix 源
    rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
    # 升级 zabbix
    # yum upgrade zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-proxy-mysql
    yum clean all
    yum upgrade zabbix-server-mysql zabbix-web-mysql zabbix-agent 
    
    # 启动 zabbix
    service zabbix-server start
    service zabbix-agent start
    service httpd start
    
    # 检查升级日志
    tail -f /var/log/zabbix/zabbix_server.log
    
    5044:20181101:212148.975 Starting Zabbix Server. Zabbix 4.0.1 (revision 86073).
      5044:20181101:212149.173 ****** Enabled features ******
      5044:20181101:212149.173 SNMP monitoring:           YES
      5044:20181101:212149.173 IPMI monitoring:           YES
      5044:20181101:212149.173 Web monitoring:            YES
      5044:20181101:212149.173 VMware monitoring:         YES
      5044:20181101:212149.173 SMTP authentication:       YES
      5044:20181101:212149.173 Jabber notifications:      YES
      5044:20181101:212149.173 Ez Texting notifications:  YES
      5044:20181101:212149.173 ODBC:                      YES
      5044:20181101:212149.173 SSH2 support:              YES
      5044:20181101:212149.173 IPv6 support:              YES
      5044:20181101:212149.173 TLS support:               YES
      5044:20181101:212149.173 ******************************
      5044:20181101:212149.173 using configuration file: /etc/zabbix/zabbix_server.conf
      5044:20181101:212149.276 current database version (mandatory/optional): 03040000/03040007
      5044:20181101:212149.360 required mandatory version: 04000000
      5044:20181101:212149.361 starting automatic database upgrade
      5044:20181101:212149.774 completed 0% of database upgrade
      5044:20181101:212149.775 completed 1% of database upgrade
      5044:20181101:212149.865 completed 2% of database upgrade
      5044:20181101:212149.867 completed 3% of database upgrade
      5044:20181101:212149.871 completed 4% of database upgrade
      5044:20181101:212149.874 completed 5% of database upgrade
      5044:20181101:212149.922 completed 6% of database upgrade
      5044:20181101:212150.015 completed 7% of database upgrade
      5044:20181101:212150.169 completed 8% of database upgrade
      5044:20181101:212150.314 completed 9% of database upgrade
      5044:20181101:212150.469 completed 10% of database upgrade
      5044:20181101:212150.523 completed 11% of database upgrade
      5044:20181101:212150.563 completed 12% of database upgrade
      5044:20181101:212150.565 completed 13% of database upgrade
      5044:20181101:212150.574 completed 14% of database upgrade
      5044:20181101:212150.621 completed 15% of database upgrade
      5044:20181101:212150.715 completed 16% of database upgrade
      5044:20181101:212150.809 completed 17% of database upgrade
      5044:20181101:212150.818 completed 18% of database upgrade
      5044:20181101:212150.867 completed 19% of database upgrade
      5044:20181101:212150.871 completed 20% of database upgrade
      5044:20181101:212150.959 completed 21% of database upgrade
      5044:20181101:212151.124 completed 22% of database upgrade
      5044:20181101:212151.209 completed 23% of database upgrade
      5044:20181101:212151.272 completed 24% of database upgrade
      5044:20181101:212151.275 completed 25% of database upgrade
      5044:20181101:212151.314 completed 26% of database upgrade
      5044:20181101:212152.118 completed 27% of database upgrade
      5044:20181101:212152.613 completed 28% of database upgrade
      5044:20181101:212153.271 completed 29% of database upgrade
      5044:20181101:212153.570 completed 30% of database upgrade
      5044:20181101:212154.869 completed 31% of database upgrade
      5044:20181101:212156.368 completed 32% of database upgrade
      5044:20181101:212156.665 completed 33% of database upgrade
      5044:20181101:212157.465 completed 34% of database upgrade
      5044:20181101:212157.820 completed 35% of database upgrade
      5044:20181101:212158.509 completed 36% of database upgrade
      5044:20181101:212200.662 completed 37% of database upgrade
      5044:20181101:212200.710 completed 38% of database upgrade
      5044:20181101:212200.715 completed 39% of database upgrade
      5044:20181101:212200.761 completed 40% of database upgrade
      5044:20181101:212200.807 completed 41% of database upgrade
      5044:20181101:212200.810 completed 42% of database upgrade
      5044:20181101:212200.811 completed 43% of database upgrade
      5044:20181101:212200.813 completed 44% of database upgrade
      5044:20181101:212200.815 completed 45% of database upgrade
      5044:20181101:212200.818 completed 46% of database upgrade
      5044:20181101:212200.913 completed 47% of database upgrade
      5044:20181101:212200.960 completed 48% of database upgrade
      5044:20181101:212201.013 completed 49% of database upgrade
      5044:20181101:212201.116 completed 50% of database upgrade
      5044:20181101:212201.119 completed 51% of database upgrade
      5044:20181101:212201.157 completed 52% of database upgrade
      5044:20181101:212201.160 completed 53% of database upgrade
      5044:20181101:212201.164 completed 54% of database upgrade
      5044:20181101:212201.166 completed 55% of database upgrade
      5044:20181101:212201.169 completed 56% of database upgrade
      5044:20181101:212201.206 completed 57% of database upgrade
      5044:20181101:212201.208 completed 58% of database upgrade
      5044:20181101:212201.305 completed 59% of database upgrade
      5044:20181101:212201.308 completed 60% of database upgrade
      5044:20181101:212201.311 completed 61% of database upgrade
      5044:20181101:212201.356 completed 62% of database upgrade
      5044:20181101:212201.363 completed 63% of database upgrade
      5044:20181101:212201.413 completed 64% of database upgrade
      5044:20181101:212201.414 completed 65% of database upgrade
      5044:20181101:212201.465 completed 66% of database upgrade
      5044:20181101:212201.517 completed 67% of database upgrade
      5044:20181101:212201.562 completed 68% of database upgrade
      5044:20181101:212201.656 completed 69% of database upgrade
      5044:20181101:212201.666 completed 70% of database upgrade
      5044:20181101:212201.719 completed 71% of database upgrade
      5044:20181101:212201.758 completed 72% of database upgrade
      5044:20181101:212201.760 completed 73% of database upgrade
      5044:20181101:212201.764 completed 74% of database upgrade
      5044:20181101:212201.766 completed 75% of database upgrade
      5044:20181101:212201.817 completed 76% of database upgrade
      5044:20181101:212201.862 completed 77% of database upgrade
      5044:20181101:212202.054 completed 78% of database upgrade
      5044:20181101:212202.112 completed 79% of database upgrade
      5044:20181101:212202.158 completed 80% of database upgrade
      5044:20181101:212202.210 completed 81% of database upgrade
      5044:20181101:212202.261 completed 82% of database upgrade
      5044:20181101:212202.315 completed 83% of database upgrade
      5044:20181101:212202.566 completed 84% of database upgrade
      5044:20181101:212202.609 completed 85% of database upgrade
      5044:20181101:212202.619 completed 86% of database upgrade
      5044:20181101:212202.656 completed 87% of database upgrade
      5044:20181101:212202.659 completed 88% of database upgrade
      5044:20181101:212202.661 completed 89% of database upgrade
      5044:20181101:212202.669 completed 90% of database upgrade
      5044:20181101:212202.761 completed 91% of database upgrade
      5044:20181101:212203.214 completed 92% of database upgrade
      5044:20181101:212203.360 completed 93% of database upgrade
      5044:20181101:212203.365 completed 94% of database upgrade
      5044:20181101:212203.403 completed 95% of database upgrade
      5044:20181101:212203.417 completed 96% of database upgrade
      5044:20181101:212203.467 completed 97% of database upgrade
      5044:20181101:212203.508 completed 98% of database upgrade
      5044:20181101:212203.564 completed 99% of database upgrade
      5044:20181101:212203.566 completed 100% of database upgrade
      5044:20181101:212203.566 database upgrade fully completed
      5044:20181101:212203.660 starting event name update forced by database upgrade
      5044:20181101:212203.706 completed 1% of event name update
      5044:20181101:212203.706 completed 2% of event name update
      5044:20181101:212203.706 completed 3% of event name update
      5044:20181101:212203.706 completed 4% of event name update
      5044:20181101:212203.706 completed 5% of event name update
      5044:20181101:212203.706 completed 6% of event name update
      5044:20181101:212203.706 completed 7% of event name update
      5044:20181101:212203.706 completed 8% of event name update
      5044:20181101:212203.706 completed 9% of event name update
      5044:20181101:212203.706 completed 10% of event name update
      5044:20181101:212203.706 completed 11% of event name update
      5044:20181101:212203.706 completed 12% of event name update
      5044:20181101:212203.707 completed 13% of event name update
      5044:20181101:212203.707 completed 14% of event name update
      5044:20181101:212203.707 completed 15% of event name update
      5044:20181101:212203.707 completed 16% of event name update
      5044:20181101:212203.707 completed 17% of event name update
      5044:20181101:212203.707 completed 18% of event name update
      5044:20181101:212203.707 completed 19% of event name update
      5044:20181101:212203.707 completed 20% of event name update
      5044:20181101:212203.707 completed 21% of event name update
      5044:20181101:212203.707 completed 22% of event name update
      5044:20181101:212203.707 completed 23% of event name update
      5044:20181101:212203.707 completed 24% of event name update
      5044:20181101:212203.707 completed 25% of event name update
      5044:20181101:212203.708 completed 26% of event name update
      5044:20181101:212203.708 completed 27% of event name update
      5044:20181101:212203.708 completed 28% of event name update
      5044:20181101:212203.708 completed 29% of event name update
      5044:20181101:212203.708 completed 30% of event name update
      5044:20181101:212203.708 completed 31% of event name update
      5044:20181101:212203.708 completed 32% of event name update
      5044:20181101:212203.710 completed 33% of event name update
      5044:20181101:212203.712 completed 34% of event name update
      5044:20181101:212203.714 completed 35% of event name update
      5044:20181101:212203.717 completed 36% of event name update
      5044:20181101:212203.717 completed 37% of event name update
      5044:20181101:212203.717 completed 38% of event name update
      5044:20181101:212203.717 completed 39% of event name update
      5044:20181101:212203.718 completed 40% of event name update
      5044:20181101:212203.718 completed 41% of event name update
      5044:20181101:212203.718 completed 42% of event name update
      5044:20181101:212203.718 completed 43% of event name update
      5044:20181101:212203.718 completed 44% of event name update
      5044:20181101:212203.718 completed 45% of event name update
      5044:20181101:212203.718 completed 46% of event name update
      5044:20181101:212203.718 completed 47% of event name update
      5044:20181101:212203.718 completed 48% of event name update
      5044:20181101:212203.719 completed 49% of event name update
      5044:20181101:212203.719 completed 50% of event name update
      5044:20181101:212203.758 completed 51% of event name update
      5044:20181101:212203.804 completed 52% of event name update
      5044:20181101:212203.804 completed 53% of event name update
      5044:20181101:212203.804 completed 54% of event name update
      5044:20181101:212203.804 completed 55% of event name update
      5044:20181101:212203.805 completed 56% of event name update
      5044:20181101:212203.805 completed 57% of event name update
      5044:20181101:212203.805 completed 58% of event name update
      5044:20181101:212203.805 completed 59% of event name update
      5044:20181101:212203.805 completed 60% of event name update
      5044:20181101:212203.805 completed 61% of event name update
      5044:20181101:212203.805 completed 62% of event name update
      5044:20181101:212203.805 completed 63% of event name update
      5044:20181101:212203.805 completed 64% of event name update
      5044:20181101:212203.805 completed 65% of event name update
      5044:20181101:212203.805 completed 66% of event name update
      5044:20181101:212203.806 completed 67% of event name update
      5044:20181101:212203.806 completed 68% of event name update
      5044:20181101:212203.806 completed 69% of event name update
      5044:20181101:212203.807 completed 70% of event name update
      5044:20181101:212203.807 completed 71% of event name update
      5044:20181101:212203.807 completed 72% of event name update
      5044:20181101:212203.807 completed 73% of event name update
      5044:20181101:212203.807 completed 74% of event name update
      5044:20181101:212203.807 completed 75% of event name update
      5044:20181101:212203.807 completed 76% of event name update
      5044:20181101:212203.807 completed 77% of event name update
      5044:20181101:212203.808 completed 78% of event name update
      5044:20181101:212203.808 completed 79% of event name update
      5044:20181101:212203.808 completed 80% of event name update
      5044:20181101:212203.808 completed 81% of event name update
      5044:20181101:212203.808 completed 82% of event name update
      5044:20181101:212203.808 completed 83% of event name update
      5044:20181101:212203.808 completed 84% of event name update
      5044:20181101:212203.808 completed 85% of event name update
      5044:20181101:212203.809 completed 86% of event name update
      5044:20181101:212203.809 completed 87% of event name update
      5044:20181101:212203.810 completed 88% of event name update
      5044:20181101:212203.810 completed 89% of event name update
      5044:20181101:212203.810 completed 90% of event name update
      5044:20181101:212203.810 completed 91% of event name update
      5044:20181101:212203.810 completed 92% of event name update
      5044:20181101:212203.810 completed 93% of event name update
      5044:20181101:212203.810 completed 94% of event name update
      5044:20181101:212203.811 completed 95% of event name update
      5044:20181101:212203.811 completed 96% of event name update
      5044:20181101:212203.811 completed 97% of event name update
      5044:20181101:212203.811 completed 98% of event name update
      5044:20181101:212203.811 completed 99% of event name update
      5044:20181101:212203.811 completed 100% of event name update
      5044:20181101:212205.304 event name update completed
    
    

    Ubuntu

    # 停止服务
    service zabbix-server stop
    service zabbix-agent stop
    service apache2 stop
    
    # 备份 zabbix 文件
    mkdir /opt/zabbix-backup/
    cp /etc/zabbix/zabbix_server.conf /opt/zabbix-backup/
    cp /etc/apache2/conf-enabled/zabbix.conf /opt/zabbix-backup/
    cp -R /usr/share/zabbix/ /opt/zabbix-backup/ 
    cp -R /usr/share/doc/zabbix-* /opt/zabbix-backup/
    
    # 升级 zabbix 源
    rm -Rf /etc/apt/sources.list.d/zabbix.list
    wget https://repo.zabbix.com/zabbix/4.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.0-2+bionic_all.deb
    dpkg -i zabbix-release_4.0-2+xenial_all.deb
    apt-get update
    
    # 添加时出现问题:dpkg: error: dpkg status database is locked by another process
    rm /var/lib/dpkg/lock
    dpkg --configure -a
    
    # 升级 zabbix
    # apt-get install --only-upgrade zabbix-server-mysql zabbix-frontend-php zabbix-agent zabbix-proxy-mysql
    apt-get install --only-upgrade zabbix-server-mysql zabbix-frontend-php zabbix-agent
    
    # 启动 zabbix
    service zabbix-server start
    service zabbix-agent start
    service apache2 start
    
    

    docker

    1. 拉取最新镜像
    2. 停止并删除当前运行容器
    3. 用最新镜像重新创建容器
    4. All Done
    # 查找当前系统中使用的镜像
    docker images
    # 拉取最新镜像
    docker pull zabbix/zabbix-web-nginx-mysql
    docker pull zabbix/zabbix-server-mysql
    # 查找容器 ID
    docker ps
    # 导出之前的容器配置信息
    docker inspect 14fd67405076
    # 停止容器
    docker stop 14fd67405076
    docker kill 14fd67405076
    # 删除容器
    docker rm 14fd67405076
    # 用最新镜像重新创建容器
    docker run --name zabbix-server-mysql -t \
    --link mysql-server:mysql \
    -e DB_SERVER_HOST="mysql-server" \
    -e MYSQL_DATABASE="zabbix" \
    -e MYSQL_USER="zabbix" \
    -e MYSQL_PASSWORD="zabbix" \
    -e MYSQL_ROOT_PASSWORD="zabbix" \
    -v /etc/localtime:/etc/localtime:ro \
    -v /data/docker/zabbix/alertscripts:/usr/lib/zabbix/alertscripts \
    -v /data/docker/zabbix/externalscripts:/usr/lib/zabbix/externalscripts \
    -p 10051:10051 \
    -d \
    zabbix/zabbix-server-mysql
    
    docker run --name zabbix-web-nginx-mysql -t \
    --link mysql-server:mysql \
    --link zabbix-server-mysql:zabbix-server \
    -e DB_SERVER_HOST="mysql-server" \
    -e MYSQL_DATABASE="zabbix" \
    -e MYSQL_USER="zabbix" \
    -e MYSQL_PASSWORD="zabbix" \
    -e MYSQL_ROOT_PASSWORD="zabbix" \
    -e PHP_TZ="Asia/Singapore" \
    -p 80:80 \
    -d \
    zabbix/zabbix-web-nginx-mysql
    
    
    2 条回复    2018-11-02 14:05:54 +08:00
    luolufang
        1
    luolufang  
       2018-11-02 14:03:04 +08:00
    我这里上次 手贱 update
    了一下
    就自动升过去了,目前貌似良好
    richzhu
        2
    richzhu  
       2018-11-02 14:05:54 +08:00
    已经 4.0.。。 目前良好,与 zabbix API 对接的 DevOps 平台也没发生什么故障~ 有坑我再来报~
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2880 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 13:49 · PVG 21:49 · LAX 05:49 · JFK 08:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.