How to build a SOLO personal blog from scratch using Docker

How to build a SOLO personal blog from scratch using Docker

1. Environmental Preparation

If you want to access your blog on the public network, first you need a cloud server, that is, renting a server from a major cloud vendor. For example, I spent 68 yuan to buy a 1-core 2G server from Qingyun. The blog you are seeing now is on this server. It is best to purchase an exclusive domain name as well. A dozen times a year is enough.

2. Install Docker

insert image description here

Because we use Docker to deploy the solo blog. So we need to install docker first. For the introduction of docker, please search Baidu by yourself.

Configure yum source

sudo yum install -y yum-utils
sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

Install Docker

sudo yum install -y docker-ce docker-ce-cli containerd.io

start up

systemctl enable docker --now

Configuration acceleration

Here we add the core configuration cgroup of docker production environment

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://82m9ar63.mirror.aliyuncs.com"],
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

test:

Enter docker version and see the following display, the installation is successful

image.png

3. Install MySQL master-slave database

We have already installed docker, here we can directly use the command to deploy the mysql database with one click (the master-slave mysql deployed by the author)

3.1、MySQL environment preparation

mkdir -p /data/master/data/mysql-master && mkdir -p /data/master/data/mysql-slave ##Data Directory mkdir -p /data/master/master && mkdir -p /data/master/slave ##Configuration Directory

Put two configuration files in the configuration directory, master.cnf and slave.cnf respectively, the contents are as follows:

[root@website master]# cat master/master.cnf
[mysqld]
log-bin=mysql-bin
binlog_format=row
server-id=1
log-error=/var/log/mysqld.log


[root@website master]# cat slave/slave.cnf
[mysqld]
log-bin=mysql-bin
binlog_format=row
server-id=2
log-error=/var/log/mysqld.log

3.2. Start the MySQL master and slave databases

Note: The password here is set to 123456, and the default data storage directory of MySQL is mapped to my /data/master/data

 docker run -itd --name mysql-master -v /data/master/data/mysql-master:/var/lib/mysql -v /data/master/master:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 mysql:5.6
 docker run -itd --name mysql-slave -v /data/master/data/mysql-slave:/var/lib/mysql -v /data/master/slave:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 -p 3316:3306 mysql:5.6

3.3. Log in to the MySQL main database

docker ps -a ## Check whether the status of the two mysql databases are both UP
docker exec -it mysql-master /bin/bash
mysql -u root -p123456 ## Log in to mysql
show variables like 'log_bin'; ##Check the opening status of bin-log. If it is ON, it means it is opened successfully. We must open binlog for master-slave synchronization
show master status; ## Remember the file name and Position that are queried, as they will be used later when configuring the slave database. ## Create a user and grant permissions CREATE USER 'bakup'@'%' IDENTIFIED BY '123456';
GRANT ALL ON *.* TO 'bakup'@'%'; 
create database solo;

3.4. Log in to MySQL slave library

 docker exec -it mysql-slave /bin/bash ## Enter the slave library mysql -u root -p123456 ## Log in to mysql
 change master to master_host='192.168.1.5', master_port=3306,master_user='bakup',master_password='bakup', master_log_file='mysql-bin.000001',master_log_pos=154; ##Configure the master-slave connection start slave; ## Start slave backup show slave status\G; ## View status

See two YES and you’re done!

insert image description here

3.5、Master-slave parameter description

  • master_host: IP address/server address of the master database
  • master_port: the port of the master library
  • master_user: User opened by the master database
  • master_password: the user's password
  • master_log_file: The log file of the master library, the binary log file, is synchronized. It is the File in show master status above
  • master_log_pos: Position in show master status above

4. Build a solo blog

After all the preparations are done, you can start installing solo
docker start solo

docker run --detach --name solo --env RUNTIME_DB="MYSQL" --env JDBC_USERNAME="root" --env JDBC_PASSWORD="123456" --publish 8080:8080 --link mysql-master:mysql-master --env JDBC_DRIVER="com.mysql.cj.jdbc.Driver" --env JDBC_URL="jdbc:mysql://192.168.1.5:3306/solo?useUnicode=yes&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC" b3log/solo --listen_port=8080 --server_scheme=http --server_host=localhost --server_port=8080

docker logs solo ## View the logs of container solo [INFO ]-[2021-11-12 18:30:32]-[org.b3log.solo.Server:254]: Solo is booting [ver=4.3.1, os=Linux, isDocker=true, inJar=false, luteAvailable=false, pid=1, runtimeDatabase=MYSQL, runtimeMode=PRODUCTION, jdbc.username=root, jdbc.URL=jdbc:mysql://192.168.1.5:3306/solo?useUnicode=yes&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC]
[INFO ]-[2021-11-12 18:30:34]-[org.b3log.solo.service.InitService:177]: It's your first time setup Solo, initialize tables in database [MYSQL]
[WARN ]-[2021-11-12 18:30:36]-[org.b3log.solo.service.InitService:150]: Solo has not been initialized, please open your browser to init Solo

When the message Solo has not been initialized, please open your browser to init Solo appears, it means that solo has been installed successfully, but has not been initialized. You can see that the port we started earlier is 8080. It feels low to use the domain name plus the port, so we use nginx to forward it.

5. Nginx implements reverse proxy solo blog

Regarding the installation of nginx, I will not go into details here. Students can go to Baidu to find the configuration file:

http {
    sendfile on;
    include mime.types;
    default_type application/octet-stream;
    keepalive_timeout 65;
    gzip on;
    upstream backend {
      server localhost:8080;
    }
    server {
        listen 80;
        server_name yunxue521.top;
       location / {
        proxy_pass http://backend$request_uri;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        }
}

You can see that we have defined a backend address pointing to port 8080 of our local machine. Nginx listens on port 80. When we access port 80, it will be forwarded to port 8080, thereby realizing port forwarding!

VI. Achievements Display

insert image description here

This is the end of this article about building a SOLO personal blog from scratch with Docker. For more relevant content about building a SOLO personal blog from scratch with Docker, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Migrating the blog to Docker

<<:  How to introduce pictures more elegantly in Vue pages

>>:  Implementation of positioning CSS child elements relative to parent elements

Recommend

How to solve the problem of clicking tomcat9.exe crashing

A reader contacted me and asked why there were pr...

Detailed steps for QT to connect to MYSQL database

The first step is to add the corresponding databa...

What is BFC? How to clear floats using CSS pseudo elements

BFC Concept: The block formatting context is an i...

MySQL sql_mode analysis and setting explanation

When inserting a set of data into the MySQL datab...

The concept and characteristics of MySQL custom variables

A MySQL custom value is a temporary container for...

uni-app implements NFC reading function

This article shares the specific code of uni-app ...

JavaScript object built-in objects, value types and reference types explained

Table of contents Object Object Definition Iterat...

Solve the problem of running hello-world after docker installation

Installed Docker V1.13.1 on centos7.3 using yum B...

Implementation of k8s node rejoining the master cluster

1. Delete node Execute kubectl delete node node01...

Detailed explanation of the reasons why MySQL connections are hung

Table of contents 1. Background Architecture Prob...

Exploring the Linux Kernel: The Secrets of Kconfig

Get a deep understanding of how the Linux configu...

Docker implements container port binding local port

Today, I encountered a small problem that after s...

How to enable remote access in Docker

Docker daemon socket The Docker daemon can listen...

Detailed explanation of the two modes of Router routing in Vue: hash and history

hash mode (default) Working principle: Monitor th...

MYSQL Left Join optimization (10 seconds to 20 milliseconds)

Table of contents 【Function Background】 [Raw SQL]...