Docker中Debian9安装Keepalived

在学习数据库集群的负载均衡时,有需要通过Docker镜像安装一个Haproxy的容器,然后再在这个容器中安装Keepalived,于是就遇到了下面这样一个坑。

正常部署是走如下两步:

apt-get update
apt-get install keepalived

但由于一些特殊原因,apt-get update这个命令执行起来速度特别慢,于是需要切换源。步骤是这样的:

1、找到需要配置的内容:

deb http://mirrors.aliyun.com/debian stretch main contrib non-free
deb-src http://mirrors.aliyun.com/debian stretch main contrib non-free
deb http://mirrors.aliyun.com/debian stretch-updates main contrib non-free
deb-src http://mirrors.aliyun.com/debian stretch-updates main contrib non-free
deb http://mirrors.aliyun.com/debian-security stretch/updates main contrib non-free
deb-src http://mirrors.aliyun.com/debian-security stretch/updates main contrib non-free

2、/etc/apt/sources.list 的内容换成步骤1中找到的内容。

问题就出在这儿,因为是Debian系统,里面既没有vi,也没有vim,修改不了sources.list文件内容。在网上找了一下解决办法,有的回答说,先安装vim,可当我输入apt-get install vim,终端上显示:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package

相当于要先执行一下apt-get update,才能执行apt-get install,坑爹。。

继续在网上找解决方法,发现可以用echo命令解决这个问题。

#先备份sources.list
mv /etc/apt/sources.list /etc/apt/sources.list.bak
#再编辑sources.list
echo "deb http://mirrors.aliyun.com/debian stretch main contrib non-free" >> /etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/debian stretch main contrib non-free" >> /etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/debian stretch-updates main contrib non-free" >> /etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/debian stretch-updates main contrib non-free" >> /etc/apt/sources.list
echo "deb http://mirrors.aliyun.com/debian-security stretch/updates main contrib non-free" >> /etc/apt/sources.list
echo "deb-src http://mirrors.aliyun.com/debian-security stretch/updates main contrib non-free" >> /etc/apt/sources.list

然后我再执行apt-get update,问题解决~

你可能感兴趣的:(Docker中Debian9安装Keepalived)