"工欲善其事必先利其器", 作为一个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
  2. 用下面内容覆盖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
  3. 更新软件包缓存

    sudo yum makecache

配置代理(可选)

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"

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

YUM配置代理

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

安装及配置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
  5. (可选): 配置代理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
  6. (可选): 配置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)
# 注销

安装 powerline

可以通过pip安装:

pip install powerline-status

参考文章:

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 -)"

️ 注意:

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

安装zsh插件: zsh-autosuggestions 和 zsh-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
)

备注:

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

最终效果

按需安装常用软件

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

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

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

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

安装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
  2. 配置REPOSITORY

    $ sudo yum install -y yum-utils
    
    $ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
  3. 安装:

    $ sudo yum install docker-ce docker-ce-cli containerd.io
  4. 启动:

    $ sudo systemctl start docker
  5. 验证:

    $ sudo docker run hello-world

其他开源组件

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

sudo yum -y install buildah podman skopeo

备注:

  • 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

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

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

最后祝大家用的顺手!

本文由博客一文多发平台 OpenWrite 发布!

容器开发运维人员的 Linux 操作机配置优化建议的更多相关文章

  1. Devops 开发运维高级篇之容器管理

    Devops 开发运维高级篇之容器管理 安装docker Dockerfile镜像脚本入门制作 Harbor镜像仓库安装及使用 不过多解释docker直接秀基操 安装docker:(jenkins服务 ...

  2. Devops 开发运维高级篇之Jenkins+Docker+SpringCloud微服务持续集成(上)

    Devops 开发运维高级篇之Jenkins+Docker+SpringCloud微服务持续集成(上) Jenkins+Docker+SpringCloud持续集成流程说明 大致流程说明: 1) 开发 ...

  3. (视频)《快速创建网站》 4.1 为啥造软件不同于造汽车,为啥是软件就一定会有Bug - 构建开发运维一体化(DevOps)

    本文是<快速创建网站>系列的第9篇,如果你还没有看过之前的内容,建议你点击以下目录中的章节先阅读其他内容再回到本文. 访问本系列目录,请点击:http://devopshub.cn/tag ...

  4. Devops 开发运维高级篇之Jenkins+Docker+SpringCloud微服务持续集成——部署方案优化

    Devops 开发运维高级篇之Jenkins+Docker+SpringCloud微服务持续集成--部署方案优化 之前我们做的方案部署都是只能选择一个微服务部署并只有一台生产服务器,每个微服务只有一个 ...

  5. Devops 开发运维高级篇之微服务代码上传和代码检查

    Devops 开发运维高级篇之微服务代码上传和代码检查 微服务持续集成(1)-项目代码上传到Gitlab 微服务持续集成(2)-从Gitlab拉取项目源码 微服务持续集成(3)-提交到SonarQub ...

  6. 安全开发运维必备,如何进行Nginx代理Web服务器性能优化与安全加固配置,看这篇指南就够了

    本章目录 1.引言 1.1 目的 1.2 目标范围 1.3 读者对象 2.参考说明 2.1 帮助参考 2.2 参数说明 3.3 模块说明 3.服务优化 3.1 系统内核 3.2 编译优化 3.3 性能 ...

  7. Redis开发运维的陷阱及避坑指南

    原文首发于博客园,作者:后青春期的Keats:地址:https://www.cnblogs.com/keatsCoder/ 转载请注明,谢谢! Linux 配置优化 我们在使用 Redis 过程中,可 ...

  8. linux apache服务器优化建议整理(很实用)

    转载:http://www.cnblogs.com/zhongbin/archive/2013/06/11/3131865.html 1.apache服务器的time_wait过多 fin_wait1 ...

  9. 逼格高又实用的Linux高级命令,开发运维都要懂!

    在运维的坑里摸爬滚打好几年了,我还记得我刚开始的时候,我只会使用一些简单的命令,写脚本的时候,也是要多简单有多简单,所以有时候写出来的脚本又长又臭. 像一些高级点的命令,比如说 Xargs 命令.管道 ...

  10. Linux、Aix(unix)、Oracle 银行外包开发运维常用命令

    我一直是银行外包开发人员,常用的操作命令固然少不了,这是我一次自己边添加边使用的笔记.内容有点乱,希望可以帮到你. rm 文件或目录rm -f 文件或目录rm -rf * 跑路的时候用du -h 文件 ...

随机推荐

  1. Hugging Face 表情包来啦!

    小编有一个朋友,微信聊基本不回复文字,内容和情绪都化身成表情包直接回复,并且一气呵成.自带上下文衔接.你身边有这样的朋友吗? 作为梦想成为第一家以表情符号上市的公司,以及在社交平台发文 emoji 不 ...

  2. Java //在150之内 是三的倍数 输出Zzz 是5个倍数输出 Lll 是7的倍数输出zlzl

    1 //在150之内 是三的倍数 输出Zzz 是5个倍数输出 Lll 是7的倍数输出zlzl 2 int i =1; 3 for(i = 1; i<=150;i++) 4 { 5 System. ...

  3. SQL之基本查询

    提纲 记录查询 使用列别名 查询语句执行顺序 数据分页 子句执行顺序 结果集排序 PS: 排序注意 多个排序字段 子句执行顺序 结果集去除重复数据 注意: 条件查询 比较运算符 注意 子句执行顺序

  4. CYQ.Data 支持 KingbaseES人大金仓数据库

    KingbaseES人大金仓数据库介绍: KingbaseES是一种关系型数据库管理系统,也被称为人大金仓数据库.KingbaseES 是北京人大金仓信息技术股份有限公司研发的,具有自主知识产权的通用 ...

  5. 使用FastWiki一分钟搭建公司的智能客服

    FastWiki 新UI介绍:基于React与LobeUI框架设计 FastWiki 最近引入了基于React的新UI,这是一个重大的更新.在设计新UI时,我们借鉴了LobeUI的框架,并且在接口调用 ...

  6. Zabbix_get基础命令浅析

    zabbix_get是Zabbix监控系统的一个命令行工具,可以用于从Zabbix服务器或代理获取数据.以下是zabbix_get的基本使用方法: 1.获取一个单独的键值对 使用以下命令可以获取一个单 ...

  7. $event - vue中默认参数的显示 - @on-change="func($event, code)" - 基础知识

    @on-change="checkAllOnChangeHandle($event,scItem.code)"

  8. 4时4态 加被动 例句:I will have been being done - will have be be do - 频率副词位置

    4时4态 频率副词的用法和位置:放在实义动词之前.放在be 动词之后.放在情态动词之后. 频率副词的位置一般是放在实义动词之前.放在be 动词之后.放在情态动词之后.放在be动词之后:She is s ...

  9. 文心一言 VS 讯飞星火 VS chatgpt (216)-- 算法导论16.2 3题

    三.假定在 0-1 背包问题中,商品的重量递增序与价值递减序完全一样.设计一个高效算法求此背包问题的变形的最优解,证明你的算法是正确的.如果要写代码,请用go语言. 文心一言: 在0-1背包问题中,如 ...

  10. 《.NET内存管理宝典 》(Pro .NET Memory Management) 阅读指南 - 第4章

    本章勘误: 暂无,等待细心的你告诉我哦. 本章注解: 暂无 本章释疑: 暂无,等待你的提问 致谢: MVP 林德熙 MVP 吕毅 sPhinX 相关链接 试读记录