以下列出了构建vitess使用的Centos镜像的简单流程,由于较早基础版本是Centos7.2的,重新构建可以基于最新的Centos版本构建
1.基础镜像拉取
#拉取官方版本
docker pull centos:7.2.1511
官方镜像地址: https://hub.docker.com/_/centos/
2. 修改镜像源,可以选择阿里云的源地址或者内部源地址
CentOS-7.2-Base.repo
[CentOS]
name=CentOS-7.2 - Base #additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch/debug
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/7/SRPMS
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
3. 依赖程序安装
#安装vim
yum install vim -y #安装wget
yum install wget -y #安装rzsz
yum install lrzsz -y #安装ssh
yum install openssh-server -y #安装net-tools(包含netstat)
yum install net-tools -y #重置镜像默认密码
echo root:xxxxxxxxxxxxxxxx | chpasswd #安装sudu权限
yum install sudo -y #添加操作用户admin
useradd admin #修改admin默认密码
echo admin:xxxxxxxxxxxx | chpasswd #添加jeduser用户sudu权限
#在vim /etc/sudoers文件中root下面添加一行,增加admin的sudo权限
#root ALL=(ALL) ALL
admin ALL=(ALL) ALL #由于ssh需要依赖于一些key,需要更新key否则ssh无法启动
#Could not load host key: /etc/ssh/ssh_host_rsa_key
#Could not load host key: /etc/ssh/ssh_host_ecdsa_key
#Could not load host key: /etc/ssh/ssh_host_ed25519_key
ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ""
ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key #安装tcpdump
yum install tcpdump -y #安装lsof
yum install lsof -y #安装dstat
yum install dstat -y #安装scp
yum install openssh-clients #安装perf
yum install perf -y #安装sysstat
yum install sysstat -y #安装perl相关
yum install perl-DBI -y
yum install perl-DBD-MySQL -y
yum install perl-Time-HiRes -y
yum install perl-IO-Socket-SSL #安装percona-toolkit
yum install perl-TermReadKey -y
yum install perl-Digest-MD5 -y
#官网下载最新版本
#https://www.percona.com/downloads/percona-toolkit/LATEST/
wget https://www.percona.com/downloads/percona-toolkit/3.0.5/binary/redhat/7/x86_64/percona-toolkit-3.0.5-1.el7.x86_64.rpm
rpm -i percona-toolkit-3.0.5-1.el7.x86_64.rpm #安装percona-xtrabackup
yum install percona-xtrabackup -y #安装bzip2
yum install bzip2 -y #安装jq,解析json工具
yum install jq #安装mysql
wget https://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm
yum localinstall mysql57-community-release-el7-11.noarch.rpm
yum install mysql-community-server.x86_64 -y #安装python-setuptools
yum install python-setuptools -y #安装orzdba #处理ssh启动脚本
#由于debian和centos文件位置不一致,所以这里直接在centos中加入/etc/init.d/ssh脚本,通过脚本调用/usr/sbin/sshd,确保两个系统调用一致;这样调用模板就可以统一
#以下内容根据需要选择
#ssh脚本内容如下
/usr/sbin/sshd
4 添加证书
#根据需要添加需要的证书,如果不需要就忽略
#切换到admin
su admin #添加信任证书
echo ssh-rsa xxxxxxxxxxxxxxxxxxxxxxxxxxxxx >> /home/admin/.ssh/authorized_keys #修改证书授权文件权限
chmod 644 /home/admin/.ssh/authorized_keys
5. 提交镜像
构建完镜像之后直接获取镜像ID然后提交成基础镜像
提交后可以压缩镜像大小
docker commit 7541391ae047 vitesss/centos:7.2.1511