搭建家庭服务器

时隔多年,又开始折腾服务器了。这次想在家里摆个服务器,就用淘汰下来的笔记本,花了两三天时间,遂记录一下。 万事始于公网 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 字  |  总阅读

搭建 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 字  |  总阅读

搭建 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 字  |  总阅读

搭建 FileRun 个人网盘

FileRun——一款简洁、漂亮且功能强大的个人网盘。 优点: 美 可直接访问本地目录 传输文件速度快(原因不明,但是比 NextCloud 快) 缺点: 没有手机端客户端 环境:CentOS 7 需求:Nginx,PHP 7.1-7.3,MySQL 安装 FileRun # 创建安装目录 mkdir -p /var/www/filerun && cd /var/www/filerun # 下载并解压安装包 wget -O FileRun.zip http://www.filerun.com/download-latest && unzip FileRun.zip # 更改安装目录权限 chmod -Rf 777 /var/www/filerun 配置 Nginx 修改 /etc/nginx/nginx.conf 中的 server 段。 # /etc/nginx/nginx.conf -> server{ } server { listen 80; server_name _; root /var/www/filerun; # 修改上传文件大小上限 client_max_body_size 10240m; # Load configuration files for the default server block. # 此处表示导入组件 include /etc/nginx/default.d/*.conf; location / { index index.php index.html index.htm; try_files $uri $uri/ /index.php index.php; } } 导入 php-fpm 组件 上方配置文件中已存在「导入额外组件」的代码,现在我们只要在目录中添加「组件文件」即可。 ...

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

搭建 Ghost 个人博客

安装必要的环境 安装 Nginx 安装 MySQL 安装 Nodejs 创建非 root 用户,以下默认该用户名为 ghostuser 安装 Ghost Ghost-cli 是专为 Ghost 开发的一款安装工具,它使得安装 Ghost 变得非常容易。 # 全局安装 Ghost-cli npm install ghost-cli@latest -g 选择一个目录作为 Ghost 的安装目录,个人建议将其放在 /var/www 中。 # 创建目录 mkdir /var/www/ghost -p && cd /var/www/ghost # 修改权限 chown ghostuser:ghostuser /var/www/ghost # 切换用户 su ghostuser # 安装 Ghost ghost install local # 登出 exit 特别注意:/var/www/ghost 及其下所有文件的所属为 ghostuser:ghostuser,请勿随意修改! Ghost 的所有操作必须由 非 root 用户 进行,若使用 root 用户 执行上述操作将会报错: gyp ERR! stack Error: EACCES: permission denied, mkdir 'xxx' 好心点的话,会给你一点提示: ...

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