前言-Preface
虽然从事软件技术工作很多很多年了,但是还没有真正运营过自己的博客。这次应该也是背后“推手”的作用让我有了这个心思吧。既然开始了,那就坚持下来吧。
Although I've been working in software technology for many years, I've never really managed my own blog. This time, perhaps it's the influence of a "pushing hand" behind the scenes that has inspired me to start. Now that I've begun, I might as well keep at it.
本博客使用的是国产开源项目——Halo。使用Docker Compose部署在去年双11购买的香港服务器上(其实是销售人员“求”着我买的)。
This blog uses Halo, a Chinese open-source project.It is deployed using Docker Compose on a Hong Kong server I purchased during last year's Singles' Day sale (actually, it was the salesperson who practically begged me to buy it).
嗯,第一篇文章就顺带讲讲怎么部署个人博客Halo吧。
So, the first post could also incidentally cover how to deploy the personal blog using Halo.
使用Docker Compose搭建-Setting Up Using Docker Compose
安装Docker及Compose
本文章以CentOS 8为例,可以完全按照下面的脚本来执行:
This article uses CentOS 8 as an example, and you can follow the script below exactly:
安装Docker - Install Docker
# Install required packages 安装必要的包
sudo yum install -y yum-utils
# Set up the Docker repository 设置Docker仓库
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# Install Docker Engine 安装Docker引擎
sudo yum install docker-ce docker-ce-cli containerd.io
# Start Docker 启动Docker服务
sudo systemctl start docker
# Enable Docker to start on boot 设置Docker服务随系统启动
sudo systemctl enable docker
安装Compose - Install Compose
# Download the current stable release of Docker Compose 下载最新文档版本的Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# Apply executable permissions to the binary 给docker-compose赋予可执行权限
sudo chmod +x /usr/local/bin/docker-compose
编写Docker Compose文件 - Creating Docker Compose File
直接复制下面的文本内容(需要将里面2处“YOUR_MYSQL_PASSWORD”改成你自己的MySQL密码)保存到docker-compose.yaml文件,这个文件你可以放在~/halo/目录下(没有halo文件夹自己创建一个)。
Copy the text below directly (be sure to replace the two placeholders 'YOUR_MYSQL_PASSWORD' with your own MySQL password) and save it to a docker-compose.yaml file. You can place this file in the ~/halo/ directory (create the halo folder if it doesn't exist).
version: "3"
services:
halo:
image: halohub/halo:2.14
restart: on-failure:3
depends_on:
halodb:
condition: service_healthy
networks:
halo_network:
volumes:
- ./halo2:/root/.halo2
ports:
- "8090:8090"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8090/actuator/health/readiness"]
interval: 30s
timeout: 5s
retries: 5
start_period: 30s
command:
- --spring.r2dbc.url=r2dbc:pool:mysql://halodb:3306/halo
- --spring.r2dbc.username=root
# MySQL 的密码,请保证与下方 MYSQL_ROOT_PASSWORD 的变量值一致。
- --spring.r2dbc.password=YOUR_MYSQL_PASSWORD
- --spring.sql.init.platform=mysql
# 外部访问地址,请根据实际需要修改
- --halo.external-url=http://localhost:8090/
halodb:
image: mysql:8.1.0
restart: on-failure:3
networks:
halo_network:
ports:
- "3306:3306"
command:
- --default-authentication-plugin=caching_sha2_password
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_general_ci
- --explicit_defaults_for_timestamp=true
volumes:
- ./mysql:/var/lib/mysql
- ./mysqlBackup:/data/mysqlBackup
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "--silent"]
interval: 3s
retries: 5
start_period: 30s
environment:
# 请修改此密码,并对应修改上方 Halo 服务的 SPRING_R2DBC_PASSWORD 变量值
- MYSQL_ROOT_PASSWORD=YOUR_MYSQL_PASSWORD
- MYSQL_DATABASE=halo
networks:
halo_network:
启动Halo服务 - Start Halo Service
进入docker-compose.yaml所在目录,输入下面的命令:
Navigate to the directory containing the docker-compose.yaml file and enter the following command:
docker-compose up -d
当你看到下面的内容就表示Halo启动好了。
When you see the following text, it indicates that Halo has started successfully.
✔ Network halo_halo_network Created 0.1s
✔ Container halo-halodb-1 Healthy 16.0s
✔ Container halo-halo-1 Started
设置Halo - Setting up Halo
Halo的端口号是:8090。
The port number for Halo is: 8090.
在浏览器里输入你的服务器IP地址:8090(比如我的:http://43.129.202.71:8090/),第一次会自动进入设置页面,根据页面上的提示填写一些简单的信息即可。以后要想进入后台管理页面,在地址后面加上/console即可(比如:http://43.129.202.71:8090/console/)。
In your browser, enter your server's IP address followed by :8090 (for example, mine is: http://43.129.202.71:8090/). The first time, it will automatically take you to the setup page, where you can fill in some basic information following the prompts on the page. To access the admin management page later, simply add /console to the address (for example: http://43.129.202.71:8090/console/).
结尾 - Conclusion
好了,我的第一篇任务完成了,你也可以尽情玩耍了。
Alright, my first task is completed, and now you can enjoy playing around with it as well.