文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

zabbix5.0.X升级到6.0.X版本(多种实现方法)

2023-08-31 10:53

关注

我这边的生产环境是centos7.9,mysql5.7.38,zabbix-server5.0.31

由于业务需要,需要用到zabbix6.0的一些功能,所以不得已升级,参考了好多资料

zabbix依赖于mysql8,php版本大于7.2,且zabbix官方没有centos7的安装包,所以最终要编译安装

一上来就编译安装结果各种报错,所以我拆解为四种步骤,逐步实现,各位可以根据自己的实际情况选择其中一种方法升级


第一种升级方法:

Linux : CentOS Stream release 8

Mysql: 8.0.26

新安装环境,数据库从5.0导出再导入6.0

新部署了一台centos8的环境其上部署了zabbix6.0,然后把原来zabbix5.0的数据导入其中

关闭selinux

# setenforce 0

# sed -i"s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config

安装mysql

#yum -y install mysql-server

# systemctl start mysqld && systemctlenable mysqld

初始化root密码

# mysql -uroot

> use mysql;

> alter user 'root'@'localhost'identified by 'root数据库密码';

> flush privileges;

创建zabbix库

> create database zabbix character setutf8mb4 collate utf8mb4_bin;

> create user zabbix@localhostidentified by 'zabbix数据库密码';

> grant all privileges on zabbix.* tozabbix@localhost;

> flush privileges;

导入数据

>use zabbix;

> source /root/zabbix.sql;

上面zabbix.sql为zabbix5.0导出的数据

安装zabbix

# rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-4.el8.noarch.rpm

# dnf cleanall

# sed -i's#https://repo.zabbix.com/://mirrors.tuna.tsinghua.edu.cn/zabbix#g'/etc/yum.repos.d/zabbix.repo

# sed -ri's/enabled=0/enabled=1/g' /etc/yum.repos.d/zabbix.repo

# dnf installzabbix-server-mysql zabbix-web-mysql zabbix-nginx-conf zabbix-sql-scriptszabbix-selinux-policy zabbix-agent

修改配置文件

# vim /etc/zabbix/zabbix_server.conf

DBPasswd=zabbix数据库密码

# vim /etc/nginx/conf.d/zabbix.conf

此处可以修改zabbix服务页面端口

启动服务

# systemctl restart zabbix-server zabbix-agent nginx php-fpm

页面数据库报错处理

提示连接数据库报version不对

修改数据库

>use zabbix;

> update dbversion set mandatory=6000000;

页面报server未启动

修改数据库

> set global log_bin_trust_function_creators = 1;

修改数据库历史数据表使用主键,zabbix6.0历史表较5.0有变化,所以需要手动修改

# mysql-uzabbix -pzabbix数据库密码 zabbix

>use zabbix;

> DROP TABLE history_old;

> DROP TABLE history_uint_old;

> DROP TABLE history_str_old;

> DROP TABLE history_log_old;

> DROP TABLE history_text_old;

# systemctl restart zabbix-server zabbix-agent nginx php-fpm mysqld


第二种升级方法:

Linux : CentOSLinux release 7.9.2009 (Core)

Mysql: 8.0.32

新安装环境,编译安装,数据库也是新的

第一种方法虽然成功,但是毕竟还要新安装服务器,不是想要的升级,还是想在centos7.9下面试试直接升级,所以我安装了个新的centos7.9环境,测试下编译安装zabbix6.0

关闭selinux

# setenforce 0

# sed -i"s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config

关闭防火墙

#systemctlstop firewalld

安装php

# yum install epel-release

# yum install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm

# yum installlibxml2-devel sqlite-devel libcurl-devel libpng-devel libjpeg-turbo-devellibXpm-devel freetype-devel libicu-devel gcc-c++ libxslt-devel oniguruma-devellibsodium-devel openldap-devel net-snmp-devel libwebp-devel

# yum--enablerepo=remi-php74 install php php-cli php-common php-devel php-embeddedphp-gd php-mbstring php-pdo php-xml php-fpm php-mysqlnd php-opcache php-mcryptphp-pecl-memcached php-pecl-mongodb php-pecl-redis php-bcmath php-intlphp-xmlrpc php-pecl-zip php-soap php-snmp php-ldap

修改php用户

#egrep"^(user|group)" /etc/php-fpm.d/www.conf

user = nginx

group = nginx

修改配置

# vim/etc/php.ini

post_max_size= 16M

max_execution_time= 300

max_input_time= 300

启动服务

# systemctl restart php-fpm

安装mysql8

# yum remove mysql -y

# rpm -qa |grep mysql

# rpm -qa |grep mariadb

# rpm -e--nodeps mariadb-libs-5.5.68-1.el7.x86_64

# yum installlibaio -y

# wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm

# rpm -ivhmysql80-community-release-el7-1.noarch.rpm

# yum cleanall

# yummakecache

# yum repolistall | grep mysql

# yum installmysql-community-server -y

# rpm --importhttps://repo.mysql.com/RPM-GPG-KEY-mysql-2022

# yum installmysql-community-server -y

# systemctlstart mysqld

# cat/var/log/mysqld.log | grep password

# mysql -uroot-p

> ALTERUSER 'root'@'localhost' IDENTIFIED BY 'root数据库密码';

> createdatabase zabbix character set utf8 collate utf8_bin;

> createuser 'zabbix'@'%' identified by 'zabbix数据库密码';

> grant allprivileges on zabbix.* to 'zabbix'@'%' with grant option;

> flush privileges;

> setglobal log_bin_trust_function_creators = 1;

# cd zabbix-6.0.X/database/mysql

# mysql-uzabbix -pZabbix zabbix < schema.sql

# mysql-uzabbix -pZabbix zabbix < images.sql

# mysql-uzabbix -pZabbix zabbix < data.sql

安装zabbix

# yum install gcc mysql-devel libevent-devel libcurl-devel libxml2-devel libssh2-develOpenIPMI-devel net-snmp-devel go java-devel -y

# groupadd--system Zabbix

# useradd--system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "ZabbixMonitoring System" Zabbix

# ./configureCFLAGS="-std=gnu99" --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql--enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-ssh2--enable-java

此处编译网上都没有指定gnu99的方法,但是我的环境不指定就报错

# make install

修改配置文件

#vim /usr/local/zabbix/etc/zabbix_server.conf

DBP=zabbix数据库密码

配置systemd启动

cat < /etc/systemd/system/zabbix-server.service

[Unit]

Description=ZabbixServer

After=syslog.targetnetwork.target network-online.target

Wants=network.targetnetwork-online.target

[Service]

Type=simple

User=root

ExecStart=/usr/local/zabbix/sbin/zabbix_server-c /usr/local/zabbix/etc/zabbix_server.conf

RemainAfterExit=yes

PIDFile=/var/run/zabbix/zabbix_server.pid

[Install]

WantedBy=multi-user.target

EOF

加入开机启动并启动

# systemctl daemon-reload

# systemctl enable zabbix-server - –now

安装zabbix-web

安装nginx

正常编译安装

# mkdir -p/usr/local/nginx/html/zabbix

# cp -R /root/Zabbix-6.0.X/ui/* /usr/local/nginx/html/zabbix

# useradd -M-s /sbin/nologin nginx

修改nginx配置

#vim /usr/local/nginx/conf/nginx.conf

user nginx;

worker_processesauto;

error_log/var/log/nginx/error.log;

pid/run/nginx.pid;

include/usr/local/nginx/modules/*.conf;

events {

worker_connections 1024;

}

http {

log_format main '$remote_addr - $remote_user[$time_local] "$request" '

'$status $body_bytes_sent"$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;

tcp_nopush on;

tcp_nodelay on;

keepalive_timeout 65;

types_hash_max_size 4096;

include /usr/local/nginx/conf/mime.types;

default_type application/octet-stream;

include /etc/nginx/conf.d/*.conf;

server {

listen 8090;

listen [::]:8090;

server_name localhost;

root /usr/local/nginx/html/zabbix;

index index.php index.html index.htm;

include /etc/nginx/default.d/*.conf;

location ~ \.php$ {

root /usr/local/nginx/html/zabbix;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;

include fastcgi_params;

}

error_page 404 /404.html;

location = /404.html {

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

}

}

}

#/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

Zabbix-agent

配置启动项

cat< /etc/systemd/system/zabbix-agent.service

[Unit]

Description=ZabbixAgent

After=syslog.targetnetwork.target network-online.target

Wants=network.targetnetwork-online.target

[Service]

Type=simple

User=root

ExecStart=/usr/local/zabbix/sbin/zabbix_agentd-c /usr/local/zabbix/etc/zabbix_agentd.conf

RemainAfterExit=yes

PIDFile=/var/run/zabbix/zabbix_agent.pid

[Install]

WantedBy=multi-user.target

EOF

设置开机启动

# systemctldaemon-reload

# systemctlenable zabbix-agent --now

----------------------------------------------------------------------------------------------------------

第三种升级方法

Linux: CentOSLinux release 7.9.2009 (Core)

Mysql: 8.0.32

Docker

现有环境,通过容器升级

安装数据库

参照上面,建立一个zabbix空库即可,server容器会自动更新生成表结构

# mysql -uroot-p

> ALTERUSER 'root'@'localhost' IDENTIFIED BY 'root数据库密码';

> createdatabase zabbix character set utf8 collate utf8_bin;

> createuser 'zabbix'@'%' identified by 'zabbix数据库密码';

> grant allprivileges on zabbix.* to 'zabbix'@'%' with grant option;

安装docker

上传docker-ce.repo

#yum -yinstall docker-ce

# vim /etc/docker/daemon.json

{

"exec-opts":["native.cgroupdriver=systemd"],

"registry-mirrors": [

"http://hub-mirror.c.163.com/",

"https://docker.mirrors.ustc.edu.cn/",

"https://docker.mirrors.ustc.edu.cn/"

]

}

# systemctldaemon-reload

# systemctl enabledocker && systemctl start docker

# docker runhello-world

安装docker-compose

#curl -Lhttps://get.daocloud.io/docker/compose/releases/download/v2.4.1/docker-compose-`uname-s`-`uname -m` > /usr/local/bin/docker-compose

#chmod +x/usr/local/bin/docker-compose

#ln -s/usr/local/bin/docker-compose /usr/bin/docker-compose

#docker-composeversion

Docker Composeversion v2.4.1

拉取镜像

# docker pullzabbix/zabbix-agent:centos-6.0.13

# docker pullzabbix/zabbix-server-mysql:6.0.13-centos

# docker pullzabbix/zabbix-web-service:centos-6.0.13

部署容器

容器如果要用容器名连接,需要配置容器网络,此处测试使用IP地址,没有使用network参数

创建目录

#mkdir /root/zabbix_workdir

# mkdir /root/zabbix_workdir/zabbix_server

# mkdir /root/zabbix_workdir/zabbix_web

# mkdir /root/zabbix_workdir/zabbix_agent

创建zabbix容器网络

#docker network create -d bridge Zabbix

#docker network ls

部署zabbix-server

#cd zabbix_server

#vim docker-compose.yml

version: '3.5'

services:

zabbix-server:

restart: unless-stopped

container_name: zabbix-server

image: zabbix/zabbix-server-mysql:centos-6.0.13

ports:

- "10051:10051"

environment:

DB_SERVER_HOST: 数据库主机IP地址

MYSQL_DATABASE: zabbix

MYSQL_USER: zabbix

MYSQL_PASSWORD: zabbix数据库密码

MYSQL_ROOT_PASSWORD: root数据库密码

TZ: Asia/Shanghai

stop_grace_period: 30s

sysctls:

- net.ipv4.ip_local_port_range=1024 65000

- net.ipv4.conf.all.accept_redirects=0

- net.ipv4.conf.all.secure_redirects=0

- net.ipv4.conf.all.send_redirects=0

networks:

default:

external:

name: zabbix

启动容器

#docker-compose up -d

部署zabbix-web

#cd zabbix_web

#vim docker-compose.yml

version: '3.5'

services:

zabbix-web:

restart: unless-stopped

container_name: zabbix-web

image: zabbix/zabbix-web-nginx-mysql:centos-6.0.13

ports:

- "8090:8080"

- "443:8443"

environment:

ZBX_SERVER_HOST: zabbix-server服务器IP地址

DB_SERVER_HOST: 数据库服务器IP地址

MYSQL_DATABASE: zabbix

MYSQL_USER: zabbix

MYSQL_PASSWORD: zabbix数据库密码

MYSQL_ROOT_PASSWORD: root数据库密码

TZ: Asia/Shanghai

sysctls:

- net.core.somaxconn=65535

networks:

default:

external:

name: Zabbix

启动容器

#docker-compose up -d

部署zabbix-agent

#cd zabbix_agent

#vim docker-compose.yml

version: '3.5'

services:

zabbix-agent:

restart: always

container_name: zabbix-agent

image: zabbix/zabbix-agent:centos-6.0.13

privileged: true

ports:

- "10050:10050"

volumes:

- /etc/localtime:/etc/localtime:ro

environment:

TZ: Asia/Shanghai

networks:

default:

external:

name: Zabbix

启动容器

#docker-compose up -d

----------------------------------------------------------------------------------------------------------

第四种升级方法

也是我们最终想实现的效果,直接在centos7下原有的zabbix5.0升级到zabbix6.0

Linux: CentOSLinux release 7.9.2009 (Core)

原Mysql:5.7.38

升级后Mysql: 8.0.32

现有环境,直接升级,暂时没考虑数据库备份

关闭selinux

# setenforce 0

# sed -i"s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config

卸载低版本组件

卸载mysql

# yum listinstalled | grep mysql

# yum removemysql mysql-server mysql-libs compat-mysql mysql-community-common.x86_64

再用rpm检查一下

# rpm -qa |grep -i mysql

如有使用下面命令删除

# rpm -e –nodeps包名

使用find及whereis找到残存文件,全部删除

# find / -namemysql

# whereismysql

如果有/etc/my.cnf可以备份或直接删除

如果有开机自启动也需要关闭

# chkconfig--list | grep -i mysql

# chkconfig--del mysqld

卸载zabbix

#yum -y removezabbix-server-mysql zabbix-agent zabbix-web-mysql-scl zabbix-nginx-conf-scl zabbix-get-5.0.31-1.el7.x86_64zabbix-release-5.0-1.el7.noarch

使用rpm检查一下

# rpm -qa |grep -i Zabbix

删除残留文件

# find / -nameZabbix

# whereis Zabbix

卸载php

# yum listinstalled | grep php

# yum -yremove rh-php72-php-common.x86_64 rh-php72.x86_64 rh-php72-runtime.x86_64

使用rpm检查一下

#rpm -qa |grep php

删除残留文件

# find / -name php

安装php

# yum -y installepel-release

# yum installhttps://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm

# yum -y installlibxml2-devel sqlite-devel libcurl-devel libpng-devel libjpeg-turbo-devellibXpm-devel freetype-devel libicu-devel gcc-c++ libxslt-devel oniguruma-devellibsodium-devel openldap-devel net-snmp-devel libwebp-devel

# yum--enablerepo=remi-php74 install php php-cli php-common php-devel php-embeddedphp-gd php-mbstring php-pdo php-xml php-fpm php-mysqlnd php-opcache php-mcryptphp-pecl-memcached php-pecl-mongodb php-pecl-redis php-bcmath php-intlphp-xmlrpc php-pecl-zip php-soap php-snmp php-ldap

修改php用户

#egrep"^(user|group)" /etc/php-fpm.d/www.conf

user = nginx

group = nginx

修改配置

# vim/etc/php.ini

post_max_size= 16M

max_execution_time= 300

max_input_time= 300

启动服务

# systemctlrestart php-fpm

安装mysql8

# yum removemysql -y

# rpm -qa |grep mysql

# rpm -qa |grep mariadb

# rpm -e--nodeps mariadb-libs-5.5.68-1.el7.x86_64

# yum installlibaio -y

# wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm

# rpm -ivhmysql80-community-release-el7-1.noarch.rpm

# yum clean all

# yummakecache

# yum repolistall | grep mysql

# yum installmysql-community-server -y

# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

# yum installmysql-community-server -y

# systemctlstart mysqld

# cat/var/log/mysqld.log | grep password

# mysql -uroot -p

> ALTERUSER 'root'@'localhost' IDENTIFIED BY 'root数据库密码';

> createdatabase zabbix character set utf8 collate utf8_bin;

> createuser 'zabbix'@'%' identified by 'zabbix数据库密码';

> grant allprivileges on zabbix.* to 'zabbix'@'%' with grant option;

> flush privileges;

> setglobal log_bin_trust_function_creators = 1;

导入数据库步骤在安装zabbix之后进行

# cdzabbix-6.0.X/database/mysql

# mysql-uzabbix -pZabbix数据库密码 zabbix < schema.sql

# mysql-uzabbix -pZabbix数据库密码 zabbix < images.sql

# mysql-uzabbix -pZabbix数据库密码 zabbix < data.sql

安装zabbix

上传zabbix-6.0.13.tar.gz并解压

#tar -xvf zabbix-6.0.13.tar.gz

安装依赖

# yum installgcc mysql-devel libevent-devel libcurl-devel libxml2-devel libssh2-develOpenIPMI-devel net-snmp-devel go java-devel -y

# groupadd--system Zabbix

# useradd--system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "ZabbixMonitoring System" Zabbix

# ./configureCFLAGS="-std=gnu99" --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql--enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi--with-ssh2 --enable-java

# make install

修改配置文件

#vim /usr/local/zabbix/etc/zabbix_server.conf

DBP=

配置systemd启动

cat< /etc/systemd/system/zabbix-server.service

[Unit]

Description=ZabbixServer

After=syslog.targetnetwork.target network-online.target

Wants=network.targetnetwork-online.target

[Service]

Type=simple

User=root

ExecStart=/usr/local/zabbix/sbin/zabbix_server-c /usr/local/zabbix/etc/zabbix_server.conf

RemainAfterExit=yes

PIDFile=/var/run/zabbix/zabbix_server.pid

[Install]

WantedBy=multi-user.target

EOF

加入开机启动并启动

# systemctldaemon-reload

# systemctlenable zabbix-server && systemctl start zabbix-server

安装zabbix-web

安装nginx

正常编译安装,此处不展开细说

# mkdir -p/usr/local/nginx/html/zabbix

# cp -R/root/Zabbix-6.0.X/ui/* /usr/local/nginx/html/zabbix

# useradd -M-s /sbin/nologin nginx

修改nginx配置

#vim /usr/local/nginx/conf/nginx.conf

user nginx;

worker_processesauto;

error_log/var/log/nginx/error.log;

pid/run/nginx.pid;

include/usr/local/nginx/modules/*.conf;

events {

worker_connections 1024;

}

http {

log_format main '$remote_addr - $remote_user[$time_local] "$request" '

'$status $body_bytes_sent"$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;

tcp_nopush on;

tcp_nodelay on;

keepalive_timeout 65;

types_hash_max_size 4096;

include /usr/local/nginx/conf/mime.types;

default_type application/octet-stream;

include /etc/nginx/conf.d/*.conf;

server {

listen 8090;

listen [::]:8090;

server_name localhost;

root /usr/local/nginx/html/zabbix;

index index.php index.html index.htm;

include /etc/nginx/default.d/*.conf;

location ~ \.php$ {

root /usr/local/nginx/html/zabbix;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;

include fastcgi_params;

}

error_page 404 /404.html;

location = /404.html {

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

}

}

}

# /usr/local/nginx/sbin/nginx-c /usr/local/nginx/conf/nginx.conf

Zabbix-agent

配置启动项

cat< /etc/systemd/system/zabbix-agent.service

[Unit]

Description=ZabbixAgent

After=syslog.targetnetwork.target network-online.target

Wants=network.targetnetwork-online.target

[Service]

Type=simple

User=root

ExecStart=/usr/local/zabbix/sbin/zabbix_agentd-c /usr/local/zabbix/etc/zabbix_agentd.conf

RemainAfterExit=yes

PIDFile=/var/run/zabbix/zabbix_agent.pid

[Install]

WantedBy=multi-user.target

EOF

设置开机启动

# systemctl daemon-reload

# systemctl enable zabbix-agent --now

----------------------------------------------------------------------------------------------------------

PS:

以上为直接从word复制过来的,有些命令显示出来有些异常,比如没有空格,大小写搞乱了,此处不一一修改了,默认看到的读者有一定linux基础,如有

来源地址:https://blog.csdn.net/a541448989/article/details/129297832

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯