From scratch to build a solo personal blog system

Personal blog to build your own system from running so far already in the past month, the entire building process can be said to step on countless pit. So the whole process of building and stepped pit wrote here, I hope you can give a friend set up a personal blog system provide some help. The whole process, including the tutorial server purchase, domain name applications and for the record, install solo, nginx apply to the use of reverse proxy ssl certificates and, well less immediately began to say nonsense.

1. build processes blog system

To give you a better understanding of the logic of the whole blog system set up, so I made it a build process flow chart, we can hope to intuitive feelings; we look at some aspects of flow chart to note is optional.

2. Server Optional

First of all have their own server, and if you can skip this step. If not, you can have a lot of server provider Optional: There are domestic Ali cloud , Tencent cloud , Huawei cloud , Baidu cloud , etc., abroad have AWS , vultr , the specific selection can be set according to their business needs. We are here to buy Ali cloud server as an example:

2.1 student Ali cloud host

Offers student discount for students Ali cloud, you can buy can save a lot of costs through cloud wing program. Specific purchase process can refer to the official tutorial: Ali cloud student computer buying guide explained . For the system to select a personal recommendation centos.

2.2 ordinary Cloud Hosting

To purchase ordinary Ali cloud host configuration may involve the issue of the election, but in general it is sufficient to entry-level servers to use, of course, if there are special needs when he was on the other. Here attach ECS purchase cloud server address of course recommended to select individual system centos.

3. The domain name purchase and registration (optional)

3.1 domain name purchase

If possible try to buy a domain name, because on the one hand convenient access via ip, on the other hand may be banned and can not be SEO optimized, and now non-popular domain name (popular domain names including .com, .cn, .net, etc.) as I was not very expensive to buy their own domain name .top three years to 43 dollars. Specific ways to buy a similar server with the purchase, generally passing cloud server providers offer to purchase the domain name service. Here we offer a cloud Ali domain name purchase Address: Ali cloud domain name purchase

3.2 domain name server record

If the domain name or the server is generally not required abroad for the record, but if that is the country in accordance with current domestic policies are required to record all domain now. In general we can be purchased through the domain name service provider domain name registration system for the record, of course, through the Ministry of Industry and Information Technology to ICP / IP address / domain name information for the record management system for the record, here is recommended by the former, because the official filing system is very slow progress is far from a third party filing system progress quickly. Here we are with Ali cloud of domain name registration system, for example, detailed domain name registration process:

The first step : enter the domain name registration system
Step two : Fill in the information and test data letter

The third step : wait for the trial of Ali cloud
this big step appointments consumption around day, if you complete the second step of data are in line with the requirements, then the next day Ali cloud customer service will give you a phone call, to tell you the information has been passed, will be submitted to the Ministry of Industry. If the information does not meet the requirements, then the customer will call you to tell you the message of concurrent irregularities at the data, resubmit after the changes are complete, a cloud Ali trial again. This process usually takes two to three days.
Step Four : Authority audit
This step is the most time-consuming, first of all there is a Ministry of Industry and SMS verification after the trial over, that is, for the record to determine whether the phone number can be used. Following the adoption of a formal information will be provided to the Authority. Authority from providing information to get feedback generally ranging from 7-20 days (this depends on the mood of the local Authority), if the Authority information through nothing else, you will receive a registration number and password. At this time, the domain name for the record is complete.

3.3 domain name server to resolve

This step is all of the most relaxing, landing domain name service provider of domain name management platform, will resolve the ip address of the domain name points to purchase server settings will take effect after about two minutes.

Of course, we can pingresolve whether the entry into force command to see:

4.solo installation

到这一步算是正式进入正题,根据官网提供的安装方式有两种分为本地使用Docker部署

4.1 本地试用

下载最新的 Solo 包解压,进入解压目录执行以下命令:

  • Windows: java -cp "WEB-INF/lib/*;WEB-INF/classes" org.b3log.solo.Starter
  • Linux: java -cp "WEB-INF/lib/*:WEB-INF/classes" org.b3log.solo.Starter
    注意:官方是不太推荐通过war包发布或者源码构建部署,因为这样的部署方式不利于后续新版本发布时的升级和更新。

### 4.2 Docker部署

第一步 获取最新镜像:

docker pull b3log/solo

运行结果:

第二步 安装MYSQL

我们既可以直接在服务器上直接安装也可以通过docker方式在docker容器中安装
方式一:docker安装

# 安装mysql:5.6,直接docker run 他会自动去官方镜想下载
# MYSQL_ROOT_PASSWORD=[的数据库密码,此处写的是123456
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6
# docker安装的mysql默认允许远程连接,可以使用Navicat等软件连接数据库
# 进入容器mysql
docker exec -it mysql bash

# 进入数据库 p后面跟你的密码
mysql -uroot -p123456

# 创建数据库(数据库名:solo;字符集utf8mb4;排序规则utf8mb4_general_ci)
create database solo DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
# 出现Query OK, 1 row affected (0.00 sec)表示成功
#退出数据库
exit
#退出容器
exit

运行结果如下:

方式二:物理机上直接安装
由于配置稍显繁琐,可以参考下边这篇博客:
Centos安装mysql(YUM源方式)

第三步 安装solo

运行如下命令:

docker run --detach --name solo --network=host \
--env RUNTIME_DB="MYSQL" \
--env JDBC_USERNAME="root" \
--env JDBC_PASSWORD="123456" \
--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=www.vcjmhg.top
  • --detach: 这个选项告诉 Docker 在启动后将程序与控制台分离,使其进入“后台”运行。
  • --name solo: solo是容器的名字,也可以改成自己喜欢的名字如mysolo,这个无所谓
  • RUNTIME_DB="MYSQL": 指明我们此处使用的数据库为MYSQL,如果使用,H2 Database,将MYSQL改成org.h2.Driver即可
  • JDBC_USERNAME="root": 指明MYSQL数据连接时使用的用户名,默认都是root
  • JDBC_PASSWORD="123456": 指明MYSQL数据库连接时用户密码,使用时注意将123456替换成自己在上一步所设置的密码
    * env JDBC_DRIVER="com.mysql.cj.jdbc.Driver":数据库连接驱动包,如果使用,H2 Database,将om.mysql.cj.jdbc.Driver改成H2即可
  • --server_host=www.vcjmhg.top: 个人域名,如果没有可设置为自己的服务器ip
  • --env JDBC_URL=...:
  • --listen_port=8080:指明solo监听的端口此处使用的是8080,如果不想配置nginx此处可以换成80

命令运行结果:

命令执行完成之后没有报错的话,通过docker ps查看当前当前容器列表中是否有名字叫solo的容器,如果有证明启动成功了,此时可以通过个人域名/ip+:8080来进行访问,类似http://192.168.217.132:8080,如果不想配置nginx可以将8080换成80,可以直接通过域名/ip来直接进行访问,类似vcjmhg的博客--https://vcjmhg.top。不出意外会出现如下界面(如果出现不能访问的情况考虑是否是防火墙配置有问题,查看是否开发8080或者80端口):

由于后边我们需要配置nginx进行反向代理以及配置ssl证书来实现https方式访问,因此在看到solo启动正常之后,此处创建的solo镜像需要删除,等配置完nginx之后重新在创建一个。
删除solo容器直接执行下边命令

docker kill --name solo
docker rm --name solo

命令执行结果如下:

5.安装nginx(可选)

安装之前为了后续配置nginx方便,我们需要在本地创建几个文件,用来挂载nginx的配置文件

# 切换到服务器根目录
cd /
# 创建主目录
mkdir dockerData
# 创建文件
mkdir dockerData/nginx dockerData/nginx/conf dockerData/nginx/logs dockerData/nginx/www dockerData/nginx/ssl

上边的文件目录名称可以任意,此处我使用dockerDate

  • dockerData/nginx 用于存放dockernginx自定义文件
  • dockerData/nginx/conf存放nginx配置文件
  • dockerData/nginx/log存放nginx日志文件
  • dockerData/nginx/www:存放nginx访问的资源文件
  • dockerData/nginx/ssl存放ssl证书
    命令执行结果如下:

启动nginx

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

命令执行结果如下:

如果没有备案,80端口可能是禁止访问的,因此可以可以将上边的80:80换成8080:80。命令执行完成之后,没有报错的话可以通过docker ps来看nginx是否正常运行,在运行的情况下访问的域名加上端口号查看是否正常安装,如果使用的80端口默认可以省略。出现如下界面表示安装成功。

导出配置文件:

docker cp nginx:/etc/nginx/nginx.conf /dockerData/nginx/conf/nginx.conf  #导出配置文件nginx.conf
docker cp nginx:/etc/nginx/conf.d /dockerData/nginx/conf/conf.d  #导出conf.d
cd /dockerData/nginx/ 
ls conf/   #查看配置文件是否导出成功
docker stop nginx  #删除刚才创建的nginx容器
docker rm nginx

命令执行结果:

重新创建一个nginx容器,挂载刚才本地导出的配置文件,便于后续更改nginx的配置信息

docker run -d -p 80:80 --name nginx \
-v /dockerData/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /dockerData/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /dockerData/nginx/www:/usr/share/nginx/html \
-v /dockerData/nginx/logs:/var/log/nginx nginx
  • -v /dockerData/nginx/conf/nginx.conf:/etc/nginx/nginx.conf : 挂载配置文件nginx.conf
  • -v /dockerData/nginx/conf/conf.d:/etc/nginx/conf.d: 挂载配置文件default.conf
  • -v /dockerData/nginx/www:/usr/share/nginx/html : 挂载项目文件
  • -v /dockerData/nginx/logs:/var/log/nginx : 挂载配置文件

命令执行结果如下:

注意: 我自己在搭建过程中发现执行docker ps命令后发现nginx并没有被启动,使用命令docker logs nginx发现挂载文件时权限不足,果断在创建nginx容器是加上--privileged=true参数(如果没有出现该问题可不加上述参数)。

即执行如下命令

docker run -d -p 80:80 --name nginx --privileged true \
-v /dockerData/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \·
-v /dockerData/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /dockerData/nginx/www:/usr/share/nginx/html \
-v /dockerData/nginx/logs:/var/log/nginx nginx

执行docker ps -a 此时容器运行正常

容器创建完成之后重新访问在浏览器访问可能会出现如下界面:

此时你可以在www目录下创建一个html文件,也可以先不用管,等后续配置完成之后自然会消失。

6. 配置ssl证书(可选)

从http升级到https只需要在nginx中配置一个证书即可,一般性的ssl证书是可以免费申请的

6.1证书选购

阿里云或者腾讯云都提供证书申请服务,这里以阿里云的证书申请为例:
第一步: 进入阿里云的证书购买地址https://www.aliyun.com/product/cas

第二步:进入购买页面,选择免费型DV SSL

第三步: 支付

第四步: 进入控制台,进行证书下载

6.2配置nginx配置文件

下载之后会得到一个名字类似于2793667_www.vcjmhg.top_nginx.zip的文件,将其上传到服务器/dockerData/nginx/ssl目录中,解压后(通过unzip命令)会得到如下两个文件

大家可以参考我的配置文件进行配置,配置自己的default.conf文件。

server {
    listen       443;
    server_name  localhost;
    ssl on;
    ssl_certificate /ssl/2793667_www.vcjmhg.top.pem;  # ssl 证书目录
    ssl_certificate_key /ssl/2793667_www.vcjmhg.top.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;    

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
       #root   /usr/share/nginx/html;
       # index  index.html index.htm;
       # 官方博客上此处用的是域名,但配置时发现不好使,所以我用的是服务器ip
       proxy_pass http://39.105.61.192:8080;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
server{
  listen 80;
  server_name www.vcjmhg.top;
  rewrite ^(.*) https://$host$1 permanent;
}

注意:上边的配置文件只是参考,要根据自己的服务器做出相应更改。
由于我们现在用的nginx容器并未监听443端口,所以需要删除现在的容器,重新启动一个新的nginx容器

#先删除原来的nginx容器
docker stop nginx;
docker rm nginx;
docker run --detach --name solo --network=host \
--env RUNTIME_DB="MYSQL" \
--env JDBC_USERNAME="root" \
--env JDBC_PASSWORD="123456" \
--env JDBC_DRIVER="com.mysql.cj.jdbc.Driver" \
--env JDBC_URL="jdbc:mysql://192.168.217.132:3306/solo?useUnicode=yes&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC" \
b3log/solo --listen_port=8080 --server_scheme=https --server_host=www.vcjmhg.top --server_port=
  • --server_scheme=http换成--server_scheme=https即可
  • --serv4er_port:最终访问端口,使用浏览器默认的80或者443的话值留空即可
  • 如果出现权限不足问题,启动时加上-privileged true参数即可

重启nginx,docker restart nginx,然后用浏览器访问https://域名类似于https://www.vcjmhg.top,登陆github账户后出现如下界面

后记

首先官方已经给了一些安装的教程,一位叫墨殇的博主也已经给了特别详细的安装教程(地址,点这里),但是我自己在配置过程中出现了好多问题,因此我在这里写下来这篇博客,希望能给他人提供一些帮助。当然可能个人水平有限,中间难免会出现一些错误,如若发现恳请指出,不胜赐教。如果按照本教程在配置过程中遇到什么问题,欢迎在博客下边留言,我若看到的话一定第一时间回复,谢谢!

Guess you like

Origin www.cnblogs.com/goWithHappy/p/solo_start.html