分享下自己的服务器 setup 吧

拿到一台新服务器,你们会有哪些 setups 呢?

分享下自己的一些基础工具,便于运维,以 Debian 为例。

修改 hostname

hostnamectl set-hostname 新的主机名

vi /etc/hosts, 将 127.0.1.1 旧主机名改为 127.0.1.1 新主机名。

添加 ssh public keys

ssh-copy-id -i ~/.ssh/id_rsa.pub user@remote_server
# 或者在服务器上
echo "public key" >> ~/.ssh/authorized_keys

别忘记检查下 /etc/ssh/sshd_config 这一行 PubkeyAuthentication yes
如果希望直接 root 登录,别忘记 PermitRootLogin prohibit-password 这一个。

最后重启 sshd systemctl restart sshd

安装 zsh + oh-my-zsh

apt update
apt upgrade
apt install -y zsh
apt install -y curl
apt install -y git
apt install -y vim
apt install -y fzf
chsh -s $(which zsh)
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions

配置 .zshrc

export ZSH="$HOME/.oh-my-zsh"
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="dst"
plugins=(git z zsh-autosuggestions fzf)
source $ZSH/oh-my-zsh.sh
export LANG=en_US.UTF-8
export LANGUAGE="en_US"
export LC_ALL=en_US.UTF-8
export LS_OPTIONS='--color=auto'
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='nvim'
# fi
alias vi="vim"

别忘记 source ~/.zshrc

配置 .vimrc

set encoding=utf-8
set fileencoding=utf-8
set termencoding=utf-8
set number 
set cursorline
set autoindent
set smartindent 
set tabstop=2
set shiftwidth=2
set expandtab
set ignorecase
set smartcase
set hlsearch
set incsearch
syntax on
set background=dark
colorscheme elflord
set timeoutlen=500
set updatetime=300

额外工具推荐

  1. btop, 资源监控工具
  2. vnstat, 网络流量监控
  3. nezha,探针
  4. duf, df 的替代
  5. yazi, 终端文件管理器
  6. tmux, 终端复用,替代 screen

配置 .tmux.conf

unbind C-b
set -g prefix C-a
bind C-a send-prefix

set-option -g status-bg colour9
set-option -g status-fg colour46

bind-key -n M-Up select-pane -U
bind-key -n M-Down select-pane -D
bind-key -n M-Left select-pane -L
bind-key -n M-Right select-pane -R

set -g status-left-length 30
set -g status-right-length 30

set -g pane-border-style fg=brightblack
set -g pane-active-border-style fg=brightgreen

bind -r < resize-pane -L 2
bind -r > resize-pane -R 2
bind -r + resize-pane -U 1
bind -r - resize-pane -D 1

bind | split-window -h
bind - split-window -v
unbind '"'
unbind %

setw -g mode-keys vi
bind -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -selection clipboard -i"

set -g history-limit 10000

仅仅是抛砖引玉,希望各位大佬分享下平时运维服务器有哪些好用工具。

13 个赞

赞,学习了 :smile:

装docker、docker-compose

防火墙和fail2ban

卸载wget,装 iputils-ping :tieba_003:

1 个赞

安装 docker: curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh, 另外,现在 docker-compose 直接被 docker 集成了吧,直接使用 docker compose

2 个赞

安装配置nftables 修改默认ssh端口 :face_with_peeking_eye:

# 添加用户
sudo useradd -m -s /bin/bash ${user}
echo "${user}:${passwd}" | sudo chpasswd

sudo usermod -aG sudo ${user}
#sudo usermod -aG docker ${user}

sudo -u ${user} bash -c "mkdir -p ~/.ssh && echo 'ssh-rsa xxxxx' >> ~/.ssh/authorized_keys"

# nopasswd

echo "${user} ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/${user}

等佬们分享完了 我给写个shell脚本

感谢分享……

第一个装 tmux 的平替 byobu

太强了!

感谢楼主分享

感谢分享

感谢分享

install debian , 安装探针, 吃灰 , game over

基础设置都固化成ansible脚本了。重装的时候直接跑一遍脚本

此话题已在最后回复的 30 天后被自动关闭。不再允许新回复。