K3S 生产环境搭建(一):zsh 安装

偏向技术
/ 0 评论 / 87 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年08月23日,已超过791天没有更新,若内容或图片失效,请留言反馈。

经过长时间反复的安装测试,本文开始记录 K3S 生产环境搭建全过程,争取搭建一个持续可用稳定的集群环境,包括 zsh + oh-my-zsh、K3S安装、KubeSphere、MySQL、Elasticsearch、Grafana + Prometheus

zsh 是属于 Shell 的一种,和 Bash 一样,但比 Bash 好用,并且由于他极丰富的插件,能够大幅度提高使用 Linux 的效率,oh-my-zsh 是基于 zsh 命令行的一个扩展工具集,提供了主题配置和高度适用的自动补全功能。

请先确认能正常访问 Github,如果无法访问,请参考手把手实现 Github 代理加速

zsh 安装

以 Centos 7.6 为例,手动安装 zsh v5.9,因为默认的 zsh 版本过低,会导致 kubectl 自动补全提示出现乱码,所以这里选择手动安装

bash
yum update -y && yum install -y make ncurses-devel gcc autoconf man
wget https://udomain.dl.sourceforge.net/project/zsh/zsh/5.9/zsh-5.9.tar.xz -O /tmp/zsh.tar.xz
tar -xf /tmp/zsh.tar.xz -C /tmp
cd /tmp/zsh-5.9
./Util/preconfig && ./configure
make -j 20 install.bin install.modules install.fns
command -v zsh | sudo tee -a /etc/shells
chsh -s /usr/local/bin/zsh
12345678

安装 git, 用于拉取 oh-my-zsh 和其他插件

bash
yum install -y git
1

安装 oh-my-zsh

bash
curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh | sh -s - -y
1

安装 zsh-autosuggestions

bash
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
1

安装 zsh-syntax-highlighting

bash
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
1

修改 ~/.zshrc

bash
# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"

# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="agnoster"

# https://kubernetes.io/zh-cn/docs/tasks/tools/included/optional-kubectl-configs-zsh/
autoload -Uz compinit
compinit

plugins=(git kubectl zsh-autosuggestions zsh-syntax-highlighting)

alias cls="clear"

export PATH=$HOME/bin:/usr/local/bin:$PATH

# tabtab source for packages
# uninstall by removing these lines
[[ -f ~/.config/tabtab/zsh/__tabtab.zsh ]] && . ~/.config/tabtab/zsh/__tabtab.zsh || true

source $ZSH/oh-my-zsh.sh
# User configuration
source ~/.bash_profile
1234567891011121314151617181920212223

zsh 脚本安装

这里提供基于 Centos 7.6 的安装脚本,需要 wgetcurl 命令可用

安装 zsh 和 oh-my-zsh

bash
curl -fsSL https://github.com/aliuq/config/raw/master/bash/install_zsh.sh | sh
# 国内加速
curl -fsSL https://hub.llll.host/aliuq/config/raw/master/bash/install_zsh.sh | sh -s - --mirror
123

同步默认插件和配置

bash
curl -fsSL https://github.com/aliuq/config/raw/master/bash/sync_k3s.sh | sh
# 国内加速
curl -fsSL https://hub.llll.host/aliuq/config/raw/master/bash/sync_k3s.sh | sh -s - --mirror
123

注意事项

  1. 默认的配置包含有一些我个人所使用的,如果不需要,可输入 vim ~/.zshrc 编辑配置文件,进行修改删除
  2. 使用脚本安装,可能出现比较诡异的问题,例如插件不生效,而实际有拉取下来,出现此类问题,使用上面的分步安装
0

评论 (0)

取消