Open hhstore opened 6 years ago
主机
, 安装必备软件: zsh, git, curl, wget, docker
等.平台控制台
, 放开对外端口: 80, 8080, 7000, 9000
, 等开发/测试端口.
华为云
, 控制台, 网络设置, 单独配置Azure
, 也需要单独配置.域名
, 解析到云主机 IP
.
二级域名
.配置 VPS 教程:
阿里云
镜像源.
sudo bash -c "cat << EOF > /etc/apt/sources.list && apt update
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
EOF"
下载包:
echo -e "export http_proxy=http://127.0.0.1:7890\nexport https_proxy=http://127.0.0.1:7890" >> ~/.bashrc
echo -e "export http_proxy=http://127.0.0.1:7890\nexport https_proxy=http://127.0.0.1:7890" >> ~/.zshrc
git
zsh
root 用户:
apt update -y
apt install curl -y
apt install git -y
apt install zsh -y
apt install vim -y
apt install tmux -y
# ssh 登录保护:
apt install fail2ban -y
# Python 包安装: for docker-compose
apt install python3-pip -y
sudo apt update -y
sudo apt install curl -y
sudo apt install git -y
sudo apt install zsh -y
sudo apt install vim -y
sudo apt install tmux -y
# set zsh:
sudo chsh -s $(which zsh)
# 参数说明:
# -m 创建用户的主目录,如 /home/xxx
# -g 指定用户所属的群组
# -G 指定用户所属的附加群组,将新用户加入 sudo 群组中,以获得 root 权限
# -s 指定用户登入后所使用的shell。注意使用 /bin/bash 之类的路径,而非 /usr/bin/bash
useradd -m -g users -G sudo -s /bin/zsh dev
# 设置密码:
passwd dev
配置 dev 用户(多用户, 可以不用配置 root 用户)
切换到 dev 用户操作:
su - dev
q: 先不定制zsh(未装oh-my-zsh)
cd ~
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
wget https://raw.githubusercontent.com/skylerlee/zeta-zsh-theme/master/zeta.zsh-theme
# cp zeta.zsh-theme ~/.oh-my-zsh/themes
ZSH_THEME="zeta"
ZSH_THEME="candy"
exit
非 server 版本 Ubuntu, 需要安装:
sudo apt install openssh-server -y
特别提醒:
多开
几个 VPS 连接窗口.重启
服务之后, 导致无法访问服务器.✅ 基于
密码
的方式登录 VPS 主机:
ssh root@22.33.22.33 -p 22
# 交互式输入密码
cd ~
mkdir .ssh
ssh-keygen
cd .ssh/
cat id_rsa.pub >> authorized_keys
chmod 600 authorized_keys
chmod 700 ~/.ssh
更改配置:
vim /etc/ssh/sshd_config
# update:
RSAAuthentication yes
PubkeyAuthentication yes
PermitRootLogin yes
# set ok, then add this:
PasswordAuthentication no
/etc/ssh/sshd_config.d
目录, 是否存在其他配置文件, 如无用, 可删除.
# 检测配置文件是否异常
sshd -t
# 重启
service sshd restart
VPS 生成的 ssh key 的
私钥,
复制到
本地路径:
~/.ssh/vps/xxx-key`.末尾
, 追加一个换行符
! 否则报错: 格式不对.
chmod 600 xxx
改一下访问权限.
# 放入本地路径: 追加一个 `换行符`
~/.ssh/vps/id_rsa.crypto
# 修正权限:
chmod 600 ~/.ssh/vps/id_rsa.crypto
ssh key
远程访问 VPS 主机:
# 示例方式:
ssh root@22.33.22.33 -p 22 -i ~/.ssh/vps/id_rsa.crypto
/etc/ssh/sshd_config
# 设置登录成功, 再改此:
PasswordAuthentication no
service sshd restart
ssh root@22.33.22.33 -p 22
默认端口
, 防止被爬虫乱扫.~/.ssh/config
文件, 增加配置项
Host vps.hw # 别名
HostName xx.xxx.xx.xxx # 替换 xx.xxx.xx.xxx 为服务器 ip 地址
Port 22 # 端口,稍后会进行修改
User xxx # 用户名
IdentityFile ~/.ssh/vps/key.hw # 私钥文件
# 命令行直接通过如下参数, 自动连接.
ssh vps.hy
<img width="500" alt="image" src="https://github.com/hhstore/blog/assets/3252130/6a9fc6f5-3afb-425c-9dd9-e74076434aee">
/etc/ssh/sshd_config
文件,找到下面2个参数:
ClientAliveInterval 60
ClientAliveCountMax 3
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
#
# change:
# - https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg
#
sudo curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
sudo docker run hello-world
run Docker as a non-privileged user:
dockerd-rootless-setuptool.sh install
# 开机启动
sudo systemctl enable docker
sudo systemctl start docker
sudo systemctl status docker
# 1. 创建 docker 用户组
sudo groupadd docker
# 2. 添加用户到 docker 用户组:
sudo usermod -aG docker $USER
# 3. 重启
sudo service docker restart
# 4. exit, 需要退出当前终端, 重新登入, 才能生效.
exit
验证 docker 配置成功:
docker run hello-world
# 方法1:
apt install python3-pip -y
pip3 install docker-compose
# 方法2:
curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
pip3 install docker-compose
{
"log-driver": "json-file",
"log-opts": { "max-size": "50m", "max-file": "3" }
}
{
"log-driver": "local",
"log-opts": {
"max-size": "50m"
}
}
sudo service docker restart
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<EOF
{
"registry-mirrors": [
"https://hub.uuuadc.top",
"https://docker.anyhub.us.kg",
"https://dockerhub.jobcher.com",
"https://dockerhub.icu",
"https://docker.ckyl.me",
"https://docker.awsl9527.cn"
]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<EOF
{
"registry-mirrors": [
"https://docker.m.daocloud.io",
"https://hub.uuuadc.top",
"https://docker.anyhub.us.kg",
"https://dockerhub.jobcher.com",
"https://dockerhub.icu",
"https://docker.ckyl.me",
"https://docker.awsl9527.cn"
]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
# 自动走镜像源:
docker pull redis
docker run hello-world
git config --global user.name "crypto"
git config --global user.email crypto@gmail.com
git config --global core.editor vim
防止 SSH 登录扫描:
apt install fail2ban -y
开启 BBR,root 账户执行
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
内核信息查看:
hostnamectl
uname -a
cat /proc/version
查看磁盘空间:
df -Th
df -hl
df -h
查看内存:
# 单位 MB
free -m
cat /proc/meminfo
查看最大文件描述符:
cat /proc/sys/fs/file-max
9223372036854775807
ulimit -n
1024
# vim /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
📖 Abstract:
💯 Related: