搭建家庭服务器

时隔多年,又开始折腾服务器了。这次想在家里摆个服务器,就用淘汰下来的笔记本,花了两三天时间,遂记录一下。 万事始于公网 IP 还得是公网 IP。但令我没想到的是,打电话给电信,刚开口说想申请个公网 IP,人家就给我下了订单,我提前想好的理由一句没说。没半个小时一个电话过来,让我检查下 OK 不 OK——太效率了! 电信,赞! 路由器拨号 光有公网 IP 还不行,还得配置光猫桥接,让路由器拨号。 这一点要吐槽电信了,打电话第一个客户说不支持桥接,问原因她也不说,就说不支持——骗鬼呢。 打了第二个电话,换了个客户,还说不支持,但说了原因,大意是改桥接问题很多,很多年前就取消了这项服务。 我不是没想过自己去改,但是我家那个光猫型号老,后台(80 端口)以及管理后台(8080 端口)都没有改桥接的地方,我不知道是不是要超级管理员账号才能改,但超级管理员密码我也拿不到,电信客户也不给,问就是“没有”、“不知道”。 最后还是电信维修师傅帮忙改的桥接,也是光速改,很快啊。赞! 清理笔记本数据 笔记本虽然之前应该备份过数据,但以防万一,还是又备份了一遍。 两台笔记本摆一起,连上 WIFI,开启 Windows 文件共享,选好想备份的文件等它传好就完事了。 选择 Linux 发行版 虽然这笔记本是当服务器来使,365 天不停机,但还是得给它安排桌面版 Linux 系统,毕竟家里爸妈放电视剧、电影还得靠它。 选 Linux 发行版时给我纠结了一下,Linux Mint 和 Manjaro 其实都很好。 Linux Mint 优势在于它是 Ubuntu 系的,很多开源软件基本第一个要支持的就是 Ubuntu,特别是那种一键式安装脚本,对 OS 依赖较强,支持的也一般包含 Ubuntu。装 Ubuntu 绝对省心。 Manjaro 优势就在于有 AUR,基本什么软件都能很方便的安装,虽然每次安装都要编译就是了。 最终还是选了 Manjaro。 安装 Linux 系统 制作启动盘一开始用的软碟通,最后发现没法启动。后面又换了 Refus,使用 DD 模式刻录,才成功。 Linux 系统配置 代理配置 代理是个大问题。 ...

九月 21, 2024  |  625 字  |  总阅读

【Hexo】CI/CD——持续集成&持续部署

这里不讲 CI/CD 的概念,我们想要做到的,就是自动化编译、部署博客,把注意力都集中在写作上。 之前已经讲过 《【Hexo】Git 一键部署》,但那仅仅是一键部署。在部署之前,还需要在本地安装 Nodejs 环境,安装依赖包,然后编译,最后才能开始部署。当然,Nodejs 环境和依赖一台机器上安装一次就够了,以后只需编译就行,但如果需要在多台机器上写作,那么每台机器都要装环境、装依赖…… 也还行,还比较便利,但还不够。 我们可以借助 CI/CD 工具,完成环境搭建、编译、部署等一系列工作,真正做到一键上传博客。 说到这里,我想到了 WordPress。 WordPress 很容易就可以做到一键上传博客,完全不用搞什么 CI/CD。 免费的 CI/CD 工具不少,这里我选择了 Gihub Action。博客文章都是存储在 Github 库中,用 Gihub Action 也比较方便。 如下是工程文件, https://github.com/vksir/blog-posts/blob/master/.github/workflows/main.yml 关于博客系统 WordPress 确实是好,但不太适合我: 文章都存储的 MySQL 数据库中。 数据库很可靠,但是我的服务器并不可靠。服务器是租的,上面的数据我并不是很放心。比起个人服务器,我更愿意把数据存储在 Github 这种地方。 性能消耗大。 WordPress 需要 MySQL、PHP 支撑,光跑这俩个组件就要占用大量内存,1H2G 的服务器有点难吃下。 Hexo 也挺好的,但也有问题: 很简单,也很复杂。 简单指的是很容易就能生成博客页面,复杂是指,如果想要做到 WordPress 那样便利,其实很麻烦,要装一堆插件,配置一堆东西,完了还没有 WordPress 好用。 二次开发也不容易。 博客主题经常就会有变更需求,只能硬写 Html、CSS、JS,着实是有点难为我这个后端开发者。如果能用用 React 之类的框架,那还简单点。 最好就是自己动手写博客,想怎么样就怎么样。框架好说,数据也好说,难的是主题。从零开始写 CSS,简直魔鬼……

五月 8, 2022  |  60 字  |  总阅读

阿里 OSS 访问图片 403

如下图, 原因是域名开启了 Referer 防盗链,如下, 添加允许访问的域名即可。

五月 8, 2022  |  5 字  |  总阅读

安装 SSL 证书

wget -O - https://get.acme.sh | sh . .bashrc # 自动更新 acme.sh --upgrade --auto-upgrade # 测试是否能成功获取 acme.sh --issue --test -d joking.vksir.zone -w /var/www/html --keylength ec-256 # 正式获取 acme.sh --issue -d joking.vksir.zone -w /var/www/html --keylength ec-256 --force # 为 Xray 安装证书 acme.sh --install-cert -d joking.vksir.zone --ecc \ --fullchain-file /usr/local/etc/xray/xray.crt \ --key-file /usr/local/etc/xray/xray.key chmod +r /usr/local/etc/xray/xray.key

五月 8, 2022  |  53 字  |  总阅读

搭建 Jupyter Notebook 云代码执行笔记

Jupyter Notebook——我实在想不好该用什么来形容它,百科的介绍是「交互式笔记」,或许交互式确是它的特点,但我感觉最大的特点还是它是个 Web 应用,能「云」,且能「执行代码」,支持 40+ 语言。 为什么需要它:因最近想学习一下与服务器进行远程通信,而本人 vim 的熟练度又着实一般,想在服务器上运行代码非常麻烦,因此搭建这么一个玩意儿方便运行代码。另外,它还能当做云笔记来用,曾想搭建一个云笔记,可印象笔记另需数据库,没那么内存给它,其它云笔记又没什么好的,因此搁置,这不 jupyter 来了,正好。 优点:远程执行代码,远端保存笔记 环境:CentOS 7 需求:Nginx,Python 安装 非常简单,这里我是基于 python 3 安装的,当然 python 2 也可以。 # 安装 pip3 install jupyter # 启动 jupyter notebook --ip=0.0.0.0 --no-browser --allow-root --port=8888 –ip=0.0.0.0:指定 IP 为本机 IP –no-browser:启动后会默认打开浏览器,这里我在远端服务器上使用,选择不打开浏览器 –allow-root:允许使用 root 用户运行 –port=8888:默认监听 8888 端口,可修改 现在可以打开浏览器进入 http://IP:8888 就可以看到 Jupyter NoteBook 的登录界面了。 它会提示你设置密码,token 在启动程序的时候会打印出来,输入此 token 和自己的密码设置即可。 初次登录需要设置密码,下次就不需要了。 Nginx 反向代理 配置 Nginx 不使用反向代理直接使用也是可以的,但无法域名访问,且无法使用 SSL 证书,信息明文传输,安全得不到保证。 ...

四月 16, 2020  |  182 字  |  总阅读

搭建 Chevereto 个人图床

平时写写文什么的,图床还是要一个的,分享啊、插入图片啊,都挺方便的。(为什么要叫「图床」啊,叫「图库」多好听呢,或者「画廊」?) Chevereto 是一款常用的图床服务,这里使用的是「免费版」,个人使用也足够了。 环境:CentOS 7 需求:Nginx,PHP 7.0-7.2(PHP 7.3 是不支持的,为此我特地把 PHP 换成了 7.2 版),MySQL 下载 前往 GitHub,下载最新发布。 # 创建安装目录 mkdir -p /var/www/chevereto && cd /var/www/chevereto # 下载 wget -O chevereto.zip https://github.com/Chevereto/Chevereto-Free/releases # 解压 x chevereto.zip x:来自 Oh My Zsh 的 extract 插件,任何压缩包一个 x 搞定。 配置 Nginx 需要 伪静态 + php-fpm。 伪静态配置文件如下 如何导入 php-fpm,参考 搭建 FileRun 个人网盘 server { server_name www.vksir.zone; root /var/www/chevereto; client_max_body_size 20m; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /index.php; } try_files $uri $uri/ /api.php; } location /admin { try_files $uri /admin/index.php?$args; } } 配置 MySQL 为 Chevereto 新建一个数据库 chevereto ,并为该数据库创建一个用户名为 chevereto 并设置密码,参考:MySQL 的安装与配置。 ...

三月 11, 2020  |  126 字  |  总阅读

【Hexo】Git 一键部署

这里要说的是部署到自己的服务器哦~其实呢,主要是有关 Git 的使用吧。 主要内容: Hexo 一键部署 使用自己的远程 Git 库 快捷登录 SSH 环境:CentOS 7 创建Git用户 && SSH快捷登录 创建Git用户 # 创建无法使用ssh登录,但可以使用git功能的用户 useradd git -s /bin/git-shell # 设置密码 passwd git # 添加用户到nginx用户组 usermod -G nginx git 为什么需要将 git添加到 nginx用户组后面再聊~ SSH快捷登录 将密钥推送到服务器 ssh-copy-id git@IP 建立远端Git库 创建库 # 创建库 cd /home/git git init --bare hexo_html.git –bare:创建一个裸仓库(也就是不包含文件的仓库) 如果这里不加 --bare,待会儿推送的时候就会报错 receive.denyCurrentBranch = false。如果定不想加的话,就在 .git/config中添加: [receive] denyCurrentBranch = ignore 这样就可以正常推送了。 使用库 直接在本地打开终端: # 克隆库 git clone git:/home/git/hexo_html.git # 测试 cd hexo_html touch testfile # 提交到本地库 git add . git commit -m "第一次提交" # 推送到远端库 git push # 换个文件夹 git clone git:/home/git/hexo_html.git ls # 文件存在,表示搭建成功 虽然是 push到远端库了,但是在远端库里,是看不到任何文件的。推送的文件已另一种形式存储在了 hexo_html.git中。 ...

三月 6, 2020  |  167 字  |  总阅读

【Hexo】NexT 进阶配置

Hexo——一款纯静态、基于 Nodejs 的博客系统。 NexT——Hexo 下的强大的主题,该博客发展到了现在,倒是算是 Hexo 还是 NexT,真的很难说清。 优点: 万能!什么功能都有!相比起 Ghost 博客系统,Hexo + NexT 完善太多 支持所有 Markdown 语法,类似于嵌套列表(Now),而 Ghost 和 WordPress 都是不支持的。强迫症如我,表示没有嵌套列表日子不能过! 缺点: 相比起 Ghost 的主题配置语言 HandBar,NexT 主题的这个 swig 语言系统着实难懂。且 NexT 的文档不是非常完善,自定义主题较为困难。 没有 Web 后台(有一个,但是太丑……),只能在命令行下发布文章,没有一种家的感觉 环境:Nodejs v12.14.1 版本:Hexo v4.2.0,NexT v7.7.2 访问量统计 <!-- 添加脚本 --> <!-- next/layout/_partials/head/head-unique.swig -> END --> <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script> <!-- 这一段是页脚 由Hexo强力驱动 等字样,删了也罢 --> <!-- next/layout/_partials/footer.swig -> FIND --> {%- if theme.footer.powered.enable %} <div class="powered-by"> {{- __('footer.powered', next_url('https://hexo.io', 'Hexo', {class: 'theme-link'})) }} {%- if theme.footer.powered.version %} v{{ hexo_version }}{%- endif %} </div> {%- endif %} {%- if theme.footer.powered.enable and theme.footer.theme.enable %} <span class="post-meta-divider">|</span> {%- endif %} {%- if theme.footer.theme.enable %} <div class="theme-info"> {%- set next_site = 'https://theme-next.org' %} {%- if theme.scheme !== 'Gemini' %} {%- set next_site = 'https://' + theme.scheme | lower + '.theme-next.org' %} {%- endif %} {{- __('footer.theme') }} – {{ next_url(next_site, 'NexT.' + theme.scheme, {class: 'theme-link'}) }} {%- if theme.footer.theme.version %} v{{ next_version }}{%- endif %} </div> {%- endif %} {%- if theme.add_this_id %} <div class="addthis_inline_share_toolbox"> <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid={{ theme.add_this_id }}" async="async"></script> </div> {%- endif %} <!-- 替换为本站总访客数 --> <!-- next/layout/_partials/footer.swig --> <div class="powered-by"> <span class="post-meta-item-icon"> <i class="fa fa-eye"></i> </span> <span id="busuanzi_container_site_uv">总访客数: <span id="busuanzi_value_site_uv"></span></span> </div> <!-- 这一段前 --> <!-- next/layout/_macro/post.swig -> FIND --> {%- endif %} {#################} {### POST BODY ###} {#################} <!-- 添加本文阅读量 --> <!-- next/layout/_macro/post.swig --> <span class="post-meta-item" id="busuanzi_container_page_pv"> <span class="post-meta-item-icon"> <i class="fa fa-eye"></i> </span> 阅读量: <span id="busuanzi_value_page_pv"></span> </span> 来自: ...

三月 6, 2020  |  403 字  |  总阅读

搭建 NextCloud 个人网盘

NextCloud——一款优秀的,非常受欢迎的个人网盘。 优点: 全平台支持:有 Windows、Linux、Mac、Android、IOS 客户端 支持文件同步(目前来看,安卓端文件同步没法使用) 缺点: 无法直接访问本地目录 添加本地文件很麻烦 环境:CentOS 7 需求:Nginx,PHP,MySQL 安装 NextCloud # 创建安装目录 mkdir -p /var/www/nextcloud && cd /var/www/nextcloud # 下载并解压 wget -O nextcloud.zip https://download.nextcloud.com/server/releases/nextcloud-18.0.1.zip && unzip nextcloud.zip && mv nextcloud/* ./ && rm -rf nextcloud # 更改安装目录权限 chmod -Rf 777 /var/www/nextcloud 配置 Nginx 修改 /etc/nginx/nginx.conf。 # /etc/nginx/nginx.conf -> server{ } upstream php-handler { server 127.0.0.1:9000; # server unix:/var/run/php/php7.2-fpm.sock; } server { #listen 443 ssl http2; #若使用https,取消本行注释,同时注释下面这行 listen 80; server_name _; #将cloud.example.com替换为你的域名 # 若使用https,取消注释下面两行 # ssl_certificate /etc/ssl/nginx/cloud.example.com.crt; # ssl_certificate_key /etc/ssl/nginx/cloud.example.com.key; # Add headers to serve security related headers # Before enabling Strict-Transport-Security headers please read into this # topic first. # add_header Strict-Transport-Security "max-age=15768000; # includeSubDomains; preload;"; # # WARNING: Only add the preload option once you read about # the consequences in https://hstspreload.org/. This option # will add the domain to a hardcoded list that is shipped # in all major browsers and getting removed from this list # could take several months. add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; add_header X-Robots-Tag none; add_header X-Download-Options noopen; add_header X-Permitted-Cross-Domain-Policies none; # Path to the root of your installation root /var/www/nextcloud; location = /robots.txt { allow all; log_not_found off; access_log off; } # The following 2 rules are only needed for the user_webfinger app. # Uncomment it if you're planning to use this app. #rewrite ^/.well-known/host-meta /public.php?service=host-meta last; #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json # last; location = /.well-known/carddav { return 301 $scheme://$host/remote.php/dav; } location = /.well-known/caldav { return 301 $scheme://$host/remote.php/dav; } # set max upload size client_max_body_size 512M; fastcgi_buffers 64 4K; # Enable gzip but do not remove ETag headers gzip on; gzip_vary on; gzip_comp_level 4; gzip_min_length 256; gzip_proxied expired no-cache no-store private no_last_modified no_etag auth; gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy; # Uncomment if your server is build with the ngx_pagespeed module # This module is currently not supported. #pagespeed off; location / { rewrite ^ /index.php$uri; } location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ { deny all; } location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { deny all; } location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\.php(?:$|/) { fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; # fastcgi_param HTTPS on; # 若使用https取消这行注释 #Avoid sending the security headers twice fastcgi_param modHeadersAvailable true; fastcgi_param front_controller_active true; fastcgi_pass php-handler; fastcgi_intercept_errors on; fastcgi_request_buffering off; } location ~ ^/(?:updater|ocs-provider)(?:$|/) { try_files $uri/ =404; index index.php; } # Adding the cache control header for js and css files # Make sure it is BELOW the PHP block location ~ \.(?:css|js|woff|svg|gif)$ { try_files $uri /index.php$uri$is_args$args; add_header Cache-Control "public, max-age=15778463"; # Add headers to serve security related headers (It is intended to # have those duplicated to the ones above) # Before enabling Strict-Transport-Security headers please read into # this topic first. # add_header Strict-Transport-Security "max-age=15768000; # includeSubDomains; preload;"; # # WARNING: Only add the preload option once you read about # the consequences in https://hstspreload.org/. This option # will add the domain to a hardcoded list that is shipped # in all major browsers and getting removed from this list # could take several months. add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; add_header X-Robots-Tag none; add_header X-Download-Options noopen; add_header X-Permitted-Cross-Domain-Policies none; # Optional: Don't log access to assets access_log off; } location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ { try_files $uri /index.php$uri$is_args$args; # Optional: Don't log access to other assets access_log off; } } 导入 php-fpm 组件,参考:搭建 FileRun 个人网盘。 ...

三月 6, 2020  |  590 字  |  总阅读

搭建 Aria2 离线下载

环境:CentOS 7 安装 Aria2 # 安装 yum install aria2 # 查看版本 aria2c --version # 添加配置文件 mkdir -p /root/.aria2 touch /root/.aria2/aria2.session nano /root/.aria2/aria2.conf /root/.aria2/aria2.conf 完整文件如下: # /root/.aria2/aria2.conf # 需要修改------------------------- # 文件的保存路径 dir=/data/download # 设置的RPC授权令牌 rpc-secret=vksir97634 # 可选修改-------------------------- # 当下载的是一个种子(以.torrent结尾)时, 自动开始BT任务 #follow-torrent=true # 断点续传 continue=true # 最大同时下载任务数, 运行时可修改 max-concurrent-downloads=5 # 禁用IPv6 disable-ipv6=true # 从会话文件中读取下载任务 input-file=/root/.aria2/aria2.session # 退出时保存`错误/未完成`的下载任务到会话文件 save-session=/root/.aria2/aria2.session # RPC监听端口, 端口被占用时可以修改 rpc-listen-port=6800 # 不推荐修改----------------------- # 启用磁盘缓存, 0为禁用缓存 #disk-cache=32M # 文件预分配方式, 能有效降低磁盘碎片 file-allocation=none # 同一服务器连接数, 添加时可指定 max-connection-per-server=5 # 最小文件分片大小, 添加时可指定 min-split-size=20M # 单个任务最大线程数, 添加时可指定 split=5 # 整体下载速度限制, 运行时可修改 #max-overall-download-limit=0 # 单个任务下载速度限制 #max-download-limit=0 # 整体上传速度限制, 运行时可修改 #max-overall-upload-limit=0 # 单个任务上传速度限制 #max-upload-limit=0 # 定时保存会话, 0为退出时才保存 #save-session-interval=60 # 启用RPC enable-rpc=true # 允许所有来源 rpc-allow-origin-all=true # 允许非外部访问 rpc-listen-all=true # 事件轮询方式, 取值:[epoll, kqueue, port, poll, select] #event-poll=select # BT监听端口, 当端口被屏蔽时使用 listen-port=6881-6999 # 单个种子最大连接数 #bt-max-peers=55 # 打开DHT功能, PT需要禁用 enable-dht=false # 打开IPv6 DHT功能, PT需要禁用 #enable-dht6=false # DHT网络监听端口 #dht-listen-port=6881-6999 # 本地节点查找, PT需要禁用 #bt-enable-lpd=false # 种子交换, PT需要禁用 enable-peer-exchange=false # 每个种子限速 #bt-request-peer-speed-limit=50K # 客户端伪装, PT需要 peer-id-prefix=-TR2770- user-agent=Transmission/2.77 # 当种子的分享率达到这个数时, 自动停止做种, 0为一直做种 seed-ratio=1.0 # 强制保存会话, 即使任务已经完成 #force-save=false # BT校验相关, 默认:true #bt-hash-check-seed=true # 继续之前的BT任务时, 无需再次校验 bt-seed-unverified=true # 保存磁力链接元数据为 .torrent 文件 bt-save-metadata=true # 启动 Aria2 aria2c –conf-path=/root/.aria2/aria2.conf -D # 查看 Aria2 监听的端口 netstat -ntlp -D:表示在后台启动 Aria2 Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:6800 0.0.0.0:* LISTEN 9398/aria2c 默认监听的端口为 6800,注意为此端口 打开防火墙。 ...

三月 6, 2020  |  296 字  |  总阅读