From ee4ad3488cda330396e2e391519aa8df7729d29b Mon Sep 17 00:00:00 2001 From: estom Date: Sat, 12 Jul 2025 06:00:49 -0400 Subject: [PATCH] =?UTF-8?q?=E5=B0=86blog=E6=89=93=E5=8C=85=E9=95=9C?= =?UTF-8?q?=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 6 +++ MyScript/blog/run_blog.sh | 31 ++++++++++++ {zshell => MyScript}/multi_sync.bat | 0 {zshell => MyScript}/multi_sync.sh | 0 MyScript/network/autossh.service | 21 ++++++++ MyScript/network/clash.sh | 74 +++++++++++++++++++++++++++++ MyScript/network/frp-route.sh | 48 +++++++++++++++++++ MyScript/network/frpc.service | 13 +++++ MyScript/network/ssh-route.sh | 53 +++++++++++++++++++++ {zshell => MyScript}/start.sh | 0 zshell/run_blog.sh | 2 - 11 files changed, 246 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 MyScript/blog/run_blog.sh rename {zshell => MyScript}/multi_sync.bat (100%) rename {zshell => MyScript}/multi_sync.sh (100%) create mode 100644 MyScript/network/autossh.service create mode 100644 MyScript/network/clash.sh create mode 100644 MyScript/network/frp-route.sh create mode 100644 MyScript/network/frpc.service create mode 100644 MyScript/network/ssh-route.sh rename {zshell => MyScript}/start.sh (100%) delete mode 100644 zshell/run_blog.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..56650b35 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM node:20-alpine +RUN npm install -g docsify-cli@latest +WORKDIR /docs +COPY . . +EXPOSE 3000 +CMD ["docsify", "serve", ".", "--port", "3000"] \ No newline at end of file diff --git a/MyScript/blog/run_blog.sh b/MyScript/blog/run_blog.sh new file mode 100644 index 00000000..0222e40e --- /dev/null +++ b/MyScript/blog/run_blog.sh @@ -0,0 +1,31 @@ + +nohup docsify serve -p 80 /root/gitee/notes &> blog.log & + + +# 使用容器的方式打包当前镜像 +docker build -t my-docsify-blog . + +# 运行容器 +docker run -d --restart=always \ + --name docsify-blog \ + -p 3000:3000 \ + -v $(pwd):/docs \ + my-docsify-blog + + +docker run --name docsify-blog \ + -p 3000:3000 \ + my-docsify-blog +# 查看日志 +docker logs -f docsify-blog + +# 停止 / 启动 +docker stop docsify-blog +docker start docsify-blog + +# 更新镜像后重新部署 +docker build -t my-docsify-blog . +docker rm -f docsify-blog +docker run -d ... # 同上 + + diff --git a/zshell/multi_sync.bat b/MyScript/multi_sync.bat similarity index 100% rename from zshell/multi_sync.bat rename to MyScript/multi_sync.bat diff --git a/zshell/multi_sync.sh b/MyScript/multi_sync.sh similarity index 100% rename from zshell/multi_sync.sh rename to MyScript/multi_sync.sh diff --git a/MyScript/network/autossh.service b/MyScript/network/autossh.service new file mode 100644 index 00000000..ecaf98f6 --- /dev/null +++ b/MyScript/network/autossh.service @@ -0,0 +1,21 @@ +[Unit] +Description=Robust SSH Reverse Tunnel and Port Forward +After=network.target + +[Service] +User=estom +# 使用绝对路径指定密钥(如果使用密钥认证) +Environment="AUTOSSH_GATETIME=0" +ExecStart=/usr/bin/autossh -M 0 -o "ExitOnForwardFailure=yes" -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -N -T -i /home/estom/.ssh/id_rsa -R 8000:localhost:22 root@8.141.4.34 + +# 关键修复参数 +Restart=always +RestartSec=10 +KillMode=process # 确保终止所有子进程 + +# 启动频率限制调整 +StartLimitIntervalSec=60 +StartLimitBurst=10 + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/MyScript/network/clash.sh b/MyScript/network/clash.sh new file mode 100644 index 00000000..bb54d9bd --- /dev/null +++ b/MyScript/network/clash.sh @@ -0,0 +1,74 @@ +# 配置信息 +/usr/local/bin/clash +~/.config/clash/config.yaml + +# clash默认监听的http/https端口 +127.0.0.1:7890 +# clash默认监听的socks5端口 +127.0.0.1:7891 +# clash默认的控制台端口 +:::9090 + +# 手动启动clash +clash -d /etc/clash/config.yaml + + +# 将clash设置为系统服务-暂不设置,容易出问题. +# 当前已经自动启动了了服务sudo systemctl stop mihomo.service +├─mihomo.service +│ └─20307 /opt/clash/bin/mihomo -d /opt/clash -f /opt/clash/runtime.yaml + +# 将http_proxy设置为当前shell的变量 +export http_proxy="http://127.0.0.1:7890" +export https_proxy="http://127.0.0.1:7890" + +# 将http_proxy设置为当前用户的变量 +# 将以下文件放到.bashrc中 +vi ~/.bashrc +export http_proxy="http://127.0.0.1:7890" +export https_proxy="http://127.0.0.1:7890" + + + +# 【可选】将http_proxy设置为系统变量 +sudo vi /etc/environment + + +# 如何关闭clash +ps -ef | grep clash +lsof -i:7890 +kill 12345 + +# 如何关闭代理 +unset http_proxy +unset https_proxy + +# 如果是通过服务启动的clash则需要通过服务管理命令关闭 + +sudo systemctl stop clash +# 以下命令可以禁用开机启动 +sudo systemctl disable clash + +# 如何配置git的代理 +git config --global http.proxy http://127.0.0.1:7890 +git config --global https.proxy http://127.0.0.1:7890 +git config --global http.proxy socks5://127.0.0.1:7891 + + +# 取消git的代理 +git config --global --unset http.proxy +git config --global --unset https.proxy + + +#如何设置ssh代理 +# ~/.ssh/config +Host github.com + HostName github.com + User git + # 使用 SOCKS5 代理(如 Clash/V2Ray) + ProxyCommand nc -x 127.0.0.1:7891 %h %p + # 或使用 HTTP 代理(需安装 proxychains) + # ProxyCommand connect -H 127.0.0.1:7890 %h %p + +# 自带的ui地址如下 +http://localhost:9090/ui/ \ No newline at end of file diff --git a/MyScript/network/frp-route.sh b/MyScript/network/frp-route.sh new file mode 100644 index 00000000..5a0a2fe3 --- /dev/null +++ b/MyScript/network/frp-route.sh @@ -0,0 +1,48 @@ +# 这是另外一套内网穿透方案——frp +# 客户端配置文件如下 +serverAddr = "8.141.4.34" +serverPort = 7000 +auth.token = "ykl123" + +[[proxies]] +name = "ssh-tcp" +type = "tcp" +localIP = "127.0.0.1" +localPort = 22 +remotePort = 6000 + + + +# 客户端服务文件如下 +[Unit] +Description=Frp Client Service +After=network.target + +[Service] +User=estom +Type=simple +ExecStart=/usr/local/bin/frpc -c /home/estom/.config/frp/frpc.toml +Restart=always +RestartSec=10 + +[Install] +WantedBy=multi-user.target + +# 客户端配置命令如下 +sudo systemctl enable frpc +sudo systemctl start frpc +sudo systemctl status frpc + + +# 服务端配置文件如下 + +[common] +bind_port = 7000 # frp 客户端连接端口 +token = ykl123 +dashboard_port = 7500 # web 控制台端口(可选) +dashboard_user = estom +dashboard_pwd = ykl123 + + +# 服务端启动命令如下。服务端可以随时连接启动,不需要额外配置 +nohup ./frps -c frps.ini & \ No newline at end of file diff --git a/MyScript/network/frpc.service b/MyScript/network/frpc.service new file mode 100644 index 00000000..2768eaf2 --- /dev/null +++ b/MyScript/network/frpc.service @@ -0,0 +1,13 @@ +[Unit] +Description=Frp Client Service +After=network.target + +[Service] +User=estom +Type=simple +ExecStart=/usr/local/bin/frpc -c /home/estom/.config/frp/frpc.toml +Restart=always +RestartSec=10 + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/MyScript/network/ssh-route.sh b/MyScript/network/ssh-route.sh new file mode 100644 index 00000000..5d24fd10 --- /dev/null +++ b/MyScript/network/ssh-route.sh @@ -0,0 +1,53 @@ +# 使用ssh隧道远程转发,实现内网穿透 +# -N:不执行远程命令,仅用于转发。 +# -f:后台运行。 +# -R:远程转发(反向隧道)。 +# ssh -NfR 公网服务器端口:内网主机:内网端口 公网用户名@公网服务器IP +ssh -NfR 8000:localhost:22 root@8.141.4.34 + +# 使用autossh实现ssh隧道远程转发,实现内网穿透,能够避免网络波动,实现自动重连 +# -M 0:不使用监控端口,通过 SSH 自身机制检测连接状态。 +autossh -M 0 -NfR 8000:localhost:22 root@8.141.4.34 + +# 为了执行autossh不需要远程认证需要将当前容器的ssh公钥添加到远程服务器的authorized_keys中 +ssh-copy-id root@8.141.4.34 + +# 需要配置公网服务器上开启远程转发服务 +GatewayPorts yes +AllowTcpForwarding yes + +# 配置完成后需要重启ssh服务 +sudo systemctl restart sshd + + +# 如何关闭远程转发——本地端的ssh隧道 +ps aux | grep "ssh -NfR" +kill 12345 # 替换为实际的 PID +# 或者执行如下命令 +pkill -f "ssh -NfR" +# 如果是autossh执行如下命令 +ps aux | grep autossh +kill 12345 # 替换为实际的 PID + + +# 关闭远程服务器的端口转发 +netstat -tulpn | grep 8000 # 替换为你转发的端口 +sudo kill 12345 # 替换为实际的 PID + + +# 最后,远程连接的方式如下 +ssh -p 8000 estom@8.141.4.34 + +# 服务开机启动。去掉了-f参数不再是后台启动。服务本身就应该启动一个阻塞的命令。 +autossh.service + + +# 修改service文件后可以这样保证配置文件生效 +# 1. 重新加载 systemd 管理器配置(使服务文件更改生效) +sudo systemctl daemon-reload + +# 2. 重启特定服务 +sudo systemctl restart your-service-name.service + +# 3. 检查服务状态 +sudo systemctl status your-service-name.service \ No newline at end of file diff --git a/zshell/start.sh b/MyScript/start.sh similarity index 100% rename from zshell/start.sh rename to MyScript/start.sh diff --git a/zshell/run_blog.sh b/zshell/run_blog.sh deleted file mode 100644 index cfb96c51..00000000 --- a/zshell/run_blog.sh +++ /dev/null @@ -1,2 +0,0 @@ - -nohup docsify serve -p 80 /root/gitee/notes &> blog.log & \ No newline at end of file