我这边的生产环境是Centos7.9,Mysql5.7.38,zabbix-server5.0.31 由于业务需要,需要用到zabbix6.0的一些功能,所以不得已升级,参考了好多资料 zabbix依赖于mysql8,PHP版本大于7.
我这边的生产环境是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 <
[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<
[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
现有环境,通过容器升级
安装数据库
参照上面,建立一个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<
[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<
[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
--结束END--
本文标题: zabbix5.0.X升级到6.0.X版本(多种实现方法)
本文链接: https://lsjlt.com/news/385261.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0