安装docker

参照官网
注意 配置源之后配置认证

基于docker安装mysql

搜索镜像

docker search mysql

下载容器

docker pull mysql:5.7

启动容器

docker run -p 3306:3306 --name mysql -v $PWD/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7 --lower_case_table_names=1

说明

-p 3306:3306 将容器端口号映射到主机上
--name my_mysql 给容器取名字
 -v $PWD/mysql:/var/lib/mysql 将容器的/var/lib/mysql挂在到当前路径的mysql 下
-e MYSQL_ROOT_PASSWORD=root 设置容器的初始密码为root 
mysql:5.7 镜像名
--lower_case_table_names=1 表名不区分大小写

连接并创建数据库

CREATE DATABASE solo CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

安装

docker run --detach --name solo \
 --network=host \
--env RUNTIME_DB="MYSQL" \
--env JDBC_USERNAME="root" \
--env JDBC_PASSWORD="root" \
--env JDBC_DRIVER="com.mysql.cj.jdbc.Driver" \
--env JDBC_URL="jdbc:mysql://127.0.0.1:3306/solo?useUnicode=yes&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC" \
b3log/solo --listen_port=8080 --server_scheme=http --server_host=blog.jiqfu.top

挂载皮肤,需要添加默认皮肤

docker run --detach --name solo \
-v $PWD/skins/:/opt/solo/skins/ \
 --network=host \
--env RUNTIME_DB="MYSQL" \
--env JDBC_USERNAME="root" \
--env JDBC_PASSWORD="root" \
--env JDBC_DRIVER="com.mysql.cj.jdbc.Driver" \
--env JDBC_URL="jdbc:mysql://127.0.0.1:3306/solo?useUnicode=yes&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC" \
b3log/solo --listen_port=80 --server_scheme=http --server_host=blog.jiqfu.top

启动报错

[ERROR]-[2020-06-07 16:11:26]-[org.b3log.latke.repository.jdbc.JdbcRepository:149]: Adds a record failed
com.mysql.cj.jdbc.exceptions.PacketTooBigException: Packet for query is too large (2,553 > 2,048). You can change this value on the server by setting the 'max_allowed_packet' variable.
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:107) ~[mysql-connector-java-8.0.20.jar:8.0.20]
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953) ~[mysql-connector-java-8.0.20.jar:8.0.20]
	at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:370) ~[mysql-connector-java-8.0.20.jar:8.0.20]
	at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44) ~[HikariCP-3.4.3.jar:?]
	at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java) ~[HikariCP-3.4.3.jar:?]

修改mysql 的连接数量

show VARIABLES like '%max_allowed_packet%';
set global max_allowed_packet = 2*1024*1024*10;

进入容器

dokcker exec -it solo /bin/sh

docker nignix安装

拉取镜像

 docker pull nginx:latest

创建准备目录

mkdir nginx nginx/conf nginx/logs nginx/www nginx/ssl

运行容器

docker run --name nginx -p 80:80 -d --rm nginx

导出配置文件

docker cp nginx:/etc/nginx/nginx.conf ./nginx/conf/nginx.conf 
导出配置文件 nginx.conf
docker cp nginx:/etc/nginx/conf.d ./nginx/conf/conf.d 
导出配置为你 nginx.conf

停止并删除Nginx

docker stop nginx

添加Nginx配置

upstream backend {
    server #服务器ip:8080; # Solo 监听端口
}

server {
    listen       80;
    server_name  blog.jiqfu.top; # 博客域名

    access_log off;

    location / {
        proxy_pass http://backend$request_uri;
        proxy_set_header  Host $http_host;
        proxy_set_header  X-Real-IP $remote_addr;
        client_max_body_size  10m;
    }
}

挂载目录并重新启动

docker run -d -p 80:80 --name nginx \
-v $PWD/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v $PWD/nginx/conf/conf.d:/etc/nginx/conf.d \
-v $PWD/nginx/www:/usr/share/nginx/html \
-v $PWD/nginx/logs:/var/log/nginx nginx

说明
-v $PWD/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \ 挂载配置文件 nginx.conf
-v $PWD/nginx/conf/conf.d:/etc/nginx/conf.d 挂载配置文件 default.conf
-v $PWD/nginx/www:/usr/share/nginx/html 挂载项目文件
-v $PWD/nginx/logs:/var/log/nginx 挂载配置文件

基于以上安装,主要是docker、mysql、Nginx 安装halo

官网:https://halo.run/archives/install-with-docker.html

修改Nginx 的反向代理地址

upstream backend {
    server #服务器ip:8090; # Solo 监听端口
}

server {
    listen       80;
    server_name  blog.jiqfu.top; # 博客域名

    access_log off;

    location / {
        proxy_pass http://backend$request_uri;
        proxy_set_header  Host $http_host;
        proxy_set_header  X-Real-IP $remote_addr;
        client_max_body_size  10m;
    }
}

配置ssl

停止docker Nginx

docker stop nginx

安装Nginx

sudo apt-get install nginx

复制之前的配置文件内容到

sudo vi /etc/nginx/sites-available/default

加载配置

校验配置
sudo nginx -t

sudo service nginx reload
如果Nginx没启动则启动
sudo service nginx start

安装certbot

sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-nginx

签发证书

sudo certbot --nginx -d blog.jiqfu.top

提示 
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
选择 2 自动配置https

刷新网页就变成https了

注意halo 系统设置中将博客首页的地址也改成https