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
构建镜像:
1
|
docker build -t mysql_xtrabackup_download . |
2 运行镜像自动下载MySQL5.7 / 8.0 + 对应版本的xtrabackup安装包
1
2
3
4
|
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主包冲突,无法安装成功,所以要替换掉它。
1
2
|
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
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
1
2
3
4
5
6
7
8
9
10
11
12
|
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
1
2
3
4
5
6
|
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,再安装就没问题了。