debian12 虚拟机安装 + 博客相册恢复

debian12 虚拟机安装 + 博客相册恢复

sound_kanade Lv1

1. 博客相册挂了

原来的虚拟机寄了,博客相册跑在上面,跟着寄了,重新整一个

2. 镜像下载

https://cdimage.debian.org/debian-cd/current/amd64/iso-dvd/

3. 创建虚拟机


|550












4. debian12 系统安装































5. 连接 debian 虚拟机


ip地址

修改配置

1
2
su root
nano /etc/ssh/sshd_conf

允许 root 登录

1
PermitRootLogin yes

使修改生效

1
systemctl restart sshd


登录测试

6. 修改密码

1
passwd

7. 时区

1
2
3
4
5
# 检查时区
timedatectl status

# 设置时区
sudo timedatectl set-timezone Asia/Shanghai

|500

8. 常用 apt、zsh 配置

修改 apt 源
https://gist.github.com/hakerdefo/5e1f51fa93ff37871b9ff738b05ba30f

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cat > /etc/apt/sources.list << EOF
deb https://ftp.debian.org/debian/ bookworm contrib main non-free non-free-firmware
# deb-src https://ftp.debian.org/debian/ bookworm contrib main non-free non-free-firmware

deb https://ftp.debian.org/debian/ bookworm-updates contrib main non-free non-free-firmware
# deb-src https://ftp.debian.org/debian/ bookworm-updates contrib main non-free non-free-firmware

deb https://ftp.debian.org/debian/ bookworm-proposed-updates contrib main non-free non-free-firmware
# deb-src https://ftp.debian.org/debian/ bookworm-proposed-updates contrib main non-free non-free-firmware

deb https://ftp.debian.org/debian/ bookworm-backports contrib main non-free non-free-firmware
# deb-src https://ftp.debian.org/debian/ bookworm-backports contrib main non-free non-free-firmware

deb https://security.debian.org/debian-security/ bookworm-security contrib main non-free non-free-firmware
# deb-src https://security.debian.org/debian-security/ bookworm-security contrib main non-free non-free-firmware
EOF

或者使用清华源
https://mirrors.tuna.tsinghua.edu.cn/help/debian/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cat > /etc/apt/sources.list << EOF
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
# deb-src https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
EOF

更新
注:如果网络无法连到 debian 镜像源,导致 apt 更新慢,可以使用代理访问;操作参考 http://blog.megumiai.com/2024/10/21/deploy/服务器代理方法/#2-1-全局环境变量

1
2
3
4
5
6
7
8
9
10
11
12
13
export ALL_PROXY="http://localhost:7890"
export HTTP_PROXY="http://localhost:7890"
export HTTPS_PROXY="http://localhost:7890"
export FTP_PROXY="http://localhost:7890"
export SOCKS_PROXY="http://localhost:7890"
export all_proxy="http://localhost:7890"
export http_proxy="http://localhost:7890"
export https_proxy="http://localhost:7890"
export ftp_proxy="http://localhost:7890"
export socks_proxy="http://localhost:7890"

apt update
apt upgrade -y

安装软件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
apt install curl vim wget zsh git net-tools tree btop \
gnupg dpkg apt-transport-https lsb-release ca-certificates neovim ufw lrzsz zip -y

# 使用 zsh
chsh -s /bin/zsh

# 安装 oh-my-zsh
sh -c "$(curl -fsSL https://install.ohmyz.sh/)"

# 安装 powerlevel10k 主题
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

# 安装 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
plugins=(git zsh-syntax-highlighting extract z)
ZSH_THEME="powerlevel10k/powerlevel10k"
source ~/.zshrc

# 其他配置
# ~/.zshrc 中配置(部分终端软件,依赖这个配置,达到跟随到命令所在目录的效果):
precmd () { echo -n "\x1b]1337;CurrentDir=$(pwd)\x07" }

# 常用 alias
dni() {
docker network inspect "$1" | jq '.[0] | {Name:.Name, Id:.Id, Driver:.Driver, IPAM:.IPAM.Config, Containers:.Containers, Options:.Options}'
}
alias cl='clear'
alias l='ls -rhtla'
alias dps='docker ps --format "table{{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}"'
alias nts='nginx -t && nginx -s reload'
alias nf='neofetch'
alias dis='docker images'
alias tss='tailscale status'
alias ts='tailscale'
alias ff='fastfetch'
alias dnl='docker network ls'
alias dlf='docker logs -f'
proxyon () {
export ALL_PROXY="http://localhost:7890"
export HTTP_PROXY="http://localhost:7890"
export HTTPS_PROXY="http://localhost:7890"
export FTP_PROXY="http://localhost:7890"
export SOCKS_PROXY="http://localhost:7890"
export all_proxy="http://localhost:7890"
export http_proxy="http://localhost:7890"
export https_proxy="http://localhost:7890"
export ftp_proxy="http://localhost:7890"
export socks_proxy="http://localhost:7890"
echo export ALL_PROXY="http://localhost:7890"
echo export HTTP_PROXY="http://localhost:7890"
echo export HTTPS_PROXY="http://localhost:7890"
echo export FTP_PROXY="http://localhost:7890"
echo export SOCKS_PROXY="http://localhost:7890"
echo export all_proxy="http://localhost:7890"
echo export http_proxy="http://localhost:7890"
echo export https_proxy="http://localhost:7890"
echo export ftp_proxy="http://localhost:7890"
echo export socks_proxy="http://localhost:7890"
}
proxyoff () {
unset ALL_PROXY
unset HTTP_PROXY
unset HTTPS_PROXY
unset FTP_PROXY
unset SOCKS_PROXY
unset all_proxy
unset http_proxy
unset https_proxy
unset ftp_proxy
unset socks_proxy
echo unset ALL_PROXY
echo unset HTTP_PROXY
echo unset HTTPS_PROXY
echo unset FTP_PROXY
echo unset SOCKS_PROXY
echo unset all_proxy
echo unset http_proxy
echo unset https_proxy
echo unset ftp_proxy
echo unset socks_proxy
}
proxyecho () {
echo ALL_PROXY="$ALL_PROXY"
echo HTTP_PROXY="$HTTP_PROXY"
echo HTTPS_PROXY="$HTTPS_PROXY"
echo FTP_PROXY="$FTP_PROXY"
echo SOCKS_PROXY="$SOCKS_PROXY"
echo all_proxy="$all_proxy"
echo http_proxy="$http_proxy"
echo https_proxy="$https_proxy"
echo ftp_proxy="$ftp_proxy"
echo socks_proxy="$socks_proxy"
}

9. 安装 docker

1
2
3
4
5
6
7
8
9
10
11
# 加入 Docker 的 GPG 公钥和 apt 源(国内清华源)
curl -sS https://download.docker.com/linux/debian/gpg | gpg --dearmor > /usr/share/keyrings/docker-ce.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-ce.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian $(lsb_release -sc) stable" > /etc/apt/sources.list.d/docker.list

# 更新并安装
apt update
apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y

# 检查
docker version
docker compose version

10. 安装 alist

官方手册: https://alist.nn.ci/zh/guide/install/docker.html#docker-compose

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
mkdir -p /opt/alist
cd /opt/alist

vim docker-compose.yml

version: '3.3'
services:
alist:
image: 'xhofe/alist:latest'
container_name: alist
volumes:
- './data:/opt/alist/data'
- '/etc/localtime:/etc/localtime:ro'
ports:
- '5244:5244'
environment:
- PUID=0
- PGID=0
- UMASK=022
restart: unless-stopped

# 启动
docker compose up -d

注:如果镜像拉不下来,要配置 dockerd 代理,可以参考 服务器代理方法 2.2.2 docker
默认用户名 admin
初始密码查看 docker 日志,有打印

添加存储

存储

访客可见目录配置


开无痕窗口测试一下访客查看的效果,成功

11. rathole 代理 alist

rathole github

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 创建目录
mkdir -p /opt/rathole
cd /opt/rathole

# 下载
curl -LO https://github.com/rapiz1/rathole/releases/download/v0.5.0/rathole-x86_64-unknown-linux-gnu.zip

# 解压
x rathole-x86_64-unknown-linux-gnu.zip

# 客户端配置文件(内容下附)
vim client.toml

# systemd 管理(内容下附)
vim /etc/systemd/system/rathole.service

# systemd 生效
systemctl daemon-reload
systemctl enable rathole.service
systemctl start rathole.service
systemctl status rathole.service

客户端 rathole.service 内容

1
2
3
4
5
6
7
8
9
10
[Unit]
Description=Rathole Server
After=network.target

[Service]
ExecStart=/opt/rathole/rathole /opt/rathole/client.toml
Restart=on-failure

[Install]
WantedBy=multi-user.target

client.toml 内容

1
2
3
4
5
6
7
# client.toml
[client]
remote_addr = "服务器ip:11111" # 远程服务器地址和长连接端口

[client.services.my-alist]
token = "my_token"
local_addr = "localhost:5244"

server.toml 内容

1
2
3
4
5
6
7
# server.toml
[server]
bind_addr = "0.0.0.0:11111" # 长连接端口

[server.services.my-alist]
token = "my_token"
bind_addr = "0.0.0.0:22222"

nginx.conf 内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# photos.megumiai.com 的 HTTPS 配置
server {
listen 443 ssl;
server_name photos.megumiai.com;

ssl_certificate /etc/nginx/ssl/megumiai.com.crt;
ssl_certificate_key /etc/nginx/ssl/megumiai.com.key;

location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_pass http://localhost:22222;
client_max_body_size 20000m;
}
}

测试

完成 ✅

  • Title: debian12 虚拟机安装 + 博客相册恢复
  • Author: sound_kanade
  • Created at : 2024-10-30 00:12:00
  • Updated at : 2025-01-22 14:43:14
  • Link: https://blog.megumiai.com/deploy/debian12_vmware_blog_photos_recovery.html
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments