Recommendations for optimizing Linux operating machine configurations for container DevOps personnel

This article was last updated on: February 7, 2024 pm

AS A PAAS PLATFORM ARCHITECT, CONTAINER-RELATED TECHNOLOGIES (DOCKER, K8S, ETC.) ARE ESSENTIAL. This article briefly introduces my own Linux operating machine configuration. Improve work efficiency and improve user experience.

Note:

This article uses CentOS 7.6 as an example, RHEL7.6 operation is similar.

Ubuntu system operation can be bypassed. It’s not difficult.

In addition, there will be some “optional” items in the following, mainly for some special cases, such as: Need to connect to the Internet through a proxy…

Replace the OS software installation source

Purpose: Speed up software downloads.

Can be replaced with: Ali, Tencent, Tsinghua, University of Science and Technology of China… of sources.

Taking Tsinghua Mirror as an example, the operation steps are as follows:

🔖 Reference article:

Tsinghua University Open Source Software Image Site - CentOS Image Usage Helphttps://mirrors.tuna.tsinghua.edu.cn/help/centos/

Procedure

  1. Back up CentOS-Base.repo first

    1
    sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
  2. Cover with the followingCentOS-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. Update the package cache

    1
    sudo yum makecache

Configure the agent (optional)

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/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 configures the proxy

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

Install and configure Git

Purpose: To use Git, after all, a lot of data, codebase, and software need to passgit clone

steps

  1. sudo yum install -y git

  2. To configure global users: git config --global user.name "<username>"

  3. Configure global email: git config --global user.email "<[email protected]>"

  4. (Optional): Configure SSH authentication

    1. 🔖 Reference documentation: GitHub - Connect to GitHub using SSH https://docs.github.com/cn/github/authenticating-to-github/connecting-to-github-with-ssh
  5. (Optional): Configure proxy 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
  6. (Optional): Configure Proxy Bypass, if the origin of the corresponding repository requires Bypass: git config --add remote.origin.proxy ""

Optimize the configuration of the shell

Purpose: zsh + plugins, to provide a rich and friendly shell experience. Such as: syntax highlighting, auto-completion, auto-suggestions, container related plugins…

Install zsh

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

Install Powerline

Can passpipInstallation:

1
pip install powerline-status

🔖 Reference article:

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

Install oh-my-zsh

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

Note:

If you can’t connect: <raw.githubusercontent.com>, take the corresponding address from GitHub: https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/install.shCopy the script and run it.

Install the zsh plugin: zsh-autosuggestions and zsh-syntax-highlighting

🔖 Reference documentation:

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. at~/.zshrcTo activate the plugin: plugins=([plugins...] zsh-syntax-highlighting)
  3. Restart zsh

zsh-autosuggestions

  1. clone: git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  2. at~/.zshrcTo activate the plugin: plugins=([plugins...] zsh-autosuggestions)
  3. Restart zsh

Use oh-my-zsh

Edit the zshrc file: vi ~/.zshrc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 修改主题 
ZSH_THEME="agnoster"

# 启用插件
plugins=(
git
ansible
docker-compose
docker
helm
kubectl
minikube
oc
pip
python
ubuntu
zsh-autosuggestions
zsh-syntax-highlighting
)

📓 Note:

  • Helm: Image package management tool on k8s
  • minikube: Minimal K8S installation tool
  • oc: A command-line tool for the commercial distribution of RedHat (OpenShift) for K8S

The final effect

Install frequently used software on demand

Purpose: Install common software and tools as needed according to your needs

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

Configure services on demand and power on:

1
2
3
systemctl enable haproxy.service 
systemctl start haproxy.service
...

Install jq, jq installation linkhttps://stedolan.github.io/jq/download/. JQ is a json formatting command line tool that is useful for day-to-day management of K8S.

Install the container class components

Docker family bucket

It is recommended to install the docker family bucket directly, saving worry and effort

🔖 Reference documentation:

Install Docker Engine on CentOS: https://docs.docker.com/engine/install/centos/

  1. Uninstall the old version:

    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
  2. CONFIGURE THE 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
  3. Installation:

    1
    $ sudo yum install docker-ce docker-ce-cli containerd.io
  4. Initiate:

    1
    $ sudo systemctl start docker
  5. Verify:

    1
    $ sudo docker run hello-world

Other open source components

For RedHat series, multiple component replacements may be installed:

1
sudo yum -y install buildah podman skopeo

📓 Note:

  • buildah: The component that builds the container image
  • podman: The component that runs the container image
  • skopeo: Transports components that move container images

Installation kubectl

Official installation documentation: https://kubernetes.io/zh/docs/tasks/tools/install-kubectl/

  1. Download: 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. mark kubectl The file is executable:chmod +x ./kubectl
  3. Place the file under the PATH path:sudo mv ./kubectl /usr/local/bin/kubectl
  4. Test that the version you installed is up to date:kubectl version --client

Install MiniKube or Kind

Here is the example of minikube:

Official installation documentation: https://kubernetes.io/zh/docs/tasks/tools/install-minikube/

It should be emphasized that:

  1. See Chinese documentation
  2. 📓 Note: Since you cannot directly connect to k8s.gcr.io in China, it is recommended to use Alibaba Cloud image repository minikube start added--image-repository Parameter.
  3. Example: minikube start --vm-driver=< 驱动名称 > --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers

Install helm v3

Binary CLI download addresshttps://github.com/helm/helm/releases/latest

Installation source documentation: https://helm.sh/docs/intro/install/

1
2
3
$ 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

Install the OpenShift command line oc

Download the binary CLI installation directly: https://mirror.openshift.com/pub/openshift-v4/clients/oc/

Install the OpenShift for Developer command lineodo

Download the binary CLI installation directly:https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/

Install Tekton - K8S native CI/CD tool

The CLI tool is calledtkn, Official Documentation: https://github.com/tektoncd/cli

Installation:

1
2
3
4
# 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

finish

Of course golang The environment is also essential.

Finally, I wish you all the best of luck! 💪💪💪


Recommendations for optimizing Linux operating machine configurations for container DevOps personnel
https://e-whisper.com/posts/55821/
Author
east4ming
Posted on
August 31, 2020
Licensed under