Tomcat 方式部署 Solo 博客系统总结

本贴最后更新于 1714 天前,其中的信息可能已经时移世异

Solo 博客系统搭建

一、环境和文件准备

  • 服务器:购买的阿里云服务器,系统为 Linux(Cent OS)。
  • JDK:版本 1.8 下载
  • Tomcat:版本 9.0.19 下载
  • Solo:war 包形式,版本 3.6.3 下载
  • MySQL 8:通用 Linux 社区版 下载

  下载准备好以上几个文件后,分别将他们放到 Cent OS 的相应目录中,具体目录自己决定。最好新建自己的文件夹,目录中不要出现中文。

  • JDK 放在目录 /usr/local/hudk/JDK/jdk-8u111-linux-x64.tar.gz;
  • Tomcat 放在目录 /usr/local/hudk/apache-tomcat-9.0.22-deployer.tar.gz;
  • Solo 放在 /usr/local/hudk/solo-v3.6.3.war

二、安装 JDK 和配置环境变量

1、解压

  切换到 /usr/local/hudk/JDK 目录下,解压 JDK 压缩包。执行命令:

$ tar -zxvf jdk-8u111-linux-x64.tar.gz

2、环境变量

  新增文件 /etc/profile.d/jdk.sh,并编辑它。执行命令:

#编辑文件
$ vim /etc/profile.d/jdk.sh

  如果/etc/profile.d/下没有 jdk.sh 文件,执行此命令会自动增加 jdk.sh 文件,并进入 vim 编辑器,按键盘字母i进入编辑状态。编辑如下内容:

export JAVA_HOME=/usr/local/hudk/JDK/jdk1.8.0_111
export PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME PATH

  分别按键盘Esc > (Shift+:) > w >q >Enter 保存并推出编辑模式。执行以下命令使 jdk.sh 文件生效。

$ source /etc/profile.d/jdk.sh

  JDK 环境变量的多种配置形式请参考 《CentOS 安装 JDK 三种形式详细总结》。

三、安装 MySQL

  安装过程可参考:《Docker 方式部署 Solo 博客系统总结》中对 MySQL 的安装介绍。安装完成后,新建用户和数据库实例,在后面部署 Solo 到 Tomcat 中时,配置文件时会用到。这个假设用户名和密码全是 mj ,数据库实例名为 solo

四、安装 Tomcat 和配置 80 端口

1、解压缩

  切换到 /usr/local/hudk/ 目录下,解压 apache-tomcat-9.0.22-deployer.tar.gz 包。执行命令:

$ tar -zxvf apache-tomcat-9.0.22-deployer.tar.gz

2、配置 server.xml

  进入 tomcat 文件目录 /usr/local/hudk/apache-tomcat-9.0.22/conf,找到文件 server.xml 并编辑它

$ vim  ./server.xml

  将其中内容:

 <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

  修改为:

 <Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

五、部署 Solo 到 Tomcat 并启动初始化

1、解压缩

  首先将 /usr/local/hudk/apache-tomcat-9.0.22/webapps/ROOT/ 目录清空;再将 /usr/local/hudk/solo-v3.6.3.war 文件解压到 /usr/local/hudk/apache-tomcat-9.0.22/webapps/ROOT/ 中。

2、修改配置文件

  要想正常访问 Solo,启动 Tomcat 前需要配置两个文件,分别是 latke.propertieslocal.properties

  先说 latke.properties,这个文件主要配置 Solo 的访问域名端口和模式。其中域名和端口,要保持和你将要在浏览器中访问的内容一致,比如你的 serverHost 值是 www.mjhdk.cn,那么以后只能使用 www.mjhdk.cn 域名才可以正常访问 Solo,如果使用 IP 地址访问的话,静态文件 js 和 css 等访问会出现问题,导致页面无法渲染。

#
# Solo - A small and beautiful blogging system written in Java.
# Copyright (c) 2010-present, b3log.org
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#

#
# Description: B3log Latke configurations.
# Version: 1.6.0.2, Mar 19, 2019
# Author: Liang Ding
#

#### Server ####
# Browser visit protocol
serverScheme=http
serverHost=www.mjhdk.cn
serverPort=80

#### Runtime Mode ####
#runtimeMode=DEVELOPMENT
runtimeMode=PRODUCTION

  local.properties 文件中主要涉及数据库的配置。

#
# Solo - A small and beautiful blogging system written in Java.
# Copyright (c) 2010-present, b3log.org
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#

#
# Description: Solo local environment configurations.
# Version: 1.1.3.15, Mar 17, 2019
# Author: Liang Ding
#

#### MySQL runtime ####
runtimeDatabase=MYSQL
jdbc.username=***
jdbc.password=******
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.URL=jdbc:mysql://0.0.0.0:3306/solo?useUnicode=yes&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC

#### H2 runtime ####
#runtimeDatabase=H2
#jdbc.username=root
#jdbc.password=
#jdbc.driver=org.h2.Driver
#jdbc.URL=jdbc:h2:~/solo_h2/db;MODE=MYSQL

# The minConnCnt MUST larger or equal to 3
jdbc.minConnCnt=5
jdbc.maxConnCnt=10

# The specific table name prefix
jdbc.tablePrefix=b3_solo

  最后配置完这两个文件,就可以尝试启动 Tomcat 了。进入 /usr/local/hudk/apache-tomcat-9.0.22/bin 目录,执行命令 ./startup.sh 启动 Tomcat。如果启动正常,访问主页时,会进行自动的数据库初始化过程,即帮你建表和加入初始数据。初始化完成后使用自己的 GitHub 账户可以登录主页,开启博客之旅。

  另有 Docker 部署方式,也是官方推荐的部署方式。请参考文章《Docker 方式部署 Solo 博客系统总结

  • Solo

    Solo 是一款小而美的开源博客系统,专为程序员设计。Solo 有着非常活跃的社区,可将文章作为帖子推送到社区,来自社区的回帖将作为博客评论进行联动(具体细节请浏览 B3log 构思 - 分布式社区网络)。

    这是一种全新的网络社区体验,让热爱记录和分享的你不再感到孤单!

    1424 引用 • 10041 回帖 • 469 关注
  • CentOS

    CentOS(Community Enterprise Operating System)是 Linux 发行版之一,它是来自于 Red Hat Enterprise Linux 依照开放源代码规定释出的源代码所编译而成。由于出自同样的源代码,因此有些要求高度稳定的服务器以 CentOS 替代商业版的 Red Hat Enterprise Linux 使用。两者的不同在于 CentOS 并不包含封闭源代码软件。

    238 引用 • 224 回帖 • 1 关注
  • 博客

    记录并分享人生的经历。

    270 引用 • 2386 回帖
  • MySQL

    MySQL 是一个关系型数据库管理系统,由瑞典 MySQL AB 公司开发,目前属于 Oracle 公司。MySQL 是最流行的关系型数据库管理系统之一。

    673 引用 • 535 回帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...
  • 感谢分享 🎉
    PS 个人建议用 Docker 来部署 Solo,这样方便后期升级。