服务器迁移以及博客转移
起因: 在原来的域名zjzdmc.top上增加了cloudflare,结果后来提示备案掉了,然后网站就访问不了提示需要备案了。之后就想着正好把域名切换一下,从zjzdmc.top切换成datehoer.com,然后就在namesilo上买了新的域名,结果发现我的腾讯云服务器没法使用。正好当时想要买个境外的服务器,并且马上就要到黑五了,所以就一直等着到黑五才买。
首先测试的是宝塔+wordpress。
发现占用服务器内存资源过高,于是就想切换成一个轻量的博客系统,不过当时是想找一个轻量的主题试试,但是在GitHub上没有找到喜欢的主题,所以就想换一个博客系统,正巧发现了hexo,然后又想着部署麻烦,还不如用docker打包成容器,这样也好迁移。
于是就有了最终的成品,nginx+docker(hexo)
这里主要感谢这篇博客文章https://www.oxygencoder.com/posts/51015.html
写的不错,给了我很大的帮助。
主要是生成这样的Dockerfile文件:
# 使用最新的node镜像作为基础环境
FROM node:latest
MAINTAINER Steven <vilsteven@gmail.com>
# 设置临时工作目录
WORKDIR /usr/temp
# 配置 npm 镜像站点
RUN npm config set registry https://registry.npm.taobao.org
# 安装 hexo-cli
RUN npm install hexo-cli -g
# 初始化 hexo blog
RUN hexo init
# 安装 icarus 主题需要的依赖
RUN npm install --save bulma-stylus@0.8.0 inferno inferno-create-element hexo-renderer-inferno hexo-component-inferno
# 方便图片附件引用
RUN npm install hexo-asset-image --save
# 资源压缩
RUN npm install hexo-all-minifier --save
# 生成唯一链接
RUN npm install hexo-abbrlink --save
# 生成sitemap,优化SEO
RUN npm install --save hexo-generator-sitemap hexo-generator-baidu-sitemap
# 手动编译optipng-bin,否则会报错,找不到文件
RUN node node_modules/optipng-bin/lib/install.js
# 下载 icarus 主题
RUN curl -o "theme.zip" -L https://github.com/ppoffice/hexo-theme-icarus/archive/refs/tags/4.4.0.zip
RUN unzip theme.zip -d themes/
RUN mv themes/hexo-theme-icarus-4.4.0 themes/icarus
RUN rm -f theme.zip
# 配置 hexo 使用 icarus 主题
RUN sed -i "s/landscape/icarus/g" _config.yml
# 删除默认 landscape 主题
RUN npm uninstall hexo-theme-landscape --save
RUN rm -f _config.landscape.yml
RUN rm -r -f themes/landscape
# 配置正式工作目录
WORKDIR /usr/blog
# hexo 默认端口号 4000
EXPOSE 4000
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
之后按照上面的博客链接教程继续操作就行了。
ps:文末附一份转移教程
然后在docker启动hexo服务即可,记得使用nohup。
然后在宿主机这里安装nginx,具体安装教程可以百度/Google,文末附一份安装教程。
按照上面的博客链接配置好nginx后,开启80和443端口,在浏览器访问链接即可。
# 开启防火墙
firewall-cmd --add-port=443/tcp --permanent
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
2
3
4
运行后发现确实占用资源要少很多,不过我觉得其实主要的原因还是因为我安装了宝塔,并且wordpress使用的是MySQL数据库。
# 这里附一份转移教程
# RSS
首先,安裝 hexo-migrator-rss
外掛。
$ npm install hexo-migrator-rss --save
一旦外掛安裝完成,執行下列指令,從 RSS 轉移所有文章。source
可以是檔案路徑或網址。
$ hexo migrate rss <source>
# Jekyll
把 _posts
資料夾內的所有檔案複製至 source/_posts
資料夾,並在 _config.yml
中修改 new_post_name
設定。
new_post_name: :year-:month-:day-:title.md
# Octopress
把 Octopress 的 source/_posts
資料夾內的所有檔案轉移至 Hexo 的 source/_posts
資料夾,並修改 _config.yml
中的 new_post_name
設定。
new_post_name: :year-:month-:day-:title.md
# WordPress
首先,安裝 hexo-migrator-wordpress
外掛。
$ npm install hexo-migrator-wordpress --save
由 WordPress 儀表板的 “工具” → “匯出” → “WordPress” 匯出網站資料 (詳情請參見 WordPress 支援頁 (opens new window))。
接著執行:
$ hexo migrate wordpress <source>
source
為 WordPress 匯出檔案的路徑或網址:
# Joomla
首先,安裝 hexo-migrator-joomla
外掛
$ npm install hexo-migrator-joomla --save
並使用 J2XML (opens new window) 元件匯出你的 Joomla 文章。
接著執行:
$ hexo migrate joomla <source>
source
為 Joomla 匯出檔案的路徑或網址。
# 这里附一份nginx安装教程
要安装nginx,需要先确保服务器上已经安装了Linux操作系统和gcc编译器。然后,执行以下步骤:
- 下载nginx源码。可以从nginx官网下载,也可以使用Linux的包管理工具(如apt-get或yum)下载。
- 解压nginx源码压缩包。
- 进入nginx源码目录,执行命令“./configure”,配置nginx编译环境。
- 执行命令“make”,编译nginx源码。
- 执行命令“make install”,安装nginx。
在安装过程中,可能需要根据服务器的具体情况进行一些调整,如修改安装路径、配置编译选项等。此外,安装完成后,还需要进行一些配置,才能使nginx正常工作。
安装nginx最好使用Linux系统,如果您不熟悉Linux操作系统,建议您咨询专业人员或查阅相关资料。