俗话说的好,科技的本质就是换皮。
——我也不知道谁说的
之前又在看别人的文章的时候又发现了感兴趣的主题,于是就打算换上了。正逢暑假,于是开工给博客换个主题玩玩。
查看主题文档的时候,发现这个主题和当前使用的博客不是一个系统。正好也打算记录一下目前博客搭建的过程,更换博客也不是不可接受的事情。于是就有了这篇文章。
正文
这次要选用的博客系统为Halo,是基于java和spring boot的一种博客系统。相比于之前的Hexo,Halo是一种动态博客系统。虽然在加载速度上比不上静态博客系统,单目前我个人可以维护博客的时间不多,Halo的维护相对较为方便,因此这也是我选择Halo的原因之一。
于我而言,我将博客部署在我在阿里云的Ubuntu轻量应用服务器上。部署的方式有两种:
- 直接下载二进制jar包部署
- 通过docker部署
为了方便之后的迁移工作,这里选用docker的方式进行部署。
Docker的安装
要通过Docker进行部署,就必须先有Docker环境。
自动安装
Docker官方有提供相应的一键安装脚本:
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
但遗憾的是,由于我的服务器的版本问题,不能使用这种方式一键安装。因此这里使用手动安装。
手动安装
卸载旧版本
Docker 的旧版本被称为 docker,docker.io 或 docker-engine 。如果已安装,请卸载它们:
$ sudo apt-get remove docker docker-engine docker.io containerd runc
我的服务器上没有安装过Docker,因此跳过这步。
更新 apt 包索引。
$ sudo apt-get update
安装 apt 依赖包
用于通过HTTPS来获取仓库:
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
添加 Docker 的官方 GPG 密钥:
$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
在这之后,我们可以验证是否拥有带有指纹的密钥。但为了方便起见,这里略过这步。
设定稳定版仓库
使用以下指令设置稳定版仓库
$ sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \
$(lsb_release -cs) \
stable"
小插曲:
在我执行这步命令的时候,我的服务器报错:
sudo: unable to resolve host abc
这其实是由于host的解析出现了问题导致的。出现这个报错其实并没有影响之前安装的步骤。要消除这个报错也简单,只需要在/etc/hosts
添加上:
127.0.0.1 [你的主机名]
就可以了。
安装 Docker Engine-Community
更新 apt 包索引。
$ sudo apt-get update
然后安装最新版本的 Docker Engine-Community 和 containerd。
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
在这里也可以使用一些其他的方法安装其他特定版本的Docker,不过同样,这里对我没有必要。因此直接安装最新版即可。
测试 Docker 是否安装成功
输入以下指令,打印出以下信息则安装成功:
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
## 安装Halo
安装好Docker后,就可以拉取镜像,安装Halo了。
按照官网的Guide,只需要以下两条命令,就可以安装起来了。
$ docker pull halohub/halo:1.5.3
$ docker run -it -d --name halo -p 8090:8090 -v ~/.halo:/root/.halo halohub/halo:1.5.3
之后博客就运行起来了。运行起来了之后不要忘记去开一下防火墙的端口号,然后通过http//:[ip]:8090/
就可以访问到博客了。
反向代理的设置
在搭建好之后,博客都只能通过ip:端口号的方式访问,这显然不够优雅。当然我们可以直接把端口映在80上然后绑定个域名,不过我这个服务器上还运行着其他的一些服务,因此不能直接使用这么简单粗暴的方法。
不过考虑到我使用的是Nginx,因此我们可以通过反向代理的方式解决这一问题。
。。。
。。。
然后嘛,嘿嘿嘿,博客还没完全搭好呢。等我之后完全弄好了再来搞这些吧233
一些其他的测试()