1. Environmental PreparationIf 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 DockerBecause 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 3. Install MySQL master-slave databaseWe 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 preparationmkdir -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 databasesNote: 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 databasedocker 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 librarydocker 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! 3.5、Master-slave parameter description
4. Build a solo blog After all the preparations are done, you can start installing 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 blogRegarding 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 DisplayThis 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:
|
<<: How to introduce pictures more elegantly in Vue pages
>>: Implementation of positioning CSS child elements relative to parent elements
Many times we want the server to run a script reg...
It is almost a standard feature for websites nowa...
There are many seemingly true "rumors" ...
netem and tc: netem is a network simulation modul...
Effect Need environment vue elementUI Drag and dr...
In HTML, you need to specify the encoding used by...
front end css3,filter can not only achieve the gr...
Most of the time, plug-ins are used to upload fil...
XHTML defines three document type declarations. T...
I installed MySQL on Windows by unzipping the com...
Mininet Mininet is a lightweight software defined...
If prompted to enter a key, select [I don’t have ...
CSS writing order 1. Position attributes (positio...
Purpose: Treat Station A as the secondary directo...
My system and software versions are as follows: S...