6

linux系列之ubuntu新装后高效环境配置处理

 1 year ago
source link: https://ttzz.eu.org/posts/2023-05-31-linux-ubuntu-setting/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

更换 Ubuntu 下载源

将 Ubuntu 的软件下像源换为国内的载镜源。

桌面版直接在【软件和更新】里 ubuntu 软件,下载自 改为其他国内镜像站,默认的中国下载区有时也很慢。

https://s3.bmp.ovh/imgs/2023/06/01/6e266e9e9e15cbe2.png

安装终端 Terminator

安装 sudo apt-get install terminator

首选项设置一下,透明度,选中复制,中键粘贴。

设置为默认终端,ctrl+alt+T 可唤起,以下是一种配置方式。

gsettings set org.gnome.desktop.default-applications.terminal exec /usr/bin/terminator
gsettings set org.gnome.desktop.default-applications.terminal exec-arg "-x"

换回原默认设置

gsettings reset org.gnome.desktop.default-applications.terminal exec
gsettings reset org.gnome.desktop.default-applications.terminal exec-arg

安装 zsh

zsh 是一款功能强大的 shell。

查看是否已安装: cat /etc/shells

下载安装 zsh: sudo apt install zsh

切换默认 shell 为 zsh,切换后记得重启终端:

chsh -s /bin/zsh

查看 shell 是否为 zsh:

# 查看当前shell
echo $SHELL

# 输出为:/usr/bin/zsh   

配置 oh my zsh

安装 ohmyzsh

  • 从 github 仓库里进行安装:
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  • 从清华大学镜像站安装:

github 国内太慢或无法访问的话,可以使用镜像站 - 清华大学开源软件镜像站: ohmyzsh Git 镜像使用帮助

  1. 安装 在本地克隆后获取安装脚本。
git clone https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git
cd ohmyzsh/tools
REMOTE=https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git sh install.sh
  1. 切换已有 ohmyzsh 至镜像源
git -C $ZSH remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git
git -C $ZSH pull

配置主题和插件

Oh-My-Zsh 默认安装了很多主题,位于目录.oh-my-zsh/themes 下。 通过 zsh 配置文件 ~/.zshrc 中的主题设置为自己喜欢的主题名字即可:

#修改选择主题的名称,如果要随机则填random,每次打开都随机应用一个主题。
ZSH_THEME="robbyrussell"

#ZSH_THEME="random"  随机

推荐插件:

  1. zsh-autosuggestions

命令自动补全插件,当你输入命令的几个字母,它会自动根据历史输入进行自动补全,然后按

git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

一款自动提示插件,功能非常强大

wget http://mimosa-pudica.net/src/incr-0.2.zsh
mkdir ~/.oh-my-zsh/plugins/incr 
mv incr-0.2.zsh ~/.oh-my-zsh/plugins/incr 
echo 'source ~/.oh-my-zsh/plugins/incr/incr*.zsh' >> ~/.zshrc 
source ~/.zshrc

注意:因为新版本的问题,需要进到目录.oh-my-zsh/plugins/incr/incr-0.2.zsh 更名为 incr.plugin.zsh 不然会提示 plugin 'incr' not found

  1. zsh-syntax-highlighting

自动命名高亮显示。

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

自动统计我们经常 cd 的目录,不同目录会有不同的权重。在我们想要进入某个目录时,使用 j <dir-name> 即可以帮助我们快速跳转到目标目录。

sudo apt-get install autojump
  1. extract

对于不同类型的压缩格式:.tar、.tar.gz、.tar.bz2、.tar.xz、.rar、.zip,解压时一律使用 x <archived file>。默认 ohmyzsh 里已经安装,启用即可。

  • 选择启用插件

在这配置文件 ~/.zshrc 修改,添加要使用的插件:

plugins=(
    zsh-syntax-highlighting
    zsh-autosuggestions
    incr
    git
    autojump
    extract
)

安装 curl

无法识别的 curl 命令的话是没安装 curl

安装命令:

sudo apt install curl 

开启 ssh

ssh 默认端口 22

sudo apt update
sudo apt install openssh-server

防火墙放开

sudo ufw allow ssh

安装 v2rayA

开源的代理工具,可以实现全局透明代理,这里用 docker 安装

# run v2raya 
docker run -d \ 
  --restart=always \ 
  --privileged \ 
  --network=host \ 
  --name v2raya \ 
  -e V2RAYA_LOG_FILE=/tmp/v2raya.log \ 
  -v /lib/modules:/lib/modules:ro \ 
  -v /etc/resolv.conf:/etc/resolv.conf \ 
  -v /etc/v2raya:/etc/v2raya \ 
  mzz2017/v2raya

详细介绍:https://v2raya.org/docs/prologue/installation/docker/#% E8% BF%90% E8% A1%8C

安装 docker 和修改 docker 下载源

一键安装 docker

2017 年后 docker 分为了 docker-CE(社区版)和 docker-EE(商业版) ,这里都是以 CE 版演示。

懒人一键安装版,直接执行官方的一键安装脚本,脚本会自动区分操作系统,安装的是体验版而不是稳定版,最好不要用于生产环境。脚本官方 github 地址

 sudo wget -qO- https://get.docker.com/ | bash

 # 如果上面的不行,执行下面两句
 curl -fsSL https://get.docker.com -o get-docker.sh
 sudo sh get-docker.sh

 # 安装成功执行下面语句,如果有类似回显,说明安装成功
 docker --version
Docker version 18.06.1-ce, build e68fc7a

Ubuntu 安装 dokcer

CE 支持 x86_64, armhf, s390x (IBM Z), and ppc64le (IBM Power) 架构的 Ubuntu

  1. 卸载旧版本

旧版本叫 docker 或 docker-engine,如有安装,先卸载它及其依赖,新版本叫 docker-ce

/var/lib/docker/ 目录下的镜像文件,容器,卷和网络将会被保留,不会被删除。

 sudo apt-get remove docker docker-engine docker.io containerd runc
  1. 添加源进行安装

首先安装 docker 的仓库,你可以从这个仓库中安装或者升级 docker。

升级 apt 包索引

$ sudo apt-get update

安装能够让 apt 使用 HTTPS 的包

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

添加官方的 GPG key

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

查看现在是否拥有了指纹 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 的密匙,执行下面搜索命令,如果有类似回显说明拥有此密匙。

$ sudo apt-key fingerprint 0EBFCD88
pub   4096R/0EBFCD88 2017-02-22
      Key fingerprint = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid                  Docker Release (CE deb) <[email protected]>
sub   4096R/F273FCD8 2017-02-22

设置稳定版源 必须安装稳定版源,即使安装体验版或者测试版也需要稳定版源,不同架构的机器需要不同安装命令,lsb_release -cs 命令会返回是哪种 Debian 发行版,比如 xenial,如果想安装体验版(edge)或者测试版(test),将命令中的 stable 换成相应的字符串即可。

$ # x86_64 / amd64架构
$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"


$ # armhf架构
$ sudo add-apt-repository \
   "deb [arch=armhf] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"


$ #  arm64架构
$ sudo add-apt-repository \
   "deb [arch=arm64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"


$ #  IBM Power (ppc64le)
$ sudo add-apt-repository \
   "deb [arch=ppc64el] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"


$ #  IBM Z (s390x)
$ sudo add-apt-repository \
   "deb [arch=s390x] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

注意:从 docker17.06 开始,稳定版也同样会被推送到体验版和测试版的仓库里

  • 安装 docker CE

升级 apt 包索引

$ sudo apt-get update

安装最新版本的 docker CE

$ sudo apt-get install docker-ce

注意:如果安装了多个 docker 仓库,使用 apt-get install 或者 apt-get update 命令时后面不跟版本信息的话,将始终安装最高版本的 docker!

安装指定版本的 docker CE 列出版本,版本号从高到低

$ apt-cache madison docker-ce
docker-ce | 18.09.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages

安装指定版本的 docker CE,需要指定完整的包名称,例如安装仓库中的这个版本 18.09.0~ce-0~ubuntu ,其命令为

$ sudo apt-get install docker-ce=18.03.0~ce-0~ubuntu

其他版本同理 docker deamon,即 docker 守护进程 /docker 引擎,在安装完成后会自动启动 如果需要升级的话,首先执行 sudo apt-get update,再重复上面的过程即可。

引用:https://zhuanlan.zhihu.com/p/54147784

修改 docker 下载源

打开 daemon.json 文件,若不存在则新增:

sudo vi /etc/docker/daemon.json

添加以下下载源:

{
  "registry-mirrors":
    [
      "http://hub-mirror.c.163.com",
    "https://docker.mirrors.ustc.edu.cn",
    "https://mirror.baidubce.com",
    "https://ljqvceaj.mirror.aliyuncs.com"
    ]
}

添加用户 docker 权限

将 docker 权限添加到当前用户,免去每次都输 sudo 命令。

  1. 创建 docker 组:sudo groupadd docker
  2. 将用户添加到 docker 组:sudo gpasswd -a ${USER} docker
  3. 重启 docker 服务:sudo systemctl restart docker

安装 docker compose

sudo apt install docker-compose

查看安装是否成功

docker-compose -v

输出版本信息说明安装成功。

解决无法访问 github

github 直接无法访问,我这里 ping 直接显示 github.com 为 127.0.0.1

  1. 使用 http://ghproxy.com

在 github 地址前直接添加这个代理地址,比如:

git clone https://ghproxy.com/https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
  1. 修改本地 hosts 方式

hosts 文件位于 etc 路径下,超级管理员修改。

vi etc/hosts

# 添加下面一行

20.205.243.166 github.com

你可以用站长工具,查询你所在位置 github.com 的 dns 解析,以上就是我所查询的地址。

共享宿主机文件夹

如果是在 vmware 虚拟机里安装的 ubuntu,开启共享宿主机文件夹。

右键虚拟机,设置,硬件 | 选项(点击选项),共享文件夹,总是启用,添加共享的文件夹。 https://s3.bmp.ovh/imgs/2023/06/06/67aec90dad58349c.png

https://s3.bmp.ovh/imgs/2023/06/06/eb0823c06f459670.png

关注一下有惊喜
wxqr.png 公众号
赞赏支持
wechatpay.png 微信打赏 alipay.png 支付宝打赏

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK