容器开发运维人员的 Linux 操作机配置优化建议

本文涉及的产品
容器镜像服务 ACR,镜像仓库100个 不限时长
容器服务 Serverless 版 ACK Serverless,952元额度 多规格
容器服务 Serverless 版 ACK Serverless,317元额度 多规格
简介: 容器开发运维人员的 Linux 操作机配置优化建议

“工欲善其事必先利其器”, 作为一个 PAAS 平台架构师, 容器相关技术 (docker, k8s 等) 是必不可少的. 本文简单介绍下我自己的 Linux 操作机配置. 提升工作效率, 提高使用体验.

注意:

本文以 CentOS 7.6 为例, RHEL7.6 操作类似.

Ubuntu 系统操作可以触类旁通. 没啥难度.

另外下文中会有一些 " 可选 " 项, 主要是针对一些特殊情况, 如: 需要通过代理连接互联网…

更换 OS 软件安装源

目的: 加快软件下载速度.

可以换成: 阿里, 腾讯, 清华, 中科大…的源.

以清华 Mirror 为例, 操作步骤如下:

🔖 参考文章:

清华大学开源软件镜像站 - CentOS 镜像使用帮助https://mirrors.tuna.tsinghua.edu.cn/help/centos/

操作步骤

  1. 先备份 CentOS-Base.repo
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
SHELL
  1. 用下面内容覆盖CentOS-Base.repo
# 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
INI
  1. 更新软件包缓存
sudo yum makecache
SHELL

配置代理(可选)

sudo vi /etc/profile.d/setproxy.sh

#!/bin/sh
# for terminal
export proxyserveraddr=127.0.0.1
export proxyserverport=8080
export HTTP_PROXY="http://$proxyserveraddr:$proxyserverport/"
export HTTPS_PROXY="http://$proxyserveraddr:$proxyserverport/"
# export FTP_PROXY="ftp://$proxyserveraddr:$proxyserverport/"
# export SOCKS_PROXY="socks://$proxyserveraddr:$proxyserverport/"
export NO_PROXY="localhost,127.0.0.1,localaddress,.localdomain.com"
export http_proxy="http://$proxyserveraddr:$proxyserverport/"
export https_proxy="http://$proxyserveraddr:$proxyserverport/"
# export ftp_proxy="ftp://$proxyserveraddr:$proxyserverport/"
# export socks_proxy="socks://$proxyserveraddr:$proxyserverport/"
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
SHELL

sudo source /etc/profile.d/setproxy.sh

YUM 配置代理

echo "proxy=http://127.0.0.1:8080" >> /etc/yum.conf
SHELL

安装及配置 Git

目的: 使用 Git, 毕竟很多资料、代码库和软件都需要通过git clone

步骤

  1. sudo yum install -y git
  2. 配置全局用户: git config --global user.name "<username>"
  3. 配置全局 email: git config --global user.email "<username@example.com>"
  4. (可选): 配置 ssh 认证
  1. 🔖 参考文档: GitHub - 使用 SSH 连接到 GitHub https://docs.github.com/cn/github/authenticating-to-github/connecting-to-github-with-ssh
  1. (可选): 配置代理 Proxy
# 查看当前代理设置 
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
SHELL
  1. (可选): 配置 Proxy Bypass, 如对应仓库的 origin 需要 Bypass: git config --add remote.origin.proxy ""

优化配置 Shell

目的: zsh + plugins, 提供丰富而友好的 shell 体验. 如: 语法高亮, 自动补全, 自动建议, 容器相关插件…

安装 zsh

sudo yum install -y zsh
zsh --version
sudo chsh -s $(which zsh)
# 注销
APPLESCRIPT

安装 powerline

可以通过 pip 安装:

pip install powerline-status
SHELL

🔖 参考文章:

powerline - Installation: https://powerline.readthedocs.io/en/latest/installation.html#pip-installation

安装 oh-my-zsh

sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
SHELL

注意:

如果连不上: <raw.githubusercontent.com>, 就从 github 对应的地址: https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/install.sh把脚本复制下来运行.

安装 zsh 插件: zsh-autosuggestionszsh-syntax-highlighting

🔖 参考文档:

zsh-syntax-highlighting

  1. clone: git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  2. ~/.zshrc 激活插件: plugins=([plugins...] zsh-syntax-highlighting)
  3. 重启 zsh

zsh-autosuggestions

  1. clone: git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  2. ~/.zshrc 激活插件: plugins=([plugins...] zsh-autosuggestions)
  3. 重启 zsh

使用 oh-my-zsh

编辑 zshrc 文件: vi ~/.zshrc

# 修改主题 
ZSH_THEME="agnoster"
#  启用插件
plugins=(
  git
  ansible
  docker-compose
  docker
  helm
  kubectl
  minikube
  oc
  pip
  python
  ubuntu
  zsh-autosuggestions
  zsh-syntax-highlighting
)
SHELL

📓 备注:

  • helm: k8s 上的镜像包管理工具
  • minikube: 最小化 K8S 安装工具
  • oc: K8S 的 RedHat 商业发行版 (OpenShift) 的命令行工具

最终效果

按需安装常用软件

目的: 根据自己需要, 按需安装常用软件和工具

sudo yum -y install dnsmasq httpd haproxy nginx \
                    python3 \
                    genisoimage libguestfs-tools
SHELL

按需配置服务和开机自启动:

systemctl enable haproxy.service 
systemctl start haproxy.service 
...
SHELL

安装 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. 卸载老版本:
$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
SHELL
  1. 配置 REPOSITORY
$ sudo yum install -y yum-utils
$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
SHELL
  1. 安装:
$ sudo yum install docker-ce docker-ce-cli containerd.io
SHELL
  1. 启动:
$ sudo systemctl start docker
SHELL
  1. 验证:
$ sudo docker run hello-world
SHELL

其他开源组件

对于 RedHat 系, 可能要安装多个组件替代:

sudo yum -y install buildah podman skopeo
SHELL

📓 备注:

  • buildah: 构建容器镜像的组件
  • podman: 运行容器镜像的组件
  • skopeo: 传输移动容器镜像的组件

安装 kubectl

官方安装文档: https://kubernetes.io/zh/docs/tasks/tools/install-kubectl/

  1. 下载: curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
  2. 标记 kubectl 文件为可执行:chmod +x ./kubectl
  3. 将文件放到 PATH 路径下:sudo mv ./kubectl /usr/local/bin/kubectl
  4. 测试你所安装的版本是最新的:kubectl version --client

安装 minikube 或 kind

这里以 minikube 为例:

官方安装文档: https://kubernetes.io/zh/docs/tasks/tools/install-minikube/

需要强调的是:

  1. 看中文文档
  2. 📓 说明: 由于国内无法直接连接 k8s.gcr.io,推荐使用阿里云镜像仓库,在 minikube start 中添加--image-repository 参数。
  3. 示例: 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/

$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
$ chmod 700 get_helm.sh
$ ./get_helm.sh
SHELL

安装 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

安装:

# Get the tar.xz
curl -LO https://github.com/tektoncd/cli/releases/download/v0.12.0/tkn_0.12.0_Darwin_x86_64.tar.gz
# Extract tkn to your PATH (e.g. /usr/local/bin)
sudo tar xvzf tkn_0.12.0_Darwin_x86_64.tar.gz -C /usr/local/bin tkn
SHELL

当然, golang 环境也是必不可少的.

最后祝大家用的顺手! 💪 💪 💪

相关实践学习
通过容器镜像仓库与容器服务快速部署spring-hello应用
本教程主要讲述如何将本地Java代码程序上传并在云端以容器化的构建、传输和运行。
深入解析Docker容器化技术
Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化,容器是完全使用沙箱机制,相互之间不会有任何接口。Docker是世界领先的软件容器平台。开发人员利用Docker可以消除协作编码时“在我的机器上可正常工作”的问题。运维人员利用Docker可以在隔离容器中并行运行和管理应用,获得更好的计算密度。企业利用Docker可以构建敏捷的软件交付管道,以更快的速度、更高的安全性和可靠的信誉为Linux和Windows Server应用发布新功能。 在本套课程中,我们将全面的讲解Docker技术栈,从环境安装到容器、镜像操作以及生产环境如何部署开发的微服务应用。本课程由黑马程序员提供。 &nbsp; &nbsp; 相关的阿里云产品:容器服务 ACK 容器服务 Kubernetes 版(简称 ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情: https://www.aliyun.com/product/kubernetes
相关文章
|
15天前
|
网络协议 安全 Linux
如何配置Linux端的ftp?
如何配置Linux端的ftp?
118 64
|
8天前
|
Oracle Java 关系型数据库
Linux下JDK环境的配置及 bash: /usr/local/java/bin/java: cannot execute binary file: exec format error问题的解决
如果遇到"exec format error"问题,文章建议先检查Linux操作系统是32位还是64位,并确保安装了与系统匹配的JDK版本。如果系统是64位的,但出现了错误,可能是因为下载了错误的JDK版本。文章提供了一个链接,指向Oracle官网上的JDK 17 Linux版本下载页面,并附有截图说明。
Linux下JDK环境的配置及 bash: /usr/local/java/bin/java: cannot execute binary file: exec format error问题的解决
|
11天前
|
Linux 编译器 开发工具
快速在linux上配置python3.x的环境以及可能报错的解决方案(python其它版本可同样方式安装)
这篇文章介绍了在Linux系统上配置Python 3.x环境的步骤,包括安装系统依赖、下载和解压Python源码、编译安装、修改环境变量,以及常见安装错误的解决方案。
20 1
|
16天前
|
Ubuntu Linux
Linux服务器的自动启动可以在哪里进行配置?
Linux服务器的自动启动可以在哪里进行配置?
72 3
|
10天前
|
消息中间件 运维 Linux
linux之centos运维kafka
linux之centos运维kafka
|
18天前
|
运维 监控 安全
构建高效运维体系:从监控到自动化的全方位实践
本文深入探讨了构建高效运维体系的关键要素,从监控、日志管理、自动化工具、容器化与微服务架构、持续集成与持续部署(CI/CD)、虚拟化与云计算以及安全与合规等方面进行了全面阐述。通过引入先进的技术和方法,结合实际案例和项目经验,为读者提供了一套完整的运维解决方案,旨在帮助企业提升运维效率,降低运营成本,确保业务稳定运行。
|
16天前
|
机器学习/深度学习 运维 Prometheus
构建高效运维体系:从自动化部署到智能监控的全方位实践
在当今数字化时代,企业对运维效率和稳定性的要求越来越高。本文将探讨如何构建一个高效的运维体系,从自动化部署、持续集成与持续交付(CI/CD)、智能监控、故障管理以及数据驱动决策等方面进行深入分析和实践指导。通过这些方法,企业可以实现更快速、更可靠的软件发布和问题解决,提升整体运营效率。
|
12天前
|
敏捷开发 运维 Prometheus
构建高效运维体系:从基础架构到自动化管理
本文探讨了如何通过优化基础架构、引入自动化工具和流程,以及加强团队协作,构建高效的运维体系。通过案例分析和实践建议,帮助运维人员实现系统的稳定性、可靠性和可维护性。
|
6天前
|
机器学习/深度学习 运维 Cloud Native
构建高效运维体系:从自动化到智能化的演进之路
在当今数字化时代,运维作为信息技术的重要支柱,其效率与创新能力直接关系到企业信息系统的稳定性和业务连续性。本文将探讨如何通过技术手段,实现运维从传统手工操作向自动化、智能化的转变,进而构建一个高效、可靠的运维体系。我们将从自动化工具的应用开始,逐步深入到智能运维的实践,最终展望云原生架构下的运维未来趋势。
|
8天前
|
运维 Ubuntu 应用服务中间件
自动化运维:使用Ansible进行配置管理和任务自动化
【9月更文挑战第27天】在现代IT基础设施中,自动化运维是提高效率、减少人为错误和确保系统一致性的关键。本文将介绍如何使用Ansible,一个流行的开源IT自动化工具,来简化日常的运维任务。我们将探索Ansible的核心概念,包括它的架构、如何安装和使用它,以及一些实际的使用案例。无论你是新手还是有经验的运维专家,这篇文章都会提供有价值的见解和技巧,以帮助你更好地利用Ansible实现自动化。
下一篇
无影云桌面