Preparation#
JD Cloud lightweight cloud host 2 cores 2G 3M 1 year cost 58 yuan
Domain name three-year cost 76 yuan
SSL single domain certificate 1 year 30 yuan (I am Ha per, actually not necessary)
Server Selection#
Other region servers: If friends directly set up such servers, it would be convenient, and there’s no need to worry about the network. If you are a student, you might consider applying for the GitHub student package. After applying, you can use Azure $100 or Ocean Digital $200 vouchers, which is quite cost-effective overall. However, the GitHub student package is not easy to apply for; I struggled for a week, got rejected three or four times, and finally succeeded (┬┬﹏┬┬).
Mainland China servers: I compared several cloud service providers, and the previous discount period has passed. Looking at Tencent Cloud and Alibaba Cloud, their cloud servers are actually not cheap. (Alibaba Cloud has a 99 yuan/year 2G2 core cloud server, which can be renewed for three years, this discount is still okay.) Currently, it seems that JD Cloud has the best deals among the domestic cloud service discounts I found.
Originally, I saw several options on the JD Cloud website, and I was quite tempted. My first thought was to buy the following types:
- Lightweight cloud host 2 cores 4G 5M 1 year 165 yuan
- Lightweight cloud host 2 cores 4G 5M 3 years 618 yuan
Please forgive someone with hamster hoarding syndrome~. However, in the end, due to being short on funds and not feeling confident about buying a cloud server for the first time, I thought I would first try the 58 yuan/year 2G2 core lightweight cloud server.
Others#
Ubuntu 20.04 LTS system (if it's JD Cloud, you might consider using CentOS, which may be more convenient and less prone to network issues)
Xshell (for remote control of the cloud server, I think this would be more convenient. JD Cloud itself provides Web Terminal login
and VNC login
, but because it’s on a web tab, I always feel it’s not smooth. If you find it troublesome, you can skip installing it~)
Install Docker and Docker Compose#
Installing Docker Compose does not necessarily require installing Docker first, but usually, Docker Compose is a tool for managing and deploying Docker container applications, so it is recommended to have Docker installed before using Docker Compose.
Docker Compose is built on Docker, simplifying the management of multiple related services (such as databases, web servers, etc.) in local or production environments by defining and running these services through a YAML file. If you plan to use Docker Compose to create and manage containerized applications, it’s best to ensure Docker is installed and running properly on the system.
Update System and Install Dependencies#
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
Add Docker's GPG Key to trusted.gpg.d Directory#
(I couldn't succeed by adding it directly here due to network timeout, so I switched to an Alibaba Cloud source)
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/docker-archive-keyring.gpg > /dev/null
Add Docker Repository#
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Update Package List and Install Docker#
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
Actually, I didn’t quite understand this logic. JD Cloud's own documentation states that using yarm
on CentOS
will automatically switch sources for faster downloads, but it does not support Ubuntu. Directly downloading Docker from that address will result in an error. I also switched to an Alibaba source for Docker, but the issue is that in the actual process (the image above), the first four steps were all downloaded from JD Cloud, and only the final step switched to Alibaba Cloud. However, as long as it works, that’s good~
Configure Docker to Use Alibaba Cloud Image Source#
sudo mkdir -p /etc/docker
sudo nano /etc/docker/daemon.json
In the daemon.json
file, add the following content (search for the corresponding URL on Alibaba Cloud's official website Container Image Service (aliyun.com) and copy the URL)
{
"registry-mirrors": ["https://<your id>.mirror.aliyuncs.com"]
}
Then press ctrl
+ x
to exit, yes to save, and press enter to save.
Restart Docker Service#
sudo systemctl daemon-reload
sudo systemctl restart docker
Install Docker Compose#
I spent a long time here.
The normal process is as follows.
Update Package List#
First, ensure your package list is up to date:
sudo apt update
Install Docker#
If you haven't installed Docker yet, you can use the following command to install it:
sudo apt install docker.io
Start and set Docker to start on boot:
sudo systemctl start docker
sudo systemctl enable docker
Download Docker Compose#
Use the following command to download the latest version of Docker Compose. You can find the latest version number on the GitHub Releases page and replace v2.10.2
with the latest version number:
sudo curl -L "https://github.com/docker/compose/releases/download/v2.10.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
At this step, I encountered network latency issues.
I couldn't download it at all.
Here are two methods provided.
Use Xftp to Upload#
Download it on your own computer, then use Xftp to upload it, and rename the uploaded file to docker-compose, paying attention to the path.
Use ghproxy Proxy for Acceleration#
At the time of writing this article, this proxy is available at https://mirror.ghproxy.com/
, just add the required github
link at the end.
curl -SL https://mirror.ghproxy.com/https://github.com/docker/compose/releases/download/v2.29.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
Grant Execute Permissions#
After downloading, you need to grant executable permissions to the file:
sudo chmod +x /usr/local/bin/docker-compose
Verify Installation#
Check if Docker Compose is installed successfully and view the version number:
docker-compose --version
Docker Compose Setup Halo Blog#
Refer to the official documentation Deploying with Docker Compose | Halo Documentation
- Create a folder anywhere in the system; this document uses
~/halo
as an example.
mkdir ~/halo && cd ~/halo
- Before pulling with docker-compose, you need to create a docker-compose.yaml file. The official website provides three instances:
- Create an instance of Halo + PostgreSQL
- Create an instance of Halo + MySQL
- Create only a Halo instance (using the default H2 database); the official does not recommend using the default H2 database in production environments.
This article adopts the first option, Halo + PostgreSQL.
Path: ~/halo/docker-compose.yaml
nano ~/halo/docker-compose.yaml
Input
version: "3"
services:
halo:
image: registry.fit2cloud.com/halo/halo:2.17
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:postgresql://halodb/halo
- --spring.r2dbc.username=halo
#
#
# Here you need to modify
# PostgreSQL password, please ensure it is consistent with the variable value of POSTGRES_PASSWORD below.
- --spring.r2dbc.password=openpostgresql # Change the password, don't keep it the same as the official one; anything else is fine, otherwise, it poses a potential danger.
- --spring.sql.init.platform=postgresql
# External access address, please modify according to actual needs, based on the IP address provided when you purchased the host.
# For example, mine is 116.X.X.241, I would change the following line to - --halo.external-url=http://116.X.X.241:8090/
- --halo.external-url=http://localhost:8090/
halodb:
image: postgres:15.4
restart: on-failure:3
networks:
halo_network:
volumes:
- ./db:/var/lib/postgresql/data
healthcheck:
test: [ "CMD", "pg_isready" ]
interval: 10s
timeout: 5s
retries: 5
environment:
- POSTGRES_PASSWORD=openpostgresql # Change this to be the same as the above spring.r2dbc.password
- POSTGRES_USER=halo
- POSTGRES_DB=halo
- PGUSER=halo
networks:
halo_network:
The official documentation provides specific parameter explanations.
Parameter Name | Description |
---|---|
spring.r2dbc.url | Database connection address, detailed information can be found in the Database Configuration section below. |
spring.r2dbc.username | Database username |
spring.r2dbc.password | Database password |
spring.sql.init.platform | Database platform name, supports postgresql , mysql , h2 |
halo.external-url | External access link; if public access is needed, it needs to be configured to the actual access address. |
Database Configuration:
Connection Method | Connection Address Format | spring.sql.init.platform |
---|---|---|
PostgreSQL | r2dbc:pool:postgresql://{HOST}:{PORT}/{DATABASE} | postgresql |
MySQL | r2dbc:pool:mysql://{HOST}:{PORT}/{DATABASE} | mysql |
MariaDB | r2dbc:pool:mariadb://{HOST}:{PORT}/{DATABASE} | mariadb |
H2 Database | r2dbc:h2:file:///${halo.work-dir}/db/halo-next?MODE=MySQL&DB_CLOSE_ON_EXIT=FALSE | h2 |
-
Start the Halo service
docker-compose up -d
Here I encountered network issues again. Even after switching to the Alibaba Cloud mirror, it didn’t help. Although the official documentation states that this source is from their self-built image library,
I still couldn't download it. Thanks to the 1panel mirror source, please do not use it maliciously. Since June, when many major mirror sources were shut down, finding a good mirror source has been really difficult /(ㄒ o ㄒ)/~~. Thanks to 1panel.
Following the same operation as before,
sudo nano /etc/docker/daemon.json
Change the content of the daemon.json
file to the following:
{
"registry-mirrors": ["https://docker.1panel.live"]
}
If friends still have issues after changing, the only thing I can think of is to use Alibaba Cloud's image repository service, where you can build your own image repository to download the Docker images you uploaded.
At this point, the blog is almost complete. Enter http://{your ip}:8090/console
to access the blog's backend. Oh, and one very important point not to forget: open port 8090 in the firewall settings of the corresponding server on JD Cloud, otherwise, you won't be able to access it.
Enter the backend, register an administrator account first, and you can edit the blog theme and upload articles.
Enter http://{your ip}:8090/
to access the blog page.