手头刚好有台Ubuntu, 决定装个microk8s玩玩, 没想到还挺曲折,记录下来以备后查。
因为这台Ubuntu没有接到Internate上,所以得使用http_proxy,因为涉及到的软件众多,proxy的设置也很麻烦:
export http_proxy = http://${ip}:3128
export https_proxy = http://${ip}:3128
测试下wget www.google.com 可以工作
在/etc/apt/apt.conf加入proxy的配置信息
Acquire::http::Proxy "http://9.21.60.170:3128";
Acquire::https::Proxy "http://9.21.60.170:3128";
记住每行的末尾一定要有”;“否则报错。
$ sudo mkdir -p /etc/systemd/system/snapd.service.d/
$ echo -e '[Service]\nEnvironment="http_proxy=http://${ip}:3128/"' \
| sudo tee /etc/systemd/system/snapd.service.d/http-proxy.conf
$ echo -e '[Service]\nEnvironment="https_proxy=http://${ip}:3128/"' \
| sudo tee /etc/systemd/system/snapd.service.d/https-proxy.conf
$ sudo systemctl daemon-reload
$ sudo systemctl restart snapd
mkdir /etc/systemd/system/docker.service.d
touch /etc/systemd/system/docker.service.d/http-proxy.conf
在该文件添加配置
[Service]
Environment="HTTP_PROXY=http://${ip}:3128/“
Environment="HTTPS_PROXY=http://${ip}:3128/“
然后运行:
$ sudo systemctl daemon-reload
$ sudo systemctl show --property Environment docker
$ sudo systemctl restart docker
修改${SNAP_DATA}/args/dockerd-env,一般来讲${SNAP_DATA} = /var/snap/microk8s/current
sudo systemctl restart snap.microk8s.daemon-docker.service
到这儿,所有proxy的配置就结束了,注意有两个坑:
参考网页:
https://askubuntu.com/questions/89437/how-to-install-packages-with-apt-get-on-a-system-connected-via-proxy
https://askubuntu.com/questions/764610/how-to-install-snap-packages-behind-web-proxy-on-ubuntu-16-04
https://stackoverflow.com/questions/23111631/cannot-download-docker-images-behind-a-proxy
https://github.com/ubuntu/microk8s/issues/344
https://github.com/ubuntu/microk8s/issues/359