centos7.6环境zabbix3.2源码编译安装版升级到zabbix4.0长期支持版

zabbix3.2源码编译安装版升级到zabbix4.0长期支持版

项目需求:
3.2版本不再支持,想升级成4.0的长期支持版

环境介绍:
zabbix服务端是编译安装的,数据库和web在一台机器上

整体思路:
先升级3.2版本到3.4过渡版本,然后再次将3.4升级成4.0版本

因为升级过程较长
为了避免影响正常的zabbix业务,克隆出一台服务器用来升级使用,升级完成后互换ip或者直接修改客户端的agent把新的服务端也加入其中
可以并行一段时间,如果没问题就可以弃用老的zabbix服务器了


大概步骤:
1.编译安装zabbix3.4.15,然后修改zabbix_server.conf连接zabbix3.2的数据库,运行zabbix_server服务端进行数据表结构升级到3.4
2.再次编译安装zabbix4.0.10,再次修改zabbix_server.conf连接到已经升级到zabbix3.4的表结构数据库中,再次运行zabbix_server服务端程序将数据库表结构升级到zabbix4.0
最终就达到了升级的目标

实际在编译安装zabbix3.4过程中发现在原来的服务器上直接编译安装zabbix3.4是安装不上的,环境被破坏了,于是在另外一台机器上编译安装服务端和web,然后修改配置连接数据库进行数据库表结构升级

准备工作:
备份zabbix-3.2相关的数据库、前端网页、执行程序文件,如果升级失败可以回滚

一、zabbix-3.2版本升级zabbix3.4版本

1.安装依赖
yum install mysql-devel gcc libxml2-devel libevent-devel net-snmp net-snmp-devel  curl  curl-devel php  php-bcmath  php-mbstring php-gettext php-session php-ctype php-xmlreader php-xmlwrer php-xml php-net-socket php-gd php-mysql -y

https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.4.15/zabbix-3.4.15.tar.gz

ln -s /usr/local/mysql/lib/libperconaserverclient.so /usr/lib/libperconaserverclient.so
./configure --prefix=/usr/local/zabbix-3.4.15 --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2

# 报错如下,找了很多方案解决不了,于是再另外的服务器中编译安装zabbix3.4
/libs/zbxserver/libzbxserver.a ../../src/libs/zbxdbcache/libzbxdbcache.a ../../src/libs/zbxhistory/libzbxhistory.a ../../src/libs/zbxmemory/libzbxmemory.a ../../src/libs/zbxregexp/libzbxregexp.a ../../src/libs/zbxself/libzbxself.a ../../src/libs/zbxnix/libzbxnix.a ../../src/libs/zbxalgo/libzbxalgo.a ../../src/libs/zbxsys/libzbxsys.a ../../src/libs/zbxconf/libzbxconf.a ../../src/libs/zbxmedia/libzbxmedia.a ../../src/libs/zbxcommon/libzbxcommon.a ../../src/libs/zbxcrypto/libzbxcrypto.a ../../src/libs/zbxcomms/libzbxcomms.a ../../src/libs/zbxcommshigh/libzbxcommshigh.a ../../src/libs/zbxjson/libzbxjson.a ../../src/libs/zbxhttp/libzbxhttp.a ../../src/libs/zbxipcservice/libzbxipcservice.a ../../src/libs/zbxexec/libzbxexec.a ../../src/libs/zbxicmpping/libzbxicmpping.a ../../src/libs/zbxdbupgrade/libzbxdbupgrade.a ../../src/libs/zbxdbhigh/libzbxdbhigh.a ../../src/libs/zbxdb/libzbxdb.a ../../src/libs/zbxmodules/libzbxmodules.a ../../src/libs/zbxtasks/libzbxtasks.a  -lmysqlclient  -lz -lcrypt -lnsl -lm -lssl -lcrypto     -lxml2    -lnetsnmp   -levent    -lcurl  -lm -ldl -lrt  -lresolv -lpcre 
../../src/libs/zbxhistory/libzbxhistory.a(history_elastic.o): In function `elastic_writer_flush':
/usr/local/src/zabbix-3.4.15/src/libs/zbxhistory/history_elastic.c:457: undefined reference to `curl_multi_wait'
../../src/libs/zbxipcservice/libzbxipcservice.a(libzbxipcservice_a-ipcservice.o): In function `ipc_client_free_events':
/usr/local/src/zabbix-3.4.15/src/libs/zbxipcservice/ipcservice.c:521: undefined reference to `event_free'
/usr/local/src/zabbix-3.4.15/src/libs/zbxipcservice/ipcservice.c:527: undefined reference to `event_free'
../../src/libs/zbxipcservice/libzbxipcservice.a(libzbxipcservice_a-ipcservice.o): In function `zbx_ipc_service_close':
/usr/local/src/zabbix-3.4.15/src/libs/zbxipcservice/ipcservice.c:1530: undefined reference to `event_free'
/usr/local/src/zabbix-3.4.15/src/libs/zbxipcservice/ipcservice.c:1531: undefined reference to `event_free'
../../src/libs/zbxipcservice/libzbxipcservice.a(libzbxipcservice_a-ipcservice.o): In function `ipc_service_add_client':
/usr/local/src/zabbix-3.4.15/src/libs/zbxipcservice/ipcservice.c:798: undefined reference to `event_new'
/usr/local/src/zabbix-3.4.15/src/libs/zbxipcservice/ipcservice.c:799: undefined reference to `event_new'
../../src/libs/zbxipcservice/libzbxipcservice.a(libzbxipcservice_a-ipcservice.o): In function `zbx_ipc_service_start':
/usr/local/src/zabbix-3.4.15/src/libs/zbxipcservice/ipcservice.c:1489: undefined reference to `event_new'
/usr/local/src/zabbix-3.4.15/src/libs/zbxipcservice/ipcservice.c:1493: undefined reference to `event_new'
collect2: ld returned 1 exit status
make[3]: *** [zabbix_server] Error 1
make[3]: Leaving directory `/usr/local/src/zabbix-3.4.15/src/zabbix_server'
make[2]: *** [install-recursive] Error 1
make[2]: Leaving directory `/usr/local/src/zabbix-3.4.15/src/zabbix_server'
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory `/usr/local/src/zabbix-3.4.15/src'
make: *** [install-recursive] Error 1

2.获取源码
https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.4.15/zabbix-3.4.15.tar.gz

# 编译安装zabbix3.4
./configure --prefix=/usr/local/zabbix3.4.15 --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --enable-java

# 将服务器默认的zabbix链接到新的服务端程序中
cd /usr/local/
rm -f zabbix
ln -s zabbix3.4.15 zabbix

修改zabbix_server.conf连接之前的3.2数据库

# 启动zabbix服务端

[root@zabbix4_clone:~]# cat /etc/init.d/zabbix_server 
#!/bin/bash
#
# chkconfig: - 90 10
# description:  Starts and stops Zabbix Server using chkconfig
#                Tested on Fedora Core 2 - 5
#                Should work on all Fedora Core versions
#
# @name:    zabbix_server
# @author:    Alexander Hagenah <[email protected]>
# @created:    18.04.2006
#
# Modified for Zabbix 2.0.0
# May 2012, Zabbix SIA
#
# Source function library.
. /etc/init.d/functions

# Variables
# Edit these to match your system settings

    # Zabbix-Directory
    BASEDIR=/usr/local/zabbix

    # Binary File
    BINARY_NAME=zabbix_server

    # Full Binary File Call
    FULLPATH=$BASEDIR/sbin/$BINARY_NAME

    # PID file
    PIDFILE=/tmp/$BINARY_NAME.pid

    # Establish args
    ERROR=0
    STOPPING=0

#
# No need to edit the things below
#

# application checking status
if [ -f $PIDFILE  ] && [ -s $PIDFILE ]
    then
    PID=`cat $PIDFILE`
    
    if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null && [ $BINARY_NAME == `ps -e | grep $PID | awk '{print $4}'` ]
    then
        STATUS="$BINARY_NAME (pid `pidof $APP`) running.."
        RUNNING=1
    else
        rm -f $PIDFILE
        STATUS="$BINARY_NAME (pid file existed ($PID) and now removed) not running.."
        RUNNING=0
    fi
else
    if [ `ps -e | grep $BINARY_NAME | head -1 | awk '{ print $1 }'` ]
        then
        STATUS="$BINARY_NAME (pid `pidof $APP`, but no pid file) running.."
    else
        STATUS="$BINARY_NAME (no pid file) not running"
    fi
    RUNNING=0
fi

# functions
start() {
    if [ $RUNNING -eq 1 ]
        then
        echo "$0 $ARG: $BINARY_NAME (pid $PID) already running"
    else
        action $"Starting $BINARY_NAME: " $FULLPATH
        touch /var/lock/subsys/$BINARY_NAME
    fi
}

stop() {
    echo -n $"Shutting down $BINARY_NAME: "
    killproc $BINARY_NAME
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$BINARY_NAME
    RUNNING=0
}


# logic
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status $BINARY_NAME
        ;;
    restart)
        stop
        sleep 10
        start
        ;;
    help|*)
        echo $"Usage: $0 {start|stop|status|restart|help}"
        cat <<EOF

            start        - start $BINARY_NAME
            stop        - stop $BINARY_NAME
            status        - show current status of $BINARY_NAME
            restart        - restart $BINARY_NAME if running by sending a SIGHUP or start if not running
            help        - this screen

EOF
    exit 1
    ;;
esac

exit 0


# 查看zabbix服务端日志,出现以下内容说明升级成功
 30788:20190626:213252.069 Starting Zabbix Server. Zabbix 3.4.15 (revision 86739).
 30788:20190626:213252.070 ****** Enabled features ******
 30788:20190626:213252.070 SNMP monitoring:           YES
 30788:20190626:213252.070 IPMI monitoring:            NO
 30788:20190626:213252.070 Web monitoring:            YES
 30788:20190626:213252.070 VMware monitoring:         YES
 30788:20190626:213252.070 SMTP authentication:       YES
 30788:20190626:213252.070 Jabber notifications:       NO
 30788:20190626:213252.070 Ez Texting notifications:  YES
 30788:20190626:213252.070 ODBC:                       NO
 30788:20190626:213252.070 SSH2 support:               NO
 30788:20190626:213252.070 IPv6 support:               NO
 30788:20190626:213252.070 TLS support:                NO
 30788:20190626:213252.070 ******************************
 30788:20190626:213252.070 using configuration file: /usr/local/zabbix-3.4.15/etc/zabbix_server.conf
 30788:20190626:213252.080 current database version (mandatory/optional): 03020000/03020000
 30788:20190626:213252.080 required mandatory version: 03040000
 30788:20190626:213252.081 optional patches were found
 30788:20190626:213252.081 starting automatic database upgrade
 30788:20190626:213252.093 completed 0% of database upgrade
 30788:20190626:213252.145 completed 1% of database upgrade
 30788:20190626:213252.244 completed 2% of database upgrade
 30788:20190626:213252.267 completed 3% of database upgrade
 30788:20190626:213252.293 completed 4% of database upgrade
 30788:20190626:213252.371 completed 5% of database upgrade
 30788:20190626:213252.416 completed 6% of database upgrade
 30788:20190626:213252.436 completed 7% of database upgrade
 30788:20190626:213252.449 completed 8% of database upgrade
 30788:20190626:213252.694 completed 9% of database upgrade
 30788:20190626:213253.316 completed 10% of database upgrade
 30788:20190626:213253.792 completed 11% of database upgrade
 30788:20190626:213253.827 completed 12% of database upgrade
 30788:20190626:213253.832 completed 13% of database upgrade
 30788:20190626:213253.855 completed 14% of database upgrade
 30788:20190626:213253.888 completed 15% of database upgrade
 30788:20190626:213253.897 completed 16% of database upgrade
 30788:20190626:213253.911 completed 17% of database upgrade
 30788:20190626:213253.922 completed 18% of database upgrade
 30788:20190626:213253.932 completed 19% of database upgrade
 30788:20190626:213253.948 completed 20% of database upgrade
 30788:20190626:213253.954 completed 21% of database upgrade
 30788:20190626:213253.965 completed 22% of database upgrade
 30788:20190626:213253.983 completed 23% of database upgrade
 30788:20190626:213253.989 completed 24% of database upgrade
 30788:20190626:213253.998 completed 25% of database upgrade
 30788:20190626:213254.012 completed 26% of database upgrade
 30788:20190626:213254.019 completed 27% of database upgrade
 30788:20190626:213254.029 completed 28% of database upgrade
 30788:20190626:213254.046 completed 29% of database upgrade
 30788:20190626:213254.058 completed 30% of database upgrade
 30788:20190626:213254.075 completed 31% of database upgrade
 30788:20190626:213254.086 completed 32% of database upgrade
 30788:20190626:213254.097 completed 33% of database upgrade
 30788:20190626:213254.101 completed 34% of database upgrade
 30788:20190626:213254.105 completed 35% of database upgrade
 30788:20190626:213254.108 completed 36% of database upgrade
 30788:20190626:213254.130 completed 37% of database upgrade
 30788:20190626:213254.138 completed 38% of database upgrade
 30788:20190626:213254.157 completed 39% of database upgrade
 30788:20190626:213254.177 completed 40% of database upgrade
 30788:20190626:213254.195 completed 41% of database upgrade
 30788:20190626:213254.205 completed 42% of database upgrade
 30788:20190626:213254.215 completed 43% of database upgrade
 30788:20190626:213254.219 completed 44% of database upgrade
 30788:20190626:213256.229 completed 45% of database upgrade
 30788:20190626:213256.810 completed 46% of database upgrade
 30788:20190626:213257.205 completed 47% of database upgrade
 30788:20190626:213259.141 completed 48% of database upgrade
 30788:20190626:213259.148 completed 49% of database upgrade
 30788:20190626:213300.869 completed 50% of database upgrade
 30788:20190626:213300.875 completed 51% of database upgrade
 30788:20190626:213300.888 completed 52% of database upgrade
 30788:20190626:213300.913 completed 53% of database upgrade
 30788:20190626:213300.919 completed 54% of database upgrade
 30788:20190626:213300.931 completed 55% of database upgrade
 30788:20190626:213300.943 completed 56% of database upgrade
 30788:20190626:213300.954 completed 57% of database upgrade
 30788:20190626:213300.974 completed 58% of database upgrade
 30788:20190626:213300.986 completed 59% of database upgrade
 30788:20190626:213300.997 completed 60% of database upgrade
 30788:20190626:213301.007 completed 61% of database upgrade
 30788:20190626:213301.018 completed 62% of database upgrade
 30788:20190626:213301.029 completed 63% of database upgrade
 30788:20190626:213301.041 completed 64% of database upgrade
 30788:20190626:213301.052 completed 65% of database upgrade
 30788:20190626:213301.057 completed 66% of database upgrade
 30788:20190626:213301.065 completed 67% of database upgrade
 30788:20190626:213301.082 completed 68% of database upgrade
 30788:20190626:213301.323 completed 69% of database upgrade
 30788:20190626:213301.392 completed 70% of database upgrade
 30788:20190626:213301.424 completed 71% of database upgrade
 30788:20190626:213301.438 completed 72% of database upgrade
 30788:20190626:213301.445 completed 73% of database upgrade
 30788:20190626:213301.459 completed 74% of database upgrade
 30788:20190626:213301.466 completed 75% of database upgrade
 30788:20190626:213301.480 completed 76% of database upgrade
 30788:20190626:213301.486 completed 77% of database upgrade
 30788:20190626:213301.496 completed 78% of database upgrade
 30788:20190626:213301.503 completed 79% of database upgrade
 30788:20190626:213301.510 completed 80% of database upgrade
 30788:20190626:213301.517 completed 81% of database upgrade
 30788:20190626:213301.536 completed 82% of database upgrade
 30788:20190626:213301.556 completed 83% of database upgrade
 30788:20190626:213301.585 completed 84% of database upgrade
 30788:20190626:213301.590 completed 85% of database upgrade
 30788:20190626:213301.640 completed 86% of database upgrade
 30788:20190626:213301.699 completed 87% of database upgrade
 30788:20190626:213301.718 completed 88% of database upgrade
 30788:20190626:213301.918 completed 89% of database upgrade
 30788:20190626:213302.407 completed 90% of database upgrade
 30788:20190626:213302.422 completed 91% of database upgrade
 30788:20190626:213302.425 completed 92% of database upgrade
 30788:20190626:213302.428 completed 93% of database upgrade
 30788:20190626:213302.431 completed 94% of database upgrade
 30788:20190626:213302.434 completed 95% of database upgrade
 30788:20190626:213302.437 completed 96% of database upgrade
 30788:20190626:213302.440 completed 97% of database upgrade
 30788:20190626:213302.455 completed 98% of database upgrade
 30788:20190626:213302.496 completed 99% of database upgrade
 30788:20190626:213302.501 completed 100% of database upgrade
 30788:20190626:213302.501 database upgrade fully completed
 30788:20190626:213303.154 server #0 started [main process]
 30799:20190626:213303.155 server #1 started [configuration syncer #1]
 30800:20190626:213303.156 server #2 started [alerter #1]
 30801:20190626:213303.157 server #3 started [alerter #2]
 30802:20190626:213303.157 server #4 started [alerter #3]
 30803:20190626:213303.158 server #5 started [housekeeper #1]
 30804:20190626:213303.158 server #6 started [timer #1]
 30805:20190626:213303.159 server #7 started [http poller #1]
 30806:20190626:213303.159 server #8 started [discoverer #1]


2.zabbix3.4升级到zabbix4.0
参考:https://www.zabbix.com/documentation/4.0/zh/manual/installation/upgrade/sources


获取zabbix4.0.10源码
https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.0.10/zabbix-4.0.10.tar.gz

# 编译安装zabbix4.0.10
./configure --prefix=/usr/local/zabbix4.0.10 --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --enable-java

Zabbix server 升级步骤
1.停止 Zabbix 进程
 /etc/init.d/zabbix_server stop

2.备份当前的数据库
这是非常重要的步骤。升级前请确保备份了数据库。如果升级失败(因磁盘空间不足、断电或其他意外导致的升级失败),备份的数据库将大有帮助。

3.备份配置文件、PHP 文件和 Zabbix 二进制文件
在升级前请确保备份了配置文件、PHP 文件和 Zabbix 二进制文件。

# 删除软连接
[root@zabbix4_clone:/usr/local]# ll zabbix
lrwxrwxrwx 1 root root 13 Jun 26 21:28 zabbix -> zabbix-3.4.15
[root@zabbix4_clone:/usr/local]# rm -f zabbix

4.从源代码包安装新的 Zabbix server4.0.10

5.检查 Zabbix server 配置文件的参数
在新版本中,Zabbix server 的配置文件发生了一些变化
[root@zabbix4_clone:/usr/local]# ln -s zabbix4.0.10 zabbix
[root@zabbix4_clone:/usr/local]# egrep -v '^#|^$' zabbix/etc/zabbix_server.conf
ListenPort=10051
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=10
DBHost=192.168.254.200    # 此时连接的是zabbix3.4的数据库(即从3.2升级到3.4的数据库)
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix    # 密码也是zabbix3.4的密码
DBSocket=/tmp/mysql.sock
DBPort=3306
StartPollers=30
StartTrappers=30
StartVMwareCollectors=20
VMwareFrequency=20
VMwarePerfFrequency=20
VMwareCacheSize=64M
VMwareTimeout=30
ListenIP=0.0.0.0
HousekeepingFrequency=12
CacheSize=256M
Timeout=15
AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts
ExternalScripts=/usr/local/zabbix/share/zabbix/externalscripts
LogSlowQueries=3000
StartProxyPollers=20


6.启动新的 Zabbix 进程
启动新的 Zabbix 进程。检查日志文件以查看进程是否成功启动。

 31846:20190626:215155.763 Starting Zabbix Server. Zabbix 4.0.10 (revision cc25224816).
 31846:20190626:215155.763 ****** Enabled features ******
 31846:20190626:215155.763 SNMP monitoring:           YES
 31846:20190626:215155.763 IPMI monitoring:            NO
 31846:20190626:215155.763 Web monitoring:            YES
 31846:20190626:215155.763 VMware monitoring:         YES
 31846:20190626:215155.763 SMTP authentication:       YES
 31846:20190626:215155.764 Jabber notifications:       NO
 31846:20190626:215155.764 Ez Texting notifications:  YES
 31846:20190626:215155.764 ODBC:                       NO
 31846:20190626:215155.764 SSH2 support:               NO
 31846:20190626:215155.764 IPv6 support:              YES
 31846:20190626:215155.764 TLS support:                NO
 31846:20190626:215155.764 ******************************
 31846:20190626:215155.764 using configuration file: /usr/local/zabbix4.0.10/etc/zabbix_server.conf
 31846:20190626:215155.776 current database version (mandatory/optional): 03040000/03040007
 31846:20190626:215155.776 required mandatory version: 04000000
 31846:20190626:215155.776 optional patches were found
 31846:20190626:215155.776 starting automatic database upgrade
 31846:20190626:215155.823 completed 0% of database upgrade
 31846:20190626:215155.825 completed 1% of database upgrade
 31846:20190626:215155.958 completed 2% of database upgrade
 31846:20190626:215155.971 completed 3% of database upgrade
 31846:20190626:215155.991 completed 4% of database upgrade
 31846:20190626:215156.002 completed 5% of database upgrade
 31846:20190626:215156.016 completed 6% of database upgrade
 31846:20190626:215156.022 completed 7% of database upgrade
 31846:20190626:215156.036 completed 8% of database upgrade
 31846:20190626:215156.048 completed 9% of database upgrade
 31846:20190626:215156.056 completed 10% of database upgrade
 31846:20190626:215156.058 completed 11% of database upgrade
 31846:20190626:215156.060 completed 12% of database upgrade
 31846:20190626:215156.065 completed 13% of database upgrade
 31846:20190626:215156.070 completed 14% of database upgrade
 31846:20190626:215156.076 completed 15% of database upgrade
 31846:20190626:215156.108 completed 16% of database upgrade
 31846:20190626:215156.111 completed 17% of database upgrade
 31846:20190626:215156.116 completed 18% of database upgrade
 31846:20190626:215156.119 completed 19% of database upgrade
 31846:20190626:215156.121 completed 20% of database upgrade
 31846:20190626:215156.126 completed 21% of database upgrade
 31846:20190626:215156.133 completed 22% of database upgrade
 31846:20190626:215156.145 completed 23% of database upgrade
 31846:20190626:215156.152 completed 24% of database upgrade

 31846:20190626:215201.414 completed 99% of database upgrade
 31846:20190626:215201.456 completed 100% of database upgrade
 31846:20190626:215201.456 database upgrade fully completed


自此,zabbix3.2升级到zabbix4.0成功

猜你喜欢

转载自www.cnblogs.com/reblue520/p/11115439.html