1 構建一個centos7.6.1810的docker鏡像,用於下載MySQL+xtrabackup所需安裝包 7.6.1810的docker鏡像,低版本最小安裝,會儘可能把所需的包拉齊。 Dockerfile文件如下 FROM centos:7.6.1810 CMD yum install -y ...
1 構建一個centos7.6.1810的docker鏡像,用於下載MySQL+xtrabackup所需安裝包
7.6.1810的docker鏡像,低版本最小安裝,會儘可能把所需的包拉齊。
Dockerfile文件如下
FROM centos:7.6.1810 CMD yum install -y https://repo.percona.com/yum/percona-release-latest.noarch.rpm https://repo.mysql.com//mysql80-community-release-el7-7.noarch.rpm epel-release && \ rm -rf /yum/mysql8.0 && mkdir -p /yum/mysql8.0 && \ yum --downloadonly --downloaddir=/yum/mysql8.0 install -y mysql-community-server percona-xtrabackup-80 zip unzip telnet lrzsz iotop ftp python-pip && \ yum-config-manager --disable mysql80-community && yum-config-manager --enable mysql57-community && \ rm -rf /yum/mysql5.7 && mkdir -p /yum/mysql5.7 && \ yum --downloadonly --downloaddir=/yum/mysql5.7 install -y mysql-community-server percona-xtrabackup-24 zip unzip telnet lrzsz iotop ftp python-pip
構建鏡像:
docker build -t mysql_xtrabackup_download .
2 運行鏡像自動下載MySQL5.7 / 8.0 + 對應版本的xtrabackup安裝包
docker run --rm \ -v /etc/localtime:/etc/localtime \ -v ${PWD}/yum:/yum \ mysql_xtrabackup_download
docker容器跑完會自動銷毀,併在當前目錄的yum文件夾下生成mysql5.7 / mysql8.0兩個安裝包
傳輸到無網路的centos7上,可以使用yum localinstall *.rpm進行安裝
3 解決衝突
下載的rpm可以用於離線安裝,但是安裝時會報錯
新版本的MySQL已經不再提供libmysqlclient.so.18.1.0,但是xtrabackup需要這個文件,所以就有一個Percona-Server-shared-56-5.6.51-rel91.0.1.el7.x86_64.rpm包提供
這個包又提供了一個/etc/my.cnf文件,導致和MySQL主包衝突,無法安裝成功,所以要替換掉它。
Transaction check error: 試圖安裝 mysql-community-server-8.0.31-1.el7.x86_64 和 Percona-Server-shared-56-5.6.51-rel91.0.1.el7.x86_64 會導致文件 /etc/my.cnf 衝突
下載Percona-Server-shared-56-5.6.51-rel91.0.1.el7.x86_64.rpm到Windows,解壓,得到兩個文件
創建文件libmysqlclient.spec
Name: libmysqlclient Version: 18.1.0 Release: 1 Summary: libmysqlclient-18.1.0 Summary(zh_CN): libmysqlclient-18.1.0 License: GPLv3+ Packager: XX Software %description libmysqlclient,Resolve MySQL and Xtrabackup installation conflicts %description -l zh_CN libmysqlclient,解決MySQL和xtrabackup安裝衝突 %install mkdir -p %{buildroot}/usr/lib64 install -m 755 -t %{buildroot}/usr/lib64 /usr/lib64/libmysqlclient.so.18.1.0 install -m 755 -t %{buildroot}/usr/lib64 /usr/lib64/libmysqlclient_r.so.18.1.0 %files /usr/lib64/libmysqlclient.so.18.1.0 /usr/lib64/libmysqlclient_r.so.18.1.0
創建文件Dockerfile
FROM centos:7.6.1810 RUN sed -e 's|^mirrorlist=|#mirrorlist=|g' \ -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \ -i.bak \ /etc/yum.repos.d/CentOS-*.repo && \ yum install -y rpm-build rpmdevtools CMD cd /tmp/libmysqlclient/ && \ mkdir -p /usr/lib64 && \ cp libmysqlclient*.so.18.1.0 /usr/lib64 && \ rpmbuild -bb libmysqlclient.spec --define "_topdir ${PWD}/rpmbuild"
四個文件放同一個目錄,然後build + run
docker build -t rpm_libmysqlclient . docker run --rm \ -v /etc/localtime:/etc/localtime \ -v ${PWD}:/tmp/libmysqlclient/ \ rpm_libmysqlclient
最後會得到rpmbuild/RPMS/x86_64/libmysqlclient-18.1.0-1.x86_64.rpm包
替換掉Percona-Server-shared-56-5.6.51-rel91.0.1.el7.x86_64.rpm,再安裝就沒問題了。