#! https://zhuanlan.zhihu.com/p/672920221
本指南用于记录一个云服务器实例从购买到完成配置本人需要的一些服务的全过程,以供今后购买新的云服务器实例需要进行配置时参考。
- 目前使用的云服务器为腾讯云的轻量应用服务器,首先在腾讯云的在控制台中创建SSH密钥
- 将实例关闭之后,将密钥绑定至实例
-
配置本机
~/.ssh/config文件 -
登录服务器,修改ssh相关配置(如关闭密码登录:将
PasswordAuthentication修改为no)
sudo vim /etc/ssh/sshd_config下载zsh
sudo apt install zsh切换到root用户下修改ubuntu用户的密码
passwd ubuntu修改默认终端为zsh(不用加sudo,因为需要修改的是当前用户的默认终端,需要输入当前用户的密码)
chsh -s /bin/zsh安装并配置oh-my-zsh
安装clash(dddd)
-
解压
clash -
将解压出的文件重命名成
clash -
将
clash移动到/usr/bin/目录下 -
赋予
clash可执行权限sudo chmod +x /usr/bin/clash
-
默认配置目录是
$HOME/.config/clash, 默认配置目录启动clash
有几率遇到
Country.mmdb下载不了的情况,需手动上传Country.mmdb文件 -
配置
$HOME/.config/clash/config.yaml文件 -
配置
systemd服务(/lib/systemd/system/clash.service)
[Unit]
Description=clash service
After=network.target
[Service]
Type=simple
User=ubuntu
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_BIND_SERVICE
ExecStart=/usr/bin/clash
Restart=always
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl start clash
sudo systemctl enable clash安装git
sudo apt update
sudo apt install git为git配置代理,新建~/.gitconfig文件,添加以下内容,在国内这一步是必须的,如果不配置,后面安装oh-my-zsh时会遇到git clone失败的情况。
[http]
proxy = http://127.0.0.1:7890
[https]
proxy = http://127.0.0.1:7890在~/.zshrc中添加以下内容,为zsh配置代理
# proxy settings
alias setproxy="export http_proxy=http://127.0.0.1:7890; export https_proxy=http://127.0.0.1:7890; echo 'Set Proxy Successfully!'"
alias unsetproxy="unset http_proxy; unset https_proxy; echo 'Unset Proxy Successfully!'"打开终端代理
setproxy安装oh-my-zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"- 配置
oh-my-zsh的插件 - 安装
zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions- 安装
zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting- 修改
~/.zshrc中的plugins选项
plugins=(git zsh-autosuggestions zsh-syntax-highlighting z sudo)source ~/.zshrcsudo mkdir /usr/share/fonts/truetype/meslolgs
sudo mv MesloLGS* /usr/share/fonts/truetype/meslolgs/
sudo apt install fontconfig
sudo fc-cache -f -v- 安装
powerlevel10k
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k- Set
ZSH_THEME="powerlevel10k/powerlevel10k"in~/.zshrc.
source ~/.zshrc- 按照提示完成配置,效果如下:
配置frp内网穿透工具
- 配置
frps.ini文件
[common]
bind_port = 7000 # 用于frp服务端与客户端通信的端口
vhost_http_port = 8889 # web服务端口,我主要用来远程连接jupyter notebook- 配置
systemd服务frps.service(/lib/systemd/system/frps.service)
[Unit]
Description=Frp Server Service
After=network.target
[Service]
Type=simple
User=ubuntu # 用户名记得修改
Restart=on-failure
RestartSec=5s
ExecStart=/home/ubuntu/frp/frps -c /home/ubuntu/frp/frps.ini # frps执行文件和配置文件
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target- 配置
frpc.ini文件,当使用一台云服务器穿透多台内网机器时,需要在frpc.ini文件中添加多个[xxx]配置,其中每台内网服务器的[xxx]是唯一的,如[ssh1]、[ssh2]等,用于区分不同的内网机器。
[common]
server_addr = xxx.xxx.xxx.xxx # 公网服务器ip
server_port = 7000
[ssh1]
type = tcp
local_ip = 127.0.0.1
local_port = 22 # 要映射的ssh端口, 需提前在服务器控制台防火墙放行
remote_port = 6000 # 映射到公网服务器的端口
[jupyter]
type = http
local_port = 8889 #要映射的jupyter端口, 需提前在服务器控制台防火墙放行
custom_domains = xxx.xxx.xxx.xxx # 公网服务器ip- 配置
systemd服务frpc.service(/lib/systemd/system/frpc.service)
[Unit]
Description=Frp Client Service
After=network.target
[Service]
Type=simple
User=nobody # 用户名记得修改
Restart=on-failure
RestartSec=5s
ExecStart=/home/ubuntu/frp/frpc -c /home/ubuntu/frp/frpc.ini # frpc执行文件和配置文件
ExecReload=/home/ubuntu/frp/frpc reload -c /home/ubuntu/frp/frpc.ini # frpc执行文件和配置文件
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target先启动frps,再启动frpc
sudo systemctl daemon-reload
sudo systemctl start frps
sudo systemctl enable frpssudo systemctl daemon-reload
sudo systemctl start frpc
sudo systemctl enable frpc修改~/.ssh/config中内网服务器登录端口号为bind_port,整个配置过程完成。
TODO,后面有空折腾再继续更新。




