容器开发运维人员的 Linux 操作机配置优化建议
本文最后更新于:2024年7月25日 下午
“工欲善其事必先利其器”, 作为一个 PAAS 平台架构师,容器相关技术 (docker, k8s 等) 是必不可少的。本文简单介绍下我自己的 Linux 操作机配置。提升工作效率,提高使用体验. ❤❤❤
❗ 注意:
本文以 CentOS 7.6 为例,RHEL7.6 操作类似.
Ubuntu 系统操作可以触类旁通。没啥难度.
另外下文中会有一些 "可选" 项,主要是针对一些特殊情况,如:需要通过代理连接互联网…
更换 OS 软件安装源
目的:加快软件下载速度.
可以换成:阿里,腾讯,清华,中科大… 的源.
以清华 Mirror 为例,操作步骤如下:
🔖 参考文章:
清华大学开源软件镜像站 - CentOS 镜像使用帮助 https://mirrors.tuna.tsinghua.edu.cn/help/centos/
操作步骤
- 
先备份 CentOS-Base.repo 1 sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
- 
用下面内容覆盖 CentOS-Base.repo1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51# CentOS-Base.repo
 #
 # The mirror system uses the connecting IP address of the client and the
 # update status of each mirror to pick mirrors that are updated to and
 # geographically close to the client. You should use this for CentOS updates
 # unless you are manually picking other mirrors.
 #
 # If the mirrorlist= does not work for you, as a fall back you can try the
 # remarked out baseurl= line instead.
 #
 #
 [base]
 name=CentOS-$releasever - Base
 baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
 #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
 enabled=1
 gpgcheck=1
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7
 #released updates
 [updates]
 name=CentOS-$releasever - Updates
 baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
 #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
 enabled=1
 gpgcheck=1
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7
 #additional packages that may be useful
 [extras]
 name=CentOS-$releasever - Extras
 baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
 #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
 enabled=1
 gpgcheck=1
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7
 #additional packages that extend functionality of existing packages
 [centosplus]
 name=CentOS-$releasever - Plus
 baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
 #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
 gpgcheck=1
 enabled=0
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7
- 
更新软件包缓存 1 sudo yum makecache
配置代理 (可选)
sudo vi /etc/profile.d/setproxy.sh
| 1 |  | 
sudo source /etc/profile.d/setproxy.sh
YUM 配置代理
| 1 |  | 
安装及配置 Git
目的:使用 Git, 毕竟很多资料、代码库和软件都需要通过 git clone
步骤
- 
sudo yum install -y git
- 
配置全局用户: git config --global user.name "<username>"
- 
配置全局 email: git config --global user.email "<username@example.com>"
- 
(可选): 配置 ssh 认证 - 🔖 参考文档: GitHub - 使用 SSH 连接到 GitHub https://docs.github.com/cn/github/authenticating-to-github/connecting-to-github-with-ssh
 
- 
(可选): 配置代理 Proxy 1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12# 查看当前代理设置
 git config --global http.proxy
 # 设置当前代理为 http://127.0.0.1::8080 或 socket5://127.0.0.1::8080
 git config --global http.proxy 'http://127.0.0.1::8080'
 git config --global https.proxy 'http://127.0.0.1::8080'
 git config --global http.proxy 'socks5://127.0.0.1::8080'
 git config --global https.proxy 'socks5://127.0.0.1::8080'
 # 删除 proxy
 git config --global --unset http.proxy
 git config --global --unset https.proxy
- 
(可选): 配置 Proxy Bypass, 如对应仓库的 origin 需要 Bypass: git config --add remote.origin.proxy ""
优化配置 Shell
目的: zsh + plugins, 提供丰富而友好的 shell 体验。如: 语法高亮,自动补全,自动建议,容器相关插件…
安装 zsh
| 1 |  | 
安装 powerline
可以通过 pip 安装:
| 1 |  | 
🔖 参考文章:
powerline - Installation: https://powerline.readthedocs.io/en/latest/installation.html#pip-installation
安装 oh-my-zsh
| 1 |  | 
⚠ 注意:
如果连不上: <raw.githubusercontent.com>, 就从 github 对应的地址: https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/install.sh 把脚本复制下来运行.
安装 zsh 插件: zsh-autosuggestions 和 zsh-syntax-highlighting
🔖 参考文档:
- zsh-syntax-highlighting INSTALL.md: https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/INSTALL.md
zsh-syntax-highlighting
- clone: git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
- 在 ~/.zshrc激活插件:plugins=( [plugins...] zsh-syntax-highlighting)
- 重启 zsh
zsh-autosuggestions
- clone: git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
- 在 ~/.zshrc激活插件:plugins=( [plugins...] zsh-autosuggestions)
- 重启 zsh
使用 oh-my-zsh
编辑 zshrc 文件: vi ~/.zshrc
| 1 |  | 
📓 备注:
- helm: k8s 上的镜像包管理工具
- minikube: 最小化 K8S 安装工具
- oc: K8S 的 RedHat 商业发行版 (OpenShift) 的命令行工具
最终效果

按需安装常用软件
目的:根据自己需要,按需安装常用软件和工具
| 1 |  | 
按需配置服务和开机自启动:
| 1 |  | 
安装 jq, jq 安装链接 https://stedolan.github.io/jq/download/. JQ 是个 json 格式化命令行工具,在日常管理 K8S 中很有用.
安装容器类组件
docker 全家桶
建议直接安装 docker 全家桶,省心省力
🔖 参考文档:
Install Docker Engine on CentOS: https://docs.docker.com/engine/install/centos/
- 
卸载老版本: 1 
 2
 3
 4
 5
 6
 7
 8$ sudo yum remove docker \
 docker-client \
 docker-client-latest \
 docker-common \
 docker-latest \
 docker-latest-logrotate \
 docker-logrotate \
 docker-engine
- 
配置 REPOSITORY 1 
 2
 3
 4
 5$ sudo yum install -y yum-utils
 $ sudo yum-config-manager \
 --add-repo \
 https://download.docker.com/linux/centos/docker-ce.repo
- 
安装: 1 $ sudo yum install docker-ce docker-ce-cli containerd.io
- 
启动: 1 $ sudo systemctl start docker
- 
验证: 1 $ sudo docker run hello-world
其他开源组件
对于 RedHat 系,可能要安装多个组件替代:
| 1 |  | 
📓 备注:
- buildah: 构建容器镜像的组件
- podman: 运行容器镜像的组件
- skopeo: 传输移动容器镜像的组件
安装 kubectl
官方安装文档: https://kubernetes.io/zh/docs/tasks/tools/install-kubectl/
-  下载: curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
- 标记 kubectl文件为可执行:chmod +x ./kubectl
- 将文件放到 PATH 路径下:sudo mv ./kubectl /usr/local/bin/kubectl
- 测试你所安装的版本是最新的:kubectl version --client
安装 minikube 或 kind
这里以 minikube 为例:
官方安装文档: https://kubernetes.io/zh/docs/tasks/tools/install-minikube/
⚠ 需要强调的是:
- 看中文文档
- 📓 说明: 由于国内无法直接连接 k8s.gcr.io,推荐使用阿里云镜像仓库,在 minikube start中添加--image-repository参数。
- 示例: minikube start --vm-driver=<驱动名称> --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers
安装 helm v3
二进制 CLI 下载地址 https://github.com/helm/helm/releases/latest
安装源文档: https://helm.sh/docs/intro/install/
| 1 |  | 
安装 OpenShift 命令行 oc
直接下载二进制 CLI 安装: https://mirror.openshift.com/pub/openshift-v4/clients/oc/
安装 OpenShift for Developer 命令行 odo
直接下载二进制 CLI 安装:https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/
安装 Tekton - K8S 原生 CI/CD 工具
CLI 工具叫做 tkn, 官方文档: https://github.com/tektoncd/cli
安装:
| 1 |  | 
完
当然,golang 环境也是必不可少的.
最后祝大家用的顺手!💪💪💪






