diff --git "a/content/posts/\344\270\252\344\272\272\345\220\221Linux\346\226\260\346\234\215\345\212\241\345\231\250\345\210\235\345\247\213\345\214\226\346\270\205\345\215\225.md" "b/content/posts/\344\270\252\344\272\272\345\220\221Linux\346\226\260\346\234\215\345\212\241\345\231\250\345\210\235\345\247\213\345\214\226\346\270\205\345\215\225.md" index f666330..a49631a 100644 --- "a/content/posts/\344\270\252\344\272\272\345\220\221Linux\346\226\260\346\234\215\345\212\241\345\231\250\345\210\235\345\247\213\345\214\226\346\270\205\345\215\225.md" +++ "b/content/posts/\344\270\252\344\272\272\345\220\221Linux\346\226\260\346\234\215\345\212\241\345\231\250\345\210\235\345\247\213\345\214\226\346\270\205\345\215\225.md" @@ -1,25 +1,26 @@ --- title: 个人向 Linux 新服务器初始化清单 date: 2023-03-14 -description: 一份 Linux 初始化清单, 避免每次拿到新的服务器都要一个个去各种地方搜集指令, 以做备忘 & 供有需要的朋友参考. 以目前最新的 Debian 11 Bullseye 为例 +lastmod: 2023-03-15T09:14:44.308Z +description: 一份 Linux 初始化清单, 避免每次拿到新的服务器都要一个个去各种地方搜集指令, 以做备忘 & 供有需要的朋友参考. 以目前最新的 + Debian 11 Bullseye 为例 +draft: false categories: -- 技术 + - 技术 tags: -- 技术 -- Linux -- Debian -- Traefik -- Headless CMS + - 技术 + - Linux + - Debian + - Traefik + - Headless CMS --- - - 一份 Linux 初始化清单, 避免每次拿到新的服务器都要一个个去各种地方搜集指令, 以做备忘 & 供有需要的朋友参考. 服务器发行版我个人推荐 Debian 系列, CentOS 系现在已经开始分裂而且说实话对新手其实并不友好. Debian 是在兼容性, 易用性和稳定性之间都取得不错平衡的发行版. 新手推荐 Ubuntu, 不过最近商业化有点过度, 夹带了越来越多的私活, 我个人所有新安装的 Linux 已经全线转向 Debian. 下文以目前最新的 Debian 11 Bullseye 为例 > azure 干净的 debian 11 镜像, 资源使用情况供参考 -> -> ~1G Disk, ~100M RAM, ~300 packages +> +> \~1G Disk, \~100M RAM, ~300 packages 本文仅列举主要事项和操作, 新手可先行阅读这篇文章熟悉概念. [云服务器入门指南](https://blog.colinx.one/posts/%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%85%A5%E9%97%A8%E6%8C%87%E5%8D%97/) @@ -38,7 +39,6 @@ tags: // 添加到wheel用户组自动获得sudo权限 useradd -m --groups wheel colin - ``` 也可直接编辑`/etc/sudoers` 文件为新用户添加 sudo 权限, 使用 `visudo` 指令可以自动帮你校验, 避免配置写错把系统搞崩 @@ -52,7 +52,6 @@ useradd -m --groups wheel colin 一般情况下,将  `/etc/apt/sources.list`  文件中 Debian 默认的源地址  `http://deb.debian.org/`  替换为  `http://mirrors.ustc.edu.cn`  即可。 ```shell - //for debian sudo sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list @@ -84,7 +83,7 @@ sudo apt install zsh tmux htop duf htop tldr screenfetch tree 注意修改权限, `~/.ssh/authorized_keys` 权限为 600. `~/.ssh/`为 400 -如失败可参考这篇文章 debug. [https://superuser.com/questions/1137438/ssh-key-authentication-fails](https://superuser.com/questions/1137438/ssh-key-authentication-fails) +如失败可参考这篇文章 debug. ### 1.5 设置 hostname @@ -97,7 +96,7 @@ sudo hostnamectl status 修改后需重启 ---- +- - - ### 1.6 SWAP @@ -124,11 +123,8 @@ sudo swapon /swap_space // 使用 s 参数查看列表 sudo swapon -s - ``` - - 每次重启后都要重新挂载磁盘分区。因此为了使之持久化,就像上面一样,我们编辑  `/etc/fstab`  并输入下面行: ``` @@ -137,7 +133,7 @@ sudo swapon -s 保存并退出文件。现在我们的交换分区会一直被挂载了。我们重启后可以在终端运行  `free -m`  来检查交换分区是否生效。 ---- +- - - ### 1.7 绑定域名   @@ -147,6 +143,7 @@ sudo swapon -s 配置文件为本机的 `~/.ssh/config` 格式如下 + ```config Host serverA HostName myserver.domain.xyz @@ -188,7 +185,6 @@ Host serverA ```shell sh -c "$(curl -fsSL [https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh](https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh))" - ``` 安装插件 @@ -202,14 +198,20 @@ git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM: 按需修改配置. 文件位置`~/.zshrc`, 下面为个人常用配置供参考. 注意去源文件修改对应项, 没有再到末尾加 ```shell +# custom theme +ZSH_THEME="af-magic" // 简洁的主题, 一行, 推荐 +ZSH_THEME="gnzh" // 更丰富的主题, 提示信息一行, 输入命令在另一行 + # custom conf override -ZSH_THEME="af-magic" CASE_SENSITIVE="false" HYPHEN_INSENSITIVE="false" plugins=(git z zsh-autosuggestions zsh-syntax-highlighting sudo) - ``` +日常管理服务器比较多,以及经常复制命令的建议用 gnzh 这个主题. + +![](https://user-images.githubusercontent.com/49100982/108254837-882d2a00-716c-11eb-9f49-3b5e6e62eb52.jpg "gnzh theme") + 自定义配置, 添加到末尾 ```shell @@ -222,6 +224,28 @@ export ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20 source ~/.zshrc ``` +```shell +// 自定义需求较高的推荐 space ship 这个主题 + +// 本地安装 nerd font 以正确显示部分图标 + +brew tap homebrew/cask-fonts +brew install --cask font--nerd-font + +// 推荐字体 fira code pro with nerd fonts. 安装完后更改本机终端字体 +brew install --cask font-fira-mono-nerd-font + +// 安装zsh 主题 space-ship + +git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$ZSH_CUSTOM/themes/spaceship-prompt" --depth=1 + +ln -s "$ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" "$ZSH_CUSTOM/themes/spaceship.zsh-theme" +// 之后设置主题 +ZSH_THEME="spaceship" + +// 还有一些自用的推荐配置件文末附录 +``` + ### 2.3 nano 代码文件规则 日常常用文本编辑器为 nano, 轻量级编辑需求完全满足. @@ -286,14 +310,106 @@ traefik 网关作为统一出口, 负责服务发现和自动维护 HTTPS 证书 END ---- +- - - ## 附录 +* Install Docker Engine +* RSSManX 安装部署指南 +* 云服务器入门指南 +* Portainer Install Doc -- Install Docker Engine [https://docs.docker.com/engine/install/](https://docs.docker.com/engine/install/) -- RSSManX 安装部署指南 [https://blog.colinx.one/posts/rssmanx%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2%E6%8C%87%E5%8D%97/](https://blog.colinx.one/posts/rssmanx%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2%E6%8C%87%E5%8D%97/) -- 云服务器入门指南 [https://blog.colinx.one/posts/%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%85%A5%E9%97%A8%E6%8C%87%E5%8D%97/](https://blog.colinx.one/posts/%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%85%A5%E9%97%A8%E6%8C%87%E5%8D%97/) -- Portainer Install Doc [https://docs.portainer.io/start/install-ce/server/docker/linux](https://docs.portainer.io/start/install-ce/server/docker/linux) - +```shell +# 个人自用配置, 搭配 space ship 主题使用, 建议安装 nerd font 以正确显示图标 +# ~/.spaceshiprc.zsh +# space ship 主题文档 +# https://spaceship-prompt.sh/getting-started/ + +SPACESHIP_USER_SHOW="always" +SPACESHIP_USER_PREFIX="" +SPACESHIP_USER_COLOR="007" +SPACESHIP_USER_COLOR_ROOT="red" +SPACESHIP_USER_SUFFIX="" + + +SPACESHIP_HOST_SHOW="always" +#SPACESHIP_HOST_PREFIX="\e[3#1m@" +SPACESHIP_HOST_PREFIX="@" +SPACESHIP_HOST_COLOR="black" +SPACESHIP_HOST_COLOR_SSH="green" + + +SPACESHIP_DIR_TRUNC="0" +SPACESHIP_DIR_TRUNC_PREFIX=".../" + +SPACESHIP_PROMPT_ORDER=( + dir # Current directory section + git # Git section (git_branch + git_status) + hg # Mercurial section (hg_branch + hg_status) + package # Package version + node # Node.js section + bun # Bun section + deno # Deno section + ruby # Ruby section + python # Python section + elm # Elm section + elixir # Elixir section + xcode # Xcode section + swift # Swift section + golang # Go section + perl # Perl section + php # PHP section + rust # Rust section + haskell # Haskell Stack section + scala # Scala section + kotlin # Kotlin section + java # Java section + lua # Lua section + dart # Dart section + julia # Julia section + crystal # Crystal section + docker # Docker section + docker_compose # Docker section + aws # Amazon Web Services section + gcloud # Google Cloud Platform section + azure # Azure section + venv # virtualenv section + conda # conda virtualenv section + dotnet # .NET section + ocaml # OCaml section + vlang # V section + zig # Zig section + purescript # PureScript section + erlang # Erlang section + kubectl # Kubectl context section + ansible # Ansible section + terraform # Terraform workspace section + pulumi # Pulumi stack section + ibmcloud # IBM Cloud section + nix_shell # Nix shell + gnu_screen # GNU Screen section + exec_time # Execution time + async # Async jobs indicator + line_sep # Line break + battery # Battery level and status + jobs # Background jobs indicator + exit_code # Exit code section + sudo # Sudo indicator + char # Prompt character +) + +SPACESHIP_RPROMPT_ORDER=( + time # Time stamps section + user # Username section + host # Hostname section +) + + +cdl() { + cd "$@" && ls; +} +cdll() { + cd "$@" && ls -lh; +} +``` \ No newline at end of file