前言

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升级步骤

备份数据库

1
2
3
# 数据库全备时间比较长且文件交大,建议压缩或者使用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

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# 停止服务
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

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
27
28
29
30
31
# 停止服务
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
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 查找当前系统中使用的镜像
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

文章目录
  1. 1. 前言
  2. 2. 更新历史
  3. 3. 官方文档
  4. 4. Zabbix升级步骤
    1. 4.1. 备份数据库
    2. 4.2. CentOS
    3. 4.3. Ubuntu
    4. 4.4. docker