# tar xf LWSetup.tar.gz
# cd LWSetup/
# vim LW_install.sh
##修改如下配置文件中标黄部分,分别为数据库IP(备库IP)、库名、用户、密码
# sh LW_install.sh MYSQL 2>&1 | tee install.log
##选择install安装
# tailf /itops/zabbix/logs/zabbix_server.log
##安装完成后会自启server进程,可以通过打印日志输出确认数据库升级进度
# 服务正常运行时,应该有以下监听端口
9000: php-fpm
10051: server
10052: zabbix-java
80: nginx
[root@server-2 ~]# tar xf LWSetup.tar.gz [root@server-2 ~]# cd LWSetup/ [root@server-2 LWSetup]# vim LW_install.sh
##全局变量 export ZBXServer="${host_ip}" #采集服务器ip地址,HA的VIP export WEB_IP="${host_ip}" #WEB服务器的,HA的VIP export Server_DBHost="192.168.164.221" #server数据库ip地址
elif [ $1 = MYSQL ];then # MySQL export MysqlPath="/itops/mysql" #MySQL安装路径 export DataPath="/data/mysql" #MySQL数据目录 export ETC="/etc" #MySQL配置文件路径 export SQLUSER="root" #MySQL安装初始化后设置帐号 export SQLPASSWORD="ITMY_p@ssw0rd" #MySQL安装初始化后设置#MySQL安装初始化后端口号 export Server_DBPort="3306" #MySQL安装初始化后端口号 export SQLZBUSER="zabbix" #server和proxy对接的msyql数据库用户名 export SQLZBPASSWD="p@ssw0rd" #server和proxy对接的mysql数据库密码 export MySQLBackage="mysql-8.0.28-el7-x86_64.tar.gz" export BOOSTBackage="boost_1_59_0.tar.gz"
[root@server-2 LWSetup]# sh LW_install.sh MYSQL 2>&1 | tee install.log **...开始安装基础环境产品 **...输入 install,即可选择安装zabbxi server环境mysql数据库或postgresql数据库 包含的环境LNMP(数据库根据选择而定)、oracle client、python3、ansible、zabbix server、zabbix agentd **...输入 custom,自定义选择安装组件 **...输入quit,退出安装 请输入你的选择 install|custom|quit: install 你的选择是 install
开始执行 lnmp_install.sh root $ yum install -y gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel
…
root $ sed -i "s@localhost@192.168.164.223@g" /itops/zabbix/share/zabbix/alertscripts/LWSendAlert/api.conf root $ chown -R itops:itops /itops/zabbix/share/zabbix/alertscripts/ root $ chmod -R 777 /itops/zabbix/share/zabbix/alertscripts/LWSendAlert
========================================[启动服务]========================================
Restarting zabbix_server (via systemctl): [ OK ] Restarting zabbix_agentd (via systemctl): [ OK ] [root@server-2 LWSetup]# tailf /itops/zabbix/logs/zabbix_server.log 53711:20221102:122150.732 completed 98% of event name update 53711:20221102:122150.732 completed 99% of event name update 53711:20221102:122150.732 completed 100% of event name update 53711:20221102:122150.851 event name update completed
…
53956:20221102:122151.057 server #237 started [history poller #2] 53962:20221102:122151.058 server #243 started [odbc poller #1] 53957:20221102:122151.058 server #238 started [history poller #3] 53958:20221102:122151.060 server #239 started [history poller #4] 53959:20221102:122151.060 server #240 started [history poller #5] ^C [root@server-2 LWSetup]# ss -lnt State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:111 *:* LISTEN 0 128 *:80 *:* LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 *:10050 *:* LISTEN 0 128 *:10051 *:* LISTEN 0 128 127.0.0.1:9000 *:* LISTEN 0 128 [::]:111 [::]:* LISTEN 0 128 [::]:2224 [::]:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 100 [::1]:25 [::]:* LISTEN 0 128 [::]:10050 [::]:* LISTEN 0 128 [::]:10051 [::]:* LISTEN 0 50 [::]:10052 [::]:* [root@server-2 LWSetup]#
|
# service pcsd start
# pcs resource show
# pcs resource delete ZabbixServer
# pcs resource create ZabbixServer systemd:zabbix_server op monitor interval=20s --group server_group
##通过第二个show命令获取服务名,进行资源删除重新添加
# pcs status
[root@server-2 ~]# service pcsd start [root@server-2 ~]# pcs resource show Resource Group: server_group virtual_ip (ocf::heartbeat:IPaddr2): Started server-1 ZabbixServer (systemd:zabbix-server): Started server-1 [root@server-2 ~]# pcs resource delete ZabbixServer Removing Constraint - colocation-virtual_ip-ZabbixServer-INFINITY Removing Constraint - order-virtual_ip-ZabbixServer-mandatory Deleting Resource - ZabbixServer [root@server-2 ~]# pcs resource create ZabbixServer systemd:zabbix_server op monitor interval=20s --group server_group [root@server-2 ~]# pcs status Cluster name: server_cluster Stack: corosync Current DC: server-1 (version 1.1.23-1.el7_9.1-9acf116022) - partition with quorum Last updated: Thu Nov 3 03:37:15 2022 Last change: Thu Nov 3 03:33:46 2022 by root via cibadmin on server-1
2 nodes configured 2 resource instances configured
Online: [ server-1 server-2 ]
Full list of resources:
Resource Group: server_group virtual_ip (ocf::heartbeat:IPaddr2): Started server-2 ZabbixServer (systemd:zabbix_server): Started server-2
Failed Resource Actions: * ZabbixServer_start_0 on server-1 'not installed' (5): call=25, status=Not installed, exitreason='', last-rc-change='Thu Nov 3 03:18:33 2022', queued=0ms, exec=31ms
Daemon Status: corosync: active/enabled pacemaker: active/enabled pcsd: active/enabled [root@server-2 ~]# |
参考章节4.4
# yum install keepalived -y
# cp -f /data/keepalived.conf /etc/keepalived/keepalived.conf
# vim /etc/keepalived/keepalived.conf
## 调整主备库keepalived优先级参数,使备库为“后续主库”使用
# service keepalived start
# pcs cluster stop --all && pcs cluster start --all ## pcs集群重启命令
[root@db-2 mysql_8]# yum install keepalived -y [root@db-2 mysql_8]# cp -f /data/keepalived.conf /etc/keepalived/keepalived.conf [root@db-2 mysql_8]# vim /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { router_id MYSQL_HA #标识相同 } vrrp_instance VI_1 { state BACKUP #都设置为BACKUP interface ens33 virtual_router_id 90 priority 100 #优先级,backup设置比主小,同为backup时优先级别越高,就会主动去抢VIP nopreempt advert_int 1 #主备心跳检查间隔 authentication { auth_type PASS auth_pass 9191 } unicast_src_ip 192.168.164.221 #表示发送VRRP单播报文使用的源IP地址 unicast_peer { 192.168.164.220 #表示对端接收VRRP单播报文的IP地址 } virtual_ipaddress { 192.168.164.224 dev ens33 scope global #VIP地址 } } virtual_server 192.168.164.224 3306 { delay_loop 6 #lb_algo rr #LVS轮询算法 #lb_kind NAT #nat_mask 255.255.255.0 persistence_timeout 50 #回话保持时间 protocol TCP real_server 192.168.164.221 3306 { weight 3 notify_down /etc/keepalived/mysql.sh #当mysq服down时,执行此脚本,杀死keepalived实现切换 TCP_CHECK { connect_timeout 3 #连接超时 nb_get_retry 3 #重试次数 delay_before_retry 3 #重试间隔时间 } } }
[root@db-2 mysql_8]# service keepalived start Redirecting to /bin/systemctl start keepalived.service
|
主MYSQL库上操作:
# service keepalived stop
# vim /etc/keepalived/keepalived.conf
## 调整主备库keepalived优先级参数,使主库为“后续备库”使用
主备server上操作:
# vim /itops/zabbix/etc/zabbix_server.conf
# vim /itops/nginx/html/zabbix/conf/zabbix.conf.php
[root@db-1 ~]# service keepalived stop Redirecting to /bin/systemctl stop keepalived.service [root@db-1 ~]# vim /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { router_id MYSQL_HA #标识相同 } vrrp_instance VI_1 { state BACKUP #都设置为BACKUP interface ens33 virtual_router_id 90 priority 90 #优先级,backup设置比主小,同为backup时优先级别越高,就会主动去抢VIP #nopreempt #不主动抢占资源,只在master这台优先级高的设置,backup不设置,当master恢复时,不把VIP抢占回来 advert_int 1 #主备心跳检查间隔 authentication { auth_type PASS auth_pass 9191 } unicast_src_ip 192.168.164.220 #表示发送VRRP单播报文使用的源IP地址 unicast_peer { 192.168.164.221 #表示对端接收VRRP单播报文的IP地址 } virtual_ipaddress { 192.168.164.224 dev ens33 scope global #VIP地址 } }
virtual_server 192.168.164.224 3306 { delay_loop 6 #lb_algo rr #LVS轮询算法 #lb_kind NAT #nat_mask 255.255.255.0 persistence_timeout 50 #回话保持时间 protocol TCP real_server 192.168.164.220 3306 { weight 1 notify_down /etc/keepalived/mysql.sh #当mysq服down时,执行此脚本,杀死keepalived实现切换 TCP_CHECK { connect_timeout 3 #连接超时 nb_get_retry 3 #重试次数 delay_before_retry 3 #重试间隔时间 } } }
[root@server-2 ~]# vim /itops/zabbix/etc/zabbix_server.conf
DBHost=192.168.164.224
[root@server-2 ~]# vim /itops/nginx/html/zabbix/conf/zabbix.conf.php
$DB['SERVER']='192.168.164.224';
[root@server-1 ~]# vim /itops/zabbix/etc/zabbix_server.conf
DBHost=192.168.164.224
[root@server-1 ~]# vim /itops/nginx/html/zabbix/conf/zabbix.conf.php
$DB['SERVER']='192.168.164.224';
[root@server-1 ~]# pcs cluster stop --all && pcs cluster start --all server-1: Stopping Cluster (pacemaker)... server-2: Stopping Cluster (pacemaker)... server-1: Stopping Cluster (corosync)... server-2: Stopping Cluster (corosync)... server-1: Starting Cluster (corosync)... server-2: Starting Cluster (corosync)... server-2: Starting Cluster (pacemaker)... server-1: Starting Cluster (pacemaker)... [root@server-1 ~]# |
可不保留原数据直接升级mysql8,后续步骤从备库全量备份并配置主备,安装过程参考《mysql+zabbix升级方案(上)》章节4.3
#导出
mysqldump --all-databases -uroot -p --add-drop-table --skip-lock-tables --single-transaction --flush-logs --hex-blob --master-data=2 > mysqldump.sql
#导入
mysql -uroot -p
source /root/mysqlbak.sql
错误信息