花里胡哨的CentOS

花里胡哨的CentOS

文章基于如下环境:

WSL2下的CentOS7:下载地址为:CentOS7

在WSL2下安装CentOS7

  1. 首先启用win10或者win11的wsl2功能(这里不过多介绍,不会的自行问度娘)

  2. 把下载好的CentOS7.zip解压到E盘根目录(其他目录下也可以)

  3. 进入取步骤2的解压目录E:\CentOS\CentOS7下;双击CentOS7.exe;等待安装完成,如图所示:

    image-20220114110431152

  4. 按任意键完成安装;此时打倒CMD命令行,执行命令"wsl -l"即可查看到安装好的CentOS7

CentOS配置阿里源与更新

  1. 在CentOS中执行以下命令查看源列表:

    yum repolist

  2. 执行命令备份源

    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

  3. 替换为阿里源

    curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

    或者

    curl http://mirrors.aliyun.com/repo/Centos-7.repo > /etc/yum.repos.d/CentOS-Base.repo

  4. 重建缓存

    yum makecache

  5. 安装epel模块(第三方仓库)

    yum install epel-release -y

    安装完成后查看版本:

    yum list | grep epel-release

  6. 升级所有包同时也升级软件和系统内核

    yum -y update

    备注:如果是命令 yum -y upgrade ;则为只升级所有包,不升级软件和系统内核

  7. 查看版本

    cat /etc/redhat-release

  8. 查看内核

    uname -r

CentOS美化

为了让我们的命令行窗口看起来酷炫一点,也为了让我们枯燥的编码日常更有(装)趣(逼)一些,我们有必要对CentOS做一些美化,主要安装以下美化包:

安装figlet或者banner

  • 安装figlet命令:yum -y install figlet

    验证安装成功:figlet welcome

  • 安装banner命令:yum -y install banner

    验证安装成功:banner welcome

二选一即可;优先figlet;因为figlet效果比较好。

安装cowsay

  • 安装命令:yum -y install cowsay
  • 验证安装成功:cowsay -f stegosaurus welcome

安装fortune

  • 安装命令:yum -y install fortune-mod.x86_64

  • 验证安装成功:fortune

  • 这个包是用于展示格言的,但默认都是英文的格言,而我们需要中文格言与诗句。因此需要手动下载 中文库

    1. 执行以下命令进行下载:

      curl https://github.com/ruanyf/fortunes/archive/refs/heads/master.zip > /usr/share/games/fortunes-master.zip

    2. 进入下载目录:cd /usr/share/games

    3. 解压文件:unzip fortunes-master.zip

    4. 清空原目录:rm -rf /usr/share/games/fortune

    5. 重新创建文件夹:mkdir /usr/share/games/fortune

    6. 复制中文库到指定位置:cp /usr/share/games/fortunes-master/data/* /usr/share/games/fortune/

    7. 重新生成索引文件:

      strfile /usr/share/games/fortune/diet strfile /usr/share/games/fortune/chinese strfile /usr/share/games/fortune/song100 strfile /usr/share/games/fortune/tang300

    8. 验证结果:fortune

    9. 命令显示的格言是随机的,但是分布比例与格言包的容量一致。如果希望四个包平均显示,即每个包都有25%的显示机会,需要使用下面的命令格式:

      fortune -e diet chinese tang300 song100

      或者

      fortune 25% diet 25% chinese 25% tang300 25% song100

安装lolcat

由于 Lolcat 是一个 ruby gem 程序,所以在你的系统中必须安装有最新版本的 RUBY;

  • 安装Ruby命令:yum -y install ruby
  • 验证安装成功:ruby --version
  • 查看ruby现有源:gem sources -l
  • 删除现在源:gem source -r https://rubygems.org/
  • 添加新源:gem sources -a https://gems.ruby-china.com/
  • 删除源和添加源可以合为一个命令:gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
  • 升级RubyGems:gem update --system 升级完成后,可再次查看版本:ruby --version

完成上述步骤后,即可开始安装lolcat

  • 从Git分为下载:wget https://github.com/busyloop/lolcat/archive/master.zip
  • 解压源码包:unzip master.zip
  • 进入bin目录中:cd lolcat-master/bin
  • 执行安装命令:gem install lolcat
  • 验证安装成功:lolcat --version 或者 ls -lh | lolcat

其他(可根据需要选择性安装)

  • 安装命令:yum -y install sl

    验证安装成功(跑火车):sl

  • htop 是 Linux 操作系统的图形化性能检测工具,如果类比的话相当于 Windows 操作系统的任务管理器

    安装命令:yum -y install htop

    验证安装成功:htop

  • Linux下 cmatrix的安装和使用(黑客屏保)

    • 安装ncurses支持包:yum -y install ncurses*

    • 下载屏保软件源码包:wget https://jaist.dl.sourceforge.net/project/cmatrix/cmatrix/1.2a/cmatrix-1.2a.tar.gz

    • 解压缩源码包:tar -zxvf cmatrix-1.2a.tar.gz

    • 进入源码包目录:cd cmatrix-1.2a/

    • 释放编译文件:./configure --prefix=/opt/cmatrix/

    • 编译且安装:make && make install

    • 进入安装屏保软件的目录,执行屏保命令:

      cd /opt/cmatrix/

      ./bin/cmatrix

    • 常用命令参数:

      cmatrix [-abBflohnsVx] [-C color]
      选项
      -a :异步滚动(默认)
      -b :随机粗体
      -B :全部粗体
      -f :force the linux $TERM type to be on #求大神解释
      -l :Linux mode (sets "matrix.fnt" font in console) #求大神解释
      -o :使用旧风格滚动(不好看)
      -h :获得帮助信息
      -n :不使用粗体(默认)
      -s :"Screensaver" mode,exits on first keystroke #求大神解释
      -x :X window 模式,好像就是显示的符号不一样
      -V :显示版本信息
      -u :刷新频率,0-9,也就是滚动的快慢
      -C :显示的颜色,支持green(默认),red,blue,white,yellow,cyan,magenta and black

  • 追逐鼠标的小猫oneko :yum -y install oneko

完成以上这些安装后,就可以进行如下骚操作了:

cool登录欢迎语

实现每次打开CentOS会话窗口就出现提示的办法方法:在/etc/profile.d文件夹下新建一个.sh文件;然后将代码写入到.sh文件中。步骤如下:

  • 在/etc/profile.d文件夹下新建welcome.sh;命令为:vim /etc/profile.d/welcome.sh

  • 把以下内容粘贴到welcome.sh文件中:

    figlet welcome fortune | cowsay -n -f stegosaurus | lolcat

  • 保存退出

  • 重新打开窗口即可看到如下效果:image-20220114162256593

安装powerlevel10k主题

为了让我们的命令行更酷炫一些,需要再安装个命令行主题包:powerlevel10k;这个主题包需要oh-my-zsh和zsh还有一些字体作为依赖。安装过程还需要用到git。具体安装步骤如下:

  • 安装Nerd字体,并设置使用的字体

    • 字体官网下载地址:https://www.nerdfonts.com/font-downloads 我用的是Cousine Nerd Font字体; 下载后解压,然后选中所有字体,右键”安装“即可;如图:

      image-20220118172700045

    • window-terminal中设置字体(如果不提前设置好字体,主题安装成功后会乱码):

      image-20220118172938604

  • 安装git

    yum install git -y

  • 安装zsh;因为powerlevel10k需要zsh 5.1以上;而使用命令 yum install zsh安装的是5.0.2版本的,不符合要求,因此需要手动下载安装包进行安装。命令如下:

    • curl http://mirror.ghettoforge.org/distributions/gf/el/7/plus/x86_64/zsh-5.1-1.gf.el7.x86_64.rpm > /root/zsh.rpm
    • 执行安装:rpm -ivh /root/zsh.rpm
    • 查看版本:echo $ZSH_VERSION
    • 删除安装包:rm -f /root/zsh.rpm
  • 安装oh-my-zsh;这里使用 gitee镜像源

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

  • 安装 zsh 插件(补全提示和高亮插件)

    • 补全提示插件

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

    • 高亮插件

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

  • 安装powerlevel10k;使用gitee镜像

    git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

  • 配置zsh主题为powerlevel10k和配置zsh插件

    • 修改 ~/.zshrc;修改内容:ZSH_THEME="powerlevel10k/powerlevel10k" ;plugins=(git zsh-autosuggestions zsh-syntax-highlighting pip)

      vim ~/.zshrc

    • 使之生效;执行以下命令,使之生效;之后进入配置向导,根据喜好选择配置

      source ~/.zshrc

      执行命令后出现如下配置界面:

      image-20220118191934450

    • 配置完成后的效果

      image-20220118202957335

posted @ 2022-01-15 19:07  yuque  阅读(171)  评论(0)    收藏  举报