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

本文涉及的产品
容器镜像服务 ACR,镜像仓库100个 不限时长
简介: 容器开发运维人员的 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代码程序上传并在云端以容器化的构建、传输和运行。
Kubernetes极速入门
Kubernetes(K8S)是Google在2014年发布的一个开源项目,用于自动化容器化应用程序的部署、扩展和管理。Kubernetes通常结合docker容器工作,并且整合多个运行着docker容器的主机集群。 本课程从Kubernetes的简介、功能、架构,集群的概念、工具及部署等各个方面进行了详细的讲解及展示,通过对本课程的学习,可以对Kubernetes有一个较为全面的认识,并初步掌握Kubernetes相关的安装部署及使用技巧。本课程由黑马程序员提供。 &nbsp; 相关的阿里云产品:容器服务 ACK 容器服务 Kubernetes 版(简称 ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情:&nbsp;https://www.aliyun.com/product/kubernetes
相关文章
|
2月前
|
Ubuntu Unix Linux
Linux网络文件系统NFS:配置与管理指南
NFS 是 Linux 系统中常用的网络文件系统协议,通过配置和管理 NFS,可以实现跨网络的文件共享。本文详细介绍了 NFS 的安装、配置、管理和常见问题的解决方法,希望对您的工作有所帮助。通过正确配置和优化 NFS,可以显著提高文件共享的效率和安全性。
243 7
|
2月前
|
机器学习/深度学习 人工智能 运维
人工智能在云计算中的运维优化:智能化的新时代
人工智能在云计算中的运维优化:智能化的新时代
272 49
|
3月前
|
数据库连接 Linux Shell
Linux下ODBC与 南大通用GBase 8s数据库的无缝连接配置指南
本文详细介绍在Linux系统下配置GBase 8s数据库ODBC的过程,涵盖环境变量设置、ODBC配置文件编辑及连接测试等步骤。首先配置数据库环境变量如GBASEDBTDIR、PATH等,接着修改odbcinst.ini和odbc.ini文件,指定驱动路径、数据库名称等信息,最后通过catalog.c工具或isql命令验证ODBC连接是否成功。
|
3月前
|
缓存 监控 开发者
掌握Docker容器化技术:提升开发效率的利器
在现代软件开发中,Docker容器化技术成为提升开发效率和应用部署灵活性的重要工具。本文介绍Docker的基本概念,并分享Dockerfile最佳实践、容器网络配置、环境变量和秘密管理、容器监控与日志管理、Docker Compose以及CI/CD集成等技巧,帮助开发者更高效地利用Docker。
|
3月前
|
缓存 资源调度 安全
深入探索Linux操作系统的心脏——内核配置与优化####
本文作为一篇技术性深度解析文章,旨在引领读者踏上一场揭秘Linux内核配置与优化的奇妙之旅。不同于传统的摘要概述,本文将以实战为导向,直接跳入核心内容,探讨如何通过精细调整内核参数来提升系统性能、增强安全性及实现资源高效利用。从基础概念到高级技巧,逐步揭示那些隐藏在命令行背后的强大功能,为系统管理员和高级用户打开一扇通往极致性能与定制化体验的大门。 --- ###
103 9
|
3月前
|
存储 安全 数据管理
如何在 Rocky Linux 8 上安装和配置 Elasticsearch
本文详细介绍了在 Rocky Linux 8 上安装和配置 Elasticsearch 的步骤,包括添加仓库、安装 Elasticsearch、配置文件修改、设置内存和文件描述符、启动和验证 Elasticsearch,以及常见问题的解决方法。通过这些步骤,你可以快速搭建起这个强大的分布式搜索和分析引擎。
111 5
|
6天前
|
Ubuntu API 网络虚拟化
ubuntu22 编译安装docker,和docker容器方式安装 deepseek
本脚本适用于Ubuntu 22.04,主要功能包括编译安装Docker和安装DeepSeek模型。首先通过Apt源配置安装Docker,确保网络稳定(建议使用VPN)。接着下载并配置Docker二进制文件,创建Docker用户组并设置守护进程。随后拉取Debian 12镜像,安装系统必备工具,配置Ollama模型管理器,并最终部署和运行DeepSeek模型,提供API接口进行交互测试。
131 15
|
1月前
|
Ubuntu NoSQL Linux
《docker基础篇:3.Docker常用命令》包括帮助启动类命令、镜像命令、有镜像才能创建容器,这是根本前提(下载一个CentOS或者ubuntu镜像演示)、容器命令、小总结
《docker基础篇:3.Docker常用命令》包括帮助启动类命令、镜像命令、有镜像才能创建容器,这是根本前提(下载一个CentOS或者ubuntu镜像演示)、容器命令、小总结
160 6
《docker基础篇:3.Docker常用命令》包括帮助启动类命令、镜像命令、有镜像才能创建容器,这是根本前提(下载一个CentOS或者ubuntu镜像演示)、容器命令、小总结
|
1月前
|
Kubernetes Linux 虚拟化
入门级容器技术解析:Docker和K8s的区别与关系
本文介绍了容器技术的发展历程及其重要组成部分Docker和Kubernetes。从传统物理机到虚拟机,再到容器化,每一步都旨在更高效地利用服务器资源并简化应用部署。容器技术通过隔离环境、减少依赖冲突和提高可移植性,解决了传统部署方式中的诸多问题。Docker作为容器化平台,专注于创建和管理容器;而Kubernetes则是一个强大的容器编排系统,用于自动化部署、扩展和管理容器化应用。两者相辅相成,共同推动了现代云原生应用的快速发展。
209 11
|
2月前
|
Ubuntu Linux 开发工具
docker 是什么?docker初认识之如何部署docker-优雅草后续将会把产品发布部署至docker容器中-因此会出相关系列文章-优雅草央千澈
Docker 是一个开源的容器化平台,允许开发者将应用程序及其依赖项打包成标准化单元(容器),确保在任何支持 Docker 的操作系统上一致运行。容器共享主机内核,提供轻量级、高效的执行环境。本文介绍如何在 Ubuntu 上安装 Docker,并通过简单步骤验证安装成功。后续文章将探讨使用 Docker 部署开源项目。优雅草央千澈 源、安装 Docker 包、验证安装 - 适用场景:开发、测试、生产环境 通过以上步骤,您可以在 Ubuntu 系统上成功安装并运行 Docker,为后续的应用部署打下基础。
96 8
docker 是什么?docker初认识之如何部署docker-优雅草后续将会把产品发布部署至docker容器中-因此会出相关系列文章-优雅草央千澈